[vlc-commits] input_clock: forward drift update to the owner
Thomas Guillem
git at videolan.org
Fri Mar 12 13:44:33 UTC 2021
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Mar 8 17:07:21 2021 +0100| [4c64d5a3e99af6c3f0cef663bdf1ef6266aa05f5] | committer: Thomas Guillem
input_clock: forward drift update to the owner
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4c64d5a3e99af6c3f0cef663bdf1ef6266aa05f5
---
src/clock/input_clock.c | 18 +++++++++++++++++-
src/clock/input_clock.h | 17 ++++++++++++++++-
src/input/es_out.c | 2 +-
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/src/clock/input_clock.c b/src/clock/input_clock.c
index f09e0bbb8f..45edf26dfc 100644
--- a/src/clock/input_clock.c
+++ b/src/clock/input_clock.c
@@ -104,6 +104,9 @@
/* */
struct input_clock_t
{
+ const struct input_clock_cbs *cbs;
+ void *cbs_data;
+
/* Last point
* It is used to detect unexpected stream discontinuities */
clock_point_t last;
@@ -145,12 +148,15 @@ static vlc_tick_t ClockGetTsOffset( input_clock_t * );
/*****************************************************************************
* input_clock_New: create a new clock
*****************************************************************************/
-input_clock_t *input_clock_New( float rate )
+input_clock_t *input_clock_New( float rate, const struct input_clock_cbs *cbs,
+ void *cbs_data )
{
input_clock_t *cl = malloc( sizeof(*cl) );
if( !cl )
return NULL;
+ cl->cbs = cbs;
+ cl->cbs_data = cbs_data;
cl->b_has_reference = false;
cl->ref = clock_point_Create( VLC_TICK_INVALID, VLC_TICK_INVALID );
cl->b_has_external_clock = false;
@@ -221,6 +227,8 @@ vlc_tick_t input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
{
cl->i_next_drift_update = VLC_TICK_INVALID;
AvgReset( &cl->drift );
+ if (cl->cbs != NULL)
+ cl->cbs->on_drift_update( 0, cl->cbs_data );
/* Feed synchro with a new reference point. */
cl->b_has_reference = true;
@@ -236,6 +244,8 @@ vlc_tick_t input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
const vlc_tick_t i_converted = ClockSystemToStream( cl, i_ck_system );
AvgUpdate( &cl->drift, i_converted - i_ck_stream );
+ if (cl->cbs != NULL)
+ cl->cbs->on_drift_update( AvgGet( &cl->drift ), cl->cbs_data );
cl->i_next_drift_update = i_ck_system + VLC_TICK_FROM_MS(200); /* FIXME why that */
}
@@ -421,7 +431,13 @@ void input_clock_SetJitter( input_clock_t *cl,
i_cr_average = 10;
if( cl->drift.range != i_cr_average )
+ {
+ /* No need to call cl->cbs->on_drift_update since
+ * input_clock_SetJitter() is called once before feeding any data */
+ assert( AvgGet( &cl->drift ) == 0 );
+
AvgRescale( &cl->drift, i_cr_average );
+ }
}
vlc_tick_t input_clock_GetJitter( input_clock_t *cl )
diff --git a/src/clock/input_clock.h b/src/clock/input_clock.h
index f9a74f0809..9184e0e3a4 100644
--- a/src/clock/input_clock.h
+++ b/src/clock/input_clock.h
@@ -34,11 +34,26 @@
*/
typedef struct input_clock_t input_clock_t;
+struct input_clock_cbs
+{
+ /**
+ * A new drift is calculted.
+ *
+ * Called with input that can't pace, when the average drift is updated
+ * (drift != 0) or reset (drift = 0)
+ *
+ * \param drift drift in us
+ * \param data user data
+ **/
+ void (*on_drift_update)(double drift, void *data);
+};
+
/**
* This function creates a new input_clock_t.
* You must use input_clock_Delete to delete it once unused.
*/
-input_clock_t *input_clock_New( float rate );
+input_clock_t *input_clock_New( float rate, const struct input_clock_cbs *cbs,
+ void *cbs_data );
/**
* This function destroys a input_clock_t created by input_clock_New.
diff --git a/src/input/es_out.c b/src/input/es_out.c
index b3b3562105..22f27b1bc1 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -1382,7 +1382,7 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, input_source_t *source, in
p_pgrm->p_meta = NULL;
p_pgrm->p_master_clock = NULL;
- p_pgrm->p_input_clock = input_clock_New( p_sys->rate );
+ p_pgrm->p_input_clock = input_clock_New( p_sys->rate, NULL, NULL );
p_pgrm->p_main_clock = vlc_clock_main_New();
if( !p_pgrm->p_input_clock || !p_pgrm->p_main_clock )
{
More information about the vlc-commits
mailing list