[vlc-commits] clock: forward clock update points

Thomas Guillem git at videolan.org
Mon Sep 23 13:36:10 CEST 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Mar  7 16:18:59 2019 +0100| [b44d83d0729f8cff4ff5820f23e161fa457db214] | committer: Thomas Guillem

clock: forward clock update points

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b44d83d0729f8cff4ff5820f23e161fa457db214
---

 src/clock/clock.c  | 62 +++++++++++++++++++++++++++++++++++++++++++-----------
 src/clock/clock.h  | 29 +++++++++++++++++++++++--
 src/input/es_out.c |  5 +++--
 3 files changed, 80 insertions(+), 16 deletions(-)

diff --git a/src/clock/clock.c b/src/clock/clock.c
index c4e89db9db..d8b8482601 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -69,6 +69,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,
@@ -92,15 +95,25 @@ 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(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)
+                                          vlc_tick_t original_ts, double rate)
 {
     vlc_clock_main_t *main_clock = clock->owner;
 
-    if (unlikely(ts == VLC_TICK_INVALID || system_now == VLC_TICK_INVALID))
+    if (unlikely(original_ts == VLC_TICK_INVALID
+     || system_now == VLC_TICK_INVALID))
         return VLC_TICK_INVALID;
-    ts += clock->delay;
+
+    const vlc_tick_t ts = original_ts + clock->delay;
 
     vlc_mutex_lock(&main_clock->lock);
 
@@ -126,7 +139,10 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
 
     main_clock->rate = rate;
     vlc_cond_broadcast(&main_clock->cond);
+
     vlc_mutex_unlock(&main_clock->lock);
+
+    vlc_clock_on_update(clock, system_now, original_ts, rate);
     return VLC_TICK_INVALID;
 }
 
@@ -156,6 +172,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)
@@ -265,7 +283,10 @@ 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);
+
     vlc_mutex_unlock(&main_clock->lock);
+
+    vlc_clock_on_update(clock, computed, ts, rate);
     return computed != INT64_MAX ? computed - system_now : INT64_MAX;
 }
 
@@ -275,7 +296,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)
@@ -322,7 +346,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));
@@ -493,7 +516,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)
@@ -501,6 +526,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)
@@ -516,15 +555,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++;
@@ -535,7 +573,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 00dcfe235c..1ab9ab7aa2 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -31,6 +31,27 @@ 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 system_ts system date when the ts will be rendered,
+     * VLC_TICK_INVALID when the clock is reset or INT64_MAX when the update is
+     * forced (an output was still rendered while paused for example). Note:
+     * when valid, this date can be in the future, it is not necessarily now.
+     * @param ts stream timestamp or VLC_TICK_INVALID when the clock is reset,
+     * should be subtracted with VLC_TICK_0 to get the original value
+     * @param rate rate used when updated
+     * @param data opaque pointer set from vlc_clock_main_New()
+     */
+    void (*on_update)(vlc_tick_t system_ts, vlc_tick_t ts, double rate,
+                      void *data);
+};
+
+/**
  * This function creates the vlc_clock_main_t of the program
  */
 vlc_clock_main_t *vlc_clock_main_New(void);
@@ -72,14 +93,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 f663a1db4d..753c607d55 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2009,9 +2009,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;
 



More information about the vlc-commits mailing list