[vlc-devel] [PATCH 15/15] lib: media: Expose attached pictures
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu Nov 12 17:44:12 CET 2020
---
include/vlc/libvlc_media.h | 14 ++++++++++++++
lib/libvlc.sym | 1 +
lib/media.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index 904e265561..5d83fd4c32 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -807,6 +807,20 @@ libvlc_media_thumbnail_request_cancel( libvlc_media_thumbnail_request_t *p_req )
LIBVLC_API void
libvlc_media_thumbnail_request_destroy( libvlc_media_thumbnail_request_t *p_req );
+/**
+ * Get this media's attached pictures
+ * @param md media descriptor object
+ * @param thumbnails address to store an array of libvlc_picture_t into [OUT]
+ * @return The number of attached pictures in the array.
+ *
+ * If this function returns 0, *thumbnails will contain NULL
+ * The caller must call libvlc_picture_release on each pictures in the returned
+ * array, and must free() the array itself
+ */
+LIBVLC_API size_t
+libvlc_media_get_attached_pictures( libvlc_media_t *md,
+ libvlc_picture_t*** thumbnails );
+
/**
* Add a slave to the current media.
*
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index ebdd2db629..5c93e8f70d 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -71,6 +71,7 @@ libvlc_media_discoverer_start
libvlc_media_discoverer_stop
libvlc_media_duplicate
libvlc_media_event_manager
+libvlc_media_get_attached_pictures
libvlc_media_get_codec_description
libvlc_media_get_duration
libvlc_media_get_meta
diff --git a/lib/media.c b/lib/media.c
index 7ab98de7c1..540b7c1642 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -1301,3 +1301,41 @@ void libvlc_media_slaves_release( libvlc_media_slave_t **pp_slaves,
}
free( pp_slaves );
}
+
+size_t
+libvlc_media_get_attached_pictures( libvlc_media_t *md,
+ libvlc_picture_t*** pictures_out )
+{
+ assert( md && pictures_out );
+ input_item_attachment_t **attachments;
+ int res = input_item_GetAttachments( md->p_input_item, &attachments );
+ if( res <= 0 )
+ {
+ *pictures_out = NULL;
+ return 0;
+ }
+ libvlc_picture_t** pictures = *pictures_out =
+ malloc( res * sizeof( *pictures ) );
+ if( !pictures )
+ {
+ for ( int i = 0; i < res; ++i )
+ vlc_input_attachment_Release( attachments[i] );
+ free( attachments );
+ return 0;
+ }
+
+ size_t nb_pictures = 0;
+ for( int i = 0; i < res; ++i )
+ {
+ input_item_attachment_t* a = attachments[i];
+ libvlc_picture_t *pic = libvlc_picture_from_attachment( a );
+ vlc_input_attachment_Release( a );
+ if( !pic )
+ continue;
+ pictures[nb_pictures] = pic;
+ nb_pictures++;
+ }
+ free( attachments );
+
+ return nb_pictures;
+}
--
2.28.0
More information about the vlc-devel
mailing list