[vlc-commits] [Git][videolan/vlc][master] 2 commits: libvlc: media_player: add a param to get selected tracks
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Wed Jul 27 08:58:53 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
db81e6e1 by Thomas Guillem at 2022-07-27T08:19:21+00:00
libvlc: media_player: add a param to get selected tracks
- - - - -
7949712a by Thomas Guillem at 2022-07-27T08:19:21+00:00
libvlc: add bool selected in libvlc_media_player_get_tracklist
Asked by API users, more convenient than dropping !selected tracks
ourself.
- - - - -
5 changed files:
- include/vlc/libvlc_media_player.h
- lib/media_internal.h
- lib/media_player.c
- lib/media_track.c
- test/libvlc/media_player.c
Changes:
=====================================
include/vlc/libvlc_media_player.h
=====================================
@@ -1356,6 +1356,8 @@ LIBVLC_API void libvlc_media_player_set_video_title_display( libvlc_media_player
*
* \param p_mi the media player
* \param type type of the track list to request
+ * \param selected filter only selected tracks if true (return all tracks, even
+ * selected ones if false)
*
* \return a valid libvlc_media_tracklist_t or NULL in case of error, if there
* is no track for a category, the returned list will have a size of 0, delete
@@ -1363,8 +1365,7 @@ LIBVLC_API void libvlc_media_player_set_video_title_display( libvlc_media_player
*/
LIBVLC_API libvlc_media_tracklist_t *
libvlc_media_player_get_tracklist( libvlc_media_player_t *p_mi,
- libvlc_track_type_t type );
-
+ libvlc_track_type_t type, bool selected );
/**
* Get the selected track for one type
=====================================
lib/media_internal.h
=====================================
@@ -106,6 +106,6 @@ libvlc_media_tracklist_from_es_array( es_format_t **es_array,
libvlc_media_tracklist_t *
libvlc_media_tracklist_from_player( vlc_player_t *player,
- libvlc_track_type_t type );
+ libvlc_track_type_t type, bool selected );
#endif
=====================================
lib/media_player.c
=====================================
@@ -1776,14 +1776,14 @@ void libvlc_media_player_set_video_title_display( libvlc_media_player_t *p_mi, l
libvlc_media_tracklist_t *
libvlc_media_player_get_tracklist(libvlc_media_player_t *p_mi,
- libvlc_track_type_t type)
+ libvlc_track_type_t type, bool selected)
{
vlc_player_t *player = p_mi->player;
vlc_player_Lock(player);
libvlc_media_tracklist_t *list =
- libvlc_media_tracklist_from_player(player, type);
+ libvlc_media_tracklist_from_player(player, type, selected);
vlc_player_Unlock(player);
=====================================
lib/media_track.c
=====================================
@@ -247,11 +247,26 @@ libvlc_media_track_create_from_player_track( const struct vlc_player_track *trac
libvlc_media_tracklist_t *
libvlc_media_tracklist_from_player( vlc_player_t *player,
- libvlc_track_type_t type )
+ libvlc_track_type_t type, bool selected )
{
const enum es_format_category_e cat = libvlc_track_type_to_escat( type );
size_t count = vlc_player_GetTrackCount( player, cat );
+
+ if( selected )
+ {
+ size_t selected_count = 0;
+ for( size_t i = 0; i < count; ++i )
+ {
+ const struct vlc_player_track *track =
+ vlc_player_GetTrackAt( player, cat, i );
+ assert( track );
+ if( track->selected )
+ selected_count++;
+ }
+ count = selected_count;
+ }
+
libvlc_media_tracklist_t *list = libvlc_media_tracklist_alloc( count );
if( count == 0 || list == NULL )
@@ -263,6 +278,9 @@ libvlc_media_tracklist_from_player( vlc_player_t *player,
vlc_player_GetTrackAt( player, cat, i );
assert( track );
+ if( selected && !track->selected )
+ continue;
+
libvlc_media_trackpriv_t *trackpriv = libvlc_media_trackpriv_new();
if( trackpriv == NULL )
{
=====================================
test/libvlc/media_player.c
=====================================
@@ -423,7 +423,7 @@ static void test_media_player_tracks(const char** argv, int argc)
struct track *tracks = alltracks[i];
libvlc_media_tracklist_t *tracklist =
- libvlc_media_player_get_tracklist(mp, type);
+ libvlc_media_player_get_tracklist(mp, type, false);
assert(tracklist);
assert(libvlc_media_tracklist_count(tracklist) == track_count);
@@ -437,6 +437,17 @@ static void test_media_player_tracks(const char** argv, int argc)
assert(libtrack->selected == track->selected);
}
libvlc_media_tracklist_delete(tracklist);
+
+ tracklist = libvlc_media_player_get_tracklist(mp, type, true);
+ assert(tracklist);
+ for (size_t j = 0; j < libvlc_media_tracklist_count(tracklist); ++j)
+ {
+ libtrack = libvlc_media_tracklist_at(tracklist, j);
+ assert(libtrack);
+ assert(libtrack->selected);
+ }
+ libvlc_media_tracklist_delete(tracklist);
+
}
/* Select (replace) a new audio track */
@@ -449,7 +460,7 @@ static void test_media_player_tracks(const char** argv, int argc)
/* Add a new video track */
libvlc_media_tracklist_t *tracklist =
- libvlc_media_player_get_tracklist(mp, libvlc_track_video);
+ libvlc_media_player_get_tracklist(mp, libvlc_track_video, false);
assert(tracklist);
libvlc_media_track_t *vtrack1 =
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/94386bab7533e8830281d5d8503e69fc44b96e8b...7949712a30439e12879153172f15c659f6608aac
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/94386bab7533e8830281d5d8503e69fc44b96e8b...7949712a30439e12879153172f15c659f6608aac
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list