[vlc-commits] player: add vlc_player_SetEsIdDelay

Thomas Guillem git at videolan.org
Tue Jun 25 20:55:14 CEST 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jun 19 14:21:35 2019 +0200| [6c4c3d503d68120cc6577e6be3e7f3de1db3b06b] | committer: Thomas Guillem

player: add vlc_player_SetEsIdDelay

This allow to set the delay of one particular track. Once set, this delay will
override the delay of the track category.

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

 include/vlc_player.h                            | 48 +++++++++++++++++++++++
 modules/gui/qt/components/player_controller.cpp |  1 +
 src/input/player.c                              | 51 +++++++++++++++++++++++++
 src/libvlccore.sym                              |  2 +
 4 files changed, 102 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 2fe226ab70..0e66690efa 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -547,6 +547,17 @@ struct vlc_player_cbs
         vlc_es_id_t *unselected_id, vlc_es_id_t *selected_id, void *data);
 
     /**
+     * Called when a track delay has changed
+     *
+     * @param player locked player instance
+     * @param es_id valid track id
+     * @param delay a valid delay or INT64_MAX if the delay of this track is
+     * canceled
+     */
+    void (*on_track_delay_changed)(vlc_player_t *player,
+        vlc_es_id_t *es_id, vlc_tick_t delay, void *data);
+
+    /**
      * Called when a new program is added, removed or updated
      *
      * @note The program is only valid from this callback context. Users should
@@ -2450,6 +2461,9 @@ vlc_player_GetCategoryDelay(vlc_player_t *player, enum es_format_category_e cat)
  * @note A successful call will trigger the
  * vlc_player_cbs.on_category_delay_changed event.
  *
+ * @warning This has no effect on tracks where the delay was set by
+ * vlc_player_SetEsIdDelay()
+ *
  * @param player locked player instance
  * @param cat AUDIO_ES or SPU_ES (VIDEO_ES not supported yet)
  * @param delay a valid time
@@ -2461,6 +2475,40 @@ vlc_player_SetCategoryDelay(vlc_player_t *player, enum es_format_category_e cat,
                             vlc_tick_t delay, enum vlc_player_whence whence);
 
 /**
+ * Get the delay of a track
+ *
+ * @see vlc_player_cbs.on_track_delay_changed
+ *
+ * @param player locked player instance
+ * @param id an ES ID (retrieved from vlc_player_cbs.on_track_list_changed or
+ * vlc_player_GetTrackAt())
+ * @return a valid delay or INT64_MAX is no delay is set for this track
+ */
+VLC_API vlc_tick_t
+vlc_player_GetEsIdDelay(vlc_player_t *player, vlc_es_id_t *es_id);
+
+/**
+ * Set the delay of one track
+ *
+ * @note A successful call will trigger the
+ * vlc_player_cbs.on_track_delay_changed event.
+ *
+ * @warning Setting the delay of one specific track will override previous and
+ * future changes of delay made by vlc_player_SetCategoryDelay()
+ *
+ * @param player locked player instance
+ * @param id an ES ID (retrieved from vlc_player_cbs.on_track_list_changed or
+ * vlc_player_GetTrackAt())
+ * @param delay a valid time or INT64_MAX to use default category delay
+ * @param whence absolute or relative
+ * @return VLC_SUCCESS or VLC_EGENERIC if the category of the es_id is not
+ * handled (VIDEO_ES not supported yet)
+ */
+VLC_API int
+vlc_player_SetEsIdDelay(vlc_player_t *player, vlc_es_id_t *es_id,
+                        vlc_tick_t delay, enum vlc_player_whence whence);
+
+/**
  * Helper to get the audio delay
  */
 static inline vlc_tick_t
diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index aeb5954cfa..553d461d41 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -810,6 +810,7 @@ static const struct vlc_player_cbs player_cbs = {
     on_player_length_changed,
     on_player_track_list_changed,
     on_player_track_selection_changed,
+    NULL /* on_player_track_delay_changed */,
     on_player_program_list_changed,
     on_player_program_selection_changed,
     on_player_titles_changed,
diff --git a/src/input/player.c b/src/input/player.c
index a038ae67d6..040d1aebef 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -55,6 +55,7 @@ struct vlc_player_track_priv
 {
     struct vlc_player_track t;
     vout_thread_t *vout; /* weak reference */
+    vlc_tick_t delay;
 };
 
 typedef struct VLC_VECTOR(struct vlc_player_program *)
@@ -417,6 +418,9 @@ vlc_player_track_New(vlc_es_id_t *id, const char *name, const es_format_t *fmt)
     if (!trackpriv)
         return NULL;
     struct vlc_player_track *track = &trackpriv->t;
+
+    trackpriv->delay = INT64_MAX;
+
     track->name = strdup(name);
     if (!track->name)
     {
@@ -2878,6 +2882,53 @@ vlc_player_GetCategoryDelay(vlc_player_t *player, enum es_format_category_e cat)
     return input->cat_delays[cat];
 }
 
+int
+vlc_player_SetEsIdDelay(vlc_player_t *player, vlc_es_id_t *es_id,
+                        vlc_tick_t delay, enum vlc_player_whence whence)
+{
+    bool absolute = whence == VLC_PLAYER_WHENCE_ABSOLUTE;
+    struct vlc_player_input *input = vlc_player_get_input_locked(player);
+    if (!input)
+        return VLC_EGENERIC;
+
+    struct vlc_player_track_priv *trackpriv =
+        vlc_player_input_FindTrackById(input, es_id, NULL);
+    if (trackpriv == NULL ||
+        (trackpriv->t.fmt.i_cat != AUDIO_ES && trackpriv->t.fmt.i_cat != SPU_ES))
+        return VLC_EGENERIC;
+
+    if (absolute)
+        trackpriv->delay = delay;
+    else
+    {
+        if (trackpriv->delay == INT64_MAX)
+            trackpriv->delay = 0;
+        trackpriv->delay += delay;
+        delay = trackpriv->delay;
+    }
+
+    input_SetEsIdDelay(input->thread, es_id, delay);
+    if (delay != INT64_MAX)
+        vlc_player_vout_OSDMessage(player, _("%s delay: %i ms"),
+                                   trackpriv->t.name,
+                                   (int)MS_FROM_VLC_TICK(delay));
+    vlc_player_SendEvent(player, on_track_delay_changed, es_id, delay);
+
+    return VLC_SUCCESS;
+}
+
+vlc_tick_t
+vlc_player_GetEsIdDelay(vlc_player_t *player, vlc_es_id_t *es_id)
+{
+    struct vlc_player_input *input = vlc_player_get_input_locked(player);
+    if (!input)
+        return 0;
+
+    struct vlc_player_track_priv *trackpriv =
+        vlc_player_input_FindTrackById(input, es_id, NULL);
+    return trackpriv ? trackpriv->delay : INT64_MAX;
+}
+
 static struct {
     const char var[sizeof("video")];
     const char sout_var[sizeof("sout-video")];
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 64a6c0123b..3e959dc21f 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -789,6 +789,7 @@ vlc_player_GetCategoryDelay
 vlc_player_GetCategoryLanguage
 vlc_player_GetCurrentMedia
 vlc_player_GetError
+vlc_player_GetEsIdDelay
 vlc_player_GetEsIdFromVout
 vlc_player_GetLength
 vlc_player_GetPosition
@@ -850,6 +851,7 @@ vlc_player_SetAssociatedSubsFPS
 vlc_player_SetAtoBLoop
 vlc_player_SetCategoryDelay
 vlc_player_SetCurrentMedia
+vlc_player_SetEsIdDelay
 vlc_player_SetMediaStoppedAction
 vlc_player_SetRecordingEnabled
 vlc_player_SetRenderer



More information about the vlc-commits mailing list