diff options
Diffstat (limited to 'drivers/theora')
-rw-r--r-- | drivers/theora/decode.c | 46 | ||||
-rw-r--r-- | drivers/theora/video_stream_theora.cpp | 58 | ||||
-rw-r--r-- | drivers/theora/video_stream_theora.h | 3 |
3 files changed, 77 insertions, 30 deletions
diff --git a/drivers/theora/decode.c b/drivers/theora/decode.c index 7be66463d8..882606ae77 100644 --- a/drivers/theora/decode.c +++ b/drivers/theora/decode.c @@ -1611,28 +1611,35 @@ static void oc_filter_hedge(unsigned char *_dst,int _dst_ystride, int sum1; int bx; int by; + int _rlimit1; + int _rlimit2; rdst=_dst; rsrc=_src; - for(bx=0;bx<8;bx++){ + for(bx=0;bx<8;++bx){ cdst=rdst; csrc=rsrc; - for(by=0;by<10;by++){ + _rlimit1 = _rlimit2 = _flimit; + for(by=0;by<10;++by){ r[by]=*csrc; csrc+=_src_ystride; } sum0=sum1=0; - for(by=0;by<4;by++){ - sum0+=abs(r[by+1]-r[by]); - sum1+=abs(r[by+5]-r[by+6]); + for(by=0;by<4;++by){ + int sumed = abs(r[by+1]-r[by]); + sum0+=sumed; + _rlimit1-=sumed; + sumed = abs(r[by+5]-r[by+6]); + sum1+=sumed; + _rlimit2-=sumed; } *_variance0+=OC_MINI(255,sum0); *_variance1+=OC_MINI(255,sum1); - if(sum0<_flimit&&sum1<_flimit&&r[5]-r[4]<_qstep&&r[4]-r[5]<_qstep){ + if(_rlimit1&&_rlimit2&&!(r[5]-r[4]-_qstep)&&!(r[4]-r[5]-_qstep)){ *cdst=(unsigned char)(r[0]*3+r[1]*2+r[2]+r[3]+r[4]+4>>3); cdst+=_dst_ystride; *cdst=(unsigned char)(r[0]*2+r[1]+r[2]*2+r[3]+r[4]+r[5]+4>>3); cdst+=_dst_ystride; - for(by=0;by<4;by++){ + for(by=0;by<4;++by){ *cdst=(unsigned char)(r[by]+r[by+1]+r[by+2]+r[by+3]*2+ r[by+4]+r[by+5]+r[by+6]+4>>3); cdst+=_dst_ystride; @@ -1642,13 +1649,13 @@ static void oc_filter_hedge(unsigned char *_dst,int _dst_ystride, *cdst=(unsigned char)(r[5]+r[6]+r[7]+r[8]*2+r[9]*3+4>>3); } else{ - for(by=1;by<=8;by++){ + for(by=1;by<=8;++by){ *cdst=(unsigned char)r[by]; cdst+=_dst_ystride; } } - rdst++; - rsrc++; + ++rdst; + ++rsrc; } } @@ -1663,19 +1670,26 @@ static void oc_filter_vedge(unsigned char *_dst,int _dst_ystride, int sum1; int bx; int by; + int _rlimit1; + int _rlimit2; cdst=_dst; - for(by=0;by<8;by++){ + for(by=0;by<8;++by){ rsrc=cdst-1; rdst=cdst; - for(bx=0;bx<10;bx++)r[bx]=*rsrc++; + for(bx=0;bx<10;++bx)r[bx]=*rsrc++; sum0=sum1=0; - for(bx=0;bx<4;bx++){ - sum0+=abs(r[bx+1]-r[bx]); - sum1+=abs(r[bx+5]-r[bx+6]); + _rlimit1 = _rlimit2 = _flimit; + for(bx=0;bx<4;++bx){ + int sumed = abs(r[bx+1]-r[bx]); + sum0+=sumed; + _rlimit1-=sumed; + sumed = abs(r[bx+5]-r[bx+6]); + sum1+=sumed; + _rlimit2-=sumed; } _variances[0]+=OC_MINI(255,sum0); _variances[1]+=OC_MINI(255,sum1); - if(sum0<_flimit&&sum1<_flimit&&r[5]-r[4]<_qstep&&r[4]-r[5]<_qstep){ + if(_rlimit1&&_rlimit2&&!(r[5]-r[4]-_qstep)&&!(r[4]-r[5]-_qstep)){ *rdst++=(unsigned char)(r[0]*3+r[1]*2+r[2]+r[3]+r[4]+4>>3); *rdst++=(unsigned char)(r[0]*2+r[1]+r[2]*2+r[3]+r[4]+r[5]+4>>3); for(bx=0;bx<4;bx++){ diff --git a/drivers/theora/video_stream_theora.cpp b/drivers/theora/video_stream_theora.cpp index bea49e34b7..ed2565177a 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; }; @@ -239,7 +243,9 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) { /* Only interested in Vorbis/Theora streams */ int stateflag = 0; - int audio_track_skip=audio_track; + int audio_track_skip=audio_track; + + while(!stateflag){ int ret=buffer_data(); if(ret==0)break; @@ -265,15 +271,21 @@ 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); - 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); + ogg_stream_clear(&test); + vorbis_info_init(&vi); + vorbis_comment_init(&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 +404,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 +414,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 +445,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 +505,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 +529,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; } + + audio_done = videobuf_time < (audio_frames_wrote/float(vi.rate)); + if (buffer_full) break; } @@ -567,7 +596,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 +740,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; } |