wasapi: parse returned sample format (fixes #11174)
[vlc.git] / modules / audio_output / wasapi.c
index 6b419c6..73e8160 100644 (file)
@@ -287,10 +287,44 @@ static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
     {
         const WAVEFORMATEXTENSIBLE *wfe = (void *)wf;
 
+        if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
+        {
+            switch (wf->wBitsPerSample)
+            {
+                case 64:
+                    audio->i_format = VLC_CODEC_FL64;
+                    break;
+                case 32:
+                    audio->i_format = VLC_CODEC_FL32;
+                    break;
+                default:
+                    return -1;
+            }
+        }
+        else if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
+        {
+            switch (wf->wBitsPerSample)
+            {
+                case 32:
+                    audio->i_format = VLC_CODEC_S32N;
+                    break;
+                case 16:
+                    audio->i_format = VLC_CODEC_S16N;
+                    break;
+                default:
+                    return -1;
+            }
+        }
+
+        if (wfe->Samples.wValidBitsPerSample != wf->wBitsPerSample)
+            return -1;
+
         for (unsigned i = 0; chans_in[i]; i++)
             if (wfe->dwChannelMask & chans_in[i])
                 audio->i_physical_channels |= pi_vlc_chan_order_wg4[i];
     }
+    else
+        return -1;
 
     audio->i_original_channels = audio->i_physical_channels;
     aout_FormatPrepare (audio);