[vlc-commits] [Git][videolan/vlc][master] 4 commits: modules: use container_of to get the WAVEFORMATEXTENSIBLE from WAVEFORMATEX

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Jun 12 11:47:46 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
1b86b2ff by Steve Lhomme at 2022-06-12T10:56:57+00:00
modules: use container_of to get the WAVEFORMATEXTENSIBLE from WAVEFORMATEX

- - - - -
63b7a09e by Steve Lhomme at 2022-06-12T10:56:57+00:00
wasapi: log the WAVEFORMATEX when there's an error

- - - - -
0921d77f by Steve Lhomme at 2022-06-12T10:56:57+00:00
wasapi: verify the cbSize matches the WAVEFORMATEXTENSIBLE size

- - - - -
8a1f453f by Steve Lhomme at 2022-06-12T10:56:57+00:00
wasapi: write output values when have no errors

- - - - -


4 changed files:

- modules/access/wasapi.c
- modules/audio_output/wasapi.c
- modules/demux/avi/avi.c
- modules/demux/mkv/matroska_segment_parse.cpp


Changes:

=====================================
modules/access/wasapi.c
=====================================
@@ -145,8 +145,9 @@ static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
 
     /* As per MSDN, IAudioClient::GetMixFormat() always uses this format. */
     assert(wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE);
+    assert(wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX));
 
-    const WAVEFORMATEXTENSIBLE *wfe = (void *)wf;
+    const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
 
     fmt->i_physical_channels = 0;
     if (wfe->dwChannelMask & SPEAKER_FRONT_LEFT)


=====================================
modules/audio_output/wasapi.c
=====================================
@@ -499,15 +499,37 @@ static void vlc_ToWave(WAVEFORMATEXTENSIBLE *restrict wf,
             wf->dwChannelMask |= chans_in[i];
 }
 
+static void LogWaveFormat(struct vlc_logger *l, const WAVEFORMATEX *restrict wf)
+{
+    vlc_debug(l, "nChannels %d", wf->nChannels);
+    vlc_debug(l, "wBitsPerSample %d", wf->wBitsPerSample);
+    vlc_debug(l, "nAvgBytesPerSec %d", wf->nAvgBytesPerSec);
+    vlc_debug(l, "nSamplesPerSec %d", wf->nSamplesPerSec);
+    vlc_debug(l, "nBlockAlign %d", wf->nBlockAlign);
+    vlc_debug(l, "cbSize %d", wf->cbSize);
+    vlc_debug(l, "wFormatTag 0x%04X", wf->wFormatTag);
+
+    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+        wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
+    {
+        const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
+        if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
+            vlc_debug(l, "SubFormat IEEE_FLOAT");
+        else if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
+            vlc_debug(l, "SubFormat PCM");
+        else
+            vlc_debug(l, "SubFormat " GUID_FMT, GUID_PRINT(wfe->SubFormat));
+        vlc_debug(l, "wValidBitsPerSample %d", wfe->Samples.wValidBitsPerSample);
+    }
+}
+
 static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
                         audio_sample_format_t *restrict audio)
 {
-    audio->i_rate = wf->nSamplesPerSec;
-    audio->i_physical_channels = 0;
-
-    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
+    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+        wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
     {
-        const WAVEFORMATEXTENSIBLE *wfe = (void *)wf;
+        const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
 
         if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
         {
@@ -549,6 +571,9 @@ static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
     else
         return -1;
 
+    audio->i_rate = wf->nSamplesPerSec;
+    audio->i_physical_channels = 0;
+
     aout_FormatPrepare (audio);
 
     if (wf->nChannels != audio->i_channels)
@@ -796,7 +821,11 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict pfmt,
             /* Render Ambisonics on the native mix format */
             hr = IAudioClient_GetMixFormat(sys->client, &pwf_mix);
             if (FAILED(hr) || vlc_FromWave(pwf_mix, &fmt))
+            {
+                msg_Dbg(s, "failed to use mix format");
+                LogWaveFormat(vlc_object_logger(s), pwf_mix);
                 vlc_ToWave(pwfe, &fmt); /* failed, fallback to default */
+            }
             else
                 pwf = pwf_mix;
 
@@ -842,8 +871,9 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict pfmt,
         assert(pwf_closest != NULL);
         if (vlc_FromWave(pwf_closest, &fmt))
         {
+            msg_Err(s, "unsupported closest audio format");
+            LogWaveFormat(vlc_object_logger(s), pwf_closest);
             CoTaskMemFree(pwf_closest);
-            msg_Err(s, "unsupported audio format");
             hr = E_INVALIDARG;
             goto error;
         }


=====================================
modules/demux/avi/avi.c
=====================================
@@ -496,7 +496,7 @@ static int Open( vlc_object_t * p_this )
                 if( p_auds->p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
                     p_auds->p_wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) )
                 {
-                    WAVEFORMATEXTENSIBLE *p_wfe = (WAVEFORMATEXTENSIBLE *)p_auds->p_wf;
+                    WAVEFORMATEXTENSIBLE *p_wfe = container_of(p_auds->p_wf, WAVEFORMATEXTENSIBLE, Format);
                     tk->fmt.i_codec = AVI_FourccGetCodec( AUDIO_ES, p_wfe->SubFormat.Data1 );
                 }
                 else


=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -1913,7 +1913,7 @@ bool matroska_segment_c::TrackInit( mkv_track_t * p_tk )
                 if( p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
                     p_tk->i_extra_data >= sizeof(WAVEFORMATEXTENSIBLE) )
                 {
-                    WAVEFORMATEXTENSIBLE *p_wext = (WAVEFORMATEXTENSIBLE*)p_wf;
+                    WAVEFORMATEXTENSIBLE *p_wext = container_of(p_wf, WAVEFORMATEXTENSIBLE, Format);
                     GUID subFormat = p_wext->SubFormat;
 
                     sf_tag_to_fourcc( &subFormat,  &p_tk->fmt.i_codec, NULL);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6f5ea06071738e90740c5507aa72857a95e0ebe8...8a1f453f3f9560fd8c61c5b7fddeb8d9e5d5c95b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6f5ea06071738e90740c5507aa72857a95e0ebe8...8a1f453f3f9560fd8c61c5b7fddeb8d9e5d5c95b
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list