Bug 1431169 - P2. Fix Apple AAC decoder on some files. r=rillian
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 17 Jan 2018 22:00:16 +0100
changeset 454107 e97d7f1498adb10c3fb615189a2e7a9479184441
parent 454106 2856cf89502b67a6685e07a5a68061a7e107ef7a
child 454108 e3c55a7d764208a7560aaf18909be790887a2e0d
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1431169
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
 }