[vlc-devel] [PATCH] coreaudio: update the play date until the first rendering

Thomas Guillem thomas at gllm.fr
Fri Sep 27 15:09:44 CEST 2019


cf. fe2e9755088a0061518514f3b7bf3601f4813794

Only the first play date was handled. This is OK in most cases but not as
accurate as handling the date until the playback is truly started.

This previous commit and this commit were inspired by the pulse module.
---
 modules/audio_output/coreaudio_common.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index d11343e72c..921c88eb28 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -242,6 +242,15 @@ drop:
     lock_unlock(p_sys);
 }
 
+static vlc_tick_t
+ca_GetLatencyLocked(audio_output_t *p_aout)
+{
+    struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
+
+    const int64_t i_out_frames = BytesToFrames(p_sys, p_sys->i_out_size);
+    return FramesToUs(p_sys, i_out_frames + p_sys->i_render_frames);
+}
+
 int
 ca_TimeGet(audio_output_t *p_aout, vlc_tick_t *delay)
 {
@@ -259,10 +268,8 @@ ca_TimeGet(audio_output_t *p_aout, vlc_tick_t *delay)
     const vlc_tick_t i_render_time_us = HostTimeToTick(p_sys->i_render_host_time);
     const vlc_tick_t i_render_delay = i_render_time_us - vlc_tick_now();
 
-    const int64_t i_out_frames = BytesToFrames(p_sys, p_sys->i_out_size);
-    *delay = FramesToUs(p_sys, i_out_frames + p_sys->i_render_frames)
-           + p_sys->i_dev_latency_us + i_render_delay;
-
+    *delay = ca_GetLatencyLocked(p_aout) + i_render_delay
+           + p_sys->i_dev_latency_us;
     lock_unlock(p_sys);
     return 0;
 }
@@ -316,10 +323,14 @@ ca_Play(audio_output_t * p_aout, block_t * p_block, vlc_tick_t date)
 
     lock_lock(p_sys);
 
-    if (p_sys->i_first_render_host_time == 0)
+    if (p_sys->i_render_host_time == 0)
     {
-        /* Setup the first render time */
-        p_sys->i_first_render_host_time = TickToHostTime(date);
+        /* Setup the first render time, this date must be updated until the
+         * first (non-silence/zero) frame is rendered by the render callback.
+         * Once the rendering is truly started, the date can be ignored. */
+
+        const vlc_tick_t first_render_time = date - ca_GetLatencyLocked(p_aout);
+        p_sys->i_first_render_host_time = TickToHostTime(first_render_time);
     }
 
     do
-- 
2.20.1



More information about the vlc-devel mailing list