[vlc-devel] [PATCH 2/4] mmdevice: support WASAPI device endpoint activation events

Thomas Guillem thomas at gllm.fr
Mon May 23 09:39:23 CEST 2016


From: Sean McGovern <gseanmcg at gmail.com>

Some devices expose more than one endpoint such as speakers and headphone
output. Disconnecting headphones does not remove the endpoint but instead marks
it as being in unplugged state.

Respond to the appropriate activation events in order to enable/disable
endpoints correctly when they are added/removed from set of "active" endpoints.

Fix #15966

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
---
 modules/audio_output/mmdevice.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index a58b7dc..8082363 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -492,7 +492,7 @@ static bool DeviceIsRender(IMMDevice *dev)
     return flow == eRender;
 }
 
-static HRESULT DeviceUpdated(audio_output_t *aout, LPCWSTR wid)
+static HRESULT DeviceUpdated(audio_output_t *aout, LPCWSTR wid, bool activating)
 {
     aout_sys_t *sys = aout->sys;
     HRESULT hr;
@@ -518,7 +518,11 @@ static HRESULT DeviceUpdated(audio_output_t *aout, LPCWSTR wid)
     char *name = DeviceName(dev);
     IMMDevice_Release(dev);
 
-    aout_HotplugReport(aout, id, (name != NULL) ? name : id);
+    if (activating)
+        aout_HotplugReport(aout, id, (name != NULL) ? name : id);
+    else
+        aout_HotplugReport(aout, id, NULL);
+
     free(name);
     free(id);
     return S_OK;
@@ -586,7 +590,7 @@ vlc_MMNotificationClient_OnDeviceAdded(IMMNotificationClient *this,
     audio_output_t *aout = sys->aout;
 
     msg_Dbg(aout, "device %ls added", wid);
-    return DeviceUpdated(aout, wid);
+    return DeviceUpdated(aout, wid, true);
 }
 
 static STDMETHODIMP
@@ -601,7 +605,7 @@ vlc_MMNotificationClient_OnDeviceRemoved(IMMNotificationClient *this,
     if (unlikely(id == NULL))
         return E_OUTOFMEMORY;
 
-    aout_HotplugReport(aout, id, NULL);
+    DeviceUpdated(aout, wid, false);
     free(id);
     return S_OK;
 }
@@ -616,15 +620,19 @@ vlc_MMNotificationClient_OnDeviceStateChanged(IMMNotificationClient *this,
     switch (state) {
         case DEVICE_STATE_UNPLUGGED:
             msg_Warn(aout, "device %ls was unplugged", wid);
+            DeviceUpdated(aout, wid, false);
             break;
         case DEVICE_STATE_ACTIVE:
             msg_Warn(aout, "device %ls became active", wid);
+            DeviceUpdated(aout, wid, true);
             break;
         case DEVICE_STATE_DISABLED:
             msg_Warn(aout, "device %ls was disabled", wid);
+            DeviceUpdated(aout, wid, false);
             break;
         case DEVICE_STATE_NOTPRESENT:
             msg_Warn(aout, "device %ls is not present anymore", wid);
+            DeviceUpdated(aout, wid, false);
             break;
         default:
             msg_Warn(aout, "device %ls: unknown state %08lx", wid, state);
@@ -645,7 +653,7 @@ vlc_MMNotificationClient_OnPropertyValueChanged(IMMNotificationClient *this,
     if (key.pid == PKEY_Device_FriendlyName.pid)
     {
         msg_Dbg(aout, "device %ls name changed", wid);
-        return DeviceUpdated(aout, wid);
+        return DeviceUpdated(aout, wid, true);
     }
     return S_OK;
 }
-- 
2.8.1



More information about the vlc-devel mailing list