WMF: fix reported sample type of 8-bit audio formats.
authorYoann Lopes <yoann.lopes@theqtcompany.com>
Tue, 14 Apr 2015 11:42:46 +0000 (13:42 +0200)
committerYoann Lopes <yoann.lopes@theqtcompany.com>
Tue, 14 Apr 2015 14:30:16 +0000 (14:30 +0000)
Always report 8-bit PCM data as unsigned integer. Even though there's
no API to actually know that, it's standard on Windows. 8-bit is
unsigned and 16-bit is signed.

Task-number: QTBUG-45540
Change-Id: I4a3c09084de688ea7afc3bc147508184fb582224
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
src/plugins/wmf/decoder/mfaudiodecodercontrol.cpp
src/plugins/wmf/player/mfplayersession.cpp

index da69f92..ff093e9 100644 (file)
@@ -193,17 +193,6 @@ void MFAudioDecoderControl::handleMediaSourceReady()
     if (mediaType) {
         m_sourceOutputFormat = m_audioFormat;
         QAudioFormat af = m_audioFormat;
-        GUID subType;
-        if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subType))) {
-            if (subType == MFAudioFormat_Float) {
-                m_sourceOutputFormat.setSampleType(QAudioFormat::Float);
-            } else {
-                m_sourceOutputFormat.setSampleType(QAudioFormat::SignedInt);
-            }
-        }
-        if (m_sourceOutputFormat.sampleType() != QAudioFormat::Float) {
-            m_sourceOutputFormat.setByteOrder(QAudioFormat::LittleEndian);
-        }
 
         UINT32 val = 0;
         if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &val))) {
@@ -216,6 +205,20 @@ void MFAudioDecoderControl::handleMediaSourceReady()
             m_sourceOutputFormat.setSampleSize(int(val));
         }
 
+        GUID subType;
+        if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subType))) {
+            if (subType == MFAudioFormat_Float) {
+                m_sourceOutputFormat.setSampleType(QAudioFormat::Float);
+            } else if (m_sourceOutputFormat.sampleSize() == 8) {
+                m_sourceOutputFormat.setSampleType(QAudioFormat::UnSignedInt);
+            } else {
+                m_sourceOutputFormat.setSampleType(QAudioFormat::SignedInt);
+            }
+        }
+        if (m_sourceOutputFormat.sampleType() != QAudioFormat::Float) {
+            m_sourceOutputFormat.setByteOrder(QAudioFormat::LittleEndian);
+        }
+
         if (m_audioFormat.sampleType() != QAudioFormat::Float
             && m_audioFormat.sampleType() != QAudioFormat::SignedInt) {
             af.setSampleType(m_sourceOutputFormat.sampleType());
index 599fa90..d6cf07e 100644 (file)
@@ -556,7 +556,10 @@ QAudioFormat MFPlayerSession::audioFormatForMFMediaType(IMFMediaType *mediaType)
     format.setSampleSize(wfx->wBitsPerSample);
     format.setCodec("audio/pcm");
     format.setByteOrder(QAudioFormat::LittleEndian);
-    format.setSampleType(QAudioFormat::SignedInt);
+    if (format.sampleSize() == 8)
+        format.setSampleType(QAudioFormat::UnSignedInt);
+    else
+        format.setSampleType(QAudioFormat::SignedInt);
 
     CoTaskMemFree(wfx);
     return format;