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
This commit is contained in:
JW Wang 2017-06-07 14:10:26 +08:00
Родитель 4031d18757
Коммит e8a94c0927
3 изменённых файлов: 55 добавлений и 21 удалений

Просмотреть файл

@ -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<MediaSourceDecoder> 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<MediaDecoder> 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<MediaDecoder> 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();

Просмотреть файл

@ -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<double>())
, 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);
//

Просмотреть файл

@ -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<bool> mStateMachineIsShutdown;
@ -755,9 +776,6 @@ protected:
// Volume of playback. 0.0 = muted. 1.0 = full volume.
Canonical<double> mVolume;
// PlaybackRate and pitch preservation status we should start at.
double mPlaybackRate = 1;
Canonical<bool> mPreservesPitch;
// Media duration set explicitly by JS. At present, this is only ever present