[FFmpeg-devel] [PATCH v2 3/8] avutil/frame: add av_frame_remove_side_data_by_props()

James Almer jamrial at gmail.com
Thu Dec 19 14:50:32 EET 2024


On 12/4/2024 11:51 AM, Niklas Haas wrote:
> From: Niklas Haas <git at haasn.dev>
> 
> As discussed in the previous commit, we often need a convenient way of
> stripping all side data related to a certain aspect of the frame. This helper
> accomplishes just that.
> 
> I considered also adding a way to match only side data matching *all*
> properties, but I think this is sufficiently useless in practise to not warrant
> inclusion in the API.
> ---
>   doc/APIchanges      |  4 ++++
>   libavutil/frame.c   | 21 +++++++++++++++++++++
>   libavutil/frame.h   | 13 +++++++++++++
>   libavutil/version.h |  2 +-
>   4 files changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index bce38829ee..e0f778db5a 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,10 @@ The last version increases of all libraries were on 2024-03-07
>   
>   API changes, most recent first:
>   
> +2024-12-xx - xxxxxxxxxx - lavu 59.49.100 - frame.h
> +  Add av_frame_remove_side_data_by_props() and

Don't add two functions, please. Just the one taking pointers to array 
and size, which can be used everywhere.

> +  av_frame_side_data_remove_by_props().
> +
>   2024-12-xx - xxxxxxxxxx - lavu 59.48.100 - frame.h
>     Add AV_SIDE_DATA_PROP_SIZE_DEPENDENT and AV_FRAME_DATA_PROP_COLOR_DEPENDENT.
>   
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 1dced3b52b..d3a45217dc 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -961,6 +961,22 @@ void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
>       remove_side_data(sd, nb_sd, type);
>   }
>   
> +void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd,
> +                                        int props)
> +{
> +    for (int i = *nb_sd - 1; i >= 0; i--) {
> +        AVFrameSideData *entry = ((*sd)[i]);
> +        const AVSideDataDescriptor *desc = av_frame_side_data_desc(entry->type);
> +        if (!desc || !(desc->props & props))
> +            continue;
> +
> +        free_side_data(&entry);
> +
> +        ((*sd)[i]) = ((*sd)[*nb_sd - 1]);
> +        (*nb_sd)--;
> +    }
> +}
> +
>   AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>                                           enum AVFrameSideDataType type)
>   {
> @@ -1032,6 +1048,11 @@ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
>       remove_side_data(&frame->side_data, &frame->nb_side_data, type);
>   }
>   
> +void av_frame_remove_side_data_by_props(AVFrame *frame, int props)
> +{
> +    av_frame_side_data_remove_by_props(&frame->side_data, &frame->nb_side_data, props);
> +}
> +
>   const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType type)
>   {
>       unsigned t = type;
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 8345010e22..5dfcd85c47 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -1013,6 +1013,11 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>    */
>   void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
>   
> +/**
> + * Remove and free all side data instances that match any of the given
> + * side data properties. (See enum AVSideDataProps)
> + */
> +void av_frame_remove_side_data_by_props(AVFrame *frame, int props);
>   
>   /**
>    * Flags for frame cropping.
> @@ -1183,6 +1188,14 @@ const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd,
>    */
>   void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
>                                  enum AVFrameSideDataType type);
> +
> +/**
> + * Remove and free all side data instances that match any of the given
> + * side data properties. (See enum AVSideDataProps)
> + */
> +void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd,
> +                                        int props);
> +
>   /**
>    * @}
>    */
> diff --git a/libavutil/version.h b/libavutil/version.h
> index efc569e090..ad1f3e68ba 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>    */
>   
>   #define LIBAVUTIL_VERSION_MAJOR  59
> -#define LIBAVUTIL_VERSION_MINOR  48
> +#define LIBAVUTIL_VERSION_MINOR  49
>   #define LIBAVUTIL_VERSION_MICRO 100
>   
>   #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241219/86ee0cd1/attachment.sig>


More information about the ffmpeg-devel mailing list