Bug 525401 - Resynchronize system clock against audio clock to avoid clock drift problems when alternating between clocks. r=chris.double
authorMatthew Gregan <kinetik@flim.org>
Fri, 05 Feb 2010 18:16:29 +1300
changeset 39440 d856fe629ad2cc6785cfea9ad1e31c6e4dbbab34
parent 39439 d7b6a97efd0632c24780c1efab28387afd874ca7
child 39441 052a1c415457e7c725e1ca9ddb8cdd67c21da233
push idunknown
push userunknown
push dateunknown
reviewerschris
bugs525401
milestone1.9.3a3pre
Bug 525401 - Resynchronize system clock against audio clock to avoid clock drift problems when alternating between clocks. r=chris.double
content/media/ogg/nsOggDecoder.cpp
--- a/content/media/ogg/nsOggDecoder.cpp
+++ b/content/media/ogg/nsOggDecoder.cpp
@@ -931,16 +931,22 @@ void nsOggDecodeStateMachine::PlayFrame(
         // Even if the frame has had its audio data written we call
         // PlayAudio to ensure that any data we have buffered in the
         // nsAudioStream is written to the hardware.
         PlayAudio(frame);
         double hwtime = mAudioStream && hasAudio ? mAudioStream->GetPosition() : -1.0;
         time = hwtime < 0.0 ?
           (TimeStamp::Now() - mPlayStartTime - mPauseDuration).ToSeconds() :
           hwtime;
+        // Resynchronize the system clock against the audio clock.
+        if (hwtime >= 0.0) {
+          mPlayStartTime = TimeStamp::Now();
+          mPlayStartTime -= TimeDuration::FromMilliseconds(hwtime * 1000.0);
+          mPauseDuration = TimeDuration(0);
+        }
         // Is it time for the next frame?  Using an integer here avoids f.p.
         // rounding errors that can cause multiple 0ms waits (Bug 495352)
         PRInt64 wait = PRInt64((frame->mTime - time)*1000);
         if (wait <= 0)
           break;
         mon.Wait(PR_MillisecondsToInterval(wait));
         if (mState == DECODER_STATE_SHUTDOWN)
           return;