diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 5e8e3941e6a..85f3ce055e2 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -836,6 +836,10 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, } else { mVideoDataRequest.Complete(); } + if (IsShutdown()) { + // Already shutdown; + return; + } // If this is a decode error, delegate to the generic error path. if (aReason == MediaDecoderReader::DECODE_ERROR) { @@ -1927,6 +1931,10 @@ MediaDecoderStateMachine::DispatchAudioDecodeTaskIfNeeded() MOZ_ASSERT(OnStateMachineThread()); ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); + if (IsShutdown()) { + return NS_ERROR_FAILURE; + } + if (NeedToDecodeAudio()) { return EnsureAudioDecodeTaskQueued(); } @@ -1973,6 +1981,10 @@ MediaDecoderStateMachine::DispatchVideoDecodeTaskIfNeeded() MOZ_ASSERT(OnStateMachineThread()); ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); + if (IsShutdown()) { + return NS_ERROR_FAILURE; + } + if (NeedToDecodeVideo()) { return EnsureVideoDecodeTaskQueued(); } diff --git a/dom/media/mediasource/MediaSourceReader.cpp b/dom/media/mediasource/MediaSourceReader.cpp index 964c32af879..b7c261d7b7f 100644 --- a/dom/media/mediasource/MediaSourceReader.cpp +++ b/dom/media/mediasource/MediaSourceReader.cpp @@ -418,6 +418,14 @@ nsRefPtr MediaSourceReader::Shutdown() { mSeekPromise.RejectIfExists(NS_ERROR_FAILURE, __func__); + // Any previous requests we've been waiting on are now unwanted. + mAudioRequest.DisconnectIfExists(); + mVideoRequest.DisconnectIfExists(); + + // Additionally, reject any outstanding promises _we_ made that we might have + // been waiting on the above to fulfill. + mAudioPromise.RejectIfExists(CANCELED, __func__); + mVideoPromise.RejectIfExists(CANCELED, __func__); MOZ_ASSERT(mMediaSourceShutdownPromise.IsEmpty()); nsRefPtr p = mMediaSourceShutdownPromise.Ensure(__func__);