[vlc-devel] [PATCH 01/20] input: add input_SetEsIdDelay

Thomas Guillem thomas at gllm.fr
Thu Jun 20 17:23:44 CEST 2019


This function set the delay of a track from its vlc_es_id_t*.
---
 src/input/es_out.c           | 28 +++++++++++++++++++++++++++-
 src/input/es_out.h           |  8 ++++++++
 src/input/es_out_timeshift.c |  1 +
 src/input/input.c            |  8 ++++++++
 src/input/input_internal.h   |  6 ++++++
 5 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index 981160479e..33a9f4ac73 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -119,6 +119,8 @@ struct es_out_id_t
     decoder_t   *p_dec_record;
     vlc_clock_t *p_clock;
 
+    vlc_tick_t delay;
+
     /* Fields for Video with CC */
     struct
     {
@@ -564,6 +566,19 @@ static bool EsOutDecodersIsEmpty( es_out_t *out )
     return true;
 }
 
+static void EsOutSetEsDelay(es_out_t *out, es_out_id_t *es, vlc_tick_t delay)
+{
+    es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
+
+    es->delay = delay;
+
+    EsOutDecoderChangeDelay(out, es);
+
+    /* Update the clock pts delay only if the extra tracks delay changed */
+    EsOutControlLocked(out, ES_OUT_SET_JITTER, p_sys->i_pts_delay,
+                       p_sys->i_pts_jitter, p_sys->i_cr_average);
+}
+
 static void EsOutSetDelay( es_out_t *out, int i_cat, vlc_tick_t i_delay )
 {
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
@@ -913,7 +928,9 @@ static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es )
     es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
 
     vlc_tick_t i_delay;
-    if( p_es->fmt.i_cat == AUDIO_ES )
+    if( p_es->delay != INT64_MAX )
+        i_delay = p_es->delay; /* The track use its own delay, and not a category delay */
+    else if( p_es->fmt.i_cat == AUDIO_ES )
         i_delay = p_sys->i_audio_delay;
     else if( p_es->fmt.i_cat == SPU_ES )
         i_delay = p_sys->i_spu_delay;
@@ -1781,6 +1798,7 @@ static es_out_id_t *EsOutAddSlaveLocked( es_out_t *out, const es_format_t *fmt,
     es->p_master = p_master;
     es->mouse_event_cb = NULL;
     es->mouse_event_userdata = NULL;
+    es->delay = INT64_MAX;
 
     vlc_list_append(&es->node, es->p_master ? &p_sys->es_slaves : &p_sys->es);
 
@@ -2983,6 +3001,14 @@ static int EsOutVaControlLocked( es_out_t *out, int i_query, va_list args )
         return VLC_SUCCESS;
     }
 
+    case ES_OUT_SET_ES_DELAY:
+    {
+        es_out_id_t *es = va_arg(args, es_out_id_t *);
+        const vlc_tick_t delay = va_arg(args, vlc_tick_t);
+        EsOutSetEsDelay(out, es, delay);
+        return VLC_SUCCESS;
+    }
+
     case ES_OUT_SET_DELAY:
     {
         const int i_cat = va_arg( args, int );
diff --git a/src/input/es_out.h b/src/input/es_out.h
index 4e885b4fad..30e199579e 100644
--- a/src/input/es_out.h
+++ b/src/input/es_out.h
@@ -57,6 +57,9 @@ enum es_out_query_private_e
     /* Get buffering state */
     ES_OUT_GET_BUFFERING,                           /* arg1=bool*               res=cannot fail */
 
+    /* Set delay for an ES identifier */
+    ES_OUT_SET_ES_DELAY,                            /* arg1=es_out_id_t *, res=cannot fail */
+
     /* Set delay for a ES category */
     ES_OUT_SET_DELAY,                               /* arg1=es_category_e,      res=cannot fail */
 
@@ -120,6 +123,11 @@ static inline bool es_out_GetEmpty( es_out_t *p_out )
     assert( !i_ret );
     return b;
 }
+static inline void es_out_SetEsDelay( es_out_t *p_out, es_out_id_t *es, vlc_tick_t i_delay )
+{
+    int i_ret = es_out_Control( p_out, ES_OUT_SET_ES_DELAY, es, i_delay );
+    assert( !i_ret );
+}
 static inline void es_out_SetDelay( es_out_t *p_out, int i_cat, vlc_tick_t i_delay )
 {
     int i_ret = es_out_Control( p_out, ES_OUT_SET_DELAY, i_cat, i_delay );
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index 09482a2a10..cff9691d71 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -741,6 +741,7 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
     case ES_OUT_SET_ES_DEFAULT_BY_ID:
     case ES_OUT_STOP_ALL_ES:
     case ES_OUT_START_ALL_ES:
+    case ES_OUT_SET_ES_DELAY:
     case ES_OUT_SET_DELAY:
     case ES_OUT_SET_RECORD_STATE:
     case ES_OUT_SET_VBI_PAGE:
diff --git a/src/input/input.c b/src/input/input.c
index 6ab5233653..efc338f33c 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -244,6 +244,14 @@ void input_SetCategoryDelay(input_thread_t *input, enum es_format_category_e cat
     es_out_SetDelay(input_priv(input)->p_es_out_display, cat, delay);
 }
 
+void input_SetEsIdDelay(input_thread_t *input, vlc_es_id_t *es_id,
+                        vlc_tick_t delay)
+{
+    assert(es_id);
+    es_out_SetEsDelay(input_priv(input)->p_es_out_display,
+                      vlc_es_id_get_out(es_id), delay);
+}
+
 /**
  * Get the item from an input thread
  * FIXME it does not increase ref count of the item.
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 96357200be..3b2f5533e9 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -372,6 +372,12 @@ void input_SetPosition( input_thread_t *, float f_position, bool b_fast );
 void input_SetCategoryDelay(input_thread_t *input, enum es_format_category_e cat,
                             vlc_tick_t delay);
 
+/**
+ * Set the delay of an ES identifier
+ */
+void input_SetEsIdDelay(input_thread_t *input, vlc_es_id_t *es_id,
+                        vlc_tick_t delay);
+
 /**
  * Get the input item for an input thread
  *
-- 
2.20.1



More information about the vlc-devel mailing list