diff options
Diffstat (limited to 'modules/gdnative/videodecoder')
-rw-r--r-- | modules/gdnative/videodecoder/register_types.cpp | 2 | ||||
-rw-r--r-- | modules/gdnative/videodecoder/video_stream_gdnative.cpp | 43 | ||||
-rw-r--r-- | modules/gdnative/videodecoder/video_stream_gdnative.h | 47 |
3 files changed, 35 insertions, 57 deletions
diff --git a/modules/gdnative/videodecoder/register_types.cpp b/modules/gdnative/videodecoder/register_types.cpp index c53e8f2c78..4181d8813f 100644 --- a/modules/gdnative/videodecoder/register_types.cpp +++ b/modules/gdnative/videodecoder/register_types.cpp @@ -36,7 +36,6 @@ static Ref<ResourceFormatLoaderVideoStreamGDNative> resource_loader_vsgdnative; void register_videodecoder_types() { - resource_loader_vsgdnative.instance(); ResourceLoader::add_resource_format_loader(resource_loader_vsgdnative, true); @@ -44,7 +43,6 @@ void register_videodecoder_types() { } void unregister_videodecoder_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_vsgdnative); resource_loader_vsgdnative.unref(); } diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index f7d87595af..9d9c5b6473 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -105,7 +105,6 @@ int64_t GDAPI godot_videodecoder_file_seek(void *ptr, int64_t pos, int whence) { } void GDAPI godot_videodecoder_register_decoder(const godot_videodecoder_interface_gdnative *p_interface) { - decoder_server.register_decoder_interface(p_interface); } } @@ -202,32 +201,19 @@ void VideoStreamPlaybackGDNative::update_texture() { // ctor and dtor VideoStreamPlaybackGDNative::VideoStreamPlaybackGDNative() : - texture(Ref<ImageTexture>(memnew(ImageTexture))), - playing(false), - paused(false), - mix_udata(nullptr), - mix_callback(nullptr), - num_channels(-1), - time(0), - seek_backward(false), - mix_rate(0), - delay_compensation(0), - pcm(nullptr), - pcm_write_idx(0), - samples_decoded(0), - file(nullptr), - interface(nullptr), - data_struct(nullptr) {} + texture(Ref<ImageTexture>(memnew(ImageTexture))) {} VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() { cleanup(); } void VideoStreamPlaybackGDNative::cleanup() { - if (data_struct) + if (data_struct) { interface->destructor(data_struct); - if (pcm) + } + if (pcm) { memfree(pcm); + } pcm = nullptr; time = 0; num_channels = -1; @@ -255,7 +241,6 @@ bool VideoStreamPlaybackGDNative::is_paused() const { } void VideoStreamPlaybackGDNative::play() { - stop(); playing = true; @@ -274,8 +259,9 @@ void VideoStreamPlaybackGDNative::stop() { void VideoStreamPlaybackGDNative::seek(float p_time) { ERR_FAIL_COND(interface == nullptr); interface->seek(data_struct, p_time); - if (p_time < time) + if (p_time < time) { seek_backward = true; + } time = p_time; // reset audio buffers memset(pcm, 0, num_channels * AUX_BUFFER_SIZE * sizeof(float)); @@ -297,7 +283,6 @@ float VideoStreamPlaybackGDNative::get_length() const { } float VideoStreamPlaybackGDNative::get_playback_position() const { - ERR_FAIL_COND_V(interface == nullptr, 0); return interface->get_playback_position(data_struct); } @@ -317,7 +302,6 @@ void VideoStreamPlaybackGDNative::set_audio_track(int p_idx) { } void VideoStreamPlaybackGDNative::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) { - mix_udata = p_userdata; mix_callback = p_callback; } @@ -339,27 +323,26 @@ int VideoStreamPlaybackGDNative::get_mix_rate() const { Ref<VideoStreamPlayback> VideoStreamGDNative::instance_playback() { Ref<VideoStreamPlaybackGDNative> pb = memnew(VideoStreamPlaybackGDNative); VideoDecoderGDNative *decoder = decoder_server.get_decoder(file.get_extension().to_lower()); - if (decoder == nullptr) + if (decoder == nullptr) { return nullptr; + } pb->set_interface(decoder->interface); pb->set_audio_track(audio_track); - if (pb->open_file(file)) + if (pb->open_file(file)) { return pb; + } return nullptr; } void VideoStreamGDNative::set_file(const String &p_file) { - file = p_file; } String VideoStreamGDNative::get_file() { - return file; } void VideoStreamGDNative::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamGDNative::set_file); ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamGDNative::get_file); @@ -367,7 +350,6 @@ void VideoStreamGDNative::_bind_methods() { } void VideoStreamGDNative::set_audio_track(int p_track) { - audio_track = p_track; } @@ -405,7 +387,8 @@ bool ResourceFormatLoaderVideoStreamGDNative::handles_type(const String &p_type) String ResourceFormatLoaderVideoStreamGDNative::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (VideoDecoderServer::get_instance()->get_extensions().has(el)) + if (VideoDecoderServer::get_instance()->get_extensions().has(el)) { return "VideoStreamGDNative"; + } return ""; } diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h index 092e10a0f5..53017a6a97 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.h +++ b/modules/gdnative/videodecoder/video_stream_gdnative.h @@ -37,13 +37,11 @@ #include "scene/resources/video_stream.h" struct VideoDecoderGDNative { - const godot_videodecoder_interface_gdnative *interface; - String plugin_name; + const godot_videodecoder_interface_gdnative *interface = nullptr; + String plugin_name = "none"; Vector<String> supported_extensions; - VideoDecoderGDNative() : - interface(nullptr), - plugin_name("none") {} + VideoDecoderGDNative() {} VideoDecoderGDNative(const godot_videodecoder_interface_gdnative *p_interface) : interface(p_interface), @@ -88,8 +86,9 @@ public: } VideoDecoderGDNative *get_decoder(const String &extension) { - if (extensions.size() == 0 || !extensions.has(extension)) + if (extensions.size() == 0 || !extensions.has(extension)) { return nullptr; + } return decoders[extensions[extension]]; } @@ -107,27 +106,26 @@ public: }; class VideoStreamPlaybackGDNative : public VideoStreamPlayback { - GDCLASS(VideoStreamPlaybackGDNative, VideoStreamPlayback); Ref<ImageTexture> texture; - bool playing; - bool paused; + bool playing = false; + bool paused = false; Vector2 texture_size; - void *mix_udata; - AudioMixCallback mix_callback; + void *mix_udata = nullptr; + AudioMixCallback mix_callback = nullptr; - int num_channels; - float time; - bool seek_backward; - int mix_rate; - double delay_compensation; + int num_channels = -1; + float time = 0; + bool seek_backward = false; + int mix_rate = 0; + double delay_compensation = 0; - float *pcm; - int pcm_write_idx; - int samples_decoded; + float *pcm = nullptr; + int pcm_write_idx = 0; + int samples_decoded = 0; void cleanup(); void update_texture(); @@ -135,10 +133,10 @@ class VideoStreamPlaybackGDNative : public VideoStreamPlayback { protected: String file_name; - FileAccess *file; + FileAccess *file = nullptr; - const godot_videodecoder_interface_gdnative *interface; - void *data_struct; + const godot_videodecoder_interface_gdnative *interface = nullptr; + void *data_struct = nullptr; public: VideoStreamPlaybackGDNative(); @@ -177,11 +175,10 @@ public: }; class VideoStreamGDNative : public VideoStream { - GDCLASS(VideoStreamGDNative, VideoStream); String file; - int audio_track; + int audio_track = 0; protected: static void @@ -194,7 +191,7 @@ public: virtual void set_audio_track(int p_track); virtual Ref<VideoStreamPlayback> instance_playback(); - VideoStreamGDNative() { audio_track = 0; } + VideoStreamGDNative() {} }; class ResourceFormatLoaderVideoStreamGDNative : public ResourceFormatLoader { |