[vlc-commits] coreaudio: start deferred
Thomas Guillem
git at videolan.org
Wed Aug 21 09:57:51 CEST 2019
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Aug 16 10:14:23 2019 +0200| [fe2e9755088a0061518514f3b7bf3601f4813794] | committer: Thomas Guillem
coreaudio: start deferred
It now use the play date argument to delay the first render until this date is
reached (TimeGet() will return -1 in during this step).
This aout module now respect the jitter delay from the new output clock.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fe2e9755088a0061518514f3b7bf3601f4813794
---
modules/audio_output/coreaudio_common.c | 71 +++++++++++++++++++++++++++++----
modules/audio_output/coreaudio_common.h | 1 +
2 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index c20a07670c..d11343e72c 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -42,6 +42,18 @@ FramesToUs(struct aout_sys_common *p_sys, uint64_t i_nb_frames)
return vlc_tick_from_samples(i_nb_frames, p_sys->i_rate);
}
+static inline size_t
+FramesToBytes(struct aout_sys_common *p_sys, uint64_t i_frames)
+{
+ return i_frames * p_sys->i_bytes_per_frame / p_sys->i_frame_length;
+}
+
+static inline uint64_t
+UsToFrames(struct aout_sys_common *p_sys, vlc_tick_t i_us)
+{
+ return samples_from_vlc_tick(i_us, p_sys->i_rate);
+}
+
static inline vlc_tick_t
HostTimeToTick(uint64_t i_host_time)
{
@@ -49,6 +61,13 @@ HostTimeToTick(uint64_t i_host_time)
return VLC_TICK_FROM_NS(i_host_time * tinfo.numer / tinfo.denom);
}
+static inline uint64_t
+TickToHostTime(vlc_tick_t i_us)
+{
+ assert(tinfo.denom != 0);
+ return NS_FROM_VLC_TICK(i_us * tinfo.denom / tinfo.numer);
+}
+
static void
ca_ClearOutBuffers(audio_output_t *p_aout)
{
@@ -136,9 +155,6 @@ ca_Render(audio_output_t *p_aout, uint32_t i_frames, uint64_t i_host_time,
lock_lock(p_sys);
- p_sys->i_render_host_time = i_host_time;
- p_sys->i_render_frames = i_frames;
-
if (p_sys->b_do_flush)
{
ca_ClearOutBuffers(p_aout);
@@ -147,9 +163,42 @@ ca_Render(audio_output_t *p_aout, uint32_t i_frames, uint64_t i_host_time,
vlc_sem_post(&p_sys->flush_sem);
}
- if (p_sys->b_paused)
+ if (p_sys->b_paused || unlikely(p_sys->i_first_render_host_time == 0))
goto drop;
+ /* Start deferred: write silence (zeros) until we reach the first render
+ * host time. */
+ if (unlikely(p_sys->i_first_render_host_time > i_host_time ))
+ {
+ /* Convert the requested bytes into host time and check that it does
+ * not overlap between the first_render host time and the current one.
+ * */
+ const size_t i_requested_us =
+ FramesToUs(p_sys, BytesToFrames(p_sys, i_requested));
+ const uint64_t i_requested_host_time = TickToHostTime(i_requested_us);
+ if (p_sys->i_first_render_host_time >= i_host_time + i_requested_host_time)
+ {
+ /* Fill the buffer with silence */
+ goto drop;
+ }
+
+ /* Write silence to reach the first_render host time */
+ const vlc_tick_t i_silence_us =
+ HostTimeToTick(p_sys->i_first_render_host_time - i_host_time);
+
+ const uint64_t i_silence_bytes =
+ FramesToBytes(p_sys, UsToFrames(p_sys, i_silence_us));
+ assert(i_silence_bytes <= i_requested);
+ memset(p_output, 0, i_silence_bytes);
+
+ i_requested -= i_silence_bytes;
+
+ /* Start the first rendering */
+ }
+
+ p_sys->i_render_host_time = i_host_time;
+ p_sys->i_render_frames = i_frames;
+
size_t i_copied = 0;
block_t *p_block = p_sys->p_out_chain;
while (p_block != NULL && i_requested != 0)
@@ -200,8 +249,9 @@ ca_TimeGet(audio_output_t *p_aout, vlc_tick_t *delay)
lock_lock(p_sys);
- if (p_sys->i_render_host_time == 0)
+ if (p_sys->i_render_host_time == 0 || p_sys->i_first_render_host_time == 0)
{
+ /* Not yet started (or reached the first_render host time) */
lock_unlock(p_sys);
return -1;
}
@@ -235,7 +285,7 @@ ca_Flush(audio_output_t *p_aout)
lock_lock(p_sys);
}
- p_sys->i_render_host_time = 0;
+ p_sys->i_render_host_time = p_sys->i_first_render_host_time = 0;
p_sys->i_render_frames = 0;
lock_unlock(p_sys);
@@ -265,6 +315,13 @@ ca_Play(audio_output_t * p_aout, block_t * p_block, vlc_tick_t date)
VLC_CODEC_FL32);
lock_lock(p_sys);
+
+ if (p_sys->i_first_render_host_time == 0)
+ {
+ /* Setup the first render time */
+ p_sys->i_first_render_host_time = TickToHostTime(date);
+ }
+
do
{
const size_t i_avalaible_bytes =
@@ -337,7 +394,7 @@ ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
p_sys->i_underrun_size = 0;
p_sys->b_paused = false;
- p_sys->i_render_host_time = 0;
+ p_sys->i_render_host_time = p_sys->i_first_render_host_time = 0;
p_sys->i_render_frames = 0;
p_sys->i_rate = fmt->i_rate;
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h
index 0df65c2aaa..782739958b 100644
--- a/modules/audio_output/coreaudio_common.h
+++ b/modules/audio_output/coreaudio_common.h
@@ -59,6 +59,7 @@ struct aout_sys_common
block_t *p_out_chain;
block_t **pp_out_last;
uint64_t i_render_host_time;
+ uint64_t i_first_render_host_time;
uint32_t i_render_frames;
vlc_sem_t flush_sem;
More information about the vlc-commits
mailing list