[vlc-devel] [V2 15/16] lib: Add a minimal picture list API
Thomas Guillem
thomas at gllm.fr
Fri Nov 13 11:46:28 CET 2020
On Fri, Nov 13, 2020, at 11:27, Hugo Beauzée-Luyssen wrote:
> ---
> 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..d54d495a25 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_nb_pictures( const
> libvlc_picture_list_t* list );
I propose libvlc_picture_list_count() instead
> +
> +/**
> + * 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..a6034392b2 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_nb_pictures
> +libvlc_picture_list_destroy
> diff --git a/lib/picture.c b/lib/picture.c
> index 7eddb0efb0..b30f9784ae 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_item_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_item_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_nb_pictures( 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..270989e142 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_item_attachment_t** attachments,
> + size_t
> nb_attachments );
> +
> #endif /* PICTURE_INTERNAL_H */
> --
> 2.29.2
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list