diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | drivers/theora/video_stream_theora.cpp | 48 | ||||
-rw-r--r-- | drivers/theora/video_stream_theora.h | 3 | ||||
-rw-r--r-- | scene/gui/video_player.cpp | 12 |
4 files changed, 46 insertions, 20 deletions
@@ -7,8 +7,7 @@ The editor, language and APIs are feature rich, yet simple to learn, allowing yo ### About -Godot has been developed by Juan Linietsky and Ariel Manzur for several years, and was born as an in-house engine, used to publish several work-for-hire titles. -Development is sponsored by OKAM Studio (http://www.okamstudio.com). +Godot has been developed by Juan Linietsky and Ariel Manzur for several years, and was born as an in-house engine, used to publish several work-for-hire titles. Godot is a member project of the [Software Freedom Conservancy](https://sfconservancy.org) ### Documentation diff --git a/drivers/theora/video_stream_theora.cpp b/drivers/theora/video_stream_theora.cpp index bea49e34b7..ed87227876 100644 --- a/drivers/theora/video_stream_theora.cpp +++ b/drivers/theora/video_stream_theora.cpp @@ -178,7 +178,7 @@ void VideoStreamPlaybackTheora::video_write(void){ void VideoStreamPlaybackTheora::clear() { - if (file_name == "") + if (!file) return; if(vorbis_p){ @@ -208,6 +208,10 @@ void VideoStreamPlaybackTheora::clear() { frames_pending = 0; videobuf_time = 0; + if (file) { + memdelete(file); + } + file=NULL; playing = false; }; @@ -266,14 +270,14 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) { 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); - vorbis_comment_clear(&vc); - audio_track_skip--; - } else { - copymem(&vo,&test,sizeof(test)); - vorbis_p=1; - } + if (audio_track_skip) { + vorbis_info_clear(&vi); + vorbis_comment_clear(&vc); + audio_track_skip--; + } else { + copymem(&vo,&test,sizeof(test)); + vorbis_p=1; + } }else{ /* whatever it is, we don't care about it */ ogg_stream_clear(&test); @@ -392,6 +396,7 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) { fprintf(stderr,"Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.\n", vo.serialno,vi.channels,vi.rate); //_setup(vi.channels, vi.rate); + }else{ /* tear down the partial vorbis setup */ vorbis_info_clear(&vi); @@ -401,6 +406,7 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) { playing = false; buffering=true; time=0; + audio_frames_wrote=0; }; float VideoStreamPlaybackTheora::get_time() const { @@ -431,8 +437,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { return; //no new frames need to be produced bool frame_done=false; + bool audio_done=false; - while (!frame_done) { + while (!frame_done || !audio_done) { //a frame needs to be produced ogg_packet op; @@ -490,6 +497,17 @@ void VideoStreamPlaybackTheora::update(float p_delta) { audio_pending=true; + if (vd.granulepos>=0) { + // print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos)); + } + + //print_line("mix audio!"); + + audio_frames_wrote+=ret-to_read; + + //print_line("AGP: "+itos(vd.granulepos)+" added "+itos(ret-to_read)); + + } else { /* no pending audio; is there a pending packet to decode? */ @@ -503,6 +521,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; } + + audio_done = videobuf_time < (audio_frames_wrote/float(vi.rate)); + if (buffer_full) break; } @@ -567,7 +588,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { } } #else - if (!frame_done){ + + + if (!frame_done || !audio_done){ //what's the point of waiting for audio to grab a page? buffer_data(); @@ -709,8 +732,9 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { texture = Ref<ImageTexture>( memnew(ImageTexture )); mix_callback=NULL; mix_udata=NULL; - audio_track=0; + audio_track=0; delay_compensation=0; + audio_frames_wrote=0; }; VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { diff --git a/drivers/theora/video_stream_theora.h b/drivers/theora/video_stream_theora.h index 95c7fe88f6..5540f050f9 100644 --- a/drivers/theora/video_stream_theora.h +++ b/drivers/theora/video_stream_theora.h @@ -32,6 +32,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback { void video_write(void); float get_time() const; + ogg_sync_state oy; ogg_page og; ogg_stream_state vo; @@ -122,7 +123,7 @@ public: Ref<VideoStreamPlayback> instance_playback() { Ref<VideoStreamPlaybackTheora> pb = memnew( VideoStreamPlaybackTheora ); - pb->set_audio_track(audio_track); + pb->set_audio_track(audio_track); pb->set_file(file); return pb; } diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index f50552b32c..b4cd437d35 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -196,10 +196,10 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) { stream=p_stream; if (stream.is_valid()) { - stream->set_audio_track(audio_track); - playback=stream->instance_playback(); + stream->set_audio_track(audio_track); + playback=stream->instance_playback(); } else { - playback=Ref<VideoStreamPlayback>(); + playback=Ref<VideoStreamPlayback>(); } if (!playback.is_null()) { @@ -249,6 +249,8 @@ void VideoPlayer::stop() { return; playback->stop(); + AudioServer::get_singleton()->stream_set_active(stream_rid,false); + resampler.clear(); set_process(false); last_audio_time=0; }; @@ -387,8 +389,8 @@ void VideoPlayer::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL, "stream/volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/paused"), _SCS("set_paused"), _SCS("is_paused") ); - ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/audio_track",PROPERTY_HINT_RANGE,"0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") ); + ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/audio_track",PROPERTY_HINT_RANGE,"0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") ); } |