Bug 1267637: P1. Consider invalid an AudioData with more than 8 audio channels. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 27 Apr 2016 17:34:41 +1000
changeset 356819 20d7a7ceea659c9b5fad595b08a346430335699a
parent 356818 ccd20487bda163d7dc290458e895a609ead8f52e
child 356820 bc2d723ca67847f79dd33f64db849f42ab61b158
push id16610
push userbmo:jyavenard@mozilla.com
push dateWed, 27 Apr 2016 08:08:26 +0000
reviewersgerald
bugs1267637
milestone49.0a1
Bug 1267637: P1. Consider invalid an AudioData with more than 8 audio channels. r?gerald Add AudioConfig::IsValid() method
dom/media/MediaInfo.h
--- 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;