Skip to content

Commit

Permalink
Change class names to maintain API compatibility with kidrigger's god…
Browse files Browse the repository at this point in the history
…ot-videodecoder
  • Loading branch information
rsubtil committed Apr 7, 2024
1 parent 233e67e commit 6e68693
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
38 changes: 19 additions & 19 deletions ffmpeg_video_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "tracy_import.h"

void FFmpegVideoStreamPlayback::seek_into_sync() {
void VideoStreamPlaybackFFMPEG::seek_into_sync() {
decoder->seek(playback_position);
Vector<Ref<DecodedFrame>> decoded_frames;
for (Ref<DecodedFrame> df : available_frames) {
Expand All @@ -47,22 +47,22 @@ void FFmpegVideoStreamPlayback::seek_into_sync() {
available_audio_frames.clear();
}

double FFmpegVideoStreamPlayback::get_current_frame_time() {
double VideoStreamPlaybackFFMPEG::get_current_frame_time() {
if (last_frame.is_valid()) {
return last_frame->get_time();
}
return 0.0f;
}

bool FFmpegVideoStreamPlayback::check_next_frame_valid(Ref<DecodedFrame> p_decoded_frame) {
bool VideoStreamPlaybackFFMPEG::check_next_frame_valid(Ref<DecodedFrame> p_decoded_frame) {
// in the case of looping, we may start a seek back to the beginning but still receive some lingering frames from the end of the last loop. these should be allowed to continue playing.
if (looping && Math::abs((p_decoded_frame->get_time() - decoder->get_duration()) - playback_position) < LENIENCE_BEFORE_SEEK)
return true;

return p_decoded_frame->get_time() <= playback_position && Math::abs(p_decoded_frame->get_time() - playback_position) < LENIENCE_BEFORE_SEEK;
}

bool FFmpegVideoStreamPlayback::check_next_audio_frame_valid(Ref<DecodedAudioFrame> p_decoded_frame) {
bool VideoStreamPlaybackFFMPEG::check_next_audio_frame_valid(Ref<DecodedAudioFrame> p_decoded_frame) {
// in the case of looping, we may start a seek back to the beginning but still receive some lingering frames from the end of the last loop. these should be allowed to continue playing.
if (looping && Math::abs((p_decoded_frame->get_time() - decoder->get_duration()) - playback_position) < LENIENCE_BEFORE_SEEK)
return true;
Expand All @@ -72,7 +72,7 @@ bool FFmpegVideoStreamPlayback::check_next_audio_frame_valid(Ref<DecodedAudioFra

const char *const upd_str = "update_internal";

void FFmpegVideoStreamPlayback::update_internal(double p_delta) {
void VideoStreamPlaybackFFMPEG::update_internal(double p_delta) {
ZoneScopedN("update_internal");

if (paused || !playing) {
Expand Down Expand Up @@ -189,7 +189,7 @@ void FFmpegVideoStreamPlayback::update_internal(double p_delta) {
}
}

Error FFmpegVideoStreamPlayback::load(Ref<FileAccess> p_file_access) {
Error VideoStreamPlaybackFFMPEG::load(Ref<FileAccess> p_file_access) {
decoder = Ref<VideoDecoder>(memnew(VideoDecoder(p_file_access)));

decoder->start_decoding();
Expand All @@ -206,19 +206,19 @@ Error FFmpegVideoStreamPlayback::load(Ref<FileAccess> p_file_access) {
return OK;
}

bool FFmpegVideoStreamPlayback::is_paused_internal() const {
bool VideoStreamPlaybackFFMPEG::is_paused_internal() const {
return paused;
}

bool FFmpegVideoStreamPlayback::is_playing_internal() const {
bool VideoStreamPlaybackFFMPEG::is_playing_internal() const {
return playing;
}

void FFmpegVideoStreamPlayback::set_paused_internal(bool p_paused) {
void VideoStreamPlaybackFFMPEG::set_paused_internal(bool p_paused) {
paused = p_paused;
}

void FFmpegVideoStreamPlayback::play_internal() {
void VideoStreamPlaybackFFMPEG::play_internal() {
if (decoder->get_decoder_state() == VideoDecoder::FAULTED) {
playing = false;
return;
Expand All @@ -229,7 +229,7 @@ void FFmpegVideoStreamPlayback::play_internal() {
playing = true;
}

void FFmpegVideoStreamPlayback::stop_internal() {
void VideoStreamPlaybackFFMPEG::stop_internal() {
if (playing) {
clear();
playback_position = 0.0f;
Expand All @@ -238,41 +238,41 @@ void FFmpegVideoStreamPlayback::stop_internal() {
playing = false;
}

void FFmpegVideoStreamPlayback::seek_internal(double p_time) {
void VideoStreamPlaybackFFMPEG::seek_internal(double p_time) {
decoder->seek(p_time * 1000.0f);
available_frames.clear();
available_audio_frames.clear();
playback_position = p_time * 1000.0f;
}

double FFmpegVideoStreamPlayback::get_length_internal() const {
double VideoStreamPlaybackFFMPEG::get_length_internal() const {
return decoder->get_duration() / 1000.0f;
}

Ref<Texture2D> FFmpegVideoStreamPlayback::get_texture_internal() const {
Ref<Texture2D> VideoStreamPlaybackFFMPEG::get_texture_internal() const {
#ifdef FFMPEG_MT_GPU_UPLOAD
return last_frame_texture;
#else
return texture;
#endif
}

double FFmpegVideoStreamPlayback::get_playback_position_internal() const {
double VideoStreamPlaybackFFMPEG::get_playback_position_internal() const {
return playback_position / 1000.0;
}

int FFmpegVideoStreamPlayback::get_mix_rate_internal() const {
int VideoStreamPlaybackFFMPEG::get_mix_rate_internal() const {
return decoder->get_audio_mix_rate();
}

int FFmpegVideoStreamPlayback::get_channels_internal() const {
int VideoStreamPlaybackFFMPEG::get_channels_internal() const {
return decoder->get_audio_channel_count();
}

FFmpegVideoStreamPlayback::FFmpegVideoStreamPlayback() {
VideoStreamPlaybackFFMPEG::VideoStreamPlaybackFFMPEG() {
}

void FFmpegVideoStreamPlayback::clear() {
void VideoStreamPlaybackFFMPEG::clear() {
last_frame.unref();
last_frame_texture.unref();
available_frames.clear();
Expand Down
12 changes: 6 additions & 6 deletions ffmpeg_video_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ using namespace godot;
// for the functions we are supposed to override are different there

#include "gdextension_build/func_redirect.h"
class FFmpegVideoStreamPlayback : public VideoStreamPlayback {
GDCLASS(FFmpegVideoStreamPlayback, VideoStreamPlayback);
class VideoStreamPlaybackFFMPEG : public VideoStreamPlayback {
GDCLASS(VideoStreamPlaybackFFMPEG, VideoStreamPlayback);
const int LENIENCE_BEFORE_SEEK = 2500;
double playback_position = 0.0f;

Expand Down Expand Up @@ -112,11 +112,11 @@ class FFmpegVideoStreamPlayback : public VideoStreamPlayback {
STREAM_FUNC_REDIRECT_0_CONST(double, get_playback_position);
STREAM_FUNC_REDIRECT_0_CONST(int, get_mix_rate);
STREAM_FUNC_REDIRECT_0_CONST(int, get_channels);
FFmpegVideoStreamPlayback();
VideoStreamPlaybackFFMPEG();
};

class FFmpegVideoStream : public VideoStream {
GDCLASS(FFmpegVideoStream, VideoStream);
class VideoStreamFFMPEG : public VideoStream {
GDCLASS(VideoStreamFFMPEG, VideoStream);

protected:
static void _bind_methods(){}; // Required by GDExtension, do not remove
Expand All @@ -125,7 +125,7 @@ class FFmpegVideoStream : public VideoStream {
if (!fa.is_valid()) {
return Ref<VideoStreamPlayback>();
}
Ref<FFmpegVideoStreamPlayback> pb;
Ref<VideoStreamPlaybackFFMPEG> pb;
pb.instantiate();
if (pb->load(fa) != OK) {
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "ffmpeg_video_stream.h"
#include "video_stream_ffmpeg_loader.h"

Ref<VideoStreamFFMpegLoader> ffmpeg_loader;
Ref<VideoStreamFFMPEGLoader> ffmpeg_loader;

static void print_codecs() {
const AVCodecDescriptor *desc = NULL;
Expand Down Expand Up @@ -74,9 +74,9 @@ void initialize_ffmpeg_module(ModuleInitializationLevel p_level) {
return;
}
print_codecs();
GDREGISTER_ABSTRACT_CLASS(FFmpegVideoStreamPlayback);
GDREGISTER_ABSTRACT_CLASS(VideoStreamFFMpegLoader);
GDREGISTER_CLASS(FFmpegVideoStream);
GDREGISTER_ABSTRACT_CLASS(VideoStreamPlaybackFFMPEG);
GDREGISTER_ABSTRACT_CLASS(VideoStreamFFMPEGLoader);
GDREGISTER_CLASS(VideoStreamFFMPEG);
ffmpeg_loader.instantiate();
#ifdef GDEXTENSION
ResourceLoader::get_singleton()->add_resource_format_loader(ffmpeg_loader);
Expand Down
28 changes: 14 additions & 14 deletions video_stream_ffmpeg_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
}
#include "ffmpeg_video_stream.h"

void VideoStreamFFMpegLoader::_update_recognized_extension_cache() const {
void VideoStreamFFMPEGLoader::_update_recognized_extension_cache() const {
if (recognized_extension_cache.size() > 0) {
return;
}
Expand All @@ -46,19 +46,19 @@ void VideoStreamFFMpegLoader::_update_recognized_extension_cache() const {
continue;
}
PackedStringArray demuxer_exts = String(current_fmt->extensions).split(",", false);
const_cast<VideoStreamFFMpegLoader *>(this)->recognized_extension_cache.append_array(demuxer_exts);
const_cast<VideoStreamFFMPEGLoader *>(this)->recognized_extension_cache.append_array(demuxer_exts);
}
}

String VideoStreamFFMpegLoader::get_resource_type_internal(const String &p_path) const {
String VideoStreamFFMPEGLoader::get_resource_type_internal(const String &p_path) const {
_update_recognized_extension_cache();
if (recognized_extension_cache.has(p_path.get_extension())) {
return "VideoStreamFFMpegLoader";
return "VideoStreamFFMPEGLoader";
}
return "";
}

Ref<Resource> VideoStreamFFMpegLoader::load_internal(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) const {
Ref<Resource> VideoStreamFFMPEGLoader::load_internal(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) const {
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
if (f.is_null()) {
if (r_error) {
Expand All @@ -67,7 +67,7 @@ Ref<Resource> VideoStreamFFMpegLoader::load_internal(const String &p_path, const
return Ref<Resource>();
}

Ref<FFmpegVideoStream> stream;
Ref<VideoStreamFFMPEG> stream;
stream.instantiate();
stream->set_file(p_path);

Expand All @@ -77,36 +77,36 @@ Ref<Resource> VideoStreamFFMpegLoader::load_internal(const String &p_path, const

return stream;
}
bool VideoStreamFFMpegLoader::handles_type_internal(const String &p_type) const {
bool VideoStreamFFMPEGLoader::handles_type_internal(const String &p_type) const {
#ifdef GDEXTENSION
return p_type == "VideoStream";
#else
return ClassDB::is_parent_class(p_type, "VideoStreamFFMpegLoader");
return ClassDB::is_parent_class(p_type, "VideoStreamFFMPEGLoader");
#endif
}

#ifdef GDEXTENSION
PackedStringArray VideoStreamFFMpegLoader::_get_recognized_extensions() const {
PackedStringArray VideoStreamFFMPEGLoader::_get_recognized_extensions() const {
_update_recognized_extension_cache();
return recognized_extension_cache;
}

bool VideoStreamFFMpegLoader::_handles_type(const StringName &p_type) const {
return VideoStreamFFMpegLoader::handles_type_internal(p_type);
bool VideoStreamFFMPEGLoader::_handles_type(const StringName &p_type) const {
return VideoStreamFFMPEGLoader::handles_type_internal(p_type);
}

Variant VideoStreamFFMpegLoader::_load(const String &p_path, const String &p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) const {
Variant VideoStreamFFMPEGLoader::_load(const String &p_path, const String &p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) const {
return load_internal(p_path, p_original_path, nullptr, p_use_sub_threads, nullptr, (CacheMode)p_cache_mode);
}

#else
void VideoStreamFFMpegLoader::get_recognized_extensions(List<String> *p_extensions) const {
void VideoStreamFFMPEGLoader::get_recognized_extensions(List<String> *p_extensions) const {
_update_recognized_extension_cache();
for (String ext : recognized_extension_cache) {
p_extensions->push_back(ext);
}
}
Ref<Resource> VideoStreamFFMpegLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
Ref<Resource> VideoStreamFFMPEGLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
return load_internal(p_path, p_original_path, r_error, p_use_sub_threads, r_progress, p_cache_mode);
}
#endif
4 changes: 2 additions & 2 deletions video_stream_ffmpeg_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ using namespace godot;

#include "gdextension_build/func_redirect.h"

class VideoStreamFFMpegLoader : public ResourceFormatLoader {
GDCLASS(VideoStreamFFMpegLoader, ResourceFormatLoader);
class VideoStreamFFMPEGLoader : public ResourceFormatLoader {
GDCLASS(VideoStreamFFMPEGLoader, ResourceFormatLoader);
PackedStringArray recognized_extension_cache;

private:
Expand Down

0 comments on commit 6e68693

Please sign in to comment.