[vlc-commits] lib: add libvlc_media_get_tracklist()
Thomas Guillem
git at videolan.org
Thu Jun 11 14:45:36 CEST 2020
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jun 2 19:06:18 2020 +0200| [40c14fbee48975100aaa92b83a99ac33fa086933] | committer: Thomas Guillem
lib: add libvlc_media_get_tracklist()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=40c14fbee48975100aaa92b83a99ac33fa086933
---
include/vlc/libvlc_media.h | 25 +++++++++++++++++++++++-
lib/libvlc.sym | 1 +
lib/media.c | 16 ++++++++++++++++
lib/media_internal.h | 5 +++++
lib/media_track.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 93 insertions(+), 1 deletion(-)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index 9ed688f935..d7ae42bb05 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -573,7 +573,7 @@ LIBVLC_API libvlc_time_t
*
* \see libvlc_MediaParsedChanged
* \see libvlc_media_get_meta
- * \see libvlc_media_tracks_get
+ * \see libvlc_media_get_tracklist
* \see libvlc_media_get_parsed_status
* \see libvlc_media_parse_flag_t
*
@@ -661,6 +661,29 @@ LIBVLC_API
unsigned libvlc_media_tracks_get( libvlc_media_t *p_md,
libvlc_media_track_t ***tracks );
+/**
+ * Get the track list for one type
+ *
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \note You need to call libvlc_media_parse_with_options() or play the media
+ * at least once before calling this function. Not doing this will result in
+ * an empty list.
+ *
+ * \see libvlc_media_parse_with_options
+ * \see libvlc_media_tracklist_count
+ * \see libvlc_media_tracklist_at
+ *
+ * \param p_md media descriptor object
+ * \param type type of the track list to request
+ *
+ * \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
+ * with libvlc_media_tracklist_delete()
+ */
+LIBVLC_API libvlc_media_tracklist_t *
+libvlc_media_get_tracklist( libvlc_media_t *p_md, libvlc_track_type_t type );
+
/**
* Get codec description from media elementary stream
*
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 1d38ed7879..58f9e94062 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -77,6 +77,7 @@ libvlc_media_get_meta
libvlc_media_get_mrl
libvlc_media_get_state
libvlc_media_get_stats
+libvlc_media_get_tracklist
libvlc_media_get_type
libvlc_media_get_user_data
libvlc_media_is_parsed
diff --git a/lib/media.c b/lib/media.c
index 8d663bc48b..e25d439a8a 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -895,6 +895,22 @@ libvlc_media_tracks_get( libvlc_media_t *p_md, libvlc_media_track_t *** pp_es )
return i_es;
}
+libvlc_media_tracklist_t *
+libvlc_media_get_tracklist( libvlc_media_t *p_md, libvlc_track_type_t type )
+{
+ assert( p_md );
+
+ input_item_t *p_input_item = p_md->p_input_item;
+
+ vlc_mutex_lock( &p_input_item->lock );
+ libvlc_media_tracklist_t *list =
+ libvlc_media_tracklist_from_es_array( p_input_item->es,
+ p_input_item->i_es, type );
+ vlc_mutex_unlock( &p_input_item->lock );
+
+ return list;
+}
+
// Get codec description from media elementary stream
const char *
libvlc_media_get_codec_description( libvlc_track_type_t i_type,
diff --git a/lib/media_internal.h b/lib/media_internal.h
index 2aa944806a..24bedfb405 100644
--- a/lib/media_internal.h
+++ b/lib/media_internal.h
@@ -87,6 +87,11 @@ void
libvlc_media_trackpriv_from_es( libvlc_media_trackpriv_t *trackpriv,
const es_format_t *es );
+libvlc_media_tracklist_t *
+libvlc_media_tracklist_from_es_array( es_format_t **es_array,
+ size_t es_count,
+ libvlc_track_type_t type );
+
void
libvlc_media_track_clean( libvlc_media_track_t *track );
diff --git a/lib/media_track.c b/lib/media_track.c
index e722d37bb9..c6bb90e14d 100644
--- a/lib/media_track.c
+++ b/lib/media_track.c
@@ -125,6 +125,53 @@ libvlc_media_track_clean( libvlc_media_track_t *track )
}
}
+static libvlc_media_tracklist_t *
+libvlc_media_tracklist_alloc( size_t count )
+{
+ size_t size;
+ if( mul_overflow( count, sizeof(libvlc_media_trackpriv_t), &size) )
+ return NULL;
+ if( add_overflow( size, sizeof(libvlc_media_tracklist_t), &size) )
+ return NULL;
+
+ libvlc_media_tracklist_t *list = malloc( size );
+ if( list == NULL )
+ return NULL;
+
+ list->count = count;
+ return list;
+}
+
+libvlc_media_tracklist_t *
+libvlc_media_tracklist_from_es_array( es_format_t **es_array,
+ size_t es_count,
+ libvlc_track_type_t type )
+{
+ size_t count = 0;
+ const enum es_format_category_e cat = libvlc_track_type_to_escat( type );
+
+ for( size_t i = 0; i < es_count; ++i )
+ {
+ if( es_array[i]->i_cat == cat )
+ count++;
+ }
+
+ libvlc_media_tracklist_t *list = libvlc_media_tracklist_alloc( count );
+
+ if( count == 0 )
+ return list;
+
+ count = 0;
+ for( size_t i = 0; i < es_count; ++i )
+ {
+ if( es_array[i]->i_cat == cat )
+ libvlc_media_trackpriv_from_es( &list->tracks[count++],
+ es_array[i] );
+ }
+
+ return list;
+}
+
size_t
libvlc_media_tracklist_count( const libvlc_media_tracklist_t *list )
{
More information about the vlc-commits
mailing list