Bug 1307022. Part 5 - move some code from OnNotDecoded() to various state objects.
MozReview-Commit-ID: 1VFK80k6dg2
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -214,16 +214,18 @@ public:
virtual bool HandleAudioDecoded(MediaData* aAudio) { return false; }
virtual bool HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart)
{
return false;
}
+ virtual bool HandleEndOfStream() { return false; }
+
protected:
using Master = MediaDecoderStateMachine;
explicit StateObject(Master* aPtr) : mMaster(aPtr) {}
TaskQueue* OwnerThread() const { return mMaster->mTaskQueue; }
MediaResource* Resource() const { return mMaster->mResource; }
MediaDecoderReaderWrapper* Reader() const { return mMaster->mReader; }
// Note this function will delete the current state object.
@@ -431,16 +433,22 @@ public:
}
bool HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
{
mMaster->Push(aVideo, MediaData::VIDEO_DATA);
mMaster->MaybeFinishDecodeFirstFrame();
return true;
}
+
+ bool HandleEndOfStream() override
+ {
+ mMaster->MaybeFinishDecodeFirstFrame();
+ return true;
+ }
};
class MediaDecoderStateMachine::DecodingState
: public MediaDecoderStateMachine::StateObject
{
public:
explicit DecodingState(Master* aPtr) : StateObject(aPtr) {}
@@ -544,16 +552,24 @@ private:
SLOG("Slow video decode, set "
"mLowAudioThresholdUsecs=%lld "
"mAmpleAudioThresholdUsecs=%lld",
mMaster->mLowAudioThresholdUsecs,
mMaster->mAmpleAudioThresholdUsecs);
}
}
+ bool HandleEndOfStream() override
+ {
+ if (mMaster->CheckIfDecodeComplete()) {
+ SetState(DECODER_STATE_COMPLETED);
+ }
+ return true;
+ }
+
// Time at which we started decoding.
TimeStamp mDecodeStartTime;
};
class MediaDecoderStateMachine::SeekingState
: public MediaDecoderStateMachine::StateObject
{
public:
@@ -680,16 +696,27 @@ public:
{
// This might be the sample we need to exit buffering.
// Schedule Step() to check it.
mMaster->Push(aVideo, MediaData::VIDEO_DATA);
mMaster->ScheduleStateMachine();
return true;
}
+ bool HandleEndOfStream() override
+ {
+ if (mMaster->CheckIfDecodeComplete()) {
+ SetState(DECODER_STATE_COMPLETED);
+ } else {
+ // Check if we can exit buffering.
+ mMaster->ScheduleStateMachine();
+ }
+ return true;
+ }
+
private:
TimeStamp mBufferingStart;
};
class MediaDecoderStateMachine::CompletedState
: public MediaDecoderStateMachine::StateObject
{
public:
@@ -1214,36 +1241,17 @@ MediaDecoderStateMachine::OnNotDecoded(M
if (isAudio) {
AudioQueue().Finish();
} else {
VideoQueue().Finish();
}
MaybeStopPrerolling();
- switch (mState) {
- case DECODER_STATE_DECODING_FIRSTFRAME:
- MaybeFinishDecodeFirstFrame();
- return;
- case DECODER_STATE_BUFFERING:
- case DECODER_STATE_DECODING: {
- if (CheckIfDecodeComplete()) {
- SetState(DECODER_STATE_COMPLETED);
- return;
- }
- // Schedule next cycle to see if we can leave buffering state.
- if (mState == DECODER_STATE_BUFFERING) {
- ScheduleStateMachine();
- }
- return;
- }
- default: {
- return;
- }
- }
+ mStateObj->HandleEndOfStream();
}
void
MediaDecoderStateMachine::MaybeFinishDecodeFirstFrame()
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(!mSentFirstFrameLoadedEvent);