summaryrefslogtreecommitdiff
path: root/dom/media/MediaInfo.h
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-04-05 17:00:28 +0200
committerMoonchild <moonchild@palemoon.org>2022-04-05 17:00:28 +0200
commit3b575dfced55cf78871937b6bd41942374c95390 (patch)
treea56f756f47a7ae3e45d66ccf02279ac2d22f0d1f /dom/media/MediaInfo.h
parent0bc66e3b04e77af307b62371ae9f4be70b2b19b7 (diff)
downloaduxp-3b575dfced55cf78871937b6bd41942374c95390.tar.gz
Revert "Merge pull request 'Update libcubeb to latest version' (#1812) from athenian200/UXP:libcubeb_final into master"
This reverts commit 0bc66e3b04e77af307b62371ae9f4be70b2b19b7, reversing changes made to 6e6b5d89964ea726b264c711bdf6f02fe0c006f5.
Diffstat (limited to 'dom/media/MediaInfo.h')
-rw-r--r--dom/media/MediaInfo.h174
1 files changed, 167 insertions, 7 deletions
diff --git a/dom/media/MediaInfo.h b/dom/media/MediaInfo.h
index 29dcf2cc97..d54cf99b2d 100644
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -33,6 +33,9 @@ public:
nsCString mValue;
};
+ // Maximum channel number we can currently handle (7.1)
+#define MAX_AUDIO_CHANNELS 8
+
class TrackInfo {
public:
enum TrackType {
@@ -314,7 +317,6 @@ public:
EmptyString(), EmptyString(), true, 1)
, mRate(0)
, mChannels(0)
- , mChannelMap(AudioConfig::ChannelLayout::UNKNOWN_MAP)
, mBitDepth(0)
, mProfile(0)
, mExtendedProfile(0)
@@ -327,7 +329,6 @@ public:
: TrackInfo(aOther)
, mRate(aOther.mRate)
, mChannels(aOther.mChannels)
- , mChannelMap(aOther.mChannelMap)
, mBitDepth(aOther.mBitDepth)
, mProfile(aOther.mProfile)
, mExtendedProfile(aOther.mExtendedProfile)
@@ -364,11 +365,6 @@ public:
// Number of audio channels.
uint32_t mChannels;
- // The AudioConfig::ChannelLayout map. Channels are ordered as per SMPTE
- // definition. A value of UNKNOWN_MAP indicates unknown layout.
- // ChannelMap is an unsigned bitmap compatible with Windows' WAVE and FFmpeg
- // channel map.
- uint32_t mChannelMap;
// Bits per sample.
uint32_t mBitDepth;
@@ -559,6 +555,170 @@ 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