[vlc-commits] lib: add libvlc_media_tracklist API

Thomas Guillem git at videolan.org
Thu Jun 11 14:45:35 CEST 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jun  2 19:04:42 2020 +0200| [e1f25a73af8782b1f24380569eb8e0bc3a6b2c1e] | committer: Thomas Guillem

lib: add libvlc_media_tracklist API

This common opaque struct will be used by the media and the media_player.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e1f25a73af8782b1f24380569eb8e0bc3a6b2c1e
---

 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..59f12f1d04 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_delete( libvlc_media_tracklist_t *list );
+
 /** @}*/
 
 # ifdef __cplusplus
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 5623ec87d5..1d38ed7879 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_delete
 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..e722d37bb9 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_delete( 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 );
+}



More information about the vlc-commits mailing list