Bug 1320466 part 1 - delegate OnNotDecoded event to state objects; r?jwwang
MozReview-Commit-ID: ChomOsqYo1d
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -191,16 +191,17 @@ public:
virtual void Exit() {}; // Exit action.
virtual void Step() {} // Perform a 'cycle' of this state object.
virtual State GetState() const = 0;
// Event handlers for various events.
virtual void HandleCDMProxyReady() {}
virtual void HandleAudioDecoded(MediaData* aAudio) {}
virtual void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) {}
+ virtual void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError);
virtual void HandleEndOfStream() {}
virtual void HandleWaitingForData() {}
virtual void HandleAudioCaptured() {}
virtual RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget);
virtual RefPtr<ShutdownPromise> HandleShutdown();
@@ -1122,16 +1123,21 @@ public:
MOZ_DIAGNOSTIC_ASSERT(false, "Shouldn't escape the SHUTDOWN state.");
}
State GetState() const override
{
return DECODER_STATE_SHUTDOWN;
}
+ void HandleNotDecoded(MediaData::Type aType, const MediaResult& aError) override
+ {
+ return;
+ }
+
RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
{
MOZ_DIAGNOSTIC_ASSERT(false, "Can't seek in shutdown state.");
return MediaDecoder::SeekPromise::CreateAndReject(true, __func__);
}
RefPtr<ShutdownPromise> HandleShutdown() override
{
@@ -1145,16 +1151,59 @@ public:
}
void HandleResumeVideoDecoding() override
{
MOZ_DIAGNOSTIC_ASSERT(false, "Already shutting down.");
}
};
+void
+MediaDecoderStateMachine::
+StateObject::HandleNotDecoded(MediaData::Type aType, const MediaResult& aError)
+{
+ bool isAudio = aType == MediaData::AUDIO_DATA;
+ MOZ_ASSERT_IF(!isAudio, aType == MediaData::VIDEO_DATA);
+
+ // If the decoder is waiting for data, we tell it to call us back when the
+ // data arrives.
+ if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
+ MOZ_ASSERT(Reader()->IsWaitForDataSupported(),
+ "Readers that send WAITING_FOR_DATA need to implement WaitForData");
+ Reader()->WaitForData(aType);
+ HandleWaitingForData();
+ return;
+ }
+
+ if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
+ if (isAudio) {
+ mMaster->EnsureAudioDecodeTaskQueued();
+ } else {
+ mMaster->EnsureVideoDecodeTaskQueued();
+ }
+ return;
+ }
+
+ // If this is a decode error, delegate to the generic error path.
+ if (aError != NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
+ mMaster->DecodeError(aError);
+ return;
+ }
+
+ // This is an EOS. Finish off the queue, and then handle things based on our
+ // state.
+ if (isAudio) {
+ AudioQueue().Finish();
+ } else {
+ VideoQueue().Finish();
+ }
+
+ HandleEndOfStream();
+}
+
RefPtr<MediaDecoder::SeekPromise>
MediaDecoderStateMachine::
StateObject::HandleSeek(SeekTarget aTarget)
{
SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
SeekJob seekJob;
seekJob.mTarget = aTarget;
return SetState<SeekingState>(Move(seekJob), EventVisibility::Observable);
@@ -1971,58 +2020,18 @@ MediaDecoderStateMachine::OnVideoPopped(
void
MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
const MediaResult& aError)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(mState != DECODER_STATE_SEEKING);
SAMPLE_LOG("OnNotDecoded (aType=%u, aError=%u)", aType, aError.Code());
- bool isAudio = aType == MediaData::AUDIO_DATA;
- MOZ_ASSERT_IF(!isAudio, aType == MediaData::VIDEO_DATA);
-
- if (IsShutdown()) {
- // Already shutdown;
- return;
- }
-
- // If the decoder is waiting for data, we tell it to call us back when the
- // data arrives.
- if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
- MOZ_ASSERT(mReader->IsWaitForDataSupported(),
- "Readers that send WAITING_FOR_DATA need to implement WaitForData");
- mReader->WaitForData(aType);
- mStateObj->HandleWaitingForData();
- return;
- }
-
- if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
- if (isAudio) {
- EnsureAudioDecodeTaskQueued();
- } else {
- EnsureVideoDecodeTaskQueued();
- }
- return;
- }
-
- // If this is a decode error, delegate to the generic error path.
- if (aError != NS_ERROR_DOM_MEDIA_END_OF_STREAM) {
- DecodeError(aError);
- return;
- }
-
- // This is an EOS. Finish off the queue, and then handle things based on our
- // state.
- if (isAudio) {
- AudioQueue().Finish();
- } else {
- VideoQueue().Finish();
- }
-
- mStateObj->HandleEndOfStream();
+
+ mStateObj->HandleNotDecoded(aType, aError);
}
void
MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideo,
TimeStamp aDecodeStartTime)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(aVideo);