diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 598b85c8c24..e9e86242cc9 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -596,6 +596,9 @@ bool MediaDecoder::IsInfinite() MediaDecoder::MediaDecoder() : mWatchManager(this), + mNextFrameStatus(AbstractThread::MainThread(), + MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED, + "MediaDecoder::mNextFrameStatus (Mirror)"), mDecoderPosition(0), mPlaybackPosition(0), mCurrentTime(0.0), @@ -606,6 +609,10 @@ MediaDecoder::MediaDecoder() : mMediaSeekable(true), mSameOriginMedia(false), mReentrantMonitor("media.decoder"), + mPlayState(AbstractThread::MainThread(), PLAY_STATE_LOADING, + "MediaDecoder::mPlayState (Canonical)"), + mNextState(AbstractThread::MainThread(), PLAY_STATE_PAUSED, + "MediaDecoder::mNextState (Canonical)"), mIgnoreProgressData(false), mInfiniteStream(false), mOwner(nullptr), @@ -628,15 +635,6 @@ MediaDecoder::MediaDecoder() : MOZ_ASSERT(NS_IsMainThread()); MediaMemoryTracker::AddMediaDecoder(this); - // Initialize canonicals. - mPlayState.Init(AbstractThread::MainThread(), PLAY_STATE_LOADING, "MediaDecoder::mPlayState (Canonical)"); - mNextState.Init(AbstractThread::MainThread(), PLAY_STATE_PAUSED, "MediaDecoder::mNextState (Canonical)"); - - // Initialize mirrors. - mNextFrameStatus.Init(AbstractThread::MainThread(), MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED, - "MediaDecoder::mNextFrameStatus (Mirror)"); - - mAudioChannel = AudioChannelService::GetDefaultAudioChannel(); // Initialize watchers. diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 6ba720c22cd..cf8a0ba4563 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -212,6 +212,14 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, mStartTime(-1), mEndTime(-1), mDurationSet(false), + mPlayState(mTaskQueue, MediaDecoder::PLAY_STATE_LOADING, + "MediaDecoderStateMachine::mPlayState (Mirror)", + aDecoder->CanonicalPlayState()), + mNextPlayState(mTaskQueue, MediaDecoder::PLAY_STATE_PAUSED, + "MediaDecoderStateMachine::mNextPlayState (Mirror)", + aDecoder->CanonicalNextPlayState()), + mNextFrameStatus(mTaskQueue, MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED, + "MediaDecoderStateMachine::mNextFrameStatus (Canonical)"), mFragmentEndTime(-1), mReader(aReader), mCurrentFrameTime(0), @@ -251,16 +259,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, MOZ_COUNT_CTOR(MediaDecoderStateMachine); NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); - // Initialize canonicals. - mNextFrameStatus.Init(mTaskQueue, MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED, - "MediaDecoderStateMachine::mNextFrameStatus (Canonical)"); - - // Initialize mirrors. - mPlayState.Init(mTaskQueue, MediaDecoder::PLAY_STATE_LOADING, "MediaDecoderStateMachine::mPlayState (Mirror)", - aDecoder->CanonicalPlayState()); - mNextPlayState.Init(mTaskQueue, MediaDecoder::PLAY_STATE_PAUSED, "MediaDecoderStateMachine::mNextPlayState (Mirror)", - aDecoder->CanonicalNextPlayState()); - + // Initialize watchers. mWatchManager.Watch(mState, &MediaDecoderStateMachine::UpdateNextFrameStatus); mWatchManager.Watch(mAudioCompleted, &MediaDecoderStateMachine::UpdateNextFrameStatus); diff --git a/dom/media/StateMirroring.h b/dom/media/StateMirroring.h index b66f3c8ae4c..473d22ba582 100644 --- a/dom/media/StateMirroring.h +++ b/dom/media/StateMirroring.h @@ -112,8 +112,13 @@ template class Canonical { public: - Canonical() {} - ~Canonical() { MOZ_DIAGNOSTIC_ASSERT(mImpl, "Should have initialized me"); } + Canonical(AbstractThread* aThread, const T& aInitialValue, const char* aName) + { + mImpl = new Impl(aThread, aInitialValue, aName); + } + + + ~Canonical() {} private: class Impl : public AbstractCanonical, public WatchTarget @@ -233,11 +238,6 @@ public: // NB: Because mirror-initiated disconnection can race with canonical- // initiated disconnection, a canonical should never be reinitialized. - void Init(AbstractThread* aThread, const T& aInitialValue, const char* aName) - { - mImpl = new Impl(aThread, aInitialValue, aName); - } - // Forward control operations to the Impl. void DisconnectAll() { return mImpl->DisconnectAll(); } @@ -272,10 +272,14 @@ template class Mirror { public: - Mirror() {} + Mirror(AbstractThread* aThread, const T& aInitialValue, const char* aName, + AbstractCanonical* aCanonical = nullptr) + { + mImpl = new Impl(aThread, aInitialValue, aName, aCanonical); + } + ~Mirror() { - MOZ_DIAGNOSTIC_ASSERT(mImpl, "Should have initialized me"); if (mImpl->OwnerThread()->IsCurrentThreadIn()) { mImpl->DisconnectIfConnected(); } else { @@ -371,14 +375,6 @@ private: }; public: - // NB: Because mirror-initiated disconnection can race with canonical- - // initiated disconnection, a mirror should never be reinitialized. - void Init(AbstractThread* aThread, const T& aInitialValue, const char* aName, - AbstractCanonical* aCanonical = nullptr) - { - mImpl = new Impl(aThread, aInitialValue, aName, aCanonical); - } - // Forward control operations to the Impl. void Connect(AbstractCanonical* aCanonical) { mImpl->Connect(aCanonical); } void DisconnectIfConnected() { mImpl->DisconnectIfConnected(); }