[Redbutton-devel] SF.net SVN: redbutton: [134] redbutton-browser/trunk/MHEGStreamPlayer.c
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-07-30 10:52:23
|
Revision: 134 Author: skilvington Date: 2006-07-30 03:52:10 -0700 (Sun, 30 Jul 2006) ViewCVS: http://svn.sourceforge.net/redbutton/?rev=134&view=rev Log Message: ----------- maintain A/V sync if audio gets ahead Modified Paths: -------------- redbutton-browser/trunk/MHEGStreamPlayer.c Modified: redbutton-browser/trunk/MHEGStreamPlayer.c =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.c 2006-07-28 21:17:34 UTC (rev 133) +++ redbutton-browser/trunk/MHEGStreamPlayer.c 2006-07-30 10:52:10 UTC (rev 134) @@ -488,7 +488,7 @@ drop_frame = (usecs < 0); if(drop_frame) { - verbose("MHEGStreamPlayer: dropped frame %u (usecs=%d)", nframes, usecs); + verbose("MHEGStreamPlayer: dropped video frame %u (usecs=%d)", nframes, usecs); } else { @@ -592,6 +592,7 @@ int64_t now_time, next_time; double now_pts, next_pts; int usecs; + double vpts = 0.0; if(!p->have_audio) return NULL; @@ -724,8 +725,20 @@ /* TODO */ /* need to make sure pts is what we expect */ /* if we missed decoding a sample, play silence */ - /* this will block until the sound card can take the data */ - MHEGAudioOutput_addSamples(&ao, af->data, af->size); + /* if the audio is getting ahead, don't play this sample */ + pthread_mutex_lock(&p->videoq_lock); + vpts = p->videoq ? p->videoq->item.pts : vpts; + pthread_mutex_unlock(&p->videoq_lock); + if(vpts <= af->pts) + { + /* this will block until the sound card can take the data */ + MHEGAudioOutput_addSamples(&ao, af->data, af->size); + } + else + { + verbose("MHEGStreamPlayer: dropped audio frame (%f ahead)", vpts - af->pts); + } +/* TODO handle case when video is ahead */ /* we can delete the frame from the queue now */ pthread_mutex_lock(&p->audioq_lock); LIST_FREE_HEAD(&p->audioq, AudioFrame, free_AudioFrameListItem); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |