diff options
-rw-r--r-- | dom/media/MediaData.h | 167 | ||||
-rw-r--r-- | dom/media/MediaInfo.h | 167 |
2 files changed, 167 insertions, 167 deletions
diff --git a/dom/media/MediaData.h b/dom/media/MediaData.h index bec9c6076b..909841eb98 100644 --- a/dom/media/MediaData.h +++ b/dom/media/MediaData.h @@ -22,6 +22,173 @@ namespace mozilla { + // Maximum channel number we can currently handle (7.1) +#define MAX_AUDIO_CHANNELS 8 + +class AudioConfig { +public: + enum Channel { + CHANNEL_INVALID = -1, + CHANNEL_MONO = 0, + CHANNEL_LEFT, + CHANNEL_RIGHT, + CHANNEL_CENTER, + CHANNEL_LS, + CHANNEL_RS, + CHANNEL_RLS, + CHANNEL_RCENTER, + CHANNEL_RRS, + CHANNEL_LFE, + }; + + class ChannelLayout { + public: + ChannelLayout() + : mChannelMap(0) + , mValid(false) + {} + explicit ChannelLayout(uint32_t aChannels) + : ChannelLayout(aChannels, SMPTEDefault(aChannels)) + {} + ChannelLayout(uint32_t aChannels, const Channel* aConfig) + : ChannelLayout() + { + if (!aConfig) { + mValid = false; + return; + } + mChannels.AppendElements(aConfig, aChannels); + UpdateChannelMap(); + } + bool operator==(const ChannelLayout& aOther) const + { + return mChannels == aOther.mChannels; + } + bool operator!=(const ChannelLayout& aOther) const + { + return mChannels != aOther.mChannels; + } + const Channel& operator[](uint32_t aIndex) const + { + return mChannels[aIndex]; + } + 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: + void UpdateChannelMap(); + const Channel* SMPTEDefault(uint32_t aChannels) const; + AutoTArray<Channel, MAX_AUDIO_CHANNELS> mChannels; + uint32_t mChannelMap; + bool mValid; + }; + + enum SampleFormat { + FORMAT_NONE = 0, + FORMAT_U8, + FORMAT_S16, + FORMAT_S24LSB, + FORMAT_S24, + FORMAT_S32, + FORMAT_FLT, +#if defined(MOZ_SAMPLE_TYPE_FLOAT32) + FORMAT_DEFAULT = FORMAT_FLT +#elif defined(MOZ_SAMPLE_TYPE_S16) + FORMAT_DEFAULT = FORMAT_S16 +#else +#error "Not supported audio type" +#endif + }; + + AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate, + AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT, + bool aInterleaved = true); + // Will create a channel configuration from default SMPTE ordering. + AudioConfig(uint32_t aChannels, uint32_t aRate, + AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT, + bool aInterleaved = true); + + const ChannelLayout& Layout() const + { + return mChannelLayout; + } + uint32_t Channels() const + { + if (!mChannelLayout.IsValid()) { + return mChannels; + } + return mChannelLayout.Count(); + } + uint32_t Rate() const + { + return mRate; + } + SampleFormat Format() const + { + return mFormat; + } + bool Interleaved() const + { + return mInterleaved; + } + bool operator==(const AudioConfig& aOther) const + { + return mChannelLayout == aOther.mChannelLayout && + mRate == aOther.mRate && mFormat == aOther.mFormat && + mInterleaved == aOther.mInterleaved; + } + bool operator!=(const AudioConfig& aOther) const + { + return !(*this == aOther); + } + + bool IsValid() const + { + return mChannelLayout.IsValid() && Format() != FORMAT_NONE && Rate() > 0; + } + + static const char* FormatToString(SampleFormat aFormat); + static uint32_t SampleSize(SampleFormat aFormat); + static uint32_t FormatToBits(SampleFormat aFormat); + +private: + // Channels configuration. + ChannelLayout mChannelLayout; + + // Channel count. + uint32_t mChannels; + + // Sample rate. + uint32_t mRate; + + // Sample format. + SampleFormat mFormat; + + bool mInterleaved; +}; + namespace layers { class Image; class ImageContainer; diff --git a/dom/media/MediaInfo.h b/dom/media/MediaInfo.h index d54cf99b2d..658c7c3fa7 100644 --- a/dom/media/MediaInfo.h +++ b/dom/media/MediaInfo.h @@ -33,9 +33,6 @@ public: nsCString mValue; }; - // Maximum channel number we can currently handle (7.1) -#define MAX_AUDIO_CHANNELS 8 - class TrackInfo { public: enum TrackType { @@ -555,170 +552,6 @@ public: const nsCString& mMimeType; }; -class AudioConfig { -public: - enum Channel { - CHANNEL_INVALID = -1, - CHANNEL_MONO = 0, - CHANNEL_LEFT, - CHANNEL_RIGHT, - CHANNEL_CENTER, - CHANNEL_LS, - CHANNEL_RS, - CHANNEL_RLS, - CHANNEL_RCENTER, - CHANNEL_RRS, - CHANNEL_LFE, - }; - - class ChannelLayout { - public: - ChannelLayout() - : mChannelMap(0) - , mValid(false) - {} - explicit ChannelLayout(uint32_t aChannels) - : ChannelLayout(aChannels, SMPTEDefault(aChannels)) - {} - ChannelLayout(uint32_t aChannels, const Channel* aConfig) - : ChannelLayout() - { - if (!aConfig) { - mValid = false; - return; - } - mChannels.AppendElements(aConfig, aChannels); - UpdateChannelMap(); - } - bool operator==(const ChannelLayout& aOther) const - { - return mChannels == aOther.mChannels; - } - bool operator!=(const ChannelLayout& aOther) const - { - return mChannels != aOther.mChannels; - } - const Channel& operator[](uint32_t aIndex) const - { - return mChannels[aIndex]; - } - 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: - void UpdateChannelMap(); - const Channel* SMPTEDefault(uint32_t aChannels) const; - AutoTArray<Channel, MAX_AUDIO_CHANNELS> mChannels; - uint32_t mChannelMap; - bool mValid; - }; - - enum SampleFormat { - FORMAT_NONE = 0, - FORMAT_U8, - FORMAT_S16, - FORMAT_S24LSB, - FORMAT_S24, - FORMAT_S32, - FORMAT_FLT, -#if defined(MOZ_SAMPLE_TYPE_FLOAT32) - FORMAT_DEFAULT = FORMAT_FLT -#elif defined(MOZ_SAMPLE_TYPE_S16) - FORMAT_DEFAULT = FORMAT_S16 -#else -#error "Not supported audio type" -#endif - }; - - AudioConfig(const ChannelLayout& aChannelLayout, uint32_t aRate, - AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT, - bool aInterleaved = true); - // Will create a channel configuration from default SMPTE ordering. - AudioConfig(uint32_t aChannels, uint32_t aRate, - AudioConfig::SampleFormat aFormat = FORMAT_DEFAULT, - bool aInterleaved = true); - - const ChannelLayout& Layout() const - { - return mChannelLayout; - } - uint32_t Channels() const - { - if (!mChannelLayout.IsValid()) { - return mChannels; - } - return mChannelLayout.Count(); - } - uint32_t Rate() const - { - return mRate; - } - SampleFormat Format() const - { - return mFormat; - } - bool Interleaved() const - { - return mInterleaved; - } - bool operator==(const AudioConfig& aOther) const - { - return mChannelLayout == aOther.mChannelLayout && - mRate == aOther.mRate && mFormat == aOther.mFormat && - mInterleaved == aOther.mInterleaved; - } - bool operator!=(const AudioConfig& aOther) const - { - return !(*this == aOther); - } - - bool IsValid() const - { - return mChannelLayout.IsValid() && Format() != FORMAT_NONE && Rate() > 0; - } - - static const char* FormatToString(SampleFormat aFormat); - static uint32_t SampleSize(SampleFormat aFormat); - static uint32_t FormatToBits(SampleFormat aFormat); - -private: - // Channels configuration. - ChannelLayout mChannelLayout; - - // Channel count. - uint32_t mChannels; - - // Sample rate. - uint32_t mRate; - - // Sample format. - SampleFormat mFormat; - - bool mInterleaved; -}; - } // namespace mozilla #endif // MediaInfo_h |