Bug 1267637: P1. Consider invalid an AudioData with more than 8 audio channels. r?gerald
Add AudioConfig::IsValid() method
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -29,16 +29,19 @@ public:
const nsACString& aValue)
: mKey(aKey)
, mValue(aValue)
{}
nsCString mKey;
nsCString mValue;
};
+ // Maximum channel number we can currently handle (7.1)
+#define MAX_AUDIO_CHANNELS 8
+
class TrackInfo {
public:
enum TrackType {
kUndefinedTrack,
kAudioTrack,
kVideoTrack,
kTextTrack
};
@@ -299,17 +302,17 @@ public:
, mExtendedProfile(aOther.mExtendedProfile)
, mCodecSpecificConfig(aOther.mCodecSpecificConfig)
, mExtraData(aOther.mExtraData)
{
}
bool IsValid() const override
{
- return mChannels > 0 && mRate > 0;
+ return mChannels > 0 && mChannels <= MAX_AUDIO_CHANNELS && mRate > 0;
}
AudioInfo* GetAsAudioInfo() override
{
return this;
}
const AudioInfo* GetAsAudioInfo() const override
@@ -511,19 +514,16 @@ private:
UniquePtr<TrackInfo> mInfo;
// A unique ID, guaranteed to change when changing streams.
uint32_t mStreamSourceID;
public:
const nsCString& mMimeType;
};
-// 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,
@@ -653,16 +653,21 @@ public:
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;