Bug 1300497. Part 3 - move some code from FinishShutdown() to Shutdown().
We don't want to receive notifications from MediaEventSource or WatchManager once shutdown begins.
MozReview-Commit-ID: LiKUjOGuxyX
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1253,16 +1253,50 @@ MediaDecoderStateMachine::Shutdown()
// To break the cycle-reference between MediaDecoderReaderWrapper and MDSM.
CancelMediaDecoderReaderWrapperCallback();
Reset();
mMediaSink->Shutdown();
+ // Prevent dangling pointers by disconnecting the listeners.
+ mAudioQueueListener.Disconnect();
+ mVideoQueueListener.Disconnect();
+ mMetadataManager.Disconnect();
+
+ // Disconnect canonicals and mirrors before shutting down our task queue.
+ mBuffered.DisconnectIfConnected();
+ mIsReaderSuspended.DisconnectIfConnected();
+ mEstimatedDuration.DisconnectIfConnected();
+ mExplicitDuration.DisconnectIfConnected();
+ mPlayState.DisconnectIfConnected();
+ mNextPlayState.DisconnectIfConnected();
+ mVolume.DisconnectIfConnected();
+ mLogicalPlaybackRate.DisconnectIfConnected();
+ mPreservesPitch.DisconnectIfConnected();
+ mSameOriginMedia.DisconnectIfConnected();
+ mMediaPrincipalHandle.DisconnectIfConnected();
+ mPlaybackBytesPerSecond.DisconnectIfConnected();
+ mPlaybackRateReliable.DisconnectIfConnected();
+ mDecoderPosition.DisconnectIfConnected();
+ mMediaSeekable.DisconnectIfConnected();
+ mMediaSeekableOnlyInBufferedRanges.DisconnectIfConnected();
+ mIsVisible.DisconnectIfConnected();
+
+ mDuration.DisconnectAll();
+ mIsShutdown.DisconnectAll();
+ mNextFrameStatus.DisconnectAll();
+ mCurrentPosition.DisconnectAll();
+ mPlaybackOffset.DisconnectAll();
+ mIsAudioDataAudible.DisconnectAll();
+
+ // Shut down the watch manager to stop further notifications.
+ mWatchManager.Shutdown();
+
DECODER_LOG("Shutdown started");
// Put a task in the decode queue to shutdown the reader.
// the queue to spin down.
return mReader->Shutdown()
->Then(OwnerThread(), __func__, this,
&MediaDecoderStateMachine::FinishShutdown,
&MediaDecoderStateMachine::FinishShutdown)
@@ -2220,55 +2254,16 @@ MediaDecoderStateMachine::BeginShutdown(
return InvokeAsync(OwnerThread(), this, __func__,
&MediaDecoderStateMachine::Shutdown);
}
RefPtr<ShutdownPromise>
MediaDecoderStateMachine::FinishShutdown()
{
MOZ_ASSERT(OnTaskQueue());
-
- // The reader's listeners hold references to the state machine,
- // creating a cycle which keeps the state machine and its shared
- // thread pools alive. So break it here.
-
- // Prevent dangling pointers by disconnecting the listeners.
- mAudioQueueListener.Disconnect();
- mVideoQueueListener.Disconnect();
- mMetadataManager.Disconnect();
-
- // Disconnect canonicals and mirrors before shutting down our task queue.
- mBuffered.DisconnectIfConnected();
- mIsReaderSuspended.DisconnectIfConnected();
- mEstimatedDuration.DisconnectIfConnected();
- mExplicitDuration.DisconnectIfConnected();
- mPlayState.DisconnectIfConnected();
- mNextPlayState.DisconnectIfConnected();
- mVolume.DisconnectIfConnected();
- mLogicalPlaybackRate.DisconnectIfConnected();
- mPreservesPitch.DisconnectIfConnected();
- mSameOriginMedia.DisconnectIfConnected();
- mMediaPrincipalHandle.DisconnectIfConnected();
- mPlaybackBytesPerSecond.DisconnectIfConnected();
- mPlaybackRateReliable.DisconnectIfConnected();
- mDecoderPosition.DisconnectIfConnected();
- mMediaSeekable.DisconnectIfConnected();
- mMediaSeekableOnlyInBufferedRanges.DisconnectIfConnected();
- mIsVisible.DisconnectIfConnected();
-
- mDuration.DisconnectAll();
- mIsShutdown.DisconnectAll();
- mNextFrameStatus.DisconnectAll();
- mCurrentPosition.DisconnectAll();
- mPlaybackOffset.DisconnectAll();
- mIsAudioDataAudible.DisconnectAll();
-
- // Shut down the watch manager before shutting down our task queue.
- mWatchManager.Shutdown();
-
MOZ_ASSERT(mState == DECODER_STATE_SHUTDOWN,
"How did we escape from the shutdown state?");
DECODER_LOG("Shutting down state machine task queue");
return OwnerThread()->BeginShutdown();
}
void
MediaDecoderStateMachine::RunStateMachine()