Bug 1431169 - P2. Fix Apple AAC decoder on some files. r?rillian draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 17 Jan 2018 22:00:16 +0100
changeset 721981 517c474b742724d3678451568dbb7e8fe204e286
parent 721976 6d19069ed315571516cca103d7294212b506d22e
child 721982 5849b1a70a8948f5d1aea0496cc2cb939b258e81
push id96016
push userbmo:jyavenard@mozilla.com
push dateThu, 18 Jan 2018 08:36:51 +0000
reviewersrillian
bugs1431169
milestone59.0a1
Bug 1431169 - P2. Fix Apple AAC decoder on some files. r?rillian It is necessary to provide the AAC's magic cookie to the decoder for some files (such as ambisonics or quad-stereo). We already do so for the Windows and FFmpeg decoder. It's another case of how did it work before really. MozReview-Commit-ID: sOtY1sPeBU
dom/media/platforms/apple/AppleATDecoder.cpp
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -365,17 +365,17 @@ AppleATDecoder::GetInputAudioDescription
   OSStatus rv = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
                                        0,
                                        NULL,
                                        &inputFormatSize,
                                        &aDesc);
   if (NS_WARN_IF(rv)) {
     return MediaResult(
       NS_ERROR_FAILURE,
-      RESULT_DETAIL("Unable to get format info:%lld", int64_t(rv)));
+      RESULT_DETAIL("Unable to get format info:%d", int32_t(rv)));
   }
 
   // If any of the methods below fail, we will return the default format as
   // created using kAudioFormatProperty_FormatInfo above.
   rv = AudioFormatGetPropertyInfo(kAudioFormatProperty_FormatList,
                                   sizeof(formatInfo),
                                   &formatInfo,
                                   &formatListSize);
@@ -564,22 +564,22 @@ AppleATDecoder::SetupDecoder(MediaRawDat
       mParsedFramesForAACMagicCookie++;
       return NS_ERROR_NOT_INITIALIZED;
     }
     // An error occurred, fallback to using default stream description
   }
 
   LOG("Initializing Apple AudioToolbox decoder");
 
+  nsTArray<uint8_t>& magicCookie =
+    mMagicCookie.Length() ? mMagicCookie : *mConfig.mExtraData;
   AudioStreamBasicDescription inputFormat;
   PodZero(&inputFormat);
-  MediaResult rv =
-    GetInputAudioDescription(inputFormat,
-                             mMagicCookie.Length() ?
-                                 mMagicCookie : *mConfig.mExtraData);
+
+  MediaResult rv = GetInputAudioDescription(inputFormat, magicCookie);
   if (NS_FAILED(rv)) {
     return rv;
   }
   // Fill in the output format manually.
   PodZero(&mOutputFormat);
   mOutputFormat.mFormatID = kAudioFormatLinearPCM;
   mOutputFormat.mSampleRate = inputFormat.mSampleRate;
   mOutputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
@@ -596,21 +596,36 @@ AppleATDecoder::SetupDecoder(MediaRawDat
 #endif
   // Set up the decoder so it gives us one sample per frame
   mOutputFormat.mFramesPerPacket = 1;
   mOutputFormat.mBytesPerPacket = mOutputFormat.mBytesPerFrame
         = mOutputFormat.mChannelsPerFrame * mOutputFormat.mBitsPerChannel / 8;
 
   OSStatus status = AudioConverterNew(&inputFormat, &mOutputFormat, &mConverter);
   if (status) {
-    LOG("Error %d constructing AudioConverter", static_cast<int>(status));
+    LOG("Error %d constructing AudioConverter", int(status));
     mConverter = nullptr;
     return MediaResult(
       NS_ERROR_FAILURE,
-      RESULT_DETAIL("Error constructing AudioConverter:%lld", int64_t(status)));
+      RESULT_DETAIL("Error constructing AudioConverter:%d", int32_t(status)));
+  }
+
+  if (magicCookie.Length() && mFormatID == kAudioFormatMPEG4AAC) {
+    status = AudioConverterSetProperty(mConverter,
+                                       kAudioConverterDecompressionMagicCookie,
+                                       magicCookie.Length(),
+                                       magicCookie.Elements());
+    if (status) {
+      LOG("Error setting AudioConverter AAC cookie:%d", int32_t(status));
+      ProcessShutdown();
+      return MediaResult(
+        NS_ERROR_FAILURE,
+        RESULT_DETAIL("Error setting AudioConverter AAC cookie:%d",
+                      int32_t(status)));
+    }
   }
 
   if (NS_FAILED(SetupChannelLayout())) {
     NS_WARNING("Couldn't retrieve channel layout, will use default layout");
   }
 
   return NS_OK;
 }