Ejemplo n.º 1
0
void
AudioSink::SetPlaying(bool aPlaying)
{
  AssertCurrentThreadInMonitor();
  mPlaying = aPlaying;
  GetReentrantMonitor().NotifyAll();
}
Ejemplo n.º 2
0
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.");
    }
  }
}
Ejemplo n.º 3
0
void
AudioSink::SetVolume(double aVolume)
{
  AssertCurrentThreadInMonitor();
  mVolume = aVolume;
  mSetVolume = true;
}
Ejemplo n.º 4
0
void
AudioSink::SetPreservesPitch(bool aPreservesPitch)
{
  AssertCurrentThreadInMonitor();
  mPreservesPitch = aPreservesPitch;
  mSetPreservesPitch = true;
}
Ejemplo n.º 5
0
void
AudioSink::StopPlayback()
{
  AssertCurrentThreadInMonitor();
  mPlaying = false;
  GetReentrantMonitor().NotifyAll();
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
void
AudioSink::SetPlaybackRate(double aPlaybackRate)
{
  AssertCurrentThreadInMonitor();
  NS_ASSERTION(mPlaybackRate != 0, "Don't set the playbackRate to 0 on AudioStream");
  mPlaybackRate = aPlaybackRate;
  mSetPlaybackRate = true;
}
Ejemplo n.º 8
0
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.
}
Ejemplo n.º 9
0
void
AudioSink::PrepareToShutdown()
{
  AssertCurrentThreadInMonitor();
  mStopAudioThread = true;
  if (mAudioStream) {
    mAudioStream->Cancel();
  }
  GetReentrantMonitor().NotifyAll();
}
Ejemplo n.º 10
0
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();
}
Ejemplo n.º 11
0
void
AudioSink::Cleanup()
{
  AssertCurrentThreadInMonitor();
  nsRefPtr<AudioStream> audioStream;
  audioStream.swap(mAudioStream);
  mStateMachine->OnAudioSinkComplete();

  ReentrantMonitorAutoExit exit(GetReentrantMonitor());
  audioStream->Shutdown();
}
Ejemplo n.º 12
0
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();
  }
}
Ejemplo n.º 13
0
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();
  }
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
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();
}
Ejemplo n.º 16
0
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;
}