Bug 1175396 - Handle mismatched sample formats. r=jwwang, a=abillings
authorMatthew Gregan <kinetik@flim.org>
Tue, 14 Jul 2015 09:21:27 -0400
changeset 275349 7b298d7ccd2a4190168321524b1fd9f047fd4589
parent 275348 716d122771c600b4bfc443ea7e1725ad5cc200d7
child 275350 48ef6d7a94344109292a787e97615adbf86dc301
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, abillings
bugs1175396
milestone40.0
Bug 1175396 - Handle mismatched sample formats. r=jwwang, a=abillings
dom/media/AudioSink.cpp
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -362,17 +362,23 @@ uint32_t
 AudioSink::PlayFromAudioQueue()
 {
   AssertOnAudioThread();
   NS_ASSERTION(!mAudioStream->IsPaused(), "Don't play when paused");
   nsRefPtr<AudioData> audio(AudioQueue().PopFront());
 
   SINK_LOG_V("playing %u frames of audio at time %lld",
              audio->mFrames, audio->mTime);
-  mAudioStream->Write(audio->mAudioData, audio->mFrames);
+  if (audio->mRate == mInfo.mRate && audio->mChannels == mInfo.mChannels) {
+    mAudioStream->Write(audio->mAudioData, audio->mFrames);
+  } else {
+    SINK_LOG_V("mismatched sample format mInfo=[%uHz/%u channels] audio=[%uHz/%u channels]",
+               mInfo.mRate, mInfo.mChannels, audio->mRate, audio->mChannels);
+    PlaySilence(audio->mFrames);
+  }
 
   StartAudioStreamPlaybackIfNeeded();
 
   if (audio->mOffset != -1) {
     mStateMachine->DispatchOnPlaybackOffsetUpdate(audio->mOffset);
   }
   return audio->mFrames;
 }