[vlc-devel] [PATCH] wasapi: use a finer sleep precision

Thomas Guillem thomas at gllm.fr
Thu May 14 16:09:55 CEST 2020


Using the device period and the remaining block sample.
---
 modules/audio_output/wasapi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 5180e93f8e8..d338351963f 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -107,6 +107,7 @@ typedef struct aout_stream_sys
     UINT64 written; /**< Frames written to the buffer */
     UINT32 frames; /**< Total buffer size (frames) */
     bool s24s32; /**< Output configured as S24N, but input as S32N */
+    vlc_tick_t period;
 } aout_stream_sys_t;
 
 static void ResetTimer(aout_stream_t *s)
@@ -304,7 +305,8 @@ static HRESULT Play(aout_stream_t *s, block_t *block, vlc_tick_t date)
             break; /* done */
 
         /* Out of buffer space, sleep */
-        vlc_tick_sleep(sys->frames * VLC_TICK_FROM_MS(500) / sys->rate);
+        vlc_tick_sleep(vlc_tick_from_samples(block->i_nb_samples, sys->rate)
+                       + sys->period);
     }
     IAudioRenderClient_Release(render);
 out:
@@ -884,7 +886,10 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict pfmt,
         msg_Dbg(s, "maximum latency: %"PRIu64"00 ns", latT);
         msg_Dbg(s, "default period : %"PRIu64"00 ns", defT);
         msg_Dbg(s, "minimum period : %"PRIu64"00 ns", minT);
+        sys->period = VLC_TICK_FROM_MSFTIME(defT);
     }
+    else
+        sys->period = 0;
 
     CoTaskMemFree(pwf_mix);
     *pfmt = fmt;
-- 
2.20.1



More information about the vlc-devel mailing list