From c1dd524919460febdabb17a549cc1e2f5e6a6f22 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Wed, 13 Oct 2010 20:10:37 +1300 Subject: [PATCH] Backed out changeset 00382c4a8b22 a=backout --- .../media/nsBuiltinDecoderStateMachine.cpp | 28 ++++++++++++++----- content/media/nsBuiltinDecoderStateMachine.h | 5 ++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/content/media/nsBuiltinDecoderStateMachine.cpp b/content/media/nsBuiltinDecoderStateMachine.cpp index 5dcbf083a86..a768335fe49 100644 --- a/content/media/nsBuiltinDecoderStateMachine.cpp +++ b/content/media/nsBuiltinDecoderStateMachine.cpp @@ -151,6 +151,7 @@ nsBuiltinDecoderStateMachine::nsBuiltinDecoderStateMachine(nsBuiltinDecoder* aDe mSeekable(PR_TRUE), mPositionChangeQueued(PR_FALSE), mAudioCompleted(PR_FALSE), + mBufferExhausted(PR_FALSE), mGotDurationFromMetaData(PR_FALSE), mStopDecodeThreads(PR_TRUE), mEventManager(aDecoder) @@ -274,6 +275,10 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() if (videoPlaying && !videoWait) { videoPlaying = mReader->DecodeVideoFrame(skipToNextKeyframe, currentTime); + { + MonitorAutoEnter mon(mDecoder->GetMonitor()); + mBufferExhausted = mDecoder->mDecoderPosition > initialDownloadPosition; + } } { MonitorAutoEnter mon(mDecoder->GetMonitor()); @@ -284,6 +289,10 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() if (audioPlaying && !audioWait) { audioPlaying = mReader->DecodeAudioData(); + { + MonitorAutoEnter mon(mDecoder->GetMonitor()); + mBufferExhausted = mDecoder->mDecoderPosition > initialDownloadPosition; + } } { @@ -305,6 +314,9 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() { // All active bitstreams' decode is well ahead of the playback // position, we may as well wait for the playback to catch up. + // Set mBufferExhausted to PR_FALSE, as we'll receive more data + // while we wait. + mBufferExhausted = PR_FALSE; mon.Wait(); } } @@ -847,14 +859,13 @@ PRInt64 nsBuiltinDecoderStateMachine::AudioDecodedMs() const PRBool nsBuiltinDecoderStateMachine::HasLowDecodedData() const { - return ((HasAudio() && - !mReader->mAudioQueue.IsFinished() && - AudioDecodedMs() < LOW_AUDIO_MS) - || + // We consider ourselves low on decoded data if we're low on audio, or + // if we're only playing video and we're low on video frames. + return (HasAudio() && AudioDecodedMs() < LOW_AUDIO_MS) + || (!HasAudio() && HasVideo() && - !mReader->mVideoQueue.IsFinished() && - (PRUint32)mReader->mVideoQueue.GetSize() < LOW_VIDEO_FRAMES)); + (PRUint32)mReader->mVideoQueue.GetSize() < LOW_VIDEO_FRAMES); } PRBool nsBuiltinDecoderStateMachine::HasAmpleDecodedData() const @@ -957,7 +968,8 @@ nsresult nsBuiltinDecoderStateMachine::Run() if (mState != DECODER_STATE_DECODING) continue; - if (HasLowDecodedData() && + if (mBufferExhausted && + HasLowDecodedData() && mDecoder->GetState() == nsBuiltinDecoder::PLAY_STATE_PLAYING && !stream->IsDataCachedToEndOfStream(mDecoder->mDecoderPosition) && !stream->IsSuspended()) @@ -1061,6 +1073,7 @@ nsresult nsBuiltinDecoderStateMachine::Run() stopEvent = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::SeekingStopped); mState = DECODER_STATE_DECODING; } + mBufferExhausted = PR_FALSE; mDecoder->GetMonitor().NotifyAll(); { @@ -1423,6 +1436,7 @@ void nsBuiltinDecoderStateMachine::LoadMetadata() void nsBuiltinDecoderStateMachine::StartBuffering() { mDecoder->GetMonitor().AssertCurrentThreadIn(); + mBufferExhausted = PR_TRUE; if (IsPlaying()) { StopPlayback(AUDIO_PAUSE); mDecoder->GetMonitor().NotifyAll(); diff --git a/content/media/nsBuiltinDecoderStateMachine.h b/content/media/nsBuiltinDecoderStateMachine.h index c5aa9b8887c..353973ff4b4 100644 --- a/content/media/nsBuiltinDecoderStateMachine.h +++ b/content/media/nsBuiltinDecoderStateMachine.h @@ -476,6 +476,11 @@ protected: // the state machine thread. Synchronised via decoder monitor. PRPackedBool mAudioCompleted; + // PR_TRUE if the decode thread has indicated that we need to buffer. + // Accessed by the decode thread and the state machine thread. + // Synchronised via the decoder monitor. + PRPackedBool mBufferExhausted; + // PR_TRUE if mDuration has a value obtained from an HTTP header, or from // the media index/metadata. Accessed on the state machine thread. PRPackedBool mGotDurationFromMetaData;