[vlc-commits] player: add vlc_player_SelectTracksByStringIds()

Thomas Guillem git at videolan.org
Fri Feb 28 20:46:39 CET 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Feb 19 15:55:11 2020 +0100| [dacc3d5ab362359e0d846c8fc64bc23241a78a52] | committer: Thomas Guillem

player: add vlc_player_SelectTracksByStringIds()

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

 include/vlc_player.h | 29 +++++++++++++++++++++++++++++
 src/libvlccore.sym   |  1 +
 src/player/input.c   | 20 ++++++++++++++++++++
 src/player/player.c  | 38 ++++++++++++++++++++++++++++++++++++++
 src/player/player.h  |  9 +++++++++
 5 files changed, 97 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 8da6111294..763aae564d 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -1516,6 +1516,35 @@ vlc_player_GetSelectedTrack(vlc_player_t *player, enum es_format_category_e cat)
     return NULL;
 }
 
+/**
+ * Select tracks by their string identifier
+ *
+ * This function can be used pre-select a list of tracks before starting the
+ * player. It has only effect for the current media. It can also be used when
+ * the player is already started.
+
+ * 'str_ids' can contain more than one track id, delimited with ','. "" or any
+ * invalid track id will cause the player to unselect all tracks of that
+ * category. NULL will disable the preference for newer tracks without
+ * unselecting any current tracks.
+ *
+ * Example:
+ * - (VIDEO_ES, "video/1,video/2") will select these 2 video tracks. If there
+ * is only one video track with the id "video/0", no tracks will be selected.
+ * - (SPU_ES, "${slave_url_md5sum}/spu/0) will select one spu added by an input
+ * slave with the corresponding url.
+ *
+ * @note The string identifier of a track can be found via vlc_es_id_GetStrId().
+ *
+ * @param player locked player instance
+ * @param cat VIDEO_ES, AUDIO_ES or SPU_ES
+ * @param str_ids list of string identifier or NULL
+ */
+VLC_API void
+vlc_player_SelectTracksByStringIds(vlc_player_t *player,
+                                   enum es_format_category_e cat,
+                                   const char *str_ids);
+
 /**
  * Select a track from an ES identifier
  *
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 3e33ecaa8d..0f60077bb2 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -852,6 +852,7 @@ vlc_player_SelectProgram
 vlc_player_SelectTeletextPage
 vlc_player_SelectTitle
 vlc_player_SelectTitleIdx
+vlc_player_SelectTracksByStringIds
 vlc_player_SetAssociatedSubsFPS
 vlc_player_SetAtoBLoop
 vlc_player_SetCategoryDelay
diff --git a/src/player/input.c b/src/player/input.c
index 37a235664b..1d689c2a9d 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -832,6 +832,14 @@ input_thread_Events(input_thread_t *input_thread,
     vlc_mutex_unlock(&player->lock);
 }
 
+void
+vlc_player_input_SelectTracksByStringIds(struct vlc_player_input *input,
+                                         enum es_format_category_e cat,
+                                         const char *str_ids)
+{
+    input_SetEsCatIds(input->thread, cat, str_ids);
+}
+
 struct vlc_player_input *
 vlc_player_input_New(vlc_player_t *player, input_item_t *item)
 {
@@ -895,6 +903,18 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
     }
     vlc_player_input_RestoreMlStates(input, false);
 
+    if (player->video_string_ids)
+        vlc_player_input_SelectTracksByStringIds(input, VIDEO_ES,
+                                                 player->video_string_ids);
+
+    if (player->audio_string_ids)
+        vlc_player_input_SelectTracksByStringIds(input, AUDIO_ES,
+                                                 player->audio_string_ids);
+
+    if (player->sub_string_ids)
+        vlc_player_input_SelectTracksByStringIds(input, SPU_ES,
+                                                 player->sub_string_ids);
+
     /* Initial sub/audio delay */
     const vlc_tick_t cat_delays[DATA_ES] = {
         [AUDIO_ES] =
diff --git a/src/player/player.c b/src/player/player.c
index 5695efaaaa..38c9b5aa57 100644
--- a/src/player/player.c
+++ b/src/player/player.c
@@ -72,6 +72,13 @@ vlc_player_OpenNextMedia(vlc_player_t *player)
 
     player->next_media_requested = false;
 
+    /* Tracks string ids are only remembered for one media */
+    free(player->video_string_ids);
+    free(player->audio_string_ids);
+    free(player->sub_string_ids);
+    player->video_string_ids = player->audio_string_ids =
+    player->sub_string_ids = NULL;
+
     int ret = VLC_SUCCESS;
     if (player->releasing_media)
     {
@@ -595,6 +602,30 @@ vlc_player_SelectEsId(vlc_player_t *player, vlc_es_id_t *id,
     return ret;
 }
 
+void
+vlc_player_SelectTracksByStringIds(vlc_player_t *player,
+                                   enum es_format_category_e cat,
+                                   const char *str_ids)
+{
+    vlc_player_assert_locked(player);
+    char **cat_str_ids;
+
+    switch (cat)
+    {
+        case VIDEO_ES: cat_str_ids = &player->video_string_ids; break;
+        case AUDIO_ES: cat_str_ids = &player->audio_string_ids; break;
+        case SPU_ES:   cat_str_ids = &player->sub_string_ids; break;
+        default: return;
+    }
+
+    free(*cat_str_ids);
+    *cat_str_ids = str_ids ? strdup(str_ids) : NULL;
+
+    struct vlc_player_input *input = vlc_player_get_input_locked(player);
+    if (input)
+        vlc_player_input_SelectTracksByStringIds(input, cat, str_ids);
+}
+
 static void
 vlc_player_CycleTrack(vlc_player_t *player, enum es_format_category_e cat,
                       bool next)
@@ -1873,6 +1904,10 @@ vlc_player_Delete(vlc_player_t *player)
     if (player->next_media)
         input_item_Release(player->next_media);
 
+    free(player->video_string_ids);
+    free(player->audio_string_ids);
+    free(player->sub_string_ids);
+
     vlc_player_DestroyTimer(player);
 
     vlc_player_aout_DelCallbacks(player);
@@ -1921,6 +1956,9 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
     player->next_media_requested = false;
     player->next_media = NULL;
 
+    player->video_string_ids = player->audio_string_ids =
+    player->sub_string_ids = NULL;
+
 #define VAR_CREATE(var, flag) do { \
     if (var_Create(player, var, flag) != VLC_SUCCESS) \
         goto error; \
diff --git a/src/player/player.h b/src/player/player.h
index d7e499a84e..202821ce23 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -237,6 +237,10 @@ struct vlc_player_t
     bool next_media_requested;
     input_item_t *next_media;
 
+    char *video_string_ids;
+    char *audio_string_ids;
+    char *sub_string_ids;
+
     enum vlc_player_state global_state;
     bool started;
 
@@ -393,6 +397,11 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item);
 void
 vlc_player_input_Delete(struct vlc_player_input *input);
 
+void
+vlc_player_input_SelectTracksByStringIds(struct vlc_player_input *input,
+                                         enum es_format_category_e cat,
+                                         const char *str_ids);
+
 vlc_tick_t
 vlc_player_input_GetTime(struct vlc_player_input *input);
 



More information about the vlc-commits mailing list