[vlc-commits] lib: Add a minimal picture list API

Hugo Beauzée-Luyssen git at videolan.org
Thu Nov 19 11:00:25 CET 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Nov 13 11:05:32 2020 +0100| [34d7c2023a4a1fb5537b910eb03d1721f8a38138] | committer: Hugo Beauzée-Luyssen

lib: Add a minimal picture list API

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

 include/vlc/libvlc_picture.h | 22 ++++++++++++++++++++
 lib/libvlc.sym               |  3 +++
 lib/picture.c                | 48 ++++++++++++++++++++++++++++++++++++++++++++
 lib/picture_internal.h       |  3 +++
 4 files changed, 76 insertions(+)

diff --git a/include/vlc/libvlc_picture.h b/include/vlc/libvlc_picture.h
index 07fbf11fc2..770a13cc40 100644
--- a/include/vlc/libvlc_picture.h
+++ b/include/vlc/libvlc_picture.h
@@ -28,6 +28,7 @@ extern "C" {
 # endif
 
 typedef struct libvlc_picture_t libvlc_picture_t;
+typedef struct libvlc_picture_list_t libvlc_picture_list_t;
 
 typedef enum libvlc_picture_type_t
 {
@@ -120,6 +121,27 @@ libvlc_picture_get_height( const libvlc_picture_t* pic );
 LIBVLC_API libvlc_time_t
 libvlc_picture_get_time( const libvlc_picture_t* pic );
 
+/**
+ * Returns the number of pictures in the list
+ */
+LIBVLC_API size_t libvlc_picture_list_count( const libvlc_picture_list_t* list );
+
+/**
+ * Returns the picture at the provided index.
+ *
+ * If the index is out of bound, the result is undefined.
+ */
+LIBVLC_API libvlc_picture_t* libvlc_picture_list_at( const libvlc_picture_list_t* list,
+                                                     size_t index );
+
+/**
+ * Destroys a picture list and releases the pictures it contains
+ * \param list The list to destroy
+ *
+ * Calling this function with a NULL list is safe and will return immediatly
+ */
+LIBVLC_API void libvlc_picture_list_destroy( libvlc_picture_list_t* list );
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index ebdd2db629..f30d67f3a9 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -288,3 +288,6 @@ libvlc_picture_get_stride
 libvlc_picture_get_width
 libvlc_picture_get_height
 libvlc_picture_get_time
+libvlc_picture_list_at
+libvlc_picture_list_count
+libvlc_picture_list_destroy
diff --git a/lib/picture.c b/lib/picture.c
index be62a91033..5f55aeaa66 100644
--- a/lib/picture.c
+++ b/lib/picture.c
@@ -195,3 +195,51 @@ libvlc_time_t libvlc_picture_get_time( const libvlc_picture_t* pic )
 {
     return pic->time;
 }
+
+libvlc_picture_list_t* libvlc_picture_list_from_attachments( input_attachment_t** attachments,
+                                                             size_t nb_attachments )
+{
+    size_t size = 0;
+    libvlc_picture_list_t* list;
+    if ( mul_overflow( nb_attachments, sizeof( libvlc_picture_t* ), &size ) )
+        return NULL;
+    if ( add_overflow( size, sizeof( *list ), &size ) )
+        return NULL;
+
+    list = malloc( size );
+    if ( !list )
+        return NULL;
+    list->count = 0;
+    for ( size_t i = 0; i < nb_attachments; ++i )
+    {
+        input_attachment_t* a = attachments[i];
+        libvlc_picture_t *pic = libvlc_picture_from_attachment( a );
+        if( !pic )
+            continue;
+        list->pictures[list->count] = pic;
+        list->count++;
+    }
+    return list;
+}
+
+size_t libvlc_picture_list_count( const libvlc_picture_list_t* list )
+{
+    assert( list );
+    return list->count;
+}
+
+libvlc_picture_t* libvlc_picture_list_at( const libvlc_picture_list_t* list,
+                                          size_t index )
+{
+    assert( list );
+    return list->pictures[index];
+}
+
+void libvlc_picture_list_destroy( libvlc_picture_list_t* list )
+{
+    if ( !list )
+        return;
+    for ( size_t i = 0; i < list->count; ++i )
+        libvlc_picture_release( list->pictures[i] );
+    free( list );
+}
diff --git a/lib/picture_internal.h b/lib/picture_internal.h
index aeb1e3f505..9fe79c6def 100644
--- a/lib/picture_internal.h
+++ b/lib/picture_internal.h
@@ -44,4 +44,7 @@ libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t* p_pic,
                                       unsigned int i_width, unsigned int i_height,
                                       bool b_crop );
 
+libvlc_picture_list_t* libvlc_picture_list_from_attachments( input_attachment_t** attachments,
+                                                             size_t nb_attachments );
+
 #endif /* PICTURE_INTERNAL_H */



More information about the vlc-commits mailing list