Bug 1248861: P9. Use ChannelLayout::MappingTable. r=gerald
☠☠ backed out by 6975c0a487de ☠ ☠
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 07 Apr 2016 15:26:20 +1000
changeset 316223 24b970861675c0cfa10876b770942def8634b73d
parent 316222 8f981dd66bee23242dc578c68e746bc28a9329f4
child 316224 b6a2c92ff375367e718e3de208e33baf5a87f9a3
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1248861
milestone48.0a1
Bug 1248861: P9. Use ChannelLayout::MappingTable. r=gerald MozReview-Commit-ID: 63584qWSKrs
dom/media/AudioConverter.cpp
dom/media/AudioConverter.h
--- a/dom/media/AudioConverter.cpp
+++ b/dom/media/AudioConverter.cpp
@@ -22,34 +22,17 @@ AudioConverter::AudioConverter(const Aud
   , mOut(aOut)
 {
   MOZ_DIAGNOSTIC_ASSERT(aIn.Channels() == aOut.Channels() &&
                         aIn.Rate() == aOut.Rate() &&
                         aIn.Format() == aOut.Format() &&
                         aIn.Interleaved() == aOut.Interleaved(),
                         "Only channel reordering is supported at this stage");
   MOZ_DIAGNOSTIC_ASSERT(aOut.Interleaved(), "planar audio format not supported");
-  InitChannelMap();
-}
-
-bool
-AudioConverter::InitChannelMap()
-{
-  if (!CanReorderAudio()) {
-    return false;
-  }
-  for (uint32_t i = 0; i < mIn.Layout().Count(); i++) {
-    for (uint32_t j = 0; j < mIn.Layout().Count(); j++) {
-      if (mOut.Layout()[j] == mIn.Layout()[i]) {
-        mChannelOrderMap[j] = i;
-        break;
-      }
-    }
-  }
-  return true;
+  mIn.Layout().MappingTable(mOut.Layout(), mChannelOrderMap);
 }
 
 bool
 AudioConverter::CanWorkInPlace() const
 {
   return mIn.Channels() * mIn.Rate() * AudioConfig::SampleSize(mIn.Format()) >=
     mOut.Channels() * mOut.Rate() * AudioConfig::SampleSize(mOut.Format());
 }
@@ -68,17 +51,17 @@ AudioConverter::Process(void* aOut, cons
 }
 
 // Reorder interleaved channels.
 // Can work in place (e.g aOut == aIn).
 template <class AudioDataType>
 void
 _ReOrderInterleavedChannels(AudioDataType* aOut, const AudioDataType* aIn,
                             uint32_t aFrames, uint32_t aChannels,
-                            const uint32_t* aChannelOrderMap)
+                            const uint8_t* aChannelOrderMap)
 {
   MOZ_DIAGNOSTIC_ASSERT(aChannels <= MAX_AUDIO_CHANNELS);
   AudioDataType val[MAX_AUDIO_CHANNELS];
   for (uint32_t i = 0; i < aFrames; i++) {
     for (uint32_t j = 0; j < aChannels; j++) {
       val[j] = aIn[aChannelOrderMap[j]];
     }
     for (uint32_t j = 0; j < aChannels; j++) {
--- a/dom/media/AudioConverter.h
+++ b/dom/media/AudioConverter.h
@@ -114,25 +114,23 @@ public:
   size_t Process(AudioDataBuffer<Type, Value>& aBuffer)
   {
     MOZ_DIAGNOSTIC_ASSERT(mIn.Format() == mOut.Format() && mIn.Format() == Type);
     return Process(aBuffer.Data(), aBuffer.Data(), aBuffer.Size());
   }
   bool CanWorkInPlace() const;
   bool CanReorderAudio() const
   {
-    return mIn.Layout().IsValid() && mOut.Layout().IsValid() &&
-      mIn.Layout().Map() == mOut.Layout().Map();
+    return mIn.Layout().MappingTable(mOut.Layout());
   }
 
 private:
   const AudioConfig mIn;
   const AudioConfig mOut;
-  uint32_t mChannelOrderMap[MAX_AUDIO_CHANNELS];
-  bool InitChannelMap();
+  uint8_t mChannelOrderMap[MAX_AUDIO_CHANNELS];
   /**
    * Process
    * Parameters:
    * aOut  : destination buffer where converted samples will be copied
    * aIn   : source buffer
    * aBytes: size in bytes of source buffer
    *
    * Return Value: size in bytes of samples converted or 0 if error