[vlc-devel] [PATCH 07/17] clock: add vlc_clock_main_CreateInput()
Thomas Guillem
thomas at gllm.fr
Mon Feb 15 10:15:02 UTC 2021
This allows to create a new master clock source: the input one. This
source will be feed by the legacy input clock: input_clock.c (from demux
PCR points). This source will be overridden by the audio master clock
source when present.
---
src/clock/clock.c | 54 +++++++++++++++++++++++++++++++++++++++++++++--
src/clock/clock.h | 9 ++++++++
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/src/clock/clock.c b/src/clock/clock.c
index 32f6b573632..c4160e9701b 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -33,7 +33,9 @@ struct vlc_clock_main_t
vlc_mutex_t lock;
vlc_cond_t cond;
+ vlc_clock_t *current;
vlc_clock_t *master;
+ vlc_clock_t *input;
unsigned rc;
@@ -125,6 +127,20 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
vlc_mutex_lock(&main_clock->lock);
+ /* Changing clock from input to master */
+ if (clock != main_clock->current && clock == main_clock->master)
+ {
+ vlc_clock_main_reset(main_clock);
+ main_clock->current = clock;
+ }
+
+ /* Only update from master or input, not both */
+ if (clock != main_clock->current)
+ {
+ vlc_mutex_unlock(&main_clock->lock);
+ return 0;
+ }
+
/* If system_now is INT64_MAX, the update is forced, don't modify anything
* but only notify the new clock point. */
if (system_now != INT64_MAX)
@@ -169,7 +185,12 @@ static void vlc_clock_master_reset(vlc_clock_t *clock)
vlc_clock_main_t *main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
- vlc_clock_main_reset(main_clock);
+
+ if (main_clock->current == clock)
+ {
+ vlc_clock_main_reset(main_clock);
+ main_clock->current = main_clock->input;
+ }
assert(main_clock->delay <= 0);
assert(clock->delay >= 0);
@@ -373,7 +394,7 @@ vlc_clock_main_t *vlc_clock_main_New(void)
vlc_mutex_init(&main_clock->lock);
vlc_cond_init(&main_clock->cond);
- main_clock->master = NULL;
+ main_clock->current = main_clock->master = main_clock->input = NULL;
main_clock->rc = 1;
main_clock->coeff = 1.0f;
@@ -590,6 +611,28 @@ vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock,
return clock;
}
+vlc_clock_t *vlc_clock_main_CreateInput(vlc_clock_main_t *main_clock,
+ const struct vlc_clock_cbs *cbs,
+ void *cbs_data)
+{
+ /* The input has always the UINT_MAX priority (the lowest) */
+ vlc_clock_t *clock = vlc_clock_main_Create(main_clock, UINT_MAX, cbs, cbs_data);
+ if (!clock)
+ return NULL;
+
+ vlc_mutex_lock(&main_clock->lock);
+ assert(main_clock->master == NULL);
+ assert(main_clock->input == NULL);
+
+ vlc_clock_set_master_callbacks(clock);
+ main_clock->input = clock;
+ main_clock->current = clock;
+ main_clock->rc++;
+ vlc_mutex_unlock(&main_clock->lock);
+
+ return clock;
+}
+
vlc_clock_t *vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock,
enum es_format_category_e cat,
const struct vlc_clock_cbs *cbs,
@@ -639,6 +682,13 @@ void vlc_clock_Delete(vlc_clock_t *clock)
{
vlc_clock_main_reset(main_clock);
main_clock->master = NULL;
+ main_clock->current = main_clock->input;
+ }
+ else if (clock == main_clock->input)
+ {
+ vlc_clock_main_reset(main_clock);
+ main_clock->input = NULL;
+ main_clock->current = NULL;
}
main_clock->rc--;
vlc_mutex_unlock(&main_clock->lock);
diff --git a/src/clock/clock.h b/src/clock/clock.h
index b852af0eb23..ce8107935ea 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -104,6 +104,15 @@ vlc_clock_t *vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock,
const struct vlc_clock_cbs *cbs,
void *cbs_data);
+/**
+ * This function create the default master clock, receiving PCR updates
+ *
+ * You must use vlc_clock_Delete to free it.
+ */
+vlc_clock_t *vlc_clock_main_CreateInput(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
*
--
2.30.0
More information about the vlc-devel
mailing list