Bug 1248861: P8. Added ChannelLayout::MappingTable method. r?gerald
MozReview-Commit-ID: 5kRa08TpGTX
--- 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: