Skip to content

Commit

Permalink
Add looping, add license, update headers
Browse files Browse the repository at this point in the history
  • Loading branch information
EIREXE committed Jul 27, 2023
1 parent 6fb3808 commit 6664560
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 55 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Álex Román (EIRTeam)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 0 additions & 1 deletion SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ else:
env.Append(LIBS=ffmpeg_libs)

ffmpeg_install_action = ffmpeg_download.ffmpeg_install(env_ffmpeg, "#bin", "thirdparty/ffmpeg")
env_ffmpeg.Depends(ffmpeg_install_action, ffmpeg_download_action)
env_ffmpeg.Depends(sources, ffmpeg_install_action)

# env_ffmpeg.Append(CPPDEFINES=["FFMPEG_MT_GPU_UPLOAD"])
Expand Down
33 changes: 31 additions & 2 deletions et_video_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* et_video_stream.cpp */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down Expand Up @@ -74,16 +74,22 @@ const char *const upd_str = "update_internal";

void ETVideoStreamPlayback::update_internal(double p_delta) {
ZoneScopedN("update_internal");

if (paused || !playing) {
return;
}

playback_position += p_delta * 1000.0f;

if (decoder->get_decoder_state() == VideoDecoder::DecoderState::END_OF_STREAM && available_frames.size() == 0) {
// if at the end of the stream but our playback enters a valid time region again, a seek operation is required to get the decoder back on track.
if (playback_position < decoder->get_last_decoded_frame_time()) {
seek_into_sync();
}
} else if (decoder->get_decoder_state() == VideoDecoder::DecoderState::END_OF_STREAM) {
playing = false;
print_line("ABORTING PLAYBACK");
return;
}

Ref<DecodedFrame> peek_frame = available_frames.size() > 0 ? available_frames[0] : nullptr;
Expand Down Expand Up @@ -141,6 +147,26 @@ void ETVideoStreamPlayback::update_internal(double p_delta) {
}
}

Ref<DecodedAudioFrame> peek_audio_frame;
if (available_audio_frames.size() > 0) {
peek_audio_frame = available_audio_frames[0];
}

bool audio_out_of_sync = false;

if (peek_audio_frame.is_valid()) {
audio_out_of_sync = Math::abs(playback_position - peek_audio_frame->get_time()) > LENIENCE_BEFORE_SEEK;

if (looping) {
out_of_sync &= Math::abs(playback_position - decoder->get_duration() - peek_audio_frame->get_time()) > LENIENCE_BEFORE_SEEK &&
Math::abs(playback_position + decoder->get_duration() - peek_audio_frame->get_time()) > LENIENCE_BEFORE_SEEK;
}
}

if (audio_out_of_sync) {
// TODO: seek audio stream individually if it desyncs
}

while (available_audio_frames.size() > 0 && check_next_audio_frame_valid(available_audio_frames[0])) {
ZoneScopedN("Audio mix");
Ref<DecodedAudioFrame> audio_frame = available_audio_frames[0];
Expand Down Expand Up @@ -193,7 +219,9 @@ void ETVideoStreamPlayback::set_paused_internal(bool p_paused) {

void ETVideoStreamPlayback::play_internal() {
if (!playing) {
clear();
playback_position = 0;
decoder->seek(0, true);
} else {
stop_internal();
}
Expand All @@ -203,7 +231,8 @@ void ETVideoStreamPlayback::play_internal() {
void ETVideoStreamPlayback::stop_internal() {
if (playing) {
clear();
seek_internal(0);
playback_position = 0.0f;
decoder->seek(playback_position, true);
}
playing = false;
}
Expand Down
21 changes: 2 additions & 19 deletions et_video_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* et_video_stream.h */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down Expand Up @@ -54,24 +54,7 @@ using namespace godot;
// We have to use this function redirection system for GDExtension because the naming conventions
// for the functions we are supposed to override are different there

#ifdef GDEXTENSION
#define STREAM_FUNCNAME(funcname) _##funcname
#else
#define STREAM_FUNCNAME(funcname) funcname
#endif

#define STREAM_FUNC_REDIRECT_0_(retval, funcname, const) \
virtual retval STREAM_FUNCNAME(funcname)() const override { return funcname##_internal(); };

#define STREAM_FUNC_REDIRECT_1_(retval, funcname, const, arg0type, arg0name) \
virtual retval STREAM_FUNCNAME(funcname)(arg0type arg0name) const override { return funcname##_internal(arg0name); };

#define STREAM_FUNC_REDIRECT_0(retval, funcname) STREAM_FUNC_REDIRECT_0_(retval, funcname, );
#define STREAM_FUNC_REDIRECT_0_CONST(retval, funcname) STREAM_FUNC_REDIRECT_0_(retval, funcname, const);

#define STREAM_FUNC_REDIRECT_1(retval, funcname, arg0type, arg0name) STREAM_FUNC_REDIRECT_1_(retval, funcname, , arg0type, arg0name);
#define STREAM_FUNC_REDIRECT_1_CONST(retval, funcname, arg0type, arg0name) STREAM_FUNC_REDIRECT_1_(retval, funcname, const, arg0type, arg0name);

#include "gdextension_build/func_redirect.h"
class ETVideoStreamPlayback : public VideoStreamPlayback {
GDCLASS(ETVideoStreamPlayback, VideoStreamPlayback);
const int LENIENCE_BEFORE_SEEK = 2500;
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* ffmpeg_codec.cpp */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* ffmpeg_codec.h */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* ffmpeg_frame.cpp */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* ffmpeg_frame.h */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.Steamworks */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
Expand Down
1 change: 0 additions & 1 deletion gdextension_build/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ else:
FFMPEG_DUMMY = "../thirdparty/ffmpeg/LICENSE.txt"
ffmpeg_download_action = ffmpeg_download.ffmpeg_download_builder(env, FFMPEG_DUMMY, "ffmpeg_download.py")
ffmpeg_install_action = ffmpeg_download.ffmpeg_install(env, f"#{addon_dir}", "../thirdparty/ffmpeg")
env.Depends(ffmpeg_install_action, ffmpeg_download_action)
env.Depends(sources, env.Install(addon_dir, "ffmpeg.gdextension"))
env.Depends(sources, ffmpeg_install_action)

Expand Down
8 changes: 4 additions & 4 deletions gdextension_build/command_queue_mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/* command_queue_mt.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
/* */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
Expand Down
8 changes: 4 additions & 4 deletions gdextension_build/command_queue_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/* command_queue_mt.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
/* */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
Expand Down
12 changes: 11 additions & 1 deletion gdextension_build/ffmpeg.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ compatibility_minimum = 4.1
[libraries]
windows.debug.x86_64 = "res://addons/ffmpeg/libgdffmpeg.windows.template_debug.x86_64.dll"
windows.release.x86_64 = "res://addons/ffmpeg/libgdffmpeg.windows.template_release.x86_64.dll"
linux.debug.x86_64 = "res://addons/ffmpeg/libgdffmpeg.linux.template_debug.x86_64.so"
linux.release.x86_64 = "res://addons/ffmpeg/libgdffmpeg.linux.template_release.x86_64.so"

[dependencies]

Expand All @@ -15,4 +17,12 @@ windows.x86_64 =
"res://addons/ffmpeg/avformat-60.dll": "",
"res://addons/ffmpeg/avutil-58.dll": "",
"res://addons/ffmpeg/swresample-4.dll": "",
"res://addons/ffmpeg/swscale-7.dll": ""}
"res://addons/ffmpeg/swscale-7.dll": ""}

linux.x86_64 =
{"res://addons/ffmpeg/libavcodec.so.60": "",
"res://addons/ffmpeg/libavfilter.so.9": "",
"res://addons/ffmpeg/libavformat.so.60": "",
"res://addons/ffmpeg/libavutil.so.58": "",
"res://addons/ffmpeg/libswresample.so.4": "",
"res://addons/ffmpeg/libswscale.so.7": ""}
7 changes: 5 additions & 2 deletions gdextension_build/ffmpeg_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ def rewrite_subfolder_paths(tf, common_path):
def _ffmpeg_emitter(target, source, env):
target += get_ffmpeg_install_sources(env, os.path.dirname(target[0].get_path()))
if env["platform"] == "windows":
pass
else:
target += [
os.path.join(os.path.dirname(target[0].get_path()), f"lib/{lib}.lib")
for lib, version in ffmpeg_versions.items()
]
else:
target += [
os.path.join(os.path.dirname(target[0].get_path()), f"lib/lib{lib}.so")
for lib, version in ffmpeg_versions.items()
]

emitter_headers = [
"libavcodec/codec.h",
Expand Down
52 changes: 52 additions & 0 deletions gdextension_build/func_redirect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************/
/* func_redirect.h */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
/* */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef FUNC_REDIRECT_H
#define FUNC_REDIRECT_H

#ifdef GDEXTENSION
#define STREAM_FUNCNAME(funcname) _##funcname
#else
#define STREAM_FUNCNAME(funcname) funcname
#endif

#define STREAM_FUNC_REDIRECT_0_(retval, funcname, const) \
virtual retval STREAM_FUNCNAME(funcname)() const override { return funcname##_internal(); };

#define STREAM_FUNC_REDIRECT_1_(retval, funcname, const, arg0type, arg0name) \
virtual retval STREAM_FUNCNAME(funcname)(arg0type arg0name) const override { return funcname##_internal(arg0name); };

#define STREAM_FUNC_REDIRECT_0(retval, funcname) STREAM_FUNC_REDIRECT_0_(retval, funcname, );
#define STREAM_FUNC_REDIRECT_0_CONST(retval, funcname) STREAM_FUNC_REDIRECT_0_(retval, funcname, const);

#define STREAM_FUNC_REDIRECT_1(retval, funcname, arg0type, arg0name) STREAM_FUNC_REDIRECT_1_(retval, funcname, , arg0type, arg0name);
#define STREAM_FUNC_REDIRECT_1_CONST(retval, funcname, arg0type, arg0name) STREAM_FUNC_REDIRECT_1_(retval, funcname, const, arg0type, arg0name);

#endif // FUNC_REDIRECT_H
30 changes: 30 additions & 0 deletions gdextension_build/gdex_print.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/**************************************************************************/
/* gdex_print.h */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
/* */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GDEX_PRINT_H
#define GDEX_PRINT_H
#ifdef GDEXTENSION
Expand Down
Loading

0 comments on commit 6664560

Please sign in to comment.