[vlc-commits] mmdevice: follow default device changes

Thomas Guillem git at videolan.org
Thu Mar 1 10:28:51 CET 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Feb 22 15:54:57 2018 +0100| [85164b7bf44895a62f968c2ebfc88d9530f1bb5a] | committer: Thomas Guillem

mmdevice: follow default device changes

Restart and request the new default device when it's changed by Windows and
when the "Default" virtual device is selected by VLC.

Fixes #19638

(cherry picked from commit 6f293db1ac490c67598fe2331d822186acaccaea)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/audio_output/mmdevice.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 9356e59949..74af74e53d 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -42,6 +42,7 @@ DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd,
    0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
 
 #include <vlc_common.h>
+#include <vlc_atomic.h>
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_charset.h>
@@ -98,6 +99,7 @@ struct aout_sys_t
     float requested_volume; /**< Requested volume, negative if none */
     signed char requested_mute; /**< Requested mute, negative if none */
     wchar_t *acquired_device; /**< Acquired device identifier, NULL if none */
+    bool request_device_restart;
     CRITICAL_SECTION lock;
     CONDITION_VARIABLE work;
     CONDITION_VARIABLE ready;
@@ -574,7 +576,15 @@ vlc_MMNotificationClient_OnDefaultDeviceChange(IMMNotificationClient *this,
     if (role != eConsole)
         return S_OK;
 
-    msg_Dbg(aout, "default device changed: %ls", wid); /* TODO? migrate */
+    EnterCriticalSection(&sys->lock);
+    if (sys->acquired_device == default_device)
+    {
+        msg_Dbg(aout, "default device changed: %ls", wid);
+        sys->request_device_restart = true;
+        aout_RestartRequest(aout, AOUT_RESTART_OUTPUT);
+    }
+    LeaveCriticalSection(&sys->lock);
+
     return S_OK;
 }
 
@@ -724,6 +734,8 @@ static int DeviceRequestLocked(audio_output_t *aout)
     aout_sys_t *sys = aout->sys;
     assert(sys->requested_device);
 
+    sys->request_device_restart = false;
+
     WakeConditionVariable(&sys->work);
     while (sys->requested_device != NULL)
         SleepConditionVariableCS(&sys->ready, &sys->lock, INFINITE);
@@ -1122,6 +1134,10 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 
     EnterMTA();
     EnterCriticalSection(&sys->lock);
+
+    if (sys->request_device_restart)
+        DeviceRestartLocked(aout);
+
     for (;;)
     {
         HRESULT hr;
@@ -1232,6 +1248,7 @@ static int Open(vlc_object_t *obj)
     sys->requested_volume = -1.f;
     sys->requested_mute = -1;
     sys->acquired_device = NULL;
+    sys->request_device_restart = false;
     InitializeCriticalSection(&sys->lock);
     InitializeConditionVariable(&sys->work);
     InitializeConditionVariable(&sys->ready);



More information about the vlc-commits mailing list