From e8a94c09275526f96c02822d43d5dea10ee446a2 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Wed, 7 Jun 2017 14:10:26 +0800 Subject: [PATCH] Bug 1371200. P2 - add more fields to MediaDecoderInit. r=cpearce Now we can init some members in the constructor and remove the setters that are called only once. MozReview-Commit-ID: 2hkrIA6pFlh --HG-- extra : rebase_source : 33c008ef1508597e64ef7f92b028867dbd4ffba6 extra : source : fa213ee733ea881f4f76dac06c9b4709aeba4b91 --- dom/html/HTMLMediaElement.cpp | 39 ++++++++++++++++++++++++----------- dom/media/MediaDecoder.cpp | 11 +++++----- dom/media/MediaDecoder.h | 26 +++++++++++++++++++---- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index f0f532c8fe70..e8578e85e0d9 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -2466,7 +2466,15 @@ nsresult HTMLMediaElement::LoadResource() } if (mMediaSource) { - MediaDecoderInit decoderInit(this); + MediaDecoderInit decoderInit( + this, + mAudioChannel, + mMuted ? 0.0 : mVolume, + mPreservesPitch, + mPlaybackRate, + mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, + mHasSuspendTaint); + RefPtr decoder = new MediaSourceDecoder(decoderInit); if (!mMediaSource->Attach(decoder)) { // TODO: Handle failure: run "If the media data cannot be fetched at @@ -4592,7 +4600,15 @@ nsresult HTMLMediaElement::InitializeDecoderAsClone(MediaDecoder* aOriginal) if (!originalResource) return NS_ERROR_FAILURE; - MediaDecoderInit decoderInit(this); + MediaDecoderInit decoderInit( + this, + mAudioChannel, + mMuted ? 0.0 : mVolume, + mPreservesPitch, + mPlaybackRate, + mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, + mHasSuspendTaint); + RefPtr decoder = aOriginal->Clone(decoderInit); if (!decoder) return NS_ERROR_FAILURE; @@ -4622,7 +4638,15 @@ nsresult HTMLMediaElement::InitializeDecoderForChannel(nsIChannel* aChannel, NS_ASSERTION(!mimeType.IsEmpty(), "We should have the Content-Type."); DecoderDoctorDiagnostics diagnostics; - MediaDecoderInit decoderInit(this); + MediaDecoderInit decoderInit( + this, + mAudioChannel, + mMuted ? 0.0 : mVolume, + mPreservesPitch, + mPlaybackRate, + mPreloadAction == HTMLMediaElement::PRELOAD_METADATA, + mHasSuspendTaint); + RefPtr decoder = DecoderTraits::CreateDecoder(mimeType, decoderInit, &diagnostics); diagnostics.StoreFormatDiagnostics(OwnerDoc(), @@ -4673,15 +4697,6 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder, // Tell the decoder about its MediaResource now so things like principals are // available immediately. mDecoder->SetResource(aStream); - mDecoder->SetAudioChannel(mAudioChannel); - mDecoder->SetVolume(mMuted ? 0.0 : mVolume); - mDecoder->SetPreservesPitch(mPreservesPitch); - mDecoder->SetPlaybackRate(mPlaybackRate); - if (mPreloadAction == HTMLMediaElement::PRELOAD_METADATA) { - mDecoder->SetMinimizePrerollUntilPlaybackStarts(); - } - // Notify the decoder of suspend taint. - mDecoder->SetSuspendTaint(mHasSuspendTaint); // Notify the decoder of the initial activity status. NotifyDecoderActivityChanges(); diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 552b36dc2560..3d190bdf20b9 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -383,13 +383,15 @@ MediaDecoder::MediaDecoder(MediaDecoderInit& aInit) , mFrameStats(new FrameStatistics()) , mVideoFrameContainer(aInit.mOwner->GetVideoFrameContainer()) , mPinnedForSeek(false) - , mMinimizePreroll(false) + , mAudioChannel(aInit.mAudioChannel) + , mMinimizePreroll(aInit.mMinimizePreroll) , mFiredMetadataLoaded(false) , mIsDocumentVisible(false) , mElementVisibility(Visibility::UNTRACKED) , mIsElementInTree(false) , mForcedHidden(false) - , mHasSuspendTaint(false) + , mHasSuspendTaint(aInit.mHasSuspendTaint) + , mPlaybackRate(aInit.mPlaybackRate) , INIT_MIRROR(mStateMachineIsShutdown, true) , INIT_MIRROR(mBuffered, TimeIntervals()) , INIT_MIRROR(mNextFrameStatus, MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE) @@ -397,8 +399,8 @@ MediaDecoder::MediaDecoder(MediaDecoderInit& aInit) , INIT_MIRROR(mStateMachineDuration, NullableTimeUnit()) , INIT_MIRROR(mPlaybackPosition, 0) , INIT_MIRROR(mIsAudioDataAudible, false) - , INIT_CANONICAL(mVolume, 0.0) - , INIT_CANONICAL(mPreservesPitch, true) + , INIT_CANONICAL(mVolume, aInit.mVolume) + , INIT_CANONICAL(mPreservesPitch, aInit.mPreservesPitch) , INIT_CANONICAL(mExplicitDuration, Maybe()) , INIT_CANONICAL(mPlayState, PLAY_STATE_LOADING) , INIT_CANONICAL(mNextState, PLAY_STATE_PAUSED) @@ -416,7 +418,6 @@ MediaDecoder::MediaDecoder(MediaDecoderInit& aInit) MOZ_ASSERT(mAbstractMainThread); MediaMemoryTracker::AddMediaDecoder(this); - mAudioChannel = AudioChannelService::GetDefaultAudioChannel(); mResourceCallback->Connect(this); // diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 458c5d65a014..d692a9360f70 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -60,9 +60,27 @@ enum class Visibility : uint8_t; struct MediaDecoderInit { MediaDecoderOwner* const mOwner; + const dom::AudioChannel mAudioChannel; + const double mVolume; + const bool mPreservesPitch; + const double mPlaybackRate; + const bool mMinimizePreroll; + const bool mHasSuspendTaint; - explicit MediaDecoderInit(MediaDecoderOwner* aOwner) + MediaDecoderInit(MediaDecoderOwner* aOwner, + dom::AudioChannel aAudioChannel, + double aVolume, + bool aPreservesPitch, + double aPlaybackRate, + bool aMinimizePreroll, + bool aHasSuspendTaint) : mOwner(aOwner) + , mAudioChannel(aAudioChannel) + , mVolume(aVolume) + , mPreservesPitch(aPreservesPitch) + , mPlaybackRate(aPlaybackRate) + , mMinimizePreroll(aMinimizePreroll) + , mHasSuspendTaint(aHasSuspendTaint) { } }; @@ -728,6 +746,9 @@ protected: MediaEventListener mOnMediaNotSeekable; protected: + // PlaybackRate and pitch preservation status we should start at. + double mPlaybackRate; + // Whether the state machine is shut down. Mirror mStateMachineIsShutdown; @@ -755,9 +776,6 @@ protected: // Volume of playback. 0.0 = muted. 1.0 = full volume. Canonical mVolume; - // PlaybackRate and pitch preservation status we should start at. - double mPlaybackRate = 1; - Canonical mPreservesPitch; // Media duration set explicitly by JS. At present, this is only ever present