[vlc-devel] [PATCH 6/6] coreaudio: start deferred

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 19 14:14:10 CEST 2019


On 2019-08-16 10:55, Thomas Guillem wrote:
> 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.
> ---
>   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 8d3a78bede..fa03269d39 100644
> --- a/modules/audio_output/coreaudio_common.c
> +++ b/modules/audio_output/coreaudio_common.c
> @@ -48,6 +48,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)
>   {
> @@ -55,6 +67,13 @@ HostTimeToTick(uint64_t i_host_time)
>       return i_host_time * tinfo.numer / tinfo.denom / 1000;
>   }
>   
> +static inline uint64_t
> +TickToHostTime(vlc_tick_t i_us)
> +{
> +    assert(tinfo.denom != 0);
> +    return i_us * tinfo.denom / tinfo.numer * 1000;

Same thing here, CLOCK_FREQ should be involved, via 
samples_from_vlc_tick() for example.

> +}
> +
>   static void
>   ca_ClearOutBuffers(audio_output_t *p_aout)
>   {
> @@ -158,9 +177,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);
> @@ -169,9 +185,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)
> @@ -222,8 +271,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;
>       }
> @@ -257,7 +307,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);
>   
> @@ -287,6 +337,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 =
> @@ -359,7 +416,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 60ef1fe9ca..06ee98407a 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;
> -- 
> 2.20.1
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list