diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 9fca81fa8cb2..4990dff3c4f9 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -290,10 +290,7 @@ void MediaDecoder::Pause() void MediaDecoder::SetVolume(double aVolume) { MOZ_ASSERT(NS_IsMainThread()); - mInitialVolume = aVolume; - if (mDecoderStateMachine) { - mDecoderStateMachine->SetVolume(aVolume); - } + mVolume = aVolume; } void MediaDecoder::ConnectDecodedStreamToOutputStream(OutputStreamData* aStream) @@ -602,7 +599,7 @@ MediaDecoder::MediaDecoder() : mDecoderPosition(0), mPlaybackPosition(0), mCurrentTime(0.0), - mInitialVolume(0.0), + mVolume(AbstractThread::MainThread(), 0.0, "MediaDecoder::mVolume (Canonical)"), mInitialPlaybackRate(1.0), mInitialPreservesPitch(true), mDuration(-1), @@ -750,7 +747,6 @@ void MediaDecoder::SetStateMachineParameters() { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); mDecoderStateMachine->SetDuration(mDuration); - mDecoderStateMachine->SetVolume(mInitialVolume); if (GetDecodedStream()) { mDecoderStateMachine->SetAudioCaptured(); } diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 9dc3bb8c40b9..6b1940760918 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -1079,9 +1079,11 @@ protected: // It is read and written from the main thread only. double mCurrentTime; - // Volume that playback should start at. 0.0 = muted. 1.0 = full - // volume. Readable/Writeable from the main thread. - double mInitialVolume; + // Volume of playback. 0.0 = muted. 1.0 = full volume. + Canonical mVolume; +public: + AbstractCanonical* CanonicalVolume() { return &mVolume; } +protected: // PlaybackRate and pitch preservation status we should start at. // Readable/Writeable from the main thread. diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 0b53d16d29e6..b6bf1a16f1b4 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -226,7 +226,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, mDecodedAudioEndTime(-1), mVideoFrameEndTime(-1), mDecodedVideoEndTime(-1), - mVolume(1.0), + mVolume(mTaskQueue, 1.0, "MediaDecoderStateMachine::mVolume (Mirror)"), mPlaybackRate(1.0), mPreservesPitch(true), mLowAudioThresholdUsecs(detail::LOW_AUDIO_USECS), @@ -307,10 +307,13 @@ MediaDecoderStateMachine::InitializationTask() // Connect mirrors. mPlayState.Connect(mDecoder->CanonicalPlayState()); mNextPlayState.Connect(mDecoder->CanonicalNextPlayState()); + mVolume.Connect(mDecoder->CanonicalVolume()); // Initialize watchers. mWatchManager.Watch(mState, &MediaDecoderStateMachine::UpdateNextFrameStatus); mWatchManager.Watch(mAudioCompleted, &MediaDecoderStateMachine::UpdateNextFrameStatus); + mWatchManager.Watch(mVolume, &MediaDecoderStateMachine::VolumeChanged); + } bool MediaDecoderStateMachine::HasFutureAudio() { @@ -1355,11 +1358,10 @@ void MediaDecoderStateMachine::SetState(State aState) mSentPlaybackEndedEvent = false; } -void MediaDecoderStateMachine::SetVolume(double volume) +void MediaDecoderStateMachine::VolumeChanged() { - NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); + MOZ_ASSERT(OnTaskQueue()); ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); - mVolume = volume; if (mAudioSink) { mAudioSink->SetVolume(mVolume); } @@ -2545,6 +2547,7 @@ MediaDecoderStateMachine::FinishShutdown() // Disconnect canonicals and mirrors before shutting down our task queue. mPlayState.DisconnectIfConnected(); mNextPlayState.DisconnectIfConnected(); + mVolume.DisconnectIfConnected(); mNextFrameStatus.DisconnectAll(); // Shut down the watch manager before shutting down our task queue. diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 9b67e779e9fb..770b8f0e71db 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -152,9 +152,6 @@ public: return mState; } - // Set the audio volume. The decoder monitor must be obtained before - // calling this. - void SetVolume(double aVolume); void SetAudioCaptured(); // Check if the decoder needs to become dormant state. @@ -447,6 +444,7 @@ protected: already_AddRefed PopAudio(); already_AddRefed PopVideo(); + void VolumeChanged(); class WakeDecoderRunnable : public nsRunnable { public: @@ -1009,10 +1007,8 @@ protected: // on decoded video data. int64_t mDecodedVideoEndTime; - // Volume of playback. 0.0 = muted. 1.0 = full volume. Read/Written - // from the state machine and main threads. Synchronised via decoder - // monitor. - double mVolume; + // Volume of playback. 0.0 = muted. 1.0 = full volume. + Mirror mVolume; // Playback rate. 1.0 : normal speed, 0.5 : two times slower. Synchronized via // decoder monitor.