[vlc-commits] wasapi: fix corner (error) case and simplify a little

Rémi Denis-Courmont git at videolan.org
Wed Aug 8 21:51:52 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Aug  8 22:50:37 2012 +0300| [350e328a95aba120c493aa00b4804724181d4ba3] | committer: Rémi Denis-Courmont

wasapi: fix corner (error) case and simplify a little

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

 modules/audio_output/wasapi.c |   55 ++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index af12649..273571c 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -83,10 +83,6 @@ struct aout_sys_t
     IAudioRenderClient *render;
     IAudioClock *clock;
 
-    union
-    {
-        ISimpleAudioVolume *simple;
-    } volume;
     IAudioSessionControl *control;
     struct IAudioSessionEvents events;
     LONG refs;
@@ -207,30 +203,50 @@ static void Flush(audio_output_t *aout, bool wait)
 
 static int SimpleVolumeSet(audio_output_t *aout, float vol)
 {
-    aout_sys_t *sys = aout->sys;
+    ISimpleAudioVolume *simple;
     HRESULT hr;
 
     if (TryEnter(aout))
         return -1;
-    hr = ISimpleAudioVolume_SetMasterVolume(sys->volume.simple, vol, NULL);
-    if (FAILED(hr))
-        msg_Warn(aout, "cannot set session volume (error 0x%lx)", hr);
+    hr = IAudioClient_GetService(aout->sys->client, &IID_ISimpleAudioVolume,
+                                 (void **)&simple);
+    if (SUCCEEDED(hr))
+    {
+        hr = ISimpleAudioVolume_SetMasterVolume(simple, vol, NULL);
+        ISimpleAudioVolume_Release(simple);
+    }
     Leave();
-    return FAILED(hr) ? -1 : 0;
+
+    if (FAILED(hr))
+    {
+        msg_Err(aout, "cannot set volume (error 0x%lx)", hr);
+        return -1;
+    }
+    return 0;
 }
 
 static int SimpleMuteSet(audio_output_t *aout, bool mute)
 {
-    aout_sys_t *sys = aout->sys;
+    ISimpleAudioVolume *simple;
     HRESULT hr;
 
     if (TryEnter(aout))
         return -1;
-    hr = ISimpleAudioVolume_SetMute(sys->volume.simple, mute, NULL);
-    if (FAILED(hr))
-        msg_Warn(aout, "cannot mute session (error 0x%lx)", hr);
+    hr = IAudioClient_GetService(aout->sys->client, &IID_ISimpleAudioVolume,
+                                 (void **)&simple);
+    if (SUCCEEDED(hr))
+    {
+        hr = ISimpleAudioVolume_SetMute(simple, mute, NULL);
+        ISimpleAudioVolume_Release(simple);
+    }
     Leave();
-    return FAILED(hr) ? -1 : 0;
+
+    if (FAILED(hr))
+    {
+        msg_Err(aout, "cannot set mute (error 0x%lx)", hr);
+        return -1;
+    }
+    return 0;
 }
 
 
@@ -576,12 +592,6 @@ static void MTAThread(void *data)
     if (FAILED(hr))
         msg_Warn(aout, "cannot get audio clock (error 0x%lx)", hr);
 
-    /*if (AOUT_FMT_LINEAR(&format) && !exclusive)*/
-    {
-        hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume,
-                                     (void **)&sys->volume.simple);
-    }
-
     hr = IAudioClient_GetService(sys->client, &IID_IAudioSessionControl,
                                  (void **)&sys->control);
     if (FAILED(hr))
@@ -599,11 +609,6 @@ static void MTAThread(void *data)
 
     if (sys->control != NULL)
         IAudioSessionControl_Release(sys->control);
-    /*if (AOUT_FMT_LINEAR(&format) && !exclusive)*/
-    {
-        if (sys->volume.simple != NULL)
-            ISimpleAudioVolume_Release(sys->volume.simple);
-    }
     if (sys->clock != NULL)
         IAudioClock_Release(sys->clock);
     IAudioRenderClient_Release(sys->render);



More information about the vlc-commits mailing list