Bug 1208371 - Don't treat audio chunks as mutable in MediaPipeline. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 10 Mar 2016 15:36:10 +0100
changeset 342184 78acdeee3d6ff5cec1bf1dccb7014a01edea913b
parent 342183 6fc4f359d6ad3aaad42cf9fc1ca4b2755be65111
child 342185 67ce299bed056656c11826e39acf2e5eeb602767
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersjesup
bugs1208371
milestone47.0a1
Bug 1208371 - Don't treat audio chunks as mutable in MediaPipeline. r?jesup MozReview-Commit-ID: 26VPBK2WOsB
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1180,44 +1180,35 @@ void MediaPipelineTransmit::PipelineList
 
   // Convert to interleaved, 16-bits integer audio, with a maximum of two
   // channels (since the WebRTC.org code below makes the assumption that the
   // input audio is either mono or stereo).
   uint32_t outputChannels = chunk.ChannelCount() == 1 ? 1 : 2;
   const int16_t* samples = nullptr;
   UniquePtr<int16_t[]> convertedSamples;
 
-  // If this track is not enabled, simply ignore the data in the chunk.
-  if (!enabled_) {
-    chunk.mBufferFormat = AUDIO_FORMAT_SILENCE;
-  }
-
   // We take advantage of the fact that the common case (microphone directly to
   // PeerConnection, that is, a normal call), the samples are already 16-bits
   // mono, so the representation in interleaved and planar is the same, and we
   // can just use that.
-  if (outputChannels == 1 && chunk.mBufferFormat == AUDIO_FORMAT_S16) {
+  if (enabled_ && outputChannels == 1 && chunk.mBufferFormat == AUDIO_FORMAT_S16) {
     samples = chunk.ChannelData<int16_t>().Elements()[0];
   } else {
     convertedSamples = MakeUnique<int16_t[]>(chunk.mDuration * outputChannels);
 
-    switch (chunk.mBufferFormat) {
-        case AUDIO_FORMAT_FLOAT32:
-          DownmixAndInterleave(chunk.ChannelData<float>(),
-                               chunk.mDuration, chunk.mVolume, outputChannels,
-                               convertedSamples.get());
-          break;
-        case AUDIO_FORMAT_S16:
-          DownmixAndInterleave(chunk.ChannelData<int16_t>(),
-                               chunk.mDuration, chunk.mVolume, outputChannels,
-                               convertedSamples.get());
-          break;
-        case AUDIO_FORMAT_SILENCE:
-          PodZero(convertedSamples.get(), chunk.mDuration * outputChannels);
-          break;
+    if (!enabled_ || chunk.mBufferFormat == AUDIO_FORMAT_SILENCE) {
+      PodZero(convertedSamples.get(), chunk.mDuration * outputChannels);
+    } else if (chunk.mBufferFormat == AUDIO_FORMAT_FLOAT32) {
+      DownmixAndInterleave(chunk.ChannelData<float>(),
+                           chunk.mDuration, chunk.mVolume, outputChannels,
+                           convertedSamples.get());
+    } else if (chunk.mBufferFormat == AUDIO_FORMAT_S16) {
+      DownmixAndInterleave(chunk.ChannelData<int16_t>(),
+                           chunk.mDuration, chunk.mVolume, outputChannels,
+                           convertedSamples.get());
     }
     samples = convertedSamples.get();
   }
 
   MOZ_ASSERT(!(rate%100)); // rate should be a multiple of 100
 
   // Check if the rate or the number of channels has changed since the last time
   // we came through. I realize it may be overkill to check if the rate has