[vlc-devel] [PATCH 2/7] mmdevice: follow default device changes

Thomas Guillem thomas at gllm.fr
Tue Feb 27 14:14:05 CET 2018


On Tue, Feb 27, 2018, at 13:54, Rémi Denis-Courmont wrote:
> Le 27 février 2018 12:41:06 GMT+02:00, Thomas Guillem <thomas at gllm.fr> a écrit :
> >Restart and request the new default device when it's changed by Windows
> >and
> >when the "Default" virtual device is selected by VLC.
> >
> >Refs #19638
> >---
> > modules/audio_output/mmdevice.c | 31 ++++++++++++++++++++++++++++++-
> > 1 file changed, 30 insertions(+), 1 deletion(-)
> >
> >diff --git a/modules/audio_output/mmdevice.c
> >b/modules/audio_output/mmdevice.c
> >index 48d05ad2d6..525f16ff6a 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
> >*/
> >+    atomic_bool request_default_device;
> >     CRITICAL_SECTION lock;
> >     CONDITION_VARIABLE work;
> >     CONDITION_VARIABLE ready;
> >@@ -136,11 +138,30 @@ static int TimeGet(audio_output_t *aout, mtime_t
> >*restrict delay)
> >     return SUCCEEDED(hr) ? 0 : -1;
> > }
> > 
> >+static bool CheckDefaultDevice(audio_output_t *aout)
> >+{
> >+    aout_sys_t *sys = aout->sys;
> >+    if (!atomic_exchange(&sys->request_default_device, false))
> >+        return false;
> >+
> >+    if (sys->acquired_device != default_device)
> >+        return false;
> >+
> >+    DeviceSelect(aout, NULL);
> >+    return true; /* Should restart */
> >+}
> >+
> > static void Play(audio_output_t *aout, block_t *block)
> > {
> >     aout_sys_t *sys = aout->sys;
> >     HRESULT hr;
> > 
> >+    if (CheckDefaultDevice(aout))
> >+    {
> >+        block_Release(block);
> >+        return;
> >+    }
> >+
> >     EnterMTA();
> >     hr = aout_stream_Play(sys->stream, block);
> >     LeaveMTA();
> >@@ -166,6 +187,9 @@ static void Flush(audio_output_t *aout, bool wait)
> >     aout_sys_t *sys = aout->sys;
> >     HRESULT hr;
> > 
> >+    if (CheckDefaultDevice(aout))
> >+        return;
> >+
> >     EnterMTA();
> >     hr = aout_stream_Flush(sys->stream, wait);
> >     LeaveMTA();
> >@@ -571,7 +595,9 @@
> >vlc_MMNotificationClient_OnDefaultDeviceChange(IMMNotificationClient
> >*this,
> >     if (role != eConsole)
> >         return S_OK;
> > 
> >-    msg_Dbg(aout, "default device changed: %ls", wid); /* TODO?
> >migrate */
> >+    msg_Dbg(aout, "default device changed: %ls", wid);
> >+    atomic_store(&sys->request_default_device, true);
> >+
> >     return S_OK;
> > }
> > 
> >@@ -1089,6 +1115,8 @@ static int Start(audio_output_t *aout,
> >audio_sample_format_t *restrict fmt)
> > {
> >     aout_sys_t *sys = aout->sys;
> > 
> >+    CheckDefaultDevice(aout);
> >+
> >     if (sys->dev == NULL)
> >         return -1;
> > 
> >@@ -1225,6 +1253,7 @@ static int Open(vlc_object_t *obj)
> >     sys->duck.lpVtbl = &vlc_AudioVolumeDuckNotification;
> >     sys->refs = 1;
> >     sys->ducks = 0;
> >+    atomic_init(&sys->request_default_device, false);
> > 
> >     sys->gain = 1.f;
> >     sys->requested_device = default_device;
> >-- 
> >2.11.0
> >
> >_______________________________________________
> >vlc-devel mailing list
> >To unsubscribe or modify your subscription options:
> >https://mailman.videolan.org/listinfo/vlc-devel
> 
> There is already an atomic function to change device. I can hardly 
> fathom why another one should be needed.
> 


> Also, this does not look like it will do the right thing if audio is 
> inactive at the time of external change.

Good point.

> -- 
> Remi Denis-Courmont
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list