From 78730160f58b5e49e93e7e638a3f316f887c0283 Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Tue, 12 Apr 2016 17:00:29 +1000 Subject: [PATCH] Bug 1224973 - Part 3: Plumb element visibility into MDSM. r=jya,jwwang change MediaDecoder::mIsVisible to be a Canonical and plumb through to the MediaDecoderStateMachine. This will be used to trigger suspending the decoding of video frames. MozReview-Commit-ID: F3Dpf0ogE7c --- dom/media/AbstractMediaDecoder.h | 2 +- dom/media/MediaDecoder.cpp | 5 +++-- dom/media/MediaDecoder.h | 8 ++++++-- dom/media/MediaDecoderReader.cpp | 4 ++++ dom/media/MediaDecoderReader.h | 2 ++ dom/media/MediaDecoderStateMachine.cpp | 9 +++++++++ dom/media/MediaDecoderStateMachine.h | 8 +++++++- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/dom/media/AbstractMediaDecoder.h b/dom/media/AbstractMediaDecoder.h index c4d2ed02cf9c..4d4a1c811071 100644 --- a/dom/media/AbstractMediaDecoder.h +++ b/dom/media/AbstractMediaDecoder.h @@ -62,7 +62,7 @@ public: // Return an event that will be notified when data arrives in MediaResource. // MediaDecoderReader will register with this event to receive notifications - // in order to udpate buffer ranges. + // in order to update buffer ranges. // Return null if this decoder doesn't support the event. virtual MediaEventSource* DataArrivedEvent() { diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index f438d1d22fe4..acaeff37f789 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -335,7 +335,7 @@ MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity) "ownerActive=%d mIsVisible=%d mIsHeuristicDormant=%d " "mPlayState=%s encrypted=%s", aDormantTimeout, aActivity, mIsDormant, mOwner->IsActive(), - mIsVisible, mIsHeuristicDormant, PlayStateStr(), + mIsVisible.Ref(), mIsHeuristicDormant, PlayStateStr(), (!mInfo ? "Unknown" : (mInfo->IsEncrypted() ? "1" : "0"))); bool prevDormant = mIsDormant; @@ -574,7 +574,8 @@ MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner) "MediaDecoder::mMediaSeekable (Canonical)") , mMediaSeekableOnlyInBufferedRanges(AbstractThread::MainThread(), false, "MediaDecoder::mMediaSeekableOnlyInBufferedRanges (Canonical)") - , mIsVisible(!mOwner->IsHidden()) + , mIsVisible(AbstractThread::MainThread(), !mOwner->IsHidden(), + "MediaDecoder::mIsVisible (Canonical)") , mTelemetryReported(false) { MOZ_COUNT_CTOR(MediaDecoder); diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index c1b6239b16ff..15a9fe7c991c 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -744,7 +744,7 @@ protected: // start playing back again. Mirror mPlaybackPosition; - // Used to distiguish whether the audio is producing sound. + // Used to distinguish whether the audio is producing sound. Mirror mIsAudioDataAudible; // Volume of playback. 0.0 = muted. 1.0 = full volume. @@ -806,7 +806,8 @@ protected: // True if the media is only seekable within its buffered ranges. Canonical mMediaSeekableOnlyInBufferedRanges; - bool mIsVisible; + // True if the decoder is visible. + Canonical mIsVisible; public: AbstractCanonical* CanonicalDurationOrNull() override; @@ -855,6 +856,9 @@ public: AbstractCanonical* CanonicalMediaSeekableOnlyInBufferedRanges() { return &mMediaSeekableOnlyInBufferedRanges; } + AbstractCanonical* CanonicalIsVisible() { + return &mIsVisible; + } private: // Notify owner when the audible state changed diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index 17db94596375..f8f3e1386d61 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -183,6 +183,10 @@ MediaDecoderReader::UpdateBuffered() mBuffered = GetBuffered(); } +void +MediaDecoderReader::VisibilityChanged() +{} + media::TimeIntervals MediaDecoderReader::GetBuffered() { diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index de4ab48aba89..4f9ace14d5c2 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -395,6 +395,8 @@ private: // Recomputes mBuffered. virtual void UpdateBuffered(); + virtual void VisibilityChanged(); + virtual void NotifyDataArrivedInternal() {} // Overrides of this function should decodes an unspecified amount of diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 1d1fce09027d..61757c78720b 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -271,6 +271,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, "MediaDecoderStateMachine::mMediaSeekable (Mirror)"), mMediaSeekableOnlyInBufferedRanges(mTaskQueue, false, "MediaDecoderStateMachine::mMediaSeekableOnlyInBufferedRanges (Mirror)"), + mIsVisible(mTaskQueue, true, "MediaDecoderStateMachine::mIsVisible (Mirror)"), mDuration(mTaskQueue, NullableTimeUnit(), "MediaDecoderStateMachine::mDuration (Canonical"), mIsShutdown(mTaskQueue, false, @@ -333,6 +334,7 @@ MediaDecoderStateMachine::InitializationTask(MediaDecoder* aDecoder) mDecoderPosition.Connect(aDecoder->CanonicalDecoderPosition()); mMediaSeekable.Connect(aDecoder->CanonicalMediaSeekable()); mMediaSeekableOnlyInBufferedRanges.Connect(aDecoder->CanonicalMediaSeekableOnlyInBufferedRanges()); + mIsVisible.Connect(aDecoder->CanonicalIsVisible()); // Initialize watchers. mWatchManager.Watch(mBuffered, &MediaDecoderStateMachine::BufferedRangeUpdated); @@ -346,6 +348,7 @@ MediaDecoderStateMachine::InitializationTask(MediaDecoder* aDecoder) mWatchManager.Watch(mExplicitDuration, &MediaDecoderStateMachine::RecomputeDuration); mWatchManager.Watch(mObservedDuration, &MediaDecoderStateMachine::RecomputeDuration); mWatchManager.Watch(mPlayState, &MediaDecoderStateMachine::PlayStateChanged); + mWatchManager.Watch(mIsVisible, &MediaDecoderStateMachine::VisibilityChanged); // Configure MediaDecoderReaderWrapper. SetMediaDecoderReaderWrapperCallback(); @@ -1312,6 +1315,11 @@ void MediaDecoderStateMachine::PlayStateChanged() ScheduleStateMachine(); } +void MediaDecoderStateMachine::VisibilityChanged() +{ + DECODER_LOG("VisibilityChanged: is visible = %c", mIsVisible ? 'T' : 'F'); +} + void MediaDecoderStateMachine::BufferedRangeUpdated() { MOZ_ASSERT(OnTaskQueue()); @@ -2085,6 +2093,7 @@ MediaDecoderStateMachine::FinishShutdown() mDecoderPosition.DisconnectIfConnected(); mMediaSeekable.DisconnectIfConnected(); mMediaSeekableOnlyInBufferedRanges.DisconnectIfConnected(); + mIsVisible.DisconnectIfConnected(); mDuration.DisconnectAll(); mIsShutdown.DisconnectAll(); diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 709d7e70f4c2..69bbbe392927 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -471,6 +471,9 @@ protected: // Notification method invoked when mPlayState changes. void PlayStateChanged(); + // Notification method invoked when mIsVisible changes. + void VisibilityChanged(); + // Sets internal state which causes playback of media to pause. // The decoder monitor must be held. void StopPlayback(); @@ -997,6 +1000,9 @@ private: // True if the media is seekable only in buffered ranges. Mirror mMediaSeekableOnlyInBufferedRanges; + // IsVisible, mirrored from the media decoder. + Mirror mIsVisible; + // Duration of the media. This is guaranteed to be non-null after we finish // decoding the first frame. Canonical mDuration; @@ -1016,7 +1022,7 @@ private: // Current playback position in the stream in bytes. Canonical mPlaybackOffset; - // Used to distiguish whether the audio is producing sound. + // Used to distinguish whether the audio is producing sound. Canonical mIsAudioDataAudible; public: