Commit b2d3ca92 authored by Chris Pearce's avatar Chris Pearce
Browse files

Bug 752141 - Release media decoder monitor when finishing audio stream. r=kinetik

parent 9d526ace
Loading
Loading
Loading
Loading
+44 −38
Original line number Diff line number Diff line
@@ -1146,6 +1146,8 @@ void nsBuiltinDecoderStateMachine::AudioLoop()
      mAudioEndTime = playedUsecs.value();
    }
  }
  {
    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
    if (mReader->mAudioQueue.AtEndOfStream() &&
        mState != DECODER_STATE_SHUTDOWN &&
        !mStopAudioThread)
@@ -1154,7 +1156,6 @@ void nsBuiltinDecoderStateMachine::AudioLoop()
      // before the audio thread terminates.
      bool seeking = false;
      {
      ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
        PRInt64 unplayedFrames = audioDuration % minWriteFrames;
        if (minWriteFrames > 1 && unplayedFrames > 0) {
          // Sound is written by libsydneyaudio to the hardware in blocks of
@@ -1167,6 +1168,7 @@ void nsBuiltinDecoderStateMachine::AudioLoop()
          if (framesToWrite < PR_UINT32_MAX / channels) {
            // Write silence manually rather than using PlaySilence(), so that
            // the AudioAPI doesn't get a copy of the audio frames.
            ReentrantMonitorAutoExit exit(mDecoder->GetReentrantMonitor());
            WriteSilence(mAudioStream, framesToWrite);
          }
        }
@@ -1187,11 +1189,15 @@ void nsBuiltinDecoderStateMachine::AudioLoop()
      }

      if (!seeking && !mAudioStream->IsPaused()) {
        {
          ReentrantMonitorAutoExit exit(mDecoder->GetReentrantMonitor());
          mAudioStream->Drain();
        }
        // Fire one last event for any extra frames that didn't fill a framebuffer.
        mEventManager.Drain(mAudioEndTime);
      }
    }
  }
  LOG(PR_LOG_DEBUG, ("%p Reached audio stream end.", mDecoder.get()));
  {
    // Must hold lock while anulling the audio stream to prevent