Bug 1121876: Configure WMF decoder to output PCM 16. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 19 Jan 2015 22:11:07 +1100
changeset 224480 f16ef283fee5dd4036683371aebe9e139656f5c0
parent 224479 1d32c46f21434e7501d12a1067c4c1cfc962176d
child 224481 b178fc3554211c0c10e0755661d5d5fb28720fe9
push id54246
push userjyavenard@mozilla.com
push dateMon, 19 Jan 2015 11:11:34 +0000
treeherdermozilla-inbound@f16ef283fee5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1121876
milestone38.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 1121876: Configure WMF decoder to output PCM 16. r=cpearce 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.