[vlc-commits] mmdevice: fix opening of invalid device

Thomas Guillem git at videolan.org
Fri Feb 9 13:34:59 CET 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Feb  9 13:29:29 2018 +0100| [a715eaa04c611de267022964c59566779539d6e6] | committer: Thomas Guillem

mmdevice: fix opening of invalid device

CD 6f95511a-91a2-45de-bd43-735bf52a2185

And check sys->dev locked since it can be written from the MMSession thread.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a715eaa04c611de267022964c59566779539d6e6
---

 modules/audio_output/mmdevice.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 40c03ee18f..2e3fdb30ab 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -1081,9 +1081,6 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 {
     aout_sys_t *sys = aout->sys;
 
-    if (sys->dev == NULL)
-        return -1;
-
     const bool b_spdif = AOUT_FMT_SPDIF(fmt);
     const bool b_hdmi = AOUT_FMT_HDMI(fmt);
     if (b_spdif || b_hdmi)
@@ -1111,6 +1108,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 
     EnterMTA();
     EnterCriticalSection(&sys->lock);
+
+    if (sys->dev == NULL)
+    {
+        LeaveCriticalSection(&sys->lock);
+        LeaveMTA();
+        return -1;
+    }
+
     for (;;)
     {
         char *modlist = var_InheritString(aout, "mmdevice-backend");
@@ -1146,25 +1151,28 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             break;
     }
 
-    IPropertyStore *props;
-    HRESULT hr = IMMDevice_OpenPropertyStore(sys->dev, STGM_READ, &props);
-    if (SUCCEEDED(hr))
+    if (sys->module != NULL)
     {
-        PROPVARIANT v;
-        PropVariantInit(&v);
-        hr = IPropertyStore_GetValue(props, &PKEY_AudioEndpoint_FormFactor, &v);
+        IPropertyStore *props;
+        HRESULT hr = IMMDevice_OpenPropertyStore(sys->dev, STGM_READ, &props);
         if (SUCCEEDED(hr))
         {
-            switch (v.uintVal)
+            PROPVARIANT v;
+            PropVariantInit(&v);
+            hr = IPropertyStore_GetValue(props, &PKEY_AudioEndpoint_FormFactor, &v);
+            if (SUCCEEDED(hr))
             {
-                case Headphones:
-                case Headset:
-                    aout->current_sink_info.headphones = true;
-                    break;
+                switch (v.uintVal)
+                {
+                    case Headphones:
+                    case Headset:
+                        aout->current_sink_info.headphones = true;
+                        break;
+                }
+                PropVariantClear(&v);
             }
-            PropVariantClear(&v);
+            IPropertyStore_Release(props);
         }
-        IPropertyStore_Release(props);
     }
 
     LeaveCriticalSection(&sys->lock);



More information about the vlc-commits mailing list