Bug 1121876 - Configure WMF decoder to output PCM 16. r=cpearce, a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 19 Jan 2015 22:11:07 +1100
changeset 242952 cd88be2b57ac
parent 242951 e017341d2486
child 242953 94e7cb795a05
push id4344
push userryanvm@gmail.com
push date2015-01-20 17:02 +0000
treeherdermozilla-beta@ea7deca21c27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sledru
bugs1121876
milestone36.0
Bug 1121876 - Configure WMF decoder to output PCM 16. r=cpearce, a=sledru Also, do not use input's bit depth for calculating output samples. They are unrelated
dom/media/fmp4/wmf/MFTDecoder.cpp
dom/media/fmp4/wmf/WMFAudioMFTManager.cpp
dom/media/fmp4/wmf/WMFAudioMFTManager.h
--- a/dom/media/fmp4/wmf/MFTDecoder.cpp
+++ b/dom/media/fmp4/wmf/MFTDecoder.cpp
@@ -97,16 +97,21 @@ MFTDecoder::SetDecoderOutputType()
   UINT32 typeIndex = 0;
   while (SUCCEEDED(mDecoder->GetOutputAvailableType(0, typeIndex++, byRef(outputType)))) {
     GUID subtype;
     hr = outputType->GetGUID(MF_MT_SUBTYPE, &subtype);
     if (FAILED(hr)) {
       continue;
     }
     if (subtype == mOutputSubtype) {
+      if (subtype == MFAudioFormat_PCM) {
+        // Set output to PCM 16 bits, we can ignore errors.
+        outputType->SetUINT32(MF_MT_SAMPLE_SIZE, 2);
+        outputType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16);
+      }
       hr = mDecoder->SetOutputType(0, outputType, 0);
       NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
       return S_OK;
     }
   }
   return E_FAIL;
 }
 
--- a/dom/media/fmp4/wmf/WMFAudioMFTManager.cpp
+++ b/dom/media/fmp4/wmf/WMFAudioMFTManager.cpp
@@ -65,17 +65,16 @@ AACAudioSpecificConfigToUserData(uint8_t
 
   aOutUserData.AppendElements(heeInfo, heeInfoLen);
   aOutUserData.AppendElements(aAudioSpecConfig, aConfigLength);
 }
 
 WMFAudioMFTManager::WMFAudioMFTManager(
   const mp4_demuxer::AudioDecoderConfig& aConfig)
   : mAudioChannels(aConfig.channel_count)
-  , mAudioBytesPerSample(aConfig.bits_per_sample / 8)
   , mAudioRate(aConfig.samples_per_second)
   , mAudioFrameOffset(0)
   , mAudioFrameSum(0)
   , mMustRecaptureAudioPosition(true)
 {
   MOZ_COUNT_CTOR(WMFAudioMFTManager);
 
   if (!strcmp(aConfig.mime_type, "audio/mpeg")) {
@@ -259,33 +258,32 @@ WMFAudioMFTManager::Output(int64_t aStre
       // First sample has a negative timestamp. Strip off the samples until
       // we reach positive territory.
       numFramesToStrip = -mAudioFrameOffset;
       mAudioFrameOffset = 0;
     }
     mMustRecaptureAudioPosition = false;
   }
   MOZ_ASSERT(numFramesToStrip >= 0);
-  int32_t numSamples = currentLength / mAudioBytesPerSample;
+  // We can assume PCM 16 output.
+  int32_t numSamples = currentLength / 2;
   int32_t numFrames = numSamples / mAudioChannels;
   int32_t offset = std::min<int32_t>(numFramesToStrip, numFrames);
   numFrames -= offset;
   numSamples -= offset * mAudioChannels;
   MOZ_ASSERT(numFrames >= 0);
   MOZ_ASSERT(numSamples >= 0);
   if (numFrames == 0) {
     // All data from this chunk stripped, loop back and try to output the next
     // frame, if possible.
     return S_OK;
   }
 
   nsAutoArrayPtr<AudioDataValue> audioData(new AudioDataValue[numSamples]);
 
-  // Just assume PCM output for now...
-  MOZ_ASSERT(mAudioBytesPerSample == 2);
   int16_t* pcm = ((int16_t*)data) + (offset * mAudioChannels);
   MOZ_ASSERT(pcm >= (int16_t*)data);
   MOZ_ASSERT(pcm <= (int16_t*)(data + currentLength));
   MOZ_ASSERT(pcm+numSamples <= (int16_t*)(data + currentLength));
   for (int32_t i = 0; i < numSamples; ++i) {
     audioData[i] = AudioSampleToFloat(pcm[i]);
   }
 
--- a/dom/media/fmp4/wmf/WMFAudioMFTManager.h
+++ b/dom/media/fmp4/wmf/WMFAudioMFTManager.h
@@ -35,17 +35,16 @@ public:
 private:
 
   HRESULT UpdateOutputType();
 
   // IMFTransform wrapper that performs the decoding.
   RefPtr<MFTDecoder> mDecoder;
 
   uint32_t mAudioChannels;
-  const uint32_t mAudioBytesPerSample;
   uint32_t mAudioRate;
   nsTArray<BYTE> mUserData;
 
   // The offset, in audio frames, at which playback started since the
   // last discontinuity.
   int64_t mAudioFrameOffset;
   // The number of audio frames that we've played since the last
   // discontinuity.