[vlc-devel] [PATCH V3 11/19] input: forward clock update points

Thomas Guillem thomas at gllm.fr
Fri Sep 6 17:20:41 CEST 2019


---
 src/input/es_out.c         | 37 ++++++++++++++++++++++++++++++++++---
 src/input/event.h          | 14 ++++++++++++++
 src/input/input_internal.h | 16 ++++++++++++++++
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index 366beefefe..47e36b4c9f 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -95,7 +95,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 */
@@ -122,6 +122,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 */
@@ -1944,6 +1947,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;
@@ -1997,22 +2001,49 @@ static bool EsIsSelected( es_out_id_t *es )
         return es->p_dec != NULL;
     }
 }
+
+static void ClockUpdate(vlc_tick_t system_ts, vlc_tick_t ts, double rate,
+                        unsigned frame_rate, unsigned frame_rate_base,
+                        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, frame_rate, frame_rate_base);
+}
+
 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..6810d4a0c2 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -64,6 +64,20 @@ 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,
+                                              unsigned frame_rate,
+                                              unsigned frame_rate_base)
+{
+    input_SendEvent(p_input, &(struct vlc_input_event) {
+        .type = INPUT_EVENT_OUTPUT_CLOCK,
+        .output_clock = { id, master, system_ts, ts, rate,
+                          frame_rate, frame_rate_base }
+    });
+}
+
 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 7a9bd1541e..fd8778dcdc 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,17 @@ 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;
+    unsigned frame_rate;
+    unsigned frame_rate_base;
+};
+
 struct vlc_input_event_title
 {
     enum {
@@ -243,6 +257,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