Bug 1275381: [aac] Rework AudioSpecificConfig if extensions are present. r?cpearce,?kamidphish draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 02 Jun 2016 12:07:06 +1000
changeset 374239 d934c8dd79a567e5064f1c430502e5aaac6721e3
parent 373787 a3e6f0d05ec220e2ca119fee2fe82ba391948411
child 522575 6390a85c1aaba84e2f05a78353fa893c8eac69ca
push id19954
push userjyavenard@mozilla.com
push dateThu, 02 Jun 2016 02:08:02 +0000
reviewerscpearce
bugs1275381
milestone49.0a1
Bug 1275381: [aac] Rework AudioSpecificConfig if extensions are present. r?cpearce,?kamidphish WMF is very strict with the AudioSpecificConfig passed on and will error if an unknown extension is found. Attempt to detect those extensions and remove them if necessary. MozReview-Commit-ID: KbooPiHmDbN
dom/media/platforms/wmf/WMFAudioMFTManager.cpp
--- a/dom/media/platforms/wmf/WMFAudioMFTManager.cpp
+++ b/dom/media/platforms/wmf/WMFAudioMFTManager.cpp
@@ -56,33 +56,51 @@ AACAudioSpecificConfigToUserData(uint8_t
   // The HEAACWAVEINFO must have payload and profile set,
   // the rest can be all 0x00.
   BYTE heeInfo[heeInfoLen] = {0};
   WORD* w = (WORD*)heeInfo;
   w[0] = 0x0; // Payload type raw AAC packet
   w[1] = aAACProfileLevelIndication;
 
   aOutUserData.AppendElements(heeInfo, heeInfoLen);
+
+  if (aAACProfileLevelIndication == 2 && aConfigLength > 2) {
+    // The AudioSpecificConfig is TTTTTFFF|FCCCCGGG
+    // (T=ObjectType, F=Frequency, C=Channel, G=GASpecificConfig)
+    // If frequency = 0xf, then the frequency is explicitly defined on 24 bits.
+    int8_t profile = (aAudioSpecConfig[0] & 0xF8) >> 3;
+    int8_t frequency =
+      (aAudioSpecConfig[0] & 0x7) << 1 | (aAudioSpecConfig[1] & 0x80) >> 7;
+    int8_t channels = (aAudioSpecConfig[1] & 0x78) >> 3;
+    int8_t gasc = aAudioSpecConfig[1] & 0x7;
+    if (frequency != 0xf && channels && !gasc) {
+      // We enter this condition if the AudioSpecificConfig should theorically
+      // be 2 bytes long but it's not.
+      // The WMF AAC decoder will error if unknown extensions are found,
+      // so remove them.
+      aConfigLength = 2;
+    }
+  }
   aOutUserData.AppendElements(aAudioSpecConfig, aConfigLength);
 }
 
 WMFAudioMFTManager::WMFAudioMFTManager(
   const AudioInfo& aConfig)
   : mAudioChannels(aConfig.mChannels)
   , mAudioRate(aConfig.mRate)
   , mAudioFrameSum(0)
   , mMustRecaptureAudioPosition(true)
 {
   MOZ_COUNT_CTOR(WMFAudioMFTManager);
 
   if (aConfig.mMimeType.EqualsLiteral("audio/mpeg")) {
     mStreamType = MP3;
   } else if (aConfig.mMimeType.EqualsLiteral("audio/mp4a-latm")) {
     mStreamType = AAC;
-    AACAudioSpecificConfigToUserData(aConfig.mProfile,
+    AACAudioSpecificConfigToUserData(aConfig.mExtendedProfile,
                                      aConfig.mCodecSpecificConfig->Elements(),
                                      aConfig.mCodecSpecificConfig->Length(),
                                      mUserData);
   } else {
     mStreamType = Unknown;
   }
 }