Bug 1285883: Limit how many frames we will parse to detect HE-AAC. r?kamidphish draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 07 Oct 2016 13:49:42 +1100
changeset 421917 8d1be920829df883a7700b83945497825ffb17a4
parent 421913 eaa2e23695e898613c7b8330506444d1f2ee4afc
child 533208 ae5e5b0f7db6b38ab51ea350d2c7a88f0762fe3b
push id31639
push userbmo:jyavenard@mozilla.com
push dateFri, 07 Oct 2016 03:37:45 +0000
reviewerskamidphish
bugs1285883
milestone52.0a1
Bug 1285883: Limit how many frames we will parse to detect HE-AAC. r?kamidphish MozReview-Commit-ID: JJEGomJZLio
dom/media/platforms/apple/AppleATDecoder.cpp
dom/media/platforms/apple/AppleATDecoder.h
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -23,16 +23,17 @@ AppleATDecoder::AppleATDecoder(const Aud
                                MediaDataDecoderCallback* aCallback)
   : mConfig(aConfig)
   , mFileStreamError(false)
   , mTaskQueue(aTaskQueue)
   , mCallback(aCallback)
   , mConverter(nullptr)
   , mStream(nullptr)
   , mIsFlushing(false)
+  , mParsedFramesForAACMagicCookie(0)
 {
   MOZ_COUNT_CTOR(AppleATDecoder);
   LOG("Creating Apple AudioToolbox decoder");
   LOG("Audio Decoder configuration: %s %d Hz %d channels %d bits per channel",
       mConfig.mMimeType.get(),
       mConfig.mRate,
       mConfig.mChannels,
       mConfig.mBitDepth);
@@ -529,25 +530,28 @@ AppleATDecoder::SetupChannelLayout()
                                            channels);
   return NS_OK;
 }
 
 nsresult
 AppleATDecoder::SetupDecoder(MediaRawData* aSample)
 {
   MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+  static const uint32_t MAX_FRAMES = 2;
 
   if (mFormatID == kAudioFormatMPEG4AAC &&
-      mConfig.mExtendedProfile == 2) {
+      mConfig.mExtendedProfile == 2 &&
+      mParsedFramesForAACMagicCookie < MAX_FRAMES) {
     // Check for implicit SBR signalling if stream is AAC-LC
     // This will provide us with an updated magic cookie for use with
     // GetInputAudioDescription.
     if (NS_SUCCEEDED(GetImplicitAACMagicCookie(aSample)) &&
         !mMagicCookie.Length()) {
       // nothing found yet, will try again later
+      mParsedFramesForAACMagicCookie++;
       return NS_ERROR_NOT_INITIALIZED;
     }
     // An error occurred, fallback to using default stream description
   }
 
   LOG("Initializing Apple AudioToolbox decoder");
 
   AudioStreamBasicDescription inputFormat;
--- a/dom/media/platforms/apple/AppleATDecoder.h
+++ b/dom/media/platforms/apple/AppleATDecoder.h
@@ -63,13 +63,14 @@ private:
   nsresult DecodeSample(MediaRawData* aSample);
   nsresult GetInputAudioDescription(AudioStreamBasicDescription& aDesc,
                                     const nsTArray<uint8_t>& aExtraData);
   // Setup AudioConverter once all information required has been gathered.
   // Will return NS_ERROR_NOT_INITIALIZED if more data is required.
   nsresult SetupDecoder(MediaRawData* aSample);
   nsresult GetImplicitAACMagicCookie(const MediaRawData* aSample);
   nsresult SetupChannelLayout();
+  uint32_t mParsedFramesForAACMagicCookie;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_AppleATDecoder_h