From 51e1ec5f589862ddfd9322daf5bcd684698fb48f Mon Sep 17 00:00:00 2001 From: iovar Date: Mon, 23 Oct 2006 03:29:06 +0000 Subject: av sync imporovements git-svn-id: https://recordmydesktop.svn.sourceforge.net/svnroot/recordmydesktop/trunk@106 f606c939-3180-4ac9-a4b8-4b8779d57d0a --- recordmydesktop/src/flush_to_ogg.c | 44 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/recordmydesktop/src/flush_to_ogg.c b/recordmydesktop/src/flush_to_ogg.c index fed07c5..15b537b 100644 --- a/recordmydesktop/src/flush_to_ogg.c +++ b/recordmydesktop/src/flush_to_ogg.c @@ -27,31 +27,53 @@ #include void *FlushToOgg(void *pdata){ - int videoflag=0,audioflag=0; + int videoflag=0,audioflag=0,a_v=0; double video_bytesout=0,audio_bytesout=0; + ogg_int64_t v_pos=0,a_pos=0; ogg_page videopage,audiopage; while(((ProgData *)pdata)->running){ - pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); - videoflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage); - pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); - if(videoflag){ - video_bytesout+=fwrite(videopage.header,1,videopage.header_len,((ProgData *)pdata)->enc_data->fp); - video_bytesout+=fwrite(videopage.body,1,videopage.body_len,((ProgData *)pdata)->enc_data->fp); - videoflag=0; + a_v=0; +// v_pos=theora_granule_time(&(((ProgData *)pdata)->enc_data->m_th_st),((ProgData *)pdata)->enc_data->m_ogg_ts.granulepos); +// a_pos= + + if(v_pos<=a_pos){ + pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); + videoflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage); + + if(videoflag){ + v_pos=theora_granule_time(&(((ProgData *)pdata)->enc_data->m_th_st), + ((ProgData *)pdata)->enc_data->m_ogg_ts.granulepos); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); + video_bytesout+=fwrite(videopage.header,1,videopage.header_len,((ProgData *)pdata)->enc_data->fp); + video_bytesout+=fwrite(videopage.body,1,videopage.body_len,((ProgData *)pdata)->enc_data->fp); + videoflag=0; + a_v=1; + } + else + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); + } + if(a_posargs.nosound){ pthread_mutex_lock(&((ProgData *)pdata)->libogg_mutex); audioflag=ogg_stream_pageout(&((ProgData *)pdata)->enc_data->m_ogg_vs,&audiopage); - pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); if(audioflag){ + a_pos=vorbis_granule_time(&(((ProgData *)pdata)->enc_data->m_vo_dsp), + ((ProgData *)pdata)->enc_data->m_vo_dsp.granulepos); + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); audio_bytesout+=fwrite(audiopage.header,1,audiopage.header_len,((ProgData *)pdata)->enc_data->fp); audio_bytesout+=fwrite(audiopage.body,1,audiopage.body_len,((ProgData *)pdata)->enc_data->fp); audioflag=0; + a_v=1; } + else + pthread_mutex_unlock(&((ProgData *)pdata)->libogg_mutex); + + } } - else + if(!a_v) usleep(10000); - +// fprintf(stderr,"v %d a %d %d\n",(int)v_pos,(int)a_pos,(int)v_pos-(int)a_pos); } //last packages videoflag=ogg_stream_flush(&((ProgData *)pdata)->enc_data->m_ogg_ts,&videopage); -- cgit v1.2.3