[vlc-commits] mmdevice: split DeviceHotplugReport()

Thomas Guillem git at videolan.org
Wed Feb 28 13:55:41 CET 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Feb 26 13:31:00 2018 +0100| [9d694a9d837ecdca87db13c0e6fbbdd40fa88650] | committer: Thomas Guillem

mmdevice: split DeviceHotplugReport()

Add DeviceGetFriendlyName() that can be used to fetch the friendly name.

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

 modules/audio_output/mmdevice.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 10cc4e5b30..66b8536379 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -446,25 +446,17 @@ static const struct IAudioVolumeDuckNotificationVtbl vlc_AudioVolumeDuckNotifica
 /*** Audio devices ***/
 
 /** Gets the user-readable device name */
-static int DeviceHotplugReport(audio_output_t *aout, LPCWSTR wid,
-                               IMMDevice *dev)
+static char *DeviceGetFriendlyName(IMMDevice *dev)
 {
     IPropertyStore *props;
-    char *name;
     PROPVARIANT v;
     HRESULT hr;
 
-    char *id = FromWide(wid);
-    if (unlikely(id == NULL))
-        return VLC_ENOMEM;
-
     hr = IMMDevice_OpenPropertyStore(dev, STGM_READ, &props);
     if (FAILED(hr))
-    {
-        free(id);
-        return VLC_EGENERIC;
-    }
+        return NULL;
 
+    char *name = NULL;
     PropVariantInit(&v);
     hr = IPropertyStore_GetValue(props, &PKEY_Device_FriendlyName, &v);
     if (SUCCEEDED(hr))
@@ -472,10 +464,23 @@ static int DeviceHotplugReport(audio_output_t *aout, LPCWSTR wid,
         name = FromWide(v.pwszVal);
         PropVariantClear(&v);
     }
-    else
-        name = id;
 
     IPropertyStore_Release(props);
+
+    return name;
+}
+
+static int DeviceHotplugReport(audio_output_t *aout, LPCWSTR wid,
+                               IMMDevice *dev)
+{
+    char *id = FromWide(wid);
+    if (!id)
+        return VLC_EGENERIC;
+
+    char *name = DeviceGetFriendlyName(dev);
+    if (name == NULL)
+        name = id;
+
     aout_HotplugReport(aout, id, name);
 
     free(id);



More information about the vlc-commits mailing list