From 4af519df25c663cd6d97bf627b3da764258714bb Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 24 Aug 2017 18:08:37 +0800 Subject: [PATCH] Bug 1393386. P1 - make PinForSeek/UnpinForSeek pure virtual. r=gerald Sub-classes should know how to pin/unpin the resource. MozReview-Commit-ID: 50S8oSD5oEU --HG-- extra : rebase_source : 5e1b7c657b759c0d1dfdd7b5c0a4b7dbc4077ffe extra : intermediate-source : 3000b76a3b97c08955c2d584ac215114c8e8f59a extra : source : a56b9846db916ff85a0cae09736c3284bd895506 --- dom/media/ChannelMediaDecoder.cpp | 23 +++++++++++++++++++ dom/media/ChannelMediaDecoder.h | 6 +++++ dom/media/MediaDecoder.cpp | 26 ---------------------- dom/media/MediaDecoder.h | 16 +++++-------- dom/media/hls/HLSDecoder.h | 2 ++ dom/media/mediasource/MediaSourceDecoder.h | 2 ++ 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/dom/media/ChannelMediaDecoder.cpp b/dom/media/ChannelMediaDecoder.cpp index 1a2d0357dee3..562a5b7796e5 100644 --- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -537,6 +537,29 @@ ChannelMediaDecoder::Resume() } } +void +ChannelMediaDecoder::PinForSeek() +{ + MOZ_ASSERT(NS_IsMainThread()); + if (!mResource || mPinnedForSeek) { + return; + } + mPinnedForSeek = true; + mResource->Pin(); +} + +void +ChannelMediaDecoder::UnpinForSeek() +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); + if (!mResource || !mPinnedForSeek) { + return; + } + mPinnedForSeek = false; + mResource->Unpin(); +} + void ChannelMediaDecoder::MetadataLoaded( UniquePtr aInfo, diff --git a/dom/media/ChannelMediaDecoder.h b/dom/media/ChannelMediaDecoder.h index c646b6c67497..0d645a33c970 100644 --- a/dom/media/ChannelMediaDecoder.h +++ b/dom/media/ChannelMediaDecoder.h @@ -87,6 +87,8 @@ public: private: MediaResource* GetResource() const override final; + void PinForSeek() override; + void UnpinForSeek() override; // Create a new state machine to run this decoder. MediaDecoderStateMachine* CreateStateMachine(); @@ -142,6 +144,10 @@ private: // True if mPlaybackBytesPerSecond is a reliable estimate. bool mPlaybackRateReliable = true; + + // True when our media stream has been pinned. We pin the stream + // while seeking. + bool mPinnedForSeek = false; }; } // namespace mozilla diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 9eb787eef6cf..86709d56e7e6 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -366,7 +366,6 @@ MediaDecoder::MediaDecoder(MediaDecoderInit& aInit) , mAbstractMainThread(aInit.mOwner->AbstractMainThread()) , mFrameStats(new FrameStatistics()) , mVideoFrameContainer(aInit.mOwner->GetVideoFrameContainer()) - , mPinnedForSeek(false) , mMinimizePreroll(aInit.mMinimizePreroll) , mFiredMetadataLoaded(false) , mIsDocumentVisible(false) @@ -1369,31 +1368,6 @@ MediaDecoder::FireTimeUpdate() GetOwner()->FireTimeUpdate(true); } -void -MediaDecoder::PinForSeek() -{ - MOZ_ASSERT(NS_IsMainThread()); - MediaResource* resource = GetResource(); - if (!resource || mPinnedForSeek) { - return; - } - mPinnedForSeek = true; - resource->Pin(); -} - -void -MediaDecoder::UnpinForSeek() -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); - MediaResource* resource = GetResource(); - if (!resource || !mPinnedForSeek) { - return; - } - mPinnedForSeek = false; - resource->Unpin(); -} - bool MediaDecoder::CanPlayThrough() { diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 56f6799a1bcb..c90b9b3c5831 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -490,6 +490,12 @@ private: // passed to a platform decoder. virtual MediaResource* GetResource() const = 0; + // Ensures our media resource has been pinned. + virtual void PinForSeek() = 0; + + // Ensures our media resource has been unpinned. + virtual void UnpinForSeek() = 0; + nsCString GetDebugInfo(); // Called when the owner's activity changed. @@ -539,12 +545,6 @@ protected: MozPromiseRequestHolder mSeekRequest; - // Ensures our media stream has been pinned. - void PinForSeek(); - - // Ensures our media stream has been unpinned. - void UnpinForSeek(); - const char* PlayStateStr(); void OnMetadataUpdate(TimedMetadata&& aMetadata); @@ -562,10 +562,6 @@ protected: RefPtr mVideoFrameContainer; - // True when our media stream has been pinned. We pin the stream - // while seeking. - bool mPinnedForSeek; - // True if the decoder has been directed to minimize its preroll before // playback starts. After the first time playback starts, we don't attempt // to minimize preroll, as we assume the user is likely to keep playing, diff --git a/dom/media/hls/HLSDecoder.h b/dom/media/hls/HLSDecoder.h index 6153c9c1995e..e12a4214522e 100644 --- a/dom/media/hls/HLSDecoder.h +++ b/dom/media/hls/HLSDecoder.h @@ -45,6 +45,8 @@ public: private: MediaResource* GetResource() const override final; + void PinForSeek() override {} + void UnpinForSeek() override {} MediaDecoderStateMachine* CreateStateMachine(); diff --git a/dom/media/mediasource/MediaSourceDecoder.h b/dom/media/mediasource/MediaSourceDecoder.h index a188a8ae75cd..b26e54d188d7 100644 --- a/dom/media/mediasource/MediaSourceDecoder.h +++ b/dom/media/mediasource/MediaSourceDecoder.h @@ -67,6 +67,8 @@ public: private: MediaResource* GetResource() const override final; + void PinForSeek() override {} + void UnpinForSeek() override {} MediaDecoderStateMachine* CreateStateMachine(); void DoSetMediaSourceDuration(double aDuration); media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval);