vlc/vlc-3.0 | branch: master | Steve Lhomme <[email protected]> | Tue Nov 24 
10:07:31 2020 +0100| [83229d3e80939f4d6160232f4a613216f05561d6] | committer: 
Steve Lhomme

audio_output/winstore: report the volume changes

After a mute it seems we need to tell report the new volume otherwise it
assumes it's 0.

We keep the gain so we can compute the proper volume to report on mute.

(cherry picked from commit d104faec191b47630871aaab546ccd76e08b730d)

Signed-off-by: Steve Lhomme <[email protected]>

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

 modules/audio_output/winstore.c | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/modules/audio_output/winstore.c b/modules/audio_output/winstore.c
index 882c95a2ba..f6130836d7 100644
--- a/modules/audio_output/winstore.c
+++ b/modules/audio_output/winstore.c
@@ -62,6 +62,8 @@ struct aout_sys_t
     wchar_t* requested_device;
     wchar_t* default_device; // read once on open
 
+    float gain;
+
     // IActivateAudioInterfaceCompletionHandler interface
     IActivateAudioInterfaceCompletionHandler client_locator;
     vlc_sem_t async_completed;
@@ -279,17 +281,18 @@ static int VolumeSet(audio_output_t *aout, float vol)
         return VLC_EGENERIC;
     HRESULT hr;
     ISimpleAudioVolume *pc_AudioVolume = NULL;
-    float gain = 1.f;
 
-    vol = vol * vol * vol; /* ISimpleAudioVolume is tapered linearly. */
+    float linear_vol = vol * vol * vol; /* ISimpleAudioVolume is tapered 
linearly. */
 
-    if (vol > 1.f)
+    if (linear_vol > 1.f)
     {
-        gain = vol;
-        vol = 1.f;
+        sys->gain = linear_vol;
+        linear_vol = 1.f;
     }
+    else
+        sys->gain = 1.f;
 
-    aout_GainRequest(aout, gain);
+    aout_GainRequest(aout, sys->gain);
 
     hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, 
&pc_AudioVolume);
     if (FAILED(hr))
@@ -298,15 +301,18 @@ static int VolumeSet(audio_output_t *aout, float vol)
         goto done;
     }
 
-    hr = ISimpleAudioVolume_SetMasterVolume(pc_AudioVolume, vol, NULL);
+    hr = ISimpleAudioVolume_SetMasterVolume(pc_AudioVolume, linear_vol, NULL);
     if (FAILED(hr))
     {
         msg_Err(aout, "cannot set volume (error 0x%lx)", hr);
         goto done;
     }
 
+    aout_VolumeReport(aout, vol);
+
 done:
-    ISimpleAudioVolume_Release(pc_AudioVolume);
+    if (pc_AudioVolume)
+        ISimpleAudioVolume_Release(pc_AudioVolume);
 
     return SUCCEEDED(hr) ? 0 : -1;
 }
@@ -333,10 +339,20 @@ static int MuteSet(audio_output_t *aout, bool mute)
         goto done;
     }
 
+    float vol;
+    hr = ISimpleAudioVolume_GetMasterVolume(pc_AudioVolume, &vol);
+    if (FAILED(hr))
+    {
+        msg_Err(aout, "cannot get volume (error 0x%lX)", hr);
+        goto done;
+    }
+
+    aout_VolumeReport(aout, cbrtf(vol * sys->gain));
     aout_MuteReport(aout, mute);
 
 done:
-    ISimpleAudioVolume_Release(pc_AudioVolume);
+    if (pc_AudioVolume)
+        ISimpleAudioVolume_Release(pc_AudioVolume);
 
     return SUCCEEDED(hr) ? 0 : -1;
 }
@@ -549,6 +565,7 @@ static int Open(vlc_object_t *obj)
     sys->requested_device = sys->default_device;
     sys->acquired_device = NULL;
     sys->client_locator = (IActivateAudioInterfaceCompletionHandler) { 
&MMDeviceLocator_vtable };
+    sys->gain = 1.f;
 
     aout->sys = sys;
     sys->stream = NULL;

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to