Bug 901633 - Part 7 - Update AudioNodeExternalInputStream to use the new AudioChunk methods. r=karlt
authorPaul Adenot <paul@paul.cx>
Wed, 29 Jul 2015 18:37:18 +0200
changeset 260329 f13da3f6b4943b43dfab477af39f8c01fff26bc5
parent 260328 10869420ec36d5db74ad3e40d26616c56f137895
child 260330 4547ae1e73ee9df217c1b8c007820bf4fb1bf792
push id29307
push userryanvm@gmail.com
push dateWed, 02 Sep 2015 01:01:53 +0000
treeherdermozilla-central@e2eb0442ece9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs901633
milestone43.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 901633 - Part 7 - Update AudioNodeExternalInputStream to use the new AudioChunk methods. r=karlt
dom/media/webaudio/AudioNodeExternalInputStream.cpp
--- a/dom/media/webaudio/AudioNodeExternalInputStream.cpp
+++ b/dom/media/webaudio/AudioNodeExternalInputStream.cpp
@@ -37,55 +37,43 @@ AudioNodeExternalInputStream::Create(Med
   return stream.forget();
 }
 
 /**
  * Copies the data in aInput to aOffsetInBlock within aBlock.
  * aBlock must have been allocated with AllocateInputBlock and have a channel
  * count that's a superset of the channels in aInput.
  */
+template <typename T>
 static void
-CopyChunkToBlock(const AudioChunk& aInput, AudioChunk *aBlock,
+CopyChunkToBlock(AudioChunk& aInput, AudioChunk *aBlock,
                  uint32_t aOffsetInBlock)
 {
   uint32_t blockChannels = aBlock->ChannelCount();
-  nsAutoTArray<const void*,2> channels;
+  nsAutoTArray<const T*,2> channels;
   if (aInput.IsNull()) {
     channels.SetLength(blockChannels);
     PodZero(channels.Elements(), blockChannels);
   } else {
-    channels.SetLength(aInput.ChannelCount());
-    PodCopy(channels.Elements(), aInput.mChannelData.Elements(), channels.Length());
+    const nsTArray<const T*>& inputChannels = aInput.ChannelData<T>();
+    channels.SetLength(inputChannels.Length());
+    PodCopy(channels.Elements(), inputChannels.Elements(), channels.Length());
     if (channels.Length() != blockChannels) {
       // We only need to upmix here because aBlock's channel count has been
       // chosen to be a superset of the channel count of every chunk.
-      AudioChannelsUpMix(&channels, blockChannels, nullptr);
+      AudioChannelsUpMix(&channels, blockChannels, static_cast<T*>(nullptr));
     }
   }
 
-  uint32_t duration = aInput.GetDuration();
   for (uint32_t c = 0; c < blockChannels; ++c) {
     float* outputData = aBlock->ChannelFloatsForWrite(c) + aOffsetInBlock;
     if (channels[c]) {
-      switch (aInput.mBufferFormat) {
-      case AUDIO_FORMAT_FLOAT32:
-        ConvertAudioSamplesWithScale(
-            static_cast<const float*>(channels[c]), outputData, duration,
-            aInput.mVolume);
-        break;
-      case AUDIO_FORMAT_S16:
-        ConvertAudioSamplesWithScale(
-            static_cast<const int16_t*>(channels[c]), outputData, duration,
-            aInput.mVolume);
-        break;
-      default:
-        NS_ERROR("Unhandled format");
-      }
+      ConvertAudioSamplesWithScale(channels[c], outputData, aInput.GetDuration(), aInput.mVolume);
     } else {
-      PodZero(outputData, duration);
+      PodZero(outputData, aInput.GetDuration());
     }
   }
 }
 
 /**
  * Converts the data in aSegment to a single chunk aBlock. aSegment must have
  * duration WEBAUDIO_BLOCK_SIZE. aFallbackChannelCount is a superset of the
  * channels in every chunk of aSegment. aBlock must be float format or null.
@@ -106,17 +94,28 @@ static void ConvertSegmentToAudioBlock(A
       return;
     }
   }
 
   AllocateAudioBlock(aFallbackChannelCount, aBlock);
 
   uint32_t duration = 0;
   for (AudioSegment::ChunkIterator ci(*aSegment); !ci.IsEnded(); ci.Next()) {
-    CopyChunkToBlock(*ci, aBlock, duration);
+    switch (ci->mBufferFormat) {
+      case AUDIO_FORMAT_S16: {
+        CopyChunkToBlock<int16_t>(*ci, aBlock, duration);
+        break;
+      }
+      case AUDIO_FORMAT_FLOAT32: {
+        CopyChunkToBlock<float>(*ci, aBlock, duration);
+        break;
+      }
+      case AUDIO_FORMAT_SILENCE:
+        break;
+    }
     duration += ci->GetDuration();
   }
 }
 
 void
 AudioNodeExternalInputStream::ProcessInput(GraphTime aFrom, GraphTime aTo,
                                            uint32_t aFlags)
 {