[vlc-commits] wasapi: work around broken interfaces (fixes #7736)

Rémi Denis-Courmont git at videolan.org
Sun Nov 25 11:33:13 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 25 12:32:41 2012 +0200| [072c7424c7b5b3abf349450e3ff007140b926963] | committer: Rémi Denis-Courmont

wasapi: work around broken interfaces (fixes #7736)

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

 modules/audio_output/wasapi.c |   38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index d7e6f9a..41fe00b 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -130,6 +130,9 @@ struct aout_sys_t
     UINT32 written; /**< Frames written to the buffer */
     UINT32 frames; /**< Total buffer size (frames) */
 
+    float volume_hack; /**< Deferred volume request */
+    int mute_hack; /**< Deferred mute request */
+
     HANDLE ready; /**< Semaphore from MTA thread */
     HANDLE done; /**< Semaphore to MTA thread */
 };
@@ -166,11 +169,29 @@ static int TimeGet(audio_output_t *aout, mtime_t *restrict delay)
     return 0;
 }
 
+static void CheckVolumeHack(audio_output_t *aout)
+{
+    aout_sys_t *sys = aout->sys;
+
+    if (unlikely(sys->volume_hack >= 0.f))
+    {   /* Apply volume now, if it failed earlier */
+        aout->volume_set(aout, sys->volume_hack);
+        sys->volume_hack = -1.f;
+    }
+    if (unlikely(sys->mute_hack >= 0))
+    {   /* Apply volume now, if it failed earlier */
+        aout->mute_set(aout, sys->mute_hack);
+        sys->mute_hack = -1;
+    }
+}
+
 static void Play(audio_output_t *aout, block_t *block)
 {
     aout_sys_t *sys = aout->sys;
     HRESULT hr = S_OK;
 
+    CheckVolumeHack(aout);
+
     if (sys->chans_to_reorder)
         aout_ChannelReorder(block->p_buffer, block->i_buffer,
                           sys->chans_to_reorder, sys->chans_table, sys->bits);
@@ -235,6 +256,8 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
     aout_sys_t *sys = aout->sys;
     HRESULT hr;
 
+    CheckVolumeHack(aout);
+
     Enter();
     if (paused)
         hr = IAudioClient_Stop(sys->client);
@@ -253,6 +276,8 @@ static void Flush(audio_output_t *aout, bool wait)
     aout_sys_t *sys = aout->sys;
     HRESULT hr;
 
+    CheckVolumeHack(aout);
+
     if (wait)
         return; /* Drain not implemented */
 
@@ -269,12 +294,13 @@ 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 = IAudioClient_GetService(aout->sys->client, &IID_ISimpleAudioVolume,
+    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume,
                                  (void **)&simple);
     if (SUCCEEDED(hr))
     {
@@ -286,19 +312,22 @@ static int SimpleVolumeSet(audio_output_t *aout, float vol)
     if (FAILED(hr))
     {
         msg_Err(aout, "cannot set volume (error 0x%lx)", hr);
+        sys->volume_hack = vol;
         return -1;
     }
+    sys->volume_hack = -1.f;
     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 = IAudioClient_GetService(aout->sys->client, &IID_ISimpleAudioVolume,
+    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume,
                                  (void **)&simple);
     if (SUCCEEDED(hr))
     {
@@ -310,8 +339,10 @@ static int SimpleMuteSet(audio_output_t *aout, bool mute)
     if (FAILED(hr))
     {
         msg_Err(aout, "cannot set mute (error 0x%lx)", hr);
+        sys->mute_hack = mute;
         return -1;
     }
+    sys->mute_hack = -1;
     return 0;
 }
 
@@ -897,6 +928,9 @@ static int Open(vlc_object_t *obj)
     GetDevices(obj, sys->it);
     Leave();
 
+    sys->volume_hack = -1.f;
+    sys->mute_hack = -1;
+
     aout->sys = sys;
     aout->start = Start;
     aout->stop = Stop;



More information about the vlc-commits mailing list