[vlc-devel] [PATCH 2/2] audio_output: coreaudio: use int64_t for host time

Alexandre Janniaux ajanni at videolabs.io
Thu Jul 23 10:41:29 CEST 2020


Hi,

On Thu, Jul 23, 2020 at 10:31:19AM +0200, Thomas Guillem wrote:
> cf. https://developer.apple.com/documentation/coreaudiotypes/audiotimestamp/1422266-mhosttime
>
> Host time is an uint64_t.
>
> Should we instead fix the unsigned calculation?
> It seems that on iOS, the host_time can be before mach_absolute_time() ? We should debug why it happens. It the host_time always late or only the first ones?

Indeed we could only change the computation only too. Overflow
isn't really check in both case currently, although I don't think
it's a real issue.

The host_time is sometimes late, often not.

So it would mean that I keep the change in functions but drop
the change for storage, is that ok with you?

Regards,
--
Alexandre Janniaux
Videolabs

>
>
> On Thu, Jul 23, 2020, at 09:57, Alexandre Janniaux wrote:
> > The computation was leading to very high render_delay (for example in
> > some measurement, render_delay = 6148914691236500), and so glitch during
> > playback with for instance the following warnings:
> >
> >     libvlc video output warning: picture is too late to be displayed
> >     (missing 4279998112535367 ms)
> >
> > Instead, use int64_t for host_time. Unsignedness is kept for computation
> > on frames / bytes.
> > ---
> >  modules/audio_output/coreaudio_common.c | 23 +++++++++++++----------
> >  modules/audio_output/coreaudio_common.h |  6 +++---
> >  2 files changed, 16 insertions(+), 13 deletions(-)
> >
> > diff --git a/modules/audio_output/coreaudio_common.c
> > b/modules/audio_output/coreaudio_common.c
> > index 797c3e623d..b3df6289b8 100644
> > --- a/modules/audio_output/coreaudio_common.c
> > +++ b/modules/audio_output/coreaudio_common.c
> > @@ -46,16 +46,17 @@ FramesToBytes(struct aout_sys_common *p_sys,
> > uint64_t i_frames)
> >  static inline uint64_t
> >  UsToFrames(struct aout_sys_common *p_sys, vlc_tick_t i_us)
> >  {
> > +    assert(i_us > 0);
> >      return samples_from_vlc_tick(i_us, p_sys->i_rate);
> >  }
> >
> >  static inline vlc_tick_t
> > -HostTimeToTick(struct aout_sys_common *p_sys, uint64_t i_host_time)
> > +HostTimeToTick(struct aout_sys_common *p_sys, int64_t i_host_time)
> >  {
> >      return VLC_TICK_FROM_NS(i_host_time * p_sys->tinfo.numer /
> > p_sys->tinfo.denom);
> >  }
> >
> > -static inline uint64_t
> > +static inline int64_t
> >  TickToHostTime(struct aout_sys_common *p_sys, vlc_tick_t i_us)
> >  {
> >      return NS_FROM_VLC_TICK(i_us * p_sys->tinfo.denom / p_sys->tinfo.numer);
> > @@ -124,7 +125,7 @@ ca_Open(audio_output_t *p_aout)
> >
> >  /* Called from render callbacks. No lock, wait, and IO here */
> >  void
> > -ca_Render(audio_output_t *p_aout, uint32_t i_frames, uint64_t
> > i_host_time,
> > +ca_Render(audio_output_t *p_aout, uint32_t i_frames, int64_t
> > i_host_time,
> >            uint8_t *p_output, size_t i_requested)
> >  {
> >      struct aout_sys_common *p_sys = (struct aout_sys_common *)
> > p_aout->sys;
> > @@ -157,7 +158,7 @@ ca_Render(audio_output_t *p_aout, uint32_t
> > i_frames, uint64_t i_host_time,
> >           * */
> >          const size_t i_requested_us =
> >              FramesToUs(p_sys, BytesToFrames(p_sys, i_requested));
> > -        const uint64_t i_requested_host_time =
> > +        const int64_t i_requested_host_time =
> >              TickToHostTime(p_sys, i_requested_us);
> >          if (p_sys->i_first_render_host_time >= i_host_time +
> > i_requested_host_time)
> >          {
> > @@ -169,7 +170,7 @@ ca_Render(audio_output_t *p_aout, uint32_t
> > i_frames, uint64_t i_host_time,
> >          const vlc_tick_t i_silence_us =
> >              HostTimeToTick(p_sys, p_sys->i_first_render_host_time -
> > i_host_time);
> >
> > -        const uint64_t i_silence_bytes =
> > +        const size_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);
> > @@ -244,17 +245,19 @@ ca_TimeGet(audio_output_t *p_aout, vlc_tick_t *delay)
> >
> >      if (p_sys->i_render_host_time == 0 || p_sys->i_first_render_host_time == 0)
> >      {
> > +        msg_Info(p_aout, "aout - not yet started");
>
> stray debug
>
> >          /* Not yet started (or reached the first_render host time) */
> >          lock_unlock(p_sys);
> >          return -1;
> >      }
> >
> > -    uint64_t i_render_delay_host_time = p_sys->i_render_host_time
> > -                                      - mach_absolute_time();
> > +    int64_t i_render_delay_host_time = p_sys->i_render_host_time
> > +                                     - mach_absolute_time();
> >      const vlc_tick_t i_render_delay =
> >          HostTimeToTick(p_sys, i_render_delay_host_time);
> >
> > -    *delay = ca_GetLatencyLocked(p_aout) + i_render_delay;
> > +    vlc_tick_t latency = ca_GetLatencyLocked(p_aout);
> > +    *delay = latency + i_render_delay;
> >      lock_unlock(p_sys);
> >      return 0;
> >  }
> > @@ -511,8 +514,8 @@ RenderCallback(void *p_data,
> > AudioUnitRenderActionFlags *ioActionFlags,
> >      VLC_UNUSED(inTimeStamp);
> >      VLC_UNUSED(inBusNumber);
> >
> > -    uint64_t i_host_time = (inTimeStamp->mFlags & kAudioTimeStampHostTimeValid)
> > -                         ? inTimeStamp->mHostTime : 0;
> > +    int64_t i_host_time = (inTimeStamp->mFlags & kAudioTimeStampHostTimeValid)
> > +                        ? inTimeStamp->mHostTime : 0;
> >
> >      ca_Render(p_data, inNumberFrames, i_host_time,
> > ioData->mBuffers[0].mData,
> >                ioData->mBuffers[0].mDataByteSize);
> > diff --git a/modules/audio_output/coreaudio_common.h
> > b/modules/audio_output/coreaudio_common.h
> > index 4bd6139493..c757cf0042 100644
> > --- a/modules/audio_output/coreaudio_common.h
> > +++ b/modules/audio_output/coreaudio_common.h
> > @@ -60,8 +60,8 @@ struct aout_sys_common
> >      bool                b_played;
> >      block_t             *p_out_chain;
> >      block_t             **pp_out_last;
> > -    uint64_t            i_render_host_time;
> > -    uint64_t            i_first_render_host_time;
> > +    int64_t             i_render_host_time;
> > +    int64_t             i_first_render_host_time;
> >      uint32_t            i_render_frames;
> >
> >      vlc_sem_t           flush_sem;
> > @@ -86,7 +86,7 @@ struct aout_sys_common
> >
> >  int ca_Open(audio_output_t *p_aout);
> >
> > -void ca_Render(audio_output_t *p_aout, uint32_t i_nb_samples, uint64_t
> > i_host_time,
> > +void ca_Render(audio_output_t *p_aout, uint32_t i_nb_samples, int64_t
> > i_host_time,
> >                 uint8_t *p_output, size_t i_requested);
> >
> >  int  ca_TimeGet(audio_output_t *p_aout, vlc_tick_t *delay);
> > --
> > 2.27.0
> >
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> 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