[vlc-devel] [PATCH 06/13] input: forward clock update points

Thomas Guillem thomas at gllm.fr
Wed Aug 21 16:13:57 CEST 2019


---
 src/input/es_out.c         | 36 +++++++++++++++++++++++++++++++++---
 src/input/event.h          | 11 +++++++++++
 src/input/input_internal.h | 14 ++++++++++++++
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index 49eb52d2bc..0f96f7290a 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -97,7 +97,7 @@ struct es_out_id_t
 {
     vlc_es_id_t id;
 
-    /* weak reference, used by input_decoder_callbacks */
+    /* weak reference, used by input_decoder_callbacks and vlc_clock_cbs */
     es_out_t *out;
 
     /* ES ID */
@@ -124,6 +124,9 @@ struct es_out_id_t
     decoder_t   *p_dec_record;
     vlc_clock_t *p_clock;
 
+    /* Used by vlc_clock_cbs, need to be const during the lifetime of the clock */
+    bool master;
+
     vlc_tick_t delay;
 
     /* Fields for Video with CC */
@@ -1947,6 +1950,7 @@ static es_out_id_t *EsOutAddSlaveLocked( es_out_t *out, const es_format_t *fmt,
     es->p_dec = NULL;
     es->p_dec_record = NULL;
     es->p_clock = NULL;
+    es->master = false;
     es->cc.type = 0;
     es->cc.i_bitmap = 0;
     es->p_master = p_master;
@@ -2000,22 +2004,48 @@ static bool EsIsSelected( es_out_id_t *es )
         return es->p_dec != NULL;
     }
 }
+
+static void ClockUpdate(const vlc_clock_t *clock, vlc_tick_t system_ts,
+                        vlc_tick_t ts, double rate, void *data)
+{
+    es_out_id_t *es = data;
+    es_out_sys_t *p_sys = container_of(es->out, es_out_sys_t, out);
+
+    input_SendEventOutputClock(p_sys->p_input, &es->id, es->master, system_ts,
+                               ts, rate);
+}
+
 static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
 {
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
     input_thread_t *p_input = p_sys->p_input;
     decoder_t *dec;
 
+    static const struct vlc_clock_cbs clock_cbs = {
+        .on_update = ClockUpdate
+    };
+
     if( p_es->fmt.i_cat != UNKNOWN_ES
      && p_es->fmt.i_cat == p_sys->i_master_source_cat
      && p_es->p_pgrm->p_master_clock == NULL )
+    {
+        p_es->master = true;
         p_es->p_pgrm->p_master_clock = p_es->p_clock =
-            vlc_clock_main_CreateMaster( p_es->p_pgrm->p_main_clock, NULL, NULL );
+            vlc_clock_main_CreateMaster( p_es->p_pgrm->p_main_clock,
+                                         &clock_cbs, p_es );
+    }
     else
+    {
+        p_es->master = false;
         p_es->p_clock = vlc_clock_main_CreateSlave( p_es->p_pgrm->p_main_clock,
-                                                    NULL, NULL );
+                                                    &clock_cbs, p_es );
+    }
+
     if( !p_es->p_clock )
+    {
+        p_es->master = false;
         return;
+    }
 
     input_thread_private_t *priv = input_priv(p_input);
     dec = input_DecoderNew( VLC_OBJECT(p_input), &p_es->fmt, p_es->p_clock,
diff --git a/src/input/event.h b/src/input/event.h
index 2d77461451..f4f44ba5e1 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -64,6 +64,17 @@ static inline void input_SendEventTimes(input_thread_t *p_input,
     });
 }
 
+static inline void input_SendEventOutputClock(input_thread_t *p_input,
+                                              vlc_es_id_t *id, bool master,
+                                              vlc_tick_t system_ts,
+                                              vlc_tick_t ts, double rate)
+{
+    input_SendEvent(p_input, &(struct vlc_input_event) {
+        .type = INPUT_EVENT_OUTPUT_CLOCK,
+        .output_clock = { id, master, system_ts, ts, rate }
+    });
+}
+
 static inline void input_SendEventStatistics(input_thread_t *p_input,
                                              const struct input_stats_t *stats)
 {
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 8e837a8c61..a627c2b080 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -90,6 +90,9 @@ typedef enum input_event_type_e
     /* At least one of "position", "time" "length" has changed */
     INPUT_EVENT_TIMES,
 
+    /* The output PTS changed */
+    INPUT_EVENT_OUTPUT_CLOCK,
+
     /* A title has been added or removed or selected.
      * It implies that the chapter has changed (no chapter event is sent) */
     INPUT_EVENT_TITLE,
@@ -154,6 +157,15 @@ struct vlc_input_event_times
     vlc_tick_t length;
 };
 
+struct vlc_input_event_output_clock
+{
+    vlc_es_id_t *id;
+    bool master;
+    vlc_tick_t system_ts;
+    vlc_tick_t ts;
+    double rate;
+};
+
 struct vlc_input_event_title
 {
     enum {
@@ -243,6 +255,8 @@ struct vlc_input_event
         int capabilities; /**< cf. VLC_INPUT_CAPABILITIES_* bitwise flags */
         /* INPUT_EVENT_TIMES */
         struct vlc_input_event_times times;
+        /* INPUT_EVENT_OUTPUT_CLOCK */
+        struct vlc_input_event_output_clock output_clock;
         /* INPUT_EVENT_TITLE */
         struct vlc_input_event_title title;
         /* INPUT_EVENT_CHAPTER */
-- 
2.20.1



More information about the vlc-devel mailing list