[vlc-devel] [PATCH 05/17] clock: handle the normal_time from the input
Thomas Guillem
thomas at gllm.fr
Tue Mar 9 15:15:34 UTC 2021
vlc_clock_t will send corrected update points directly.
The player won't have to fetch the normal_time from the demux and fix
its timer accordingly.
---
src/clock/clock.c | 23 +++++++++++++++++++++--
src/clock/clock.h | 9 +++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/clock/clock.c b/src/clock/clock.c
index 0bb2a9fe375..27ca27153ee 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -46,6 +46,9 @@ struct vlc_clock_main_t
double rate;
double coeff;
vlc_tick_t input_drift;
+ /* Time reference of the input, if VLC_TICK_0 (default), PTS and PCR use
+ * the same time base */
+ vlc_tick_t normal_time;
vlc_tick_t offset;
vlc_tick_t delay;
@@ -159,6 +162,8 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
vlc_cond_broadcast(&main_clock->cond);
}
+ original_ts -= main_clock->normal_time - VLC_TICK_0;
+
vlc_mutex_unlock(&main_clock->lock);
vlc_clock_on_update(clock, system_now, original_ts, rate, frame_rate,
@@ -296,18 +301,23 @@ static vlc_tick_t vlc_clock_slave_update(vlc_clock_t *clock,
{
vlc_clock_main_t *main_clock = clock->owner;
+ vlc_mutex_lock(&main_clock->lock);
+
if (system_now == INT64_MAX)
{
+ ts -= main_clock->normal_time - VLC_TICK_0;
+
+ vlc_mutex_unlock(&main_clock->lock);
/* If system_now is INT64_MAX, the update is forced, don't modify anything
* but only notify the new clock point. */
vlc_clock_on_update(clock, INT64_MAX, ts, rate, frame_rate, frame_rate_base);
return INT64_MAX;
}
- vlc_mutex_lock(&main_clock->lock);
-
vlc_tick_t computed = clock->to_system_locked(clock, system_now, ts, rate);
+ ts -= main_clock->normal_time - VLC_TICK_0;
+
vlc_mutex_unlock(&main_clock->lock);
vlc_clock_on_update(clock, computed, ts, rate, frame_rate, frame_rate_base);
@@ -377,6 +387,7 @@ vlc_clock_main_t *vlc_clock_main_New(void)
main_clock->coeff = 1.0f;
main_clock->rate = 1.0f;
main_clock->offset = VLC_TICK_INVALID;
+ main_clock->normal_time = VLC_TICK_0;
main_clock->delay = 0;
main_clock->first_pcr =
@@ -450,6 +461,14 @@ void vlc_clock_main_SetInputDrift(vlc_clock_main_t *main_clock, double drift)
vlc_mutex_unlock(&main_clock->lock);
}
+void vlc_clock_main_SetInputNormalTime(vlc_clock_main_t *main_clock,
+ vlc_tick_t normal_time)
+{
+ vlc_mutex_lock(&main_clock->lock);
+ main_clock->normal_time = normal_time;
+ vlc_mutex_unlock(&main_clock->lock);
+}
+
void vlc_clock_main_ChangePause(vlc_clock_main_t *main_clock, vlc_tick_t now,
bool paused)
{
diff --git a/src/clock/clock.h b/src/clock/clock.h
index f628024e057..aab656f7b6e 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -98,6 +98,15 @@ void vlc_clock_main_SetInputDejitter(vlc_clock_main_t *main_clock,
**/
void vlc_clock_main_SetInputDrift(vlc_clock_main_t *main_clock, double drift);
+/**
+ * Set the normal time of the input
+ *
+ * It corresponds to the real starting time of the input. Substracing PTS to
+ * this normal_time will give the playback time.
+ */
+void vlc_clock_main_SetInputNormalTime(vlc_clock_main_t *main_clock,
+ vlc_tick_t normal_time);
+
/**
* This function sets the dejitter delay to absorb the clock jitter
*
--
2.30.0
More information about the vlc-devel
mailing list