[vlc-devel] [PATCH 2/2] lib: media_player: split libvlc_media_player_select_track
Thomas Guillem
thomas at gllm.fr
Wed Sep 9 14:38:13 CEST 2020
More than one users reported that they would prefer having a new function to
unselect. Furthermore, having a type and a track of the same type as arguments
feels confusing.
---
include/vlc/libvlc_media_player.h | 22 +++++++++++++++++-----
lib/libvlc.sym | 1 +
lib/media_player.c | 31 +++++++++++++++++--------------
test/libvlc/media_player.c | 4 ++--
4 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index ed5bb933ce3..7dec44f1af2 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1345,21 +1345,33 @@ libvlc_media_player_get_track_from_id( libvlc_media_player_t *p_mi,
/**
- * Select a track or unselect all tracks for one type
+ * Select a track
+ *
+ * This will unselected the current track.
*
* \version LibVLC 4.0.0 and later.
*
* \note Use libvlc_media_player_select_tracks() for multiple selection
*
* \param p_mi the media player
- * \param type type of the selected track
- * \param track track to select or NULL to unselect all tracks of for this type
+ * \param track track to select, can't be NULL
*/
LIBVLC_API void
libvlc_media_player_select_track( libvlc_media_player_t *p_mi,
- libvlc_track_type_t type,
const libvlc_media_track_t *track );
+/**
+ * Unselect all tracks for a given type
+ *
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \param p_mi the media player
+ * \param type type to unselect
+ */
+LIBVLC_API void
+libvlc_media_player_unselect_track_type( libvlc_media_player_t *p_mi,
+ libvlc_track_type_t type );
+
/**
* Select multiple tracks for one type
*
@@ -1374,7 +1386,7 @@ libvlc_media_player_select_track( libvlc_media_player_t *p_mi,
*
* \param p_mi the media player
* \param type type of the selected track
- * \param tracks pointer to the track array
+ * \param tracks pointer to the track array, or NULL if track_count is 0
* \param track_count number of tracks in the track array
*/
LIBVLC_API void
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index e70d6b2e712..ea3e886dbb0 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -187,6 +187,7 @@ libvlc_media_player_get_tracklist
libvlc_media_player_get_track_from_id
libvlc_media_player_get_selected_track
libvlc_media_player_select_track
+libvlc_media_player_unselect_track_type
libvlc_media_player_select_tracks
libvlc_media_player_select_tracks_by_ids
libvlc_media_release
diff --git a/lib/media_player.c b/lib/media_player.c
index 6ec6025022b..4db7f96af05 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -1898,27 +1898,30 @@ libvlc_media_player_get_track_from_id( libvlc_media_player_t *p_mi,
void
libvlc_media_player_select_track(libvlc_media_player_t *p_mi,
- libvlc_track_type_t type,
const libvlc_media_track_t *track)
{
- assert( track == NULL || type == track->i_type );
+ assert( track != NULL );
vlc_player_t *player = p_mi->player;
vlc_player_Lock(player);
- if (track != NULL)
- {
- const libvlc_media_trackpriv_t *trackpriv =
- libvlc_media_track_to_priv(track);
- vlc_player_SelectEsId(player, trackpriv->es_id,
- VLC_PLAYER_SELECT_EXCLUSIVE);
- }
- else
- {
- const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
- vlc_player_UnselectTrackCategory(player, cat);
- }
+ const libvlc_media_trackpriv_t *trackpriv =
+ libvlc_media_track_to_priv(track);
+ vlc_player_SelectEsId(player, trackpriv->es_id,
+ VLC_PLAYER_SELECT_EXCLUSIVE);
+
+ vlc_player_Unlock(player);
+}
+
+void
+libvlc_media_player_unselect_track_type( libvlc_media_player_t *p_mi,
+ libvlc_track_type_t type )
+{
+ vlc_player_t *player = p_mi->player;
+ const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
+ vlc_player_Lock(player);
+ vlc_player_UnselectTrackCategory(player, cat);
vlc_player_Unlock(player);
}
diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c
index 6b6796c4925..78d7fb18555 100644
--- a/test/libvlc/media_player.c
+++ b/test/libvlc/media_player.c
@@ -442,7 +442,7 @@ static void test_media_player_tracks(const char** argv, int argc)
/* Select (replace) a new audio track */
libtrack = libvlc_media_player_get_track_from_id(mp, "audio/0");
assert(libtrack);
- libvlc_media_player_select_track(mp, libvlc_track_audio, libtrack);
+ libvlc_media_player_select_track(mp, libtrack);
libvlc_media_track_release(libtrack);
atracks[0].toselect = true;
atracks[2].toselect = false;
@@ -471,7 +471,7 @@ static void test_media_player_tracks(const char** argv, int argc)
libvlc_media_track_release(vtrack2);
/* Unselect all spu tracks */
- libvlc_media_player_select_track(mp, libvlc_track_text, NULL);
+ libvlc_media_player_unselect_track_type(mp, libvlc_track_text);
stracks[0].toselect = stracks[1].toselect = false;
/* Check that all tracks are added and selected according to previous
--
2.28.0
More information about the vlc-devel
mailing list