Bug 1285883: Limit how many frames we will parse to detect HE-AAC. r=kamidphish, a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 07 Oct 2016 13:49:42 +1100
changeset 428815 f500377fea6beae1c6b95d6ef964ff971eee1a26
parent 428814 1cd295569b2bd7b40cab83c179525fd549c73051
child 428816 0db6d766839549102ba72115bdeafb7484a8cbc2
push id33416
push userpaul@paul.cx
push dateMon, 24 Oct 2016 16:26:20 +0000
reviewerskamidphish, ritu
bugs1285883
milestone50.0
Bug 1285883: Limit how many frames we will parse to detect HE-AAC. r=kamidphish, a=ritu 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);
@@ -533,25 +534,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