Bug 1175396 - Handle mismatched sample formats. r=jwwang, a=2.1+
authorMatthew Gregan <kinetik@flim.org>
Tue, 14 Jul 2015 09:21:27 -0400
changeset 222171 fe4c34c770e5
parent 222170 ab048a85e6a1
child 222172 29d54b125d3a
push id555
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 22:36:13 +0000
treeherdermozilla-b2g34_v2_1@fe4c34c770e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, 2
bugs1175396
milestone34.0
Bug 1175396 - Handle mismatched sample formats. r=jwwang, a=2.1+
content/media/AudioSink.cpp
--- a/content/media/AudioSink.cpp
+++ b/content/media/AudioSink.cpp
@@ -298,17 +298,23 @@ AudioSink::PlayFromAudioQueue()
     ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
     NS_WARN_IF_FALSE(mPlaying, "Should be playing");
     // Awaken the decode loop if it's waiting for space to free up in the
     // audio queue.
     GetReentrantMonitor().NotifyAll();
   }
   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->OnPlaybackOffsetUpdate(audio->mOffset);
   }
   return audio->mFrames;
 }