From 598c3289ab305f093f633809833165a89b3abab5 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 1 May 2015 14:54:06 -0700 Subject: [PATCH] Bug 1159974 - Dispatch SetAudioCaptured. r=jww While we're at it, I figured it was time to experiment with lambdas. :-) --- dom/media/MediaDecoder.cpp | 4 ++-- dom/media/MediaDecoderStateMachine.cpp | 11 ----------- dom/media/MediaDecoderStateMachine.h | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 9b8c82d1654d..9593217bf8d5 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -535,7 +535,7 @@ void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream, { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); if (mDecoderStateMachine) { - mDecoderStateMachine->SetAudioCaptured(); + mDecoderStateMachine->DispatchAudioCaptured(); } if (!GetDecodedStream()) { int64_t t = mDecoderStateMachine ? @@ -748,7 +748,7 @@ void MediaDecoder::SetStateMachineParameters() ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); mDecoderStateMachine->SetDuration(mDuration); if (GetDecodedStream()) { - mDecoderStateMachine->SetAudioCaptured(); + mDecoderStateMachine->DispatchAudioCaptured(); } if (mMinimizePreroll) { mDecoderStateMachine->SetMinimizePrerollUntilPlaybackStarts(); diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index c9a6d293b082..4fcffd00af09 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1372,17 +1372,6 @@ void MediaDecoderStateMachine::VolumeChanged() } } -void MediaDecoderStateMachine::SetAudioCaptured() -{ - NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); - AssertCurrentThreadInMonitor(); - if (!mAudioCaptured) { - mAudioCaptured = true; - // Schedule the state machine to send stream data as soon as possible. - ScheduleStateMachine(); - } -} - double MediaDecoderStateMachine::GetCurrentTime() const { return static_cast(mCurrentFrameTime) / static_cast(USECS_PER_S); diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 4104690be21f..6eb09c8b17ea 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -152,7 +152,20 @@ public: return mState; } - void SetAudioCaptured(); + void DispatchAudioCaptured() + { + nsRefPtr self = this; + nsCOMPtr r = NS_NewRunnableFunction([self] () -> void + { + MOZ_ASSERT(self->OnTaskQueue()); + ReentrantMonitorAutoEnter mon(self->mDecoder->GetReentrantMonitor()); + if (!self->mAudioCaptured) { + self->mAudioCaptured = true; + self->ScheduleStateMachine(); + } + }); + TaskQueue()->Dispatch(r.forget()); + } // Check if the decoder needs to become dormant state. bool IsDormantNeeded();