[vlc-devel] [V3 10/13] lib: Allow a picture to be constructed from an attachment

Rémi Denis-Courmont remi at remlab.net
Wed Nov 18 20:07:52 CET 2020


Le mercredi 18 novembre 2020, 16:23:56 EET Hugo Beauzée-Luyssen a écrit :
> ---
>  lib/picture.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
> 
> diff --git a/lib/picture.c b/lib/picture.c
> index fc8b769b2a..910440d84e 100644
> --- a/lib/picture.c
> +++ b/lib/picture.c
> @@ -30,6 +30,8 @@
>  #include <vlc_atomic.h>
>  #include <vlc_picture.h>
>  #include <vlc_block.h>
> +#include <vlc_image.h>
> +#include <vlc_input.h>
>  #include <vlc_fs.h>
> 
>  #include "picture_internal.h"
> @@ -41,6 +43,13 @@ struct libvlc_picture_t
>      block_t* converted;
>      video_format_t fmt;
>      libvlc_time_t time;
> +    input_attachment_t* attachment;
> +};
> +
> +struct libvlc_picture_list_t
> +{
> +    size_t count;
> +    libvlc_picture_t* pictures[];
>  };
> 
>  libvlc_picture_t* libvlc_picture_new( vlc_object_t* p_obj, picture_t*
> input, @@ -54,6 +63,7 @@ libvlc_picture_t* libvlc_picture_new(
> vlc_object_t* p_obj, picture_t* input, vlc_atomic_rc_init( &pic->rc );
>      pic->type = type;
>      pic->time = MS_FROM_VLC_TICK( input->date );
> +    pic->attachment = NULL;
>      vlc_fourcc_t format;
>      switch ( type )
>      {
> @@ -79,6 +89,51 @@ libvlc_picture_t* libvlc_picture_new( vlc_object_t*
> p_obj, picture_t* input, return pic;
>  }
> 
> +static void libvlc_picture_block_release( block_t* block )
> +{
> +    free( block );
> +}
> +
> +static const struct vlc_block_callbacks block_cbs =
> +{
> +    libvlc_picture_block_release,
> +};
> +
> +static libvlc_picture_t* libvlc_picture_from_attachment(
> input_attachment_t* attachment ) +{
> +    vlc_fourcc_t fcc = image_Mime2Fourcc( attachment->psz_mime );
> +    if ( !fcc || ( fcc != VLC_CODEC_PNG && fcc != VLC_CODEC_JPEG ) )
> +        return NULL;

The first test is redundant.

> +    libvlc_picture_t *pic = malloc( sizeof( *pic ) );
> +    if ( unlikely( pic == NULL ) )
> +        return NULL;
> +    pic->converted = malloc( sizeof( *pic->converted ) );
> +    if ( unlikely( pic->converted == NULL ) )
> +    {
> +        free(pic);
> +        return NULL;
> +    }
> +    vlc_atomic_rc_init( &pic->rc );
> +    pic->attachment = vlc_input_attachment_Hold( attachment );
> +    pic->time = VLC_TICK_INVALID;
> +    block_Init( pic->converted, &block_cbs, attachment->p_data,
> +                attachment->i_data);
> +    video_format_Init( &pic->fmt, fcc );
> +    switch ( fcc )
> +    {
> +    case VLC_CODEC_PNG:
> +        pic->type = libvlc_picture_Png;
> +        break;
> +    case VLC_CODEC_JPEG:
> +        pic->type = libvlc_picture_Jpg;
> +        break;
> +    default:
> +        vlc_assert_unreachable();
> +    }
> +
> +    return pic;
> +}
> +
>  void libvlc_picture_retain( libvlc_picture_t* pic )
>  {
>      vlc_atomic_rc_inc( &pic->rc );
> @@ -91,6 +146,8 @@ void libvlc_picture_release( libvlc_picture_t* pic )
>      video_format_Clean( &pic->fmt );
>      if ( pic->converted )
>          block_Release( pic->converted );
> +    if ( pic->attachment )
> +        vlc_input_attachment_Release( pic->attachment );
>      free( pic );
>  }


-- 
Rémi Denis-Courmont




More information about the vlc-devel mailing list