diff options
Diffstat (limited to 'modules/theora')
-rw-r--r-- | modules/theora/SCsub | 16 | ||||
-rw-r--r-- | modules/theora/config.py | 2 | ||||
-rw-r--r-- | modules/theora/doc_classes/VideoStreamTheora.xml | 5 | ||||
-rw-r--r-- | modules/theora/register_types.cpp | 6 | ||||
-rw-r--r-- | modules/theora/register_types.h | 4 | ||||
-rw-r--r-- | modules/theora/video_stream_theora.cpp | 91 | ||||
-rw-r--r-- | modules/theora/video_stream_theora.h | 46 |
7 files changed, 74 insertions, 96 deletions
diff --git a/modules/theora/SCsub b/modules/theora/SCsub index a01e65b4b0..6038ea086a 100644 --- a/modules/theora/SCsub +++ b/modules/theora/SCsub @@ -6,6 +6,9 @@ Import("env_modules") env_theora = env_modules.Clone() # Thirdparty source files + +thirdparty_obj = [] + if env["builtin_libtheora"]: thirdparty_dir = "#thirdparty/libtheora/" thirdparty_sources = [ @@ -80,7 +83,16 @@ if env["builtin_libtheora"]: env_thirdparty = env_theora.Clone() env_thirdparty.disable_warnings() - env_thirdparty.add_source_files(env.modules_sources, thirdparty_sources) + env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) + env.modules_sources += thirdparty_obj + # Godot source files -env_theora.add_source_files(env.modules_sources, "*.cpp") + +module_obj = [] + +env_theora.add_source_files(module_obj, "*.cpp") +env.modules_sources += module_obj + +# Needed to force rebuilding the module files when the thirdparty library is updated. +env.Depends(module_obj, thirdparty_obj) diff --git a/modules/theora/config.py b/modules/theora/config.py index 413acce2df..b063ed51f9 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return env.module_check_dependencies("theora", ["ogg", "vorbis"]) def configure(env): diff --git a/modules/theora/doc_classes/VideoStreamTheora.xml b/modules/theora/doc_classes/VideoStreamTheora.xml index 92244a4d28..cb8852d5ef 100644 --- a/modules/theora/doc_classes/VideoStreamTheora.xml +++ b/modules/theora/doc_classes/VideoStreamTheora.xml @@ -4,7 +4,8 @@ [VideoStream] resource for Ogg Theora videos. </brief_description> <description> - [VideoStream] resource handling the [url=https://www.theora.org/]Ogg Theora[/url] video format with [code].ogv[/code] extension. + [VideoStream] resource handling the [url=https://www.theora.org/]Ogg Theora[/url] video format with [code].ogv[/code] extension. The Theora codec is less efficient than [VideoStreamWebm]'s VP8 and VP9, but it requires less CPU resources to decode. The Theora codec is decoded on the CPU. + [b]Note:[/b] While Ogg Theora videos can also have an [code].ogg[/code] extension, you will have to rename the extension to [code].ogv[/code] to use those videos within Godot. </description> <tutorials> </tutorials> @@ -22,7 +23,7 @@ <argument index="0" name="file" type="String"> </argument> <description> - Sets the Ogg Theora video file that this [VideoStreamTheora] resource handles. The [code]file[/code] name should have the [code].o[/code] extension. + Sets the Ogg Theora video file that this [VideoStreamTheora] resource handles. The [code]file[/code] name should have the [code].ogv[/code] extension. </description> </method> </methods> diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index f58e27c855..0218b8c7a4 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -35,7 +35,6 @@ static Ref<ResourceFormatLoaderTheora> resource_loader_theora; void register_theora_types() { - resource_loader_theora.instance(); ResourceLoader::add_resource_format_loader(resource_loader_theora, true); @@ -43,7 +42,6 @@ void register_theora_types() { } void unregister_theora_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_theora); resource_loader_theora.unref(); } diff --git a/modules/theora/register_types.h b/modules/theora/register_types.h index 4f0670b2c7..654d70e417 100644 --- a/modules/theora/register_types.h +++ b/modules/theora/register_types.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index b9f276fb12..243265769e 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,13 +30,12 @@ #include "video_stream_theora.h" +#include "core/config/project_settings.h" #include "core/os/os.h" -#include "core/project_settings.h" #include "thirdparty/misc/yuv2rgb.h" int VideoStreamPlaybackTheora::buffer_data() { - char *buffer = ogg_sync_buffer(&oy, 4096); #ifdef THEORA_USE_THREAD_STREAMING @@ -69,18 +68,20 @@ int VideoStreamPlaybackTheora::buffer_data() { int VideoStreamPlaybackTheora::queue_page(ogg_page *page) { if (theora_p) { ogg_stream_pagein(&to, page); - if (to.e_o_s) + if (to.e_o_s) { theora_eos = true; + } } if (vorbis_p) { ogg_stream_pagein(&vo, page); - if (vo.e_o_s) + if (vo.e_o_s) { vorbis_eos = true; + } } return 0; } -void VideoStreamPlaybackTheora::video_write(void) { +void VideoStreamPlaybackTheora::video_write() { th_ycbcr_buffer yuv; th_decode_ycbcr_out(td, yuv); @@ -93,15 +94,12 @@ void VideoStreamPlaybackTheora::video_write(void) { //uv_offset=(ti.pic_x/2)+(yuv[1].stride)*(ti.pic_y/2); if (px_fmt == TH_PF_444) { - yuv444_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); } else if (px_fmt == TH_PF_422) { - yuv422_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); } else if (px_fmt == TH_PF_420) { - yuv420_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); }; @@ -116,9 +114,9 @@ void VideoStreamPlaybackTheora::video_write(void) { } void VideoStreamPlaybackTheora::clear() { - - if (!file) + if (!file) { return; + } if (vorbis_p) { ogg_stream_clear(&vo); @@ -164,7 +162,6 @@ void VideoStreamPlaybackTheora::clear() { }; void VideoStreamPlaybackTheora::set_file(const String &p_file) { - ERR_FAIL_COND(playing); ogg_packet op; th_setup_info *ts = nullptr; @@ -209,7 +206,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { while (!stateflag) { int ret = buffer_data(); - if (ret == 0) break; + if (ret == 0) { + break; + } while (ogg_sync_pageout(&oy, &og) > 0) { ogg_stream_state test; @@ -231,7 +230,6 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { copymem(&to, &test, sizeof(test)); theora_p = 1; } else if (!vorbis_p && vorbis_synthesis_headerin(&vi, &vc, &op) >= 0) { - /* it is vorbis */ if (audio_track_skip) { vorbis_info_clear(&vi); @@ -286,7 +284,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { return; } vorbis_p++; - if (vorbis_p == 3) break; + if (vorbis_p == 3) { + break; + } } /* The header pages/packets will arrive before anything else we @@ -372,14 +372,13 @@ float VideoStreamPlaybackTheora::get_time() const { }; Ref<Texture2D> VideoStreamPlaybackTheora::get_texture() const { - return texture; } void VideoStreamPlaybackTheora::update(float p_delta) { - - if (!file) + if (!file) { return; + } if (!playing || paused) { //printf("not playing\n"); @@ -413,13 +412,11 @@ void VideoStreamPlaybackTheora::update(float p_delta) { /* if there's pending, decoded audio, grab it */ ret = vorbis_synthesis_pcmout(&vd, &pcm); if (ret > 0) { - const int AUXBUF_LEN = 4096; int to_read = ret; float aux_buffer[AUXBUF_LEN]; while (to_read) { - int m = MIN(AUXBUF_LEN / vi.channels, to_read); int count = 0; @@ -447,7 +444,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { audio_frames_wrote += ret - to_read; } else { - /* no pending audio; is there a pending packet to decode? */ if (ogg_stream_packetout(&vo, &op) > 0) { if (vorbis_synthesis(&vb, &op) == 0) { /* test for success! */ @@ -460,14 +456,14 @@ void VideoStreamPlaybackTheora::update(float p_delta) { audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate)); - if (buffer_full) + if (buffer_full) { break; + } } while (theora_p && !frame_done) { /* theora is one in, one out... */ if (ogg_stream_packetout(&to, &op) > 0) { - if (false && pp_inc) { pp_level += pp_inc; th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, @@ -534,7 +530,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { /* are we at or past time for this video frame? */ if (videobuf_ready && videobuf_time <= get_time()) { - //video_write(); //videobuf_ready=0; } else { @@ -554,10 +549,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; void VideoStreamPlaybackTheora::play() { - - if (!playing) + if (!playing) { time = 0; - else { + } else { stop(); } @@ -567,9 +561,7 @@ void VideoStreamPlaybackTheora::play() { }; void VideoStreamPlaybackTheora::stop() { - if (playing) { - clear(); set_file(file_name); //reset } @@ -578,86 +570,68 @@ void VideoStreamPlaybackTheora::stop() { }; bool VideoStreamPlaybackTheora::is_playing() const { - return playing; }; void VideoStreamPlaybackTheora::set_paused(bool p_paused) { - paused = p_paused; }; bool VideoStreamPlaybackTheora::is_paused() const { - return paused; }; -void VideoStreamPlaybackTheora::set_loop(bool p_enable){ - -}; +void VideoStreamPlaybackTheora::set_loop(bool p_enable) { +} bool VideoStreamPlaybackTheora::has_loop() const { - return false; }; float VideoStreamPlaybackTheora::get_length() const { - return 0; }; String VideoStreamPlaybackTheora::get_stream_name() const { - return ""; }; int VideoStreamPlaybackTheora::get_loop_count() const { - return 0; }; float VideoStreamPlaybackTheora::get_playback_position() const { - return get_time(); }; -void VideoStreamPlaybackTheora::seek(float p_time){ - - // no -}; +void VideoStreamPlaybackTheora::seek(float p_time) { +} void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) { - mix_callback = p_callback; mix_udata = p_userdata; } int VideoStreamPlaybackTheora::get_channels() const { - return vi.channels; } void VideoStreamPlaybackTheora::set_audio_track(int p_idx) { - audio_track = p_idx; } int VideoStreamPlaybackTheora::get_mix_rate() const { - return vi.rate; } #ifdef THEORA_USE_THREAD_STREAMING void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { - VideoStreamPlaybackTheora *vs = (VideoStreamPlaybackTheora *)ud; while (!vs->thread_exit) { - //just fill back the buffer if (!vs->thread_eof) { - int to_read = vs->ring_buffer.space_left(); if (to_read) { int read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read); @@ -673,7 +647,6 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { #endif VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { - file = nullptr; theora_p = 0; vorbis_p = 0; @@ -704,19 +677,18 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { }; VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { - #ifdef THEORA_USE_THREAD_STREAMING memdelete(thread_sem); #endif clear(); - if (file) + if (file) { memdelete(file); + } }; void VideoStreamTheora::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamTheora::set_file); ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamTheora::get_file); @@ -726,7 +698,6 @@ void VideoStreamTheora::_bind_methods() { //////////// RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { @@ -750,19 +721,17 @@ RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderTheora::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("ogv"); } bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "VideoStream"); } String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); - if (el == "ogv") + if (el == "ogv") { return "VideoStreamTheora"; + } return ""; } diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index f98368ed8b..d2036b5cb4 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -35,7 +35,7 @@ #include "core/os/file_access.h" #include "core/os/semaphore.h" #include "core/os/thread.h" -#include "core/ring_buffer.h" +#include "core/templates/ring_buffer.h" #include "scene/resources/video_stream.h" #include "servers/audio_server.h" @@ -45,7 +45,6 @@ //#define THEORA_USE_THREAD_STREAMING class VideoStreamPlaybackTheora : public VideoStreamPlayback { - GDCLASS(VideoStreamPlaybackTheora, VideoStreamPlayback); enum { @@ -63,7 +62,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback { int buffer_data(); int queue_page(ogg_page *page); - void video_write(void); + void video_write(); float get_time() const; bool theora_eos; @@ -126,42 +125,41 @@ protected: void clear(); public: - virtual void play(); - virtual void stop(); - virtual bool is_playing() const; + virtual void play() override; + virtual void stop() override; + virtual bool is_playing() const override; - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; + virtual void set_paused(bool p_paused) override; + virtual bool is_paused() const override; - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; + virtual void set_loop(bool p_enable) override; + virtual bool has_loop() const override; - virtual float get_length() const; + virtual float get_length() const override; virtual String get_stream_name() const; virtual int get_loop_count() const; - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual float get_playback_position() const override; + virtual void seek(float p_time) override; void set_file(const String &p_file); - virtual Ref<Texture2D> get_texture() const; - virtual void update(float p_delta); + virtual Ref<Texture2D> get_texture() const override; + virtual void update(float p_delta) override; - virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); - virtual int get_channels() const; - virtual int get_mix_rate() const; + virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) override; + virtual int get_channels() const override; + virtual int get_mix_rate() const override; - virtual void set_audio_track(int p_idx); + virtual void set_audio_track(int p_idx) override; VideoStreamPlaybackTheora(); ~VideoStreamPlaybackTheora(); }; class VideoStreamTheora : public VideoStream { - GDCLASS(VideoStreamTheora, VideoStream); String file; @@ -171,7 +169,7 @@ protected: static void _bind_methods(); public: - Ref<VideoStreamPlayback> instance_playback() { + Ref<VideoStreamPlayback> instance_playback() override { Ref<VideoStreamPlaybackTheora> pb = memnew(VideoStreamPlaybackTheora); pb->set_audio_track(audio_track); pb->set_file(file); @@ -180,7 +178,7 @@ public: void set_file(const String &p_file) { file = p_file; } String get_file() { return file; } - void set_audio_track(int p_track) { audio_track = p_track; } + void set_audio_track(int p_track) override { audio_track = p_track; } VideoStreamTheora() { audio_track = 0; } }; |