Bug 1284177 - P1: Provide observable notification for video suspend. r=jwwang
To support mochitests, report change in video decode suspend state via
events mozentervideosuspend/mozexitvideosuspend.
MozReview-Commit-ID: EwMduLzcMVg
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -692,16 +692,22 @@ MediaDecoder::OnPlaybackEvent(MediaEvent
SeekingStarted();
break;
case MediaEventType::DecodeError:
DecodeError();
break;
case MediaEventType::Invalidate:
Invalidate();
break;
+ case MediaEventType::EnterVideoSuspend:
+ mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("mozentervideosuspend"));
+ break;
+ case MediaEventType::ExitVideoSuspend:
+ mOwner->DispatchAsyncEvent(NS_LITERAL_STRING("mozexitvideosuspend"));
+ break;
}
}
void
MediaDecoder::FinishShutdown()
{
MOZ_ASSERT(NS_IsMainThread());
mDecoderStateMachine->BreakCycles();
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1323,18 +1323,18 @@ void MediaDecoderStateMachine::PlayState
ScheduleStateMachine();
}
void MediaDecoderStateMachine::VisibilityChanged()
{
MOZ_ASSERT(OnTaskQueue());
DECODER_LOG("VisibilityChanged: mIsVisible=%d, "
- "mVideoDecodeSuspended=%d, mIsReaderSuspended=%d",
- mIsVisible.Ref(), mVideoDecodeSuspended, mIsReaderSuspended.Ref());
+ "mVideoDecodeSuspended=%c, mIsReaderSuspended=%d",
+ mIsVisible.Ref(), mVideoDecodeSuspended ? 'T' : 'F', mIsReaderSuspended.Ref());
if (!HasVideo()) {
return;
}
// If not playing then there's nothing to do.
if (mPlayState != MediaDecoder::PLAY_STATE_PLAYING) {
return;
@@ -1353,16 +1353,17 @@ void MediaDecoderStateMachine::Visibilit
// Resuming from suspended decoding
// If suspend timer exists, destroy it.
mVideoDecodeSuspendTimer.Reset();
if (mVideoDecodeSuspended) {
mVideoDecodeSuspended = false;
+ mOnPlaybackEvent.Notify(MediaEventType::ExitVideoSuspend);
mReader->SetVideoBlankDecode(false);
if (mIsReaderSuspended) {
return;
}
// If an existing seek is in flight don't bother creating a new
// one to catch up.
@@ -2924,16 +2925,17 @@ MediaDecoderStateMachine::VideoRequestSt
}
void
MediaDecoderStateMachine::OnSuspendTimerResolved()
{
DECODER_LOG("OnSuspendTimerResolved");
mVideoDecodeSuspendTimer.CompleteRequest();
mVideoDecodeSuspended = true;
+ mOnPlaybackEvent.Notify(MediaEventType::EnterVideoSuspend);
mReader->SetVideoBlankDecode(true);
}
void
MediaDecoderStateMachine::OnSuspendTimerRejected()
{
DECODER_LOG("OnSuspendTimerRejected");
MOZ_ASSERT(OnTaskQueue());
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -115,17 +115,19 @@ extern LazyLogModule gMediaDecoderLog;
extern LazyLogModule gMediaSampleLog;
enum class MediaEventType : int8_t {
PlaybackStarted,
PlaybackStopped,
PlaybackEnded,
SeekStarted,
DecodeError,
- Invalidate
+ Invalidate,
+ EnterVideoSuspend,
+ ExitVideoSuspend
};
/*
The state machine class. This manages the decoding and seeking in the
MediaDecoderReader on the decode task queue, and A/V sync on the shared
state machine thread, and controls the audio "push" thread.
All internal state is synchronised via the decoder monitor. State changes