From 291e7ca6b48d04b904a6dd26c8039df0e9aef0ea Mon Sep 17 00:00:00 2001 From: JW Wang Date: Wed, 8 Mar 2017 20:44:43 +0800 Subject: [PATCH] Bug 1345711 - Ensure MediaDecoderStateMachine::InitializationTask() is the first task to run on the task queue. r=kaku MozReview-Commit-ID: KCtXmckLkZr --HG-- extra : rebase_source : 10e36d96f795084f2d9803e08092b7cfad034f35 extra : intermediate-source : 64bef3af2e55f579250c500c1760ea8c36caccb8 extra : source : b37cc5f40ac90d0c0d63ab4915238982033e5ca4 --- dom/media/MediaDecoderStateMachine.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index d785a94c2f49..ade9f04f6bd8 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2682,6 +2682,11 @@ MediaDecoderStateMachine::InitializationTask(MediaDecoder* aDecoder) mWatchManager.Watch(mIsVisible, &MediaDecoderStateMachine::VisibilityChanged); } + + MOZ_ASSERT(!mStateObj); + auto* s = new DecodeMetadataState(this); + mStateObj.reset(s); + s->Enter(); } void @@ -2817,7 +2822,7 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) // Dispatch initialization that needs to happen on that task queue. nsCOMPtr r = NewRunnableMethod>( this, &MediaDecoderStateMachine::InitializationTask, aDecoder); - mTaskQueue->Dispatch(r.forget()); + mTaskQueue->DispatchStateChange(r.forget()); mAudioQueueListener = AudioQueue().PopEvent().Connect( mTaskQueue, this, &MediaDecoderStateMachine::OnAudioPopped); @@ -2840,14 +2845,6 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); - RefPtr self = this; - OwnerThread()->Dispatch(NS_NewRunnableFunction([self] () { - MOZ_ASSERT(!self->mStateObj); - auto s = new DecodeMetadataState(self); - self->mStateObj.reset(s); - s->Enter(); - })); - return NS_OK; }