[vlc-devel] [RFC PATCH 4/6] lib: add libvlc_media_tracklist API

Thomas Guillem thomas at gllm.fr
Tue Jun 2 22:02:08 CEST 2020


This common opaque struct will be used by the media and the media_player.
---
 include/vlc/libvlc_media_track.h | 43 ++++++++++++++++++++++++++++++++
 lib/libvlc.sym                   |  3 +++
 lib/media_track.c                | 30 ++++++++++++++++++++++
 3 files changed, 76 insertions(+)

diff --git a/include/vlc/libvlc_media_track.h b/include/vlc/libvlc_media_track.h
index d0f1232f5a..cad3822a4f 100644
--- a/include/vlc/libvlc_media_track.h
+++ b/include/vlc/libvlc_media_track.h
@@ -141,6 +141,49 @@ typedef struct libvlc_media_track_t
 
 } libvlc_media_track_t;
 
+/**
+ * Opaque struct containing a list of tracks
+ */
+typedef struct libvlc_media_tracklist_t libvlc_media_tracklist_t;
+
+/**
+ * Get the number of tracks in a tracklist
+ *
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \param list valid tracklist
+ *
+ * \return number of tracks, or 0 if the list is empty
+ */
+LIBVLC_API size_t
+libvlc_media_tracklist_count( const libvlc_media_tracklist_t *list );
+
+/**
+ * Get a track at a specific index
+ *
+ * \warning The behaviour is undefined if the index is not valid.
+ *
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \param list valid tracklist
+ * \param index valid index in the range [0; count[
+ *
+ * \return a valid track (can't be NULL if libvlc_media_tracklist_count()
+ * returned a valid count)
+ */
+LIBVLC_API libvlc_media_track_t *
+libvlc_media_tracklist_at( libvlc_media_tracklist_t *list, size_t index );
+
+/**
+ * Release a tracklist
+ *
+ * \version LibVLC 4.0.0 and later.
+ *
+ * \param list valid tracklist
+ */
+LIBVLC_API void
+libvlc_media_tracklist_release( libvlc_media_tracklist_t *list );
+
 /** @}*/
 
 # ifdef __cplusplus
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 5623ec87d5..9ccab493a5 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -85,6 +85,9 @@ libvlc_media_thumbnail_request_by_time
 libvlc_media_thumbnail_request_by_pos
 libvlc_media_thumbnail_request_cancel
 libvlc_media_thumbnail_request_destroy
+libvlc_media_tracklist_at
+libvlc_media_tracklist_count
+libvlc_media_tracklist_release
 libvlc_media_list_add_media
 libvlc_media_list_count
 libvlc_media_list_event_manager
diff --git a/lib/media_track.c b/lib/media_track.c
index 91b4d2d3b1..0fdcffdbd9 100644
--- a/lib/media_track.c
+++ b/lib/media_track.c
@@ -33,6 +33,12 @@
 #include "libvlc_internal.h"
 #include "media_internal.h"
 
+struct libvlc_media_tracklist_t
+{
+    size_t count;
+    libvlc_media_trackpriv_t tracks[];
+};
+
 void
 libvlc_media_trackpriv_from_es( libvlc_media_trackpriv_t *trackpriv,
                                 const es_format_t *es  )
@@ -118,3 +124,27 @@ libvlc_media_track_clean( libvlc_media_track_t *track )
         break;
     }
 }
+
+size_t
+libvlc_media_tracklist_count( const libvlc_media_tracklist_t *list )
+{
+    return list->count;
+}
+
+libvlc_media_track_t *
+libvlc_media_tracklist_at( libvlc_media_tracklist_t *list, size_t idx )
+{
+    assert( idx < list->count );
+    return &list->tracks[idx].t;
+}
+
+void
+libvlc_media_tracklist_release( libvlc_media_tracklist_t *list )
+{
+    for( size_t i = 0; i < list->count; ++i )
+    {
+        libvlc_media_trackpriv_t *trackpriv = &list->tracks[i];
+        libvlc_media_track_clean( &trackpriv->t );
+    }
+    free( list );
+}
-- 
2.20.1



More information about the vlc-devel mailing list