[vlc-commits] player: add vout<->es_id getters

Thomas Guillem git at videolan.org
Mon Jun 3 16:16:15 CEST 2019


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 31 09:52:10 2019 +0200| [55f66069ab962716235fd2994de597f1845adc17] | committer: Thomas Guillem

player: add vout<->es_id getters

Events are not enough, specially when an interface pops in the middle of a
player playback.

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

 include/vlc_player.h | 34 ++++++++++++++++++++++++++++++++++
 src/input/player.c   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym   |  2 ++
 3 files changed, 80 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 3d924e927d..90b8683dbe 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -1674,6 +1674,40 @@ VLC_API const struct vlc_player_track *
 vlc_player_GetTrack(vlc_player_t *player, vlc_es_id_t *es_id);
 
 /**
+ * Get and the video output used by a ES identifier
+ *
+ * @warning A same vout can be associated with multiple ES during the lifetime
+ * of the player. The information returned by this function becomes invalid
+ * when the player is unlocked. The returned vout doesn't need to be released,
+ * but must be held with vout_Hold() if it is accessed after the player is
+ * unlocked.
+ *
+ * @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 vout or NULL (if the track is disabled, it it's not a video
+ * track, or if the vout failed to start)
+ */
+VLC_API vout_thread_t *
+vlc_player_GetVoutFromEsId(vlc_player_t *player, vlc_es_id_t *es_id);
+
+/**
+ * Get the ES identifier of a video output
+ *
+ * @warning A same vout can be associated with multiple ES during the lifetime
+ * of the player. The information returned by this function becomes invalid
+ * when the player is unlocked. The returned es_id doesn't need to be released,
+ * but must be held with vlc_es_id_Hold() if it accessed after the player is
+ * unlocked.
+ *
+ * @param player locked player instance
+ * @param vout vout (can't be NULL)
+ * @return a valid ES identifier or NULL (if the vout is stopped)
+ */
+VLC_API vlc_es_id_t *
+vlc_player_GetEsIdFromVout(vlc_player_t *player, vout_thread_t *vout);
+
+/**
  * Helper to get the selected track from an ES category
  *
  * @warning The player can have more than one selected track for a same ES
diff --git a/src/input/player.c b/src/input/player.c
index 874490e115..3162b042ee 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -53,6 +53,7 @@ static_assert(VLC_PLAYER_TITLE_MENU == INPUT_TITLE_MENU &&
 struct vlc_player_track_priv
 {
     struct vlc_player_track t;
+    vout_thread_t *vout; /* weak reference */
 };
 
 typedef struct VLC_VECTOR(struct vlc_player_program *)
@@ -1301,6 +1302,39 @@ vlc_player_GetTrack(vlc_player_t *player, vlc_es_id_t *id)
     return trackpriv ? &trackpriv->t : NULL;
 }
 
+vout_thread_t *
+vlc_player_GetVoutFromEsId(vlc_player_t *player, vlc_es_id_t *es_id)
+{
+    struct vlc_player_track_priv *trackpriv =
+        vlc_player_GetPrivTrack(player, es_id);
+    return trackpriv ? trackpriv->vout : NULL;
+}
+
+vlc_es_id_t *
+vlc_player_GetEsIdFromVout(vlc_player_t *player, vout_thread_t *vout)
+{
+    struct vlc_player_input *input = vlc_player_get_input_locked(player);
+
+    if (!input)
+        return NULL;
+
+    static const enum es_format_category_e cats[] = {
+        VIDEO_ES, AUDIO_ES /* for visualisation filters */
+    };
+    for (size_t i = 0; i < ARRAY_SIZE(cats); ++i)
+    {
+        enum es_format_category_e cat = cats[i];
+        vlc_player_track_vector *vec =
+            vlc_player_input_GetTrackVector(input, cat);
+        for (size_t j = 0; j < vec->size; ++j)
+        {
+            struct vlc_player_track_priv *trackpriv = vec->data[j];
+            if (trackpriv->vout == vout)
+                return trackpriv->t.es_id;
+        }
+    }
+    return NULL;
+}
 
 static inline const char *
 es_format_category_to_string(enum es_format_category_e cat)
@@ -1828,9 +1862,18 @@ vlc_player_input_HandleVoutEvent(struct vlc_player_input *input,
     };
 
     vlc_player_t *player = input->player;
+
+    vlc_player_track_vector *vec =
+        vlc_player_input_GetTrackVector(input, vlc_es_id_GetCat(ev->id));
+    struct vlc_player_track_priv *trackpriv =
+        vec ? vlc_player_track_vector_FindById(vec, ev->id, NULL) : NULL;
+    if (!trackpriv)
+        return;
+
     switch (ev->action)
     {
         case VLC_INPUT_EVENT_VOUT_ADDED:
+            trackpriv->vout = ev->vout;
             vlc_player_SendEvent(player, on_vout_changed,
                                  VLC_PLAYER_VOUT_STARTED, ev->vout, ev->id);
 
@@ -1853,6 +1896,7 @@ vlc_player_input_HandleVoutEvent(struct vlc_player_input *input,
                 var_DelCallback(ev->vout, osd_vars[i],
                                 vlc_player_VoutOSDCallback, player);
 
+            trackpriv->vout = NULL;
             vlc_player_SendEvent(player, on_vout_changed,
                                  VLC_PLAYER_VOUT_STOPPED, ev->vout, ev->id);
             break;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 083ddef896..87190a3573 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -795,6 +795,7 @@ vlc_player_GetAudioDelay
 vlc_player_GetCapabilities
 vlc_player_GetCurrentMedia
 vlc_player_GetError
+vlc_player_GetEsIdFromVout
 vlc_player_GetLength
 vlc_player_GetPosition
 vlc_player_GetProgram
@@ -816,6 +817,7 @@ vlc_player_GetTrack
 vlc_player_GetTrackAt
 vlc_player_GetTrackCount
 vlc_player_GetV4l2Object
+vlc_player_GetVoutFromEsId
 vlc_player_HasTeletextMenu
 vlc_player_IncrementRate
 vlc_player_InvalidateNextMedia



More information about the vlc-commits mailing list