Commit 942a71b7 authored by Alex Chronopoulos's avatar Alex Chronopoulos
Browse files

Bug 1286041 - Assert audio callback is not called in initialized state. r=jwwang

MozReview-Commit-ID: JX7QVba9O2I

--HG--
extra : rebase_source : 4058fcc3795b24fa3e209ca59a347b6e41564a65
parent b8d65507
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -400,6 +400,9 @@ AudioStream::Start()
{
  MonitorAutoLock mon(mMonitor);
  MOZ_ASSERT(mState == INITIALIZED);
  // Callback might start before the return of the invoke
  // change state to avoid any assert break.
  mState = STARTED;
  auto r = InvokeCubeb(cubeb_stream_start);
  mState = r == CUBEB_OK ? STARTED : ERRORED;
  LOG("started, state %s", mState == STARTED ? "STARTED" : "ERRORED");
@@ -593,13 +596,7 @@ AudioStream::DataCallback(void* aBuffer, long aFrames)
  auto writer = AudioBufferWriter(
    reinterpret_cast<AudioDataValue*>(aBuffer), mOutChannels, aFrames);

  // FIXME: cubeb_pulse sometimes calls us before cubeb_stream_start() is called.
  // We don't want to consume audio data until Start() is called by the client.
  if (mState == INITIALIZED) {
    NS_WARNING("data callback fires before cubeb_stream_start() is called");
    mAudioClock.UpdateFrameHistory(0, aFrames);
    return writer.WriteZeros(aFrames);
  }
  MOZ_ASSERT(mState != INITIALIZED);

  // NOTE: wasapi (others?) can call us back *after* stop()/Shutdown() (mState == SHUTDOWN)
  // Bug 996162