From 6932daf12e2be2cdfc820c0b5bf0cac2978e6ba7 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Tue, 27 Jan 2015 19:30:11 +1300 Subject: [PATCH] Bug 1123535 - Don't hold decoder monitor while calling PreReadMetadata. r=kentuckyfriedtakahe --- dom/media/MediaDecoderStateMachine.cpp | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index c521ff454b6a..72259442370b 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1578,9 +1578,9 @@ void MediaDecoderStateMachine::StartDecoding() void MediaDecoderStateMachine::StartWaitForResources() { - NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(), - "Should be on state machine or decode thread."); - AssertCurrentThreadInMonitor(); + ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); + NS_ASSERTION(OnDecodeThread(), + "Should be on decode thread."); SetState(DECODER_STATE_WAIT_FOR_RESOURCES); DECODER_LOG("StartWaitForResources"); } @@ -2179,28 +2179,28 @@ nsresult MediaDecoderStateMachine::DecodeMetadata() MOZ_ASSERT(mState == DECODER_STATE_DECODING_METADATA); DECODER_LOG("Decoding Media Headers"); - mReader->PreReadMetadata(); - - if (mReader->IsWaitingMediaResources()) { - StartWaitForResources(); - return NS_OK; - } - nsresult res; MediaInfo info; + bool isAwaitingResources = false; { ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor()); - res = mReader->ReadMetadata(&info, getter_Transfers(mMetadataTags)); - } + mReader->PreReadMetadata(); - if (NS_SUCCEEDED(res)) { - if (mState == DECODER_STATE_DECODING_METADATA && - mReader->IsWaitingMediaResources()) { - // change state to DECODER_STATE_WAIT_FOR_RESOURCES + if (mReader->IsWaitingMediaResources()) { StartWaitForResources(); - // affect values only if ReadMetadata succeeds return NS_OK; } + res = mReader->ReadMetadata(&info, getter_Transfers(mMetadataTags)); + isAwaitingResources = mReader->IsWaitingMediaResources(); + } + + if (NS_SUCCEEDED(res) && + mState == DECODER_STATE_DECODING_METADATA && + isAwaitingResources) { + // change state to DECODER_STATE_WAIT_FOR_RESOURCES + StartWaitForResources(); + // affect values only if ReadMetadata succeeds + return NS_OK; } if (NS_SUCCEEDED(res)) {