[vlc-devel] [PATCH 02/17] clock: allow to return VLC_TICK_INVALID from convert calls

Thomas Guillem thomas at gllm.fr
Wed Feb 17 09:36:07 UTC 2021


On Tue, Feb 16, 2021, at 17:54, Rémi Denis-Courmont wrote:
> Le maanantaina 15. helmikuuta 2021, 12.14.57 EET Thomas Guillem a écrit :
> > For now, when the main clock is reset, vlc_clock_ConvertToSystem() won't
> > return VLC_TICK_INVALID since it will fallback to
> > vlc_clock_monotonic_to_system_locked() but this behavior will change in
> > next commits.
> 
> As I recall, we had agreed that timestamping must never fail?

Yes, we agreed on that. After a second though, I agree to discard these patches.

But since the input can now be reset before the output see it, it must be handled.

For now, I propose to return system_now when the input is reset. That means that output asking for pts conversion will likely display their frame right away when the input is reset.

Then, I will propose a new patch set doing the following. When the input is reset, the old reference of the output clock is not discarded but kept until all output ES acknowledges it. Output ES will be able to ack it by calling vlc_clock_Reset().

This means that output ES will be able to convert "old" (or "reset") PTS while the input is reset. This can be very useful if we add a new control like ES_OUT_RESET_PCR that drain instead of flush. Demuxers could use this new control to signal discontinuity that doesn't need any flush (and avoid dropping lot of frames when a discontinuity is seen by the input thread). 

> 
> > ---
> >  src/clock/clock.c | 17 ++++++++++++++++-
> >  src/clock/clock.h | 12 ++++++++----
> >  2 files changed, 24 insertions(+), 5 deletions(-)
> > 
> > diff --git a/src/clock/clock.c b/src/clock/clock.c
> > index cfbb5eb6f6d..32f6b573632 100644
> > --- a/src/clock/clock.c
> > +++ b/src/clock/clock.c
> > @@ -306,6 +306,8 @@ static vlc_tick_t vlc_clock_slave_update(vlc_clock_t
> > *clock, vlc_tick_t computed = clock->to_system_locked(clock, system_now,
> > ts, rate);
> > 
> >      vlc_mutex_unlock(&main_clock->lock);
> > +    if (computed == VLC_TICK_INVALID)
> > +        return computed;
> > 
> >      vlc_clock_on_update(clock, computed, ts, rate, frame_rate,
> > frame_rate_base); return computed - system_now;
> > @@ -349,7 +351,11 @@ void vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t
> > system_now, vlc_tick_t ts, if (main_clock->pause_date != VLC_TICK_INVALID)
> >              deadline = INT64_MAX;
> >          else
> > +        {
> >              deadline = clock->to_system_locked(clock, system_now, ts,
> > rate); +            if (deadline == VLC_TICK_INVALID)
> > +                break;
> > +        }
> >          deadline = __MIN(deadline, max_deadline);
> > 
> >          if (vlc_cond_timedwait(&main_clock->cond, &main_clock->lock,
> > deadline)) @@ -508,16 +514,25 @@ vlc_tick_t
> > vlc_clock_ConvertToSystem(vlc_clock_t *clock, vlc_tick_t system_now, return
> > system;
> >  }
> > 
> > -void vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t
> > system_now, +int vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock,
> > vlc_tick_t system_now, vlc_tick_t *ts_array, size_t ts_count, double rate)
> >  {
> >      vlc_clock_main_t *main_clock = clock->owner;
> >      vlc_mutex_lock(&main_clock->lock);
> >      for (size_t i = 0; i < ts_count; ++i)
> > +    {
> >          ts_array[i] = clock->to_system_locked(clock, system_now,
> > ts_array[i], rate);
> > +        if (ts_array[i] == VLC_TICK_INVALID)
> > +        {
> > +            vlc_mutex_unlock(&main_clock->lock);
> > +            return VLC_EGENERIC;
> > +        }
> > +    }
> >      vlc_mutex_unlock(&main_clock->lock);
> > +
> > +    return VLC_SUCCESS;
> >  }
> > 
> >  static void vlc_clock_set_master_callbacks(vlc_clock_t *clock)
> > diff --git a/src/clock/clock.h b/src/clock/clock.h
> > index e7373391697..b852af0eb23 100644
> > --- a/src/clock/clock.h
> > +++ b/src/clock/clock.h
> > @@ -168,16 +168,20 @@ void vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t
> > system_now, vlc_tick_t ts,
> > 
> >  /**
> >   * This function converts a timestamp from stream to system
> > - * @return the valid system time or INT64_MAX when the clock is paused
> > + * @return the valid system time, INT64_MAX when the clock is paused or
> > + * VLC_TICK_INVALID when the main clock is reset (the master source is
> > flushed). */
> >  vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t *clock, vlc_tick_t
> > system_now, vlc_tick_t ts, double rate);
> > 
> >  /**
> >   * This functon converts an array of timestamp from stream to system
> > + *
> > + * @return VLC_SUCCESS or VLC_EGENERIC if the clock is reset (the master
> > source + * is flushed).
> >   */
> > -void vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t
> > system_now, -                                    vlc_tick_t *ts_array,
> > size_t ts_count, -                                    double rate);
> > +int vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t
> > system_now, +                                   vlc_tick_t *ts_array,
> > size_t ts_count, +                                   double rate);
> > 
> >  #endif /*VLC_CLOCK_H*/
> 
> 
> -- 
> Rémi Denis-Courmont
> http://www.remlab.net/
> 
> 
> 
> _______________________________________________
> 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