[vlc-devel] [PATCH 13/14] player: add vlc_player_SelectTracksByStringIds()
Thomas Guillem
thomas at gllm.fr
Fri Feb 21 16:59:44 CET 2020
---
include/vlc_player.h | 29 +++++++++++++++++++++++++++++
src/libvlccore.sym | 1 +
src/player/input.c | 23 +++++++++++++++++++++++
src/player/player.c | 37 +++++++++++++++++++++++++++++++++++++
src/player/player.h | 9 +++++++++
5 files changed, 99 insertions(+)
diff --git a/include/vlc_player.h b/include/vlc_player.h
index 8da61112940..763aae564d8 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 7ebb0f98adf..c4cffe38ec2 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -854,6 +854,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 37a235664b0..ca688a5d38e 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -832,6 +832,17 @@ 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)
+{
+ const input_control_param_t param = {
+ .cat_ids = { cat, str_ids ? strdup(str_ids) : NULL }
+ };
+ input_ControlPush(input->thread, INPUT_CONTROL_SET_ES_CAT_IDS, ¶m);
+}
+
struct vlc_player_input *
vlc_player_input_New(vlc_player_t *player, input_item_t *item)
{
@@ -895,6 +906,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 487e6a1c6d8..f4d42a496c1 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,29 @@ 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;
+ }
+
+ *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)
@@ -1883,6 +1913,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_DestroyLocks(player);
vlc_player_DestroyTimer(player);
@@ -1933,6 +1967,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 d7e499a84ed..202821ce238 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);
--
2.20.1
More information about the vlc-devel
mailing list