[vlc-commits] mmdevice: follow default device changes

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


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Feb 22 15:54:57 2018 +0100| [6f293db1ac490c67598fe2331d822186acaccaea] | 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

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

 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 aaa1b5987c..10cc4e5b30 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -37,6 +37,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>
@@ -93,6 +94,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;
@@ -569,7 +571,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;
 }
 
@@ -719,6 +729,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);
@@ -1117,6 +1129,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 (;;)
     {
         char *modlist = var_InheritString(aout, "mmdevice-backend");
@@ -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