[vlc-devel] [PATCH 1/2] mmdevice: handle "--no-volume-save"

Thomas Guillem thomas at gllm.fr
Tue Feb 27 15:03:47 CET 2018


It's handled the other way around than old aout modules.

By default, "volume-save" is true and we keep the current behavior (the volume
is saved by Windows for this session). If "volume-save" is false, then we use
the prefered volume set by the user "mmdevice-volume" and don't use the VLC
audio session.

This reverts commit 6bbc6b6cb191f1a4dd29bd059c90e9cbaf0edb16.

Fixes #19664
---
 modules/audio_output/mmdevice.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index ca142f5d6a..c3d5b00078 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -197,7 +197,7 @@ static void Flush(audio_output_t *aout, bool wait)
     vlc_FromHR(aout, hr);
 }
 
-static int VolumeSet(audio_output_t *aout, float vol)
+static int VolumeSetLocked(audio_output_t *aout, float vol)
 {
     aout_sys_t *sys = aout->sys;
     float gain = 1.f;
@@ -212,12 +212,20 @@ static int VolumeSet(audio_output_t *aout, float vol)
 
     aout_GainRequest(aout, gain);
 
-    EnterCriticalSection(&sys->lock);
     sys->gain = gain;
     sys->requested_volume = vol;
+    return 0;
+}
+
+static int VolumeSet(audio_output_t *aout, float vol)
+{
+    aout_sys_t *sys = aout->sys;
+
+    EnterCriticalSection(&sys->lock);
+    int ret = VolumeSetLocked(aout, vol);
     WakeConditionVariable(&sys->work);
     LeaveCriticalSection(&sys->lock);
-    return 0;
+    return ret;
 }
 
 static int MuteSet(audio_output_t *aout, bool mute)
@@ -912,7 +920,8 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
     manager = pv;
     if (SUCCEEDED(hr))
     {
-        LPCGUID guid = &GUID_VLC_AUD_OUT;
+        LPCGUID guid = var_InheritBool(aout, "volume-save") ? &GUID_VLC_AUD_OUT
+                                                            : NULL;
 
         /* Register session control */
         hr = IAudioSessionManager_GetAudioSessionControl(manager, guid, 0,
@@ -1266,9 +1275,6 @@ static void Stop(audio_output_t *aout)
 
 static int Open(vlc_object_t *obj)
 {
-    if (!var_InheritBool(obj, "volume-save"))
-        return VLC_EGENERIC;
-
     audio_output_t *aout = (audio_output_t *)obj;
 
     aout_sys_t *sys = malloc(sizeof (*sys));
@@ -1291,6 +1297,10 @@ static int Open(vlc_object_t *obj)
     sys->requested_volume = -1.f;
     sys->requested_mute = -1;
     sys->acquired_device = NULL;
+
+    if (!var_InheritBool(aout, "volume-save"))
+        VolumeSetLocked(aout, var_InheritFloat(aout, "mmdevice-volume"));
+
     InitializeCriticalSection(&sys->lock);
     InitializeConditionVariable(&sys->work);
     InitializeConditionVariable(&sys->ready);
@@ -1475,6 +1485,9 @@ static const char *const ppsz_mmdevice_passthrough_texts[] = {
 #define DEVICE_TEXT N_("Output device")
 #define DEVICE_LONGTEXT N_("Select your audio output device")
 
+#define VOLUME_TEXT N_("Audio volume")
+#define VOLUME_LONGTEXT N_("Audio volume in hundredths of decibels (dB).")
+
 vlc_module_begin()
     set_shortname("MMDevice")
     set_description(N_("Windows Multimedia Device output"))
@@ -1491,4 +1504,6 @@ vlc_module_begin()
                              ppsz_mmdevice_passthrough_texts )
     add_string("mmdevice-audio-device", NULL, DEVICE_TEXT, DEVICE_LONGTEXT, false)
         change_string_cb(ReloadAudioDevices)
+    add_float("mmdevice-volume", 1.f, VOLUME_TEXT, VOLUME_LONGTEXT, true)
+        change_float_range( 0.f, 1.25f )
 vlc_module_end()
-- 
2.11.0



More information about the vlc-devel mailing list