Bug 1248861: P8. Added ChannelLayout::MappingTable method. r=gerald
☠☠ backed out by e9251880e176 ☠ ☠
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 07 Apr 2016 15:11:59 +1000
changeset 316222 8f981dd66bee23242dc578c68e746bc28a9329f4
parent 316221 becc0e4fbbb50b0ec0e73344dc965e11e3a2ba31
child 316223 24b970861675c0cfa10876b770942def8634b73d
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: P8. Added ChannelLayout::MappingTable method. r=gerald MozReview-Commit-ID: 5kRa08TpGTX
dom/media/MediaInfo.cpp
dom/media/MediaInfo.h
--- a/dom/media/MediaInfo.cpp
+++ b/dom/media/MediaInfo.cpp
@@ -94,16 +94,38 @@ AudioConfig::ChannelLayout::SMPTEDefault
       static const Channel config[] = { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RLS, CHANNEL_RRS, CHANNEL_LS, CHANNEL_RS };
       return config;
     }
     default:
       return nullptr;
   }
 }
 
+bool
+AudioConfig::ChannelLayout::MappingTable(const ChannelLayout& aOther,
+                                         uint8_t* aMap) const
+{
+  if (!IsValid() || !aOther.IsValid() ||
+      Map() != aOther.Map()) {
+    return false;
+  }
+  if (!aMap) {
+    return true;
+  }
+  for (uint32_t i = 0; i < Count(); i++) {
+    for (uint32_t j = 0; j < Count(); j++) {
+      if (aOther[j] == mChannels[i]) {
+        aMap[j] = i;
+        break;
+      }
+    }
+  }
+  return true;
+}
+
 /**
  * AudioConfig::ChannelConfig
  */
 
 /* static */ const char*
 AudioConfig::FormatToString(AudioConfig::SampleFormat aFormat)
 {
   switch (aFormat) {
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -522,16 +522,26 @@ public:
     uint32_t Count() const
     {
       return mChannels.Length();
     }
     uint32_t Map() const
     {
       return mChannelMap;
     }
+    // Calculate the mapping table from the current layout to aOther such that
+    // one can easily go from one layout to the other by doing:
+    // out[channel] = in[map[channel]].
+    // Returns true if the reordering is possible or false otherwise.
+    // If true, then aMap, if set, will be updated to contain the mapping table
+    // allowing conversion from the current layout to aOther.
+    // If aMap is nullptr, then MappingTable can be used to simply determine if
+    // the current layout can be easily reordered to aOther.
+    // aMap must be an array of size MAX_AUDIO_CHANNELS.
+    bool MappingTable(const ChannelLayout& aOther, uint8_t* aMap = nullptr) const;
     bool IsValid() const {
       return mValid;
     }
     bool HasChannel(Channel aChannel) const
     {
       return mChannelMap & (1 << aChannel);
     }
   private: