[vlc-devel] [PATCH 05/13] clock: forward clock update points
Thomas Guillem
thomas at gllm.fr
Thu Aug 22 10:55:12 CEST 2019
On Wed, Aug 21, 2019, at 19:18, Rémi Denis-Courmont wrote:
> Le keskiviikkona 21. elokuuta 2019, 17.13.56 EEST Thomas Guillem a écrit :
> > ---
> > src/clock/clock.c | 63 ++++++++++++++++++++++++++++++++++++++--------
> > src/clock/clock.h | 30 ++++++++++++++++++++--
> > src/input/es_out.c | 5 ++--
> > 3 files changed, 84 insertions(+), 14 deletions(-)
> >
> > diff --git a/src/clock/clock.c b/src/clock/clock.c
> > index de2f2a61b9..24780ea652 100644
> > --- a/src/clock/clock.c
> > +++ b/src/clock/clock.c
> > @@ -71,6 +71,9 @@ struct vlc_clock_t
> > vlc_clock_main_t *owner;
> > vlc_tick_t delay;
> > vlc_tick_t dejitter;
> > +
> > + const struct vlc_clock_cbs *cbs;
> > + void *cbs_data;
> > };
> >
> > static vlc_tick_t main_stream_to_system(vlc_clock_main_t *main_clock,
> > @@ -94,6 +97,14 @@ static void vlc_clock_main_reset(vlc_clock_main_t
> > *main_clock) vlc_cond_broadcast(&main_clock->cond);
> > }
> >
> > +static inline void vlc_clock_on_update(vlc_clock_t *clock,
> > + vlc_tick_t system_now,
> > + vlc_tick_t ts, double rate)
> > +{
> > + if (clock->cbs)
> > + clock->cbs->on_update(clock, system_now, ts, rate,
> > clock->cbs_data); +}
> > +
> > static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
> > vlc_tick_t system_now,
> > vlc_tick_t ts, double rate)
> > @@ -128,7 +139,11 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t
> > *clock,
> >
> > main_clock->rate = rate;
> > vlc_cond_broadcast(&main_clock->cond);
> > +
> > + ts -= main_clock->first_pcr;
> > vlc_mutex_unlock(&main_clock->lock);
> > +
> > + vlc_clock_on_update(clock, system_now, ts, rate);
> > return 0;
> > }
> >
> > @@ -158,6 +173,8 @@ static void vlc_clock_master_reset(vlc_clock_t *clock)
> > }
> >
> > vlc_mutex_unlock(&main_clock->lock);
> > +
> > + vlc_clock_on_update(clock, VLC_TICK_INVALID, VLC_TICK_INVALID, 1.f);
> > }
> >
> > static vlc_tick_t vlc_clock_master_set_delay(vlc_clock_t *clock, vlc_tick_t
> > delay) @@ -267,8 +284,17 @@ static vlc_tick_t
> > vlc_clock_slave_update(vlc_clock_t *clock,
> > vlc_mutex_lock(&main_clock->lock);
> >
> > vlc_tick_t computed = clock->to_system_locked(clock, system_now, ts,
> > rate); +
> > + /* Forward new ts only if there is no master clocks */
> > + ts -= main_clock->first_pcr;
> > vlc_mutex_unlock(&main_clock->lock);
> > - return computed != INT64_MAX ? computed - system_now :
> > VLC_TICK_INVALID; +
> > + if (computed != INT64_MAX)
> > + {
> > + vlc_clock_on_update(clock, computed, ts, rate);
> > + return computed - system_now;
> > + }
> > + return VLC_TICK_INVALID;
> > }
> >
> > static void vlc_clock_slave_reset(vlc_clock_t *clock)
> > @@ -277,7 +303,10 @@ static void vlc_clock_slave_reset(vlc_clock_t *clock)
> > vlc_mutex_lock(&main_clock->lock);
> > main_clock->wait_sync_ref =
> > clock_point_Create(VLC_TICK_INVALID, VLC_TICK_INVALID);
> > +
> > vlc_mutex_unlock(&main_clock->lock);
> > +
> > + vlc_clock_on_update(clock, VLC_TICK_INVALID, VLC_TICK_INVALID, 1.0f);
> > }
> >
> > static vlc_tick_t vlc_clock_slave_set_delay(vlc_clock_t *clock, vlc_tick_t
> > delay) @@ -324,7 +353,6 @@ static void
> > vlc_clock_slave_set_dejitter(vlc_clock_t *clock, vlc_tick_t delay)
> > VLC_UNUSED(delay);
> > }
> >
> > -
> > vlc_clock_main_t *vlc_clock_main_New(void)
> > {
> > vlc_clock_main_t *main_clock = malloc(sizeof(vlc_clock_main_t));
> > @@ -503,7 +531,9 @@ static void vlc_clock_set_slave_callbacks(vlc_clock_t
> > *clock) clock->to_system_locked = vlc_clock_slave_to_system_locked;
> > }
> >
> > -vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock)
> > +static vlc_clock_t *vlc_clock_main_Create(vlc_clock_main_t *main_clock,
> > + const struct vlc_clock_cbs *cbs,
> > + void *cbs_data)
> > {
> > vlc_clock_t *clock = malloc(sizeof(vlc_clock_t));
> > if (clock == NULL)
> > @@ -511,6 +541,20 @@ vlc_clock_t
> > *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock)
> >
> > clock->owner = main_clock;
> > clock->delay = 0;
> > + clock->cbs = cbs;
> > + clock->cbs_data = cbs_data;
> > + assert(!cbs || cbs->on_update);
> > +
> > + return clock;
> > +}
> > +
> > +vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock,
> > + const struct vlc_clock_cbs *cbs,
> > + void *cbs_data)
> > +{
> > + vlc_clock_t *clock = vlc_clock_main_Create(main_clock, cbs, cbs_data);
> > + if (!clock)
> > + return NULL;
> >
> > vlc_mutex_lock(&main_clock->lock);
> > if (main_clock->master != NULL)
> > @@ -526,15 +570,14 @@ vlc_clock_t
> > *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock) return clock;
> > }
> >
> > -vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock)
> > +vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock,
> > + const struct vlc_clock_cbs *cbs,
> > + void *cbs_data)
> > {
> > - vlc_clock_t *clock = malloc(sizeof(vlc_clock_t));
> > - if (clock == NULL)
> > + vlc_clock_t *clock = vlc_clock_main_Create(main_clock, cbs, cbs_data);
> > + if (!clock)
> > return NULL;
> >
> > - clock->owner = main_clock;
> > - clock->delay = 0;
> > -
> > vlc_mutex_lock(&main_clock->lock);
> > vlc_clock_set_slave_callbacks(clock);
> > main_clock->rc++;
> > @@ -545,7 +588,7 @@ vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t
> > *main_clock)
> >
> > vlc_clock_t *vlc_clock_CreateSlave(const vlc_clock_t *clock)
> > {
> > - return vlc_clock_main_CreateSlave(clock->owner);
> > + return vlc_clock_main_CreateSlave(clock->owner, NULL, NULL);
> > }
> >
> > void vlc_clock_main_SetMaster(vlc_clock_main_t *main_clock, vlc_clock_t
> > *clock) diff --git a/src/clock/clock.h b/src/clock/clock.h
> > index b4394dec8e..db946d6cd2 100644
> > --- a/src/clock/clock.h
> > +++ b/src/clock/clock.h
> > @@ -30,6 +30,28 @@ enum vlc_clock_master_source
> > typedef struct vlc_clock_main_t vlc_clock_main_t;
> > typedef struct vlc_clock_t vlc_clock_t;
> >
> > +/**
> > + * Callbacks for the owner of the main clock
> > + */
> > +struct vlc_clock_cbs
> > +{
> > + /**
> > + * Called when a clock is updated
> > + *
> > + * @param clock a clock created by vlc_clock_main_CreateMaster() or
> > + * vlc_clock_main_CreateSlave()
> > + * @param system_ts system date when the ts will be renderer or
> > + * VLC_TICK_INVALID when the clock is reset. Note: this date can be in
> > the + * future, it is not necassarilly now.
> > + * @param ts stream timestamp or VLC_TICK_INVALID when the clock is
> > reset + * @param rate rate used when updated
> > + * @param data opaque pointer set from vlc_clock_main_New()
> > + */
> > + void (*on_update)(const vlc_clock_t *clock,
> > + vlc_tick_t system_ts, vlc_tick_t ts, double rate,
> > + void *data);
>
> Passing both the clock and an opaque is a bit weird. Also spelling.
OK
>
> > +};
> > +
> > /**
> > * This function creates the vlc_clock_main_t of the program
> > */
> > @@ -88,14 +110,18 @@ void vlc_clock_main_SetMaster(vlc_clock_main_t
> > *main_clock, vlc_clock_t *clock); *
> > * You must use vlc_clock_Delete to free it.
> > */
> > -vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock);
> > +vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock,
> > + const struct vlc_clock_cbs *cbs,
> > + void *cbs_data);
> >
> > /**
> > * This function creates a new slave vlc_clock_t interface
> > *
> > * You must use vlc_clock_Delete to free it.
> > */
> > -vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock);
> > +vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock,
> > + const struct vlc_clock_cbs *cbs,
> > + void *cbs_data);
> >
> > /**
> > * This function creates a new slave vlc_clock_t interface
> > diff --git a/src/input/es_out.c b/src/input/es_out.c
> > index 2db2fa7d2c..49eb52d2bc 100644
> > --- a/src/input/es_out.c
> > +++ b/src/input/es_out.c
> > @@ -2010,9 +2010,10 @@ static void EsOutCreateDecoder( es_out_t *out,
> > es_out_id_t *p_es ) && p_es->fmt.i_cat == p_sys->i_master_source_cat
> > && p_es->p_pgrm->p_master_clock == NULL )
> > p_es->p_pgrm->p_master_clock = p_es->p_clock =
> > - vlc_clock_main_CreateMaster( p_es->p_pgrm->p_main_clock );
> > + vlc_clock_main_CreateMaster( p_es->p_pgrm->p_main_clock, NULL,
> > NULL ); else
> > - p_es->p_clock = vlc_clock_main_CreateSlave(
> > p_es->p_pgrm->p_main_clock ); + p_es->p_clock =
> > vlc_clock_main_CreateSlave( p_es->p_pgrm->p_main_clock, +
> > NULL, NULL ); if( !p_es->p_clock )
> > return;
>
>
> --
> 雷米‧德尼-库尔蒙
> 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