Bug 1286041 - Assert audio callback is not called in initialized state. r=jwwang
authorAlex Chronopoulos <achronop@gmail.com>
Tue, 12 Jul 2016 16:53:58 +0200
changeset 315180 f737abca53388fb8a00a6656d2989ece1edc590f
parent 315179 1db5e766a1ecaf1f1f501932215d717304c6fa70
child 315181 b3fe9952f090c88d53af51ee3ed49d29cbb58b06
push id32563
push userihsiao@mozilla.com
push dateMon, 26 Sep 2016 11:18:33 +0000
treeherderautoland@eb840c87b5fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1286041
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286041 - Assert audio callback is not called in initialized state. r=jwwang
dom/media/AudioStream.cpp
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -397,19 +397,22 @@ AudioStream::SetVolume(double aVolume)
   }
 }
 
 void
 AudioStream::Start()
 {
   MonitorAutoLock mon(mMonitor);
   MOZ_ASSERT(mState == INITIALIZED);
+  mState = STARTED;
   auto r = InvokeCubeb(cubeb_stream_start);
-  mState = r == CUBEB_OK ? STARTED : ERRORED;
-  LOG("started, state %s", mState == STARTED ? "STARTED" : "ERRORED");
+  if (r != CUBEB_OK) {
+    mState = ERRORED;
+  }
+  LOG("started, state %s", mState == STARTED ? "STARTED" : mState == DRAINED ? "DRAINED" : "ERRORED");
 }
 
 void
 AudioStream::Pause()
 {
   MonitorAutoLock mon(mMonitor);
   MOZ_ASSERT(mState != INITIALIZED, "Must be Start()ed.");
   MOZ_ASSERT(mState != STOPPED, "Already Pause()ed.");
@@ -591,23 +594,17 @@ long
 AudioStream::DataCallback(void* aBuffer, long aFrames)
 {
   MonitorAutoLock mon(mMonitor);
   MOZ_ASSERT(mState != SHUTDOWN, "No data callback after shutdown");
 
   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
 
   if (mAudioClock.GetInputRate() == mAudioClock.GetOutputRate()) {
     GetUnprocessed(writer);
   } else {
     GetTimeStretched(writer);