Bug 1329098. Part 1 - copy DispatchDecodeTasksIfNeeded() into BufferingState.
MozReview-Commit-ID: 2q8FhTFTJ6g
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1498,16 +1498,18 @@ public:
if (mMaster->HasVideo()) {
mMaster->mVideoDecodeSuspended = true;
mMaster->mOnPlaybackEvent.Notify(MediaEventType::EnterVideoSuspend);
Reader()->SetVideoBlankDecode(true);
}
}
private:
+ void DispatchDecodeTasksIfNeeded();
+
TimeStamp mBufferingStart;
// The maximum number of second we spend buffering when we are short on
// unbuffered data.
const uint32_t mBufferingWait = 15;
};
/**
@@ -2209,16 +2211,39 @@ NextFrameSeekingState::HandleVideoNotDec
default:
// Raise an error since we can't finish video seek anyway.
mMaster->DecodeError(aError);
}
}
void
MediaDecoderStateMachine::
+BufferingState::DispatchDecodeTasksIfNeeded()
+{
+ const bool needToDecodeAudio =
+ mMaster->IsAudioDecoding() &&
+ ((!mMaster->mSentFirstFrameLoadedEvent && AudioQueue().GetSize() == 0) ||
+ (!mMaster->mMinimizePreroll && !mMaster->HaveEnoughDecodedAudio()));
+
+ const bool needToDecodeVideo =
+ mMaster->IsVideoDecoding() &&
+ ((!mMaster->mSentFirstFrameLoadedEvent && VideoQueue().GetSize() == 0) ||
+ (!mMaster->mMinimizePreroll && !mMaster->HaveEnoughDecodedVideo()));
+
+ if (needToDecodeAudio) {
+ mMaster->EnsureAudioDecodeTaskQueued();
+ }
+
+ if (needToDecodeVideo) {
+ mMaster->EnsureVideoDecodeTaskQueued();
+ }
+}
+
+void
+MediaDecoderStateMachine::
BufferingState::Step()
{
TimeStamp now = TimeStamp::Now();
MOZ_ASSERT(!mBufferingStart.IsNull(), "Must know buffering start time.");
// With buffering heuristics we will remain in the buffering state if
// we've not decoded enough data to begin playback, or if we've not
// downloaded a reasonable amount of data inside our buffering time.
@@ -2227,21 +2252,21 @@ BufferingState::Step()
bool isLiveStream = Resource()->IsLiveStream();
if ((isLiveStream || !mMaster->CanPlayThrough()) &&
elapsed < TimeDuration::FromSeconds(mBufferingWait * mMaster->mPlaybackRate) &&
mMaster->HasLowBufferedData(mBufferingWait * USECS_PER_S) &&
IsExpectingMoreData()) {
SLOG("Buffering: wait %ds, timeout in %.3lfs",
mBufferingWait, mBufferingWait - elapsed.ToSeconds());
mMaster->ScheduleStateMachineIn(USECS_PER_S);
- mMaster->DispatchDecodeTasksIfNeeded();
+ DispatchDecodeTasksIfNeeded();
return;
}
} else if (mMaster->OutOfDecodedAudio() || mMaster->OutOfDecodedVideo()) {
- mMaster->DispatchDecodeTasksIfNeeded();
+ DispatchDecodeTasksIfNeeded();
MOZ_ASSERT(!mMaster->OutOfDecodedAudio() ||
mMaster->IsRequestingAudioData() ||
mMaster->IsWaitingAudioData());
MOZ_ASSERT(!mMaster->OutOfDecodedVideo() ||
mMaster->IsRequestingVideoData() ||
mMaster->IsWaitingVideoData());
SLOG("In buffering mode, waiting to be notified: outOfAudio: %d, "
"mAudioStatus: %s, outOfVideo: %d, mVideoStatus: %s",