Bug 557432 - Lock the audio stream while getting it's played duration. r=doublec
authorChris Pearce <chris@pearce.org.nz>
Thu, 08 Apr 2010 20:16:02 +1200
changeset 40582 b64df24f49103e54977195c091da915520b131c3
parent 40581 6f250c9b680ba60704cfbd5e939b2e9c8e20c05c
child 40583 ae1034cd50675344dc3b88ee13f0dfc99746448a
child 40619 49d669800db9502b01933c3f2e5d258abe8752a4
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs557432
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 557432 - Lock the audio stream while getting it's played duration. r=doublec
content/media/ogg/nsOggPlayStateMachine.cpp
--- a/content/media/ogg/nsOggPlayStateMachine.cpp
+++ b/content/media/ogg/nsOggPlayStateMachine.cpp
@@ -928,18 +928,18 @@ nsresult nsOggPlayStateMachine::Run()
         // Play the remaining media.
         while (mState == DECODER_STATE_COMPLETED &&
                (mReader->mVideoQueue.GetSize() > 0 ||
                 (HasAudio() && !mAudioCompleted)))
         {
           AdvanceFrame();
         }
 
-        if (mAudioStream) {
-          // Close the audop stream so that next time audio is used a new stream
+        if (HasAudio()) {
+          // Close the audio stream so that next time audio is used a new stream
           // is created. The StopPlayback call also resets the IsPlaying() state
           // so audio is restarted correctly.
           StopPlayback(AUDIO_SHUTDOWN);
         }
 
         if (mState != DECODER_STATE_COMPLETED)
           continue;
 
@@ -1120,19 +1120,26 @@ void nsOggPlayStateMachine::RenderVideoF
     mDecoder->SetVideoData(data.mYSize, mInfo.mAspectRatio, image);
   }
 }
 
 PRInt64
 nsOggPlayStateMachine::GetAudioClock()
 {
   NS_ASSERTION(IsThread(mDecoder->mStateMachineThread), "Should be on state machine thread.");
-  if (!mAudioStream || !HasAudio())
+  if (!HasAudio())
     return -1;
-  PRInt64 t = mAudioStream->GetPosition();
+  PRInt64 t;
+  {
+    MonitorAutoExit exitMon(mDecoder->GetMonitor());
+    MonitorAutoEnter audioMon(mAudioMonitor);
+    if (!mAudioStream)
+      return -1;
+    t = mAudioStream->GetPosition();
+  }
   return (t == -1) ? -1 : t + mAudioStartTime;
 }
 
 void nsOggPlayStateMachine::AdvanceFrame()
 {
   NS_ASSERTION(IsThread(mDecoder->mStateMachineThread), "Should be on state machine thread.");
   mDecoder->GetMonitor().AssertCurrentThreadIn();