void AudioSink::SetPlaying(bool aPlaying) { AssertCurrentThreadInMonitor(); mPlaying = aPlaying; GetReentrantMonitor().NotifyAll(); }
void AudioSink::UpdateStreamSettings() { AssertCurrentThreadInMonitor(); bool setVolume = mSetVolume; bool setPlaybackRate = mSetPlaybackRate; bool setPreservesPitch = mSetPreservesPitch; double volume = mVolume; double playbackRate = mPlaybackRate; bool preservesPitch = mPreservesPitch; mSetVolume = false; mSetPlaybackRate = false; mSetPreservesPitch = false; { ReentrantMonitorAutoExit exit(GetReentrantMonitor()); if (setVolume) { mAudioStream->SetVolume(volume); } if (setPlaybackRate && NS_FAILED(mAudioStream->SetPlaybackRate(playbackRate))) { NS_WARNING("Setting the playback rate failed in AudioSink."); } if (setPreservesPitch && NS_FAILED(mAudioStream->SetPreservesPitch(preservesPitch))) { NS_WARNING("Setting the pitch preservation failed in AudioSink."); } } }
void AudioSink::SetVolume(double aVolume) { AssertCurrentThreadInMonitor(); mVolume = aVolume; mSetVolume = true; }
void AudioSink::SetPreservesPitch(bool aPreservesPitch) { AssertCurrentThreadInMonitor(); mPreservesPitch = aPreservesPitch; mSetPreservesPitch = true; }
void AudioSink::StopPlayback() { AssertCurrentThreadInMonitor(); mPlaying = false; GetReentrantMonitor().NotifyAll(); }
bool AudioSink::HasUnplayedFrames() { AssertCurrentThreadInMonitor(); // Experimentation suggests that GetPositionInFrames() is zero-indexed, // so we need to add 1 here before comparing it to mWritten. return mAudioStream && mAudioStream->GetPositionInFrames() + 1 < mWritten; }
void AudioSink::SetPlaybackRate(double aPlaybackRate) { AssertCurrentThreadInMonitor(); NS_ASSERTION(mPlaybackRate != 0, "Don't set the playbackRate to 0 on AudioStream"); mPlaybackRate = aPlaybackRate; mSetPlaybackRate = true; }
void AudioSink::Cleanup() { AssertCurrentThreadInMonitor(); mEndPromise.Resolve(true, __func__); // Since the promise if resolved asynchronously, we don't shutdown // AudioStream here so MDSM::ResyncAudioClock can get the correct // audio position. }
void AudioSink::PrepareToShutdown() { AssertCurrentThreadInMonitor(); mStopAudioThread = true; if (mAudioStream) { mAudioStream->Cancel(); } GetReentrantMonitor().NotifyAll(); }
void AudioSink::Cleanup() { // Must hold lock while shutting down and anulling the audio stream to prevent // state machine thread trying to use it while we're destroying it. AssertCurrentThreadInMonitor(); mAudioStream->Shutdown(); mAudioStream = nullptr; mStateMachine->OnAudioSinkComplete(); }
void AudioSink::Cleanup() { AssertCurrentThreadInMonitor(); nsRefPtr<AudioStream> audioStream; audioStream.swap(mAudioStream); mStateMachine->OnAudioSinkComplete(); ReentrantMonitorAutoExit exit(GetReentrantMonitor()); audioStream->Shutdown(); }
void AudioSink::WaitForAudioToPlay() { // Wait while we're not playing, and we're not shutting down, or we're // playing and we've got no audio to play. AssertCurrentThreadInMonitor(); while (!mStopAudioThread && (!mPlaying || ExpectMoreAudioData())) { if (!mPlaying && !mAudioStream->IsPaused()) { mAudioStream->Pause(); } GetReentrantMonitor().Wait(); } }
void AudioSink::Drain() { MOZ_ASSERT(mPlaying && !mAudioStream->IsPaused()); AssertCurrentThreadInMonitor(); // If the media was too short to trigger the start of the audio stream, // start it now. mAudioStream->Start(); { ReentrantMonitorAutoExit exit(GetReentrantMonitor()); mAudioStream->Drain(); } }
int64_t AudioSink::GetPosition() { AssertCurrentThreadInMonitor(); int64_t pos; if (mAudioStream && (pos = mAudioStream->GetPosition()) >= 0) { // Update the last good position when we got a good one. mLastGoodPosition = pos; } return mStartTime + mLastGoodPosition; }
void AudioSink::Cleanup() { AssertCurrentThreadInMonitor(); nsRefPtr<AudioStream> audioStream; audioStream.swap(mAudioStream); // Suppress the callback when the stop is requested by MediaDecoderStateMachine. // See Bug 115334. if (!mStopAudioThread) { mStateMachine->DispatchOnAudioSinkComplete(); } ReentrantMonitorAutoExit exit(GetReentrantMonitor()); audioStream->Shutdown(); }
bool AudioSink::IsPlaybackContinuing() { AssertCurrentThreadInMonitor(); if (mPlaying && mAudioStream->IsPaused()) { mAudioStream->Resume(); } // If we're shutting down, captured, or at EOS, break out and exit the audio // thread. if (mStopAudioThread || AudioQueue().AtEndOfStream()) { return false; } UpdateStreamSettings(); return true; }