Bug 1248861: P9. Use ChannelLayout::MappingTable. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 07 Apr 2016 15:26:20 +1000
changeset 292694 cce16017b59d6edbc0b080cba59b9f12526880be
parent 292693 bf78ded55e21463df4a8e5878afa396ccbd41100
child 292695 3e1ffa75a042d7cab3d00a472e6811df216ee152
push id74954
push userjyavenard@mozilla.com
push dateTue, 12 Apr 2016 03:01:39 +0000
treeherdermozilla-inbound@ef6f7eda31ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1248861
milestone48.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 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