Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Leandro Santiago <leandrosansilva@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avutil/frame: add new functions to get frame side data
Date: Mon, 10 Mar 2025 11:52:40 +0100
Message-ID: <ee2009f3-5568-4eaf-a765-1a8674befc50@gmail.com> (raw)
In-Reply-To: <15e94abf-61dc-49ab-a209-bf6d1b3701ae@gmail.com>

Just pinging to see if anyone has had time to look at this patch :-)

I also noticed that this patch did not trigger an entry on patchwork. Is it normal or should the patches go to patchwork automatically?

Also, what's the correct approach within ffmpeg codebase to implement unit tests? Or would you recommend using the FATE tests?

On 3/4/25 12:55, Leandro Santiago wrote:
> The functions are:
>
> av_frame_side_data_get_nth_c()
> av_frame_side_data_get_nth()
> av_frame_get_nth_side_data()
>
> They mimic the counterparts without the `_nth` suffix/infix, with an extra
> argument, which specifies the relative position of the entry of a given
> type.
>
> Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com>
> ---
>  libavutil/frame.c     | 10 ++++++++++
>  libavutil/frame.h     | 43 ++++++++++++++++++++++++++++++++++++++++---
>  libavutil/side_data.c | 14 +++++++++++---
>  3 files changed, 61 insertions(+), 6 deletions(-)
>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 71bde48f8b..dd0fd06378 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -699,6 +699,16 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>      );
>  }
>  
> +AVFrameSideData *av_frame_get_nth_side_data(const AVFrame *frame,
> +                                            enum AVFrameSideDataType type,
> +                                            int n)
> +{
> +    return (AVFrameSideData *)av_frame_side_data_get_nth(
> +        frame->side_data, frame->nb_side_data,
> +        type, n
> +    );
> +}
> +
>  static int frame_copy_video(AVFrame *dst, const AVFrame *src)
>  {
>      int planes;
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 49260ae2dd..56375280bb 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -1017,12 +1017,22 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
>                                                   AVBufferRef *buf);
>  
>  /**
> - * @return a pointer to the side data of a given type on success, NULL if there
> + * @return a pointer to the first side data of a given type on success, NULL if there
>   * is no side data with such type in this frame.
>   */
>  AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>                                          enum AVFrameSideDataType type);
>  
> +/**
> + * @return a pointer to the side data of a given type on success,
> + * after skipping the first matches. Otherwise return NULL if there
> + * is no side data with such type in this frame or if all the matches were skipped.
> + * @param n the relative position of the side data entry
> + */
> +AVFrameSideData *av_frame_get_nth_side_data(const AVFrame *frame,
> +                                            enum AVFrameSideDataType type,
> +                                            int n);
> +
>  /**
>   * Remove and free all side data instances of the given type.
>   */
> @@ -1170,7 +1180,7 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
>                               const AVFrameSideData *src, unsigned int flags);
>  
>  /**
> - * Get a side data entry of a specific type from an array.
> + * Get the first side data entry of a specific type from an array.
>   *
>   * @param sd    array of side data.
>   * @param nb_sd integer containing the number of entries in the array.
> @@ -1184,7 +1194,24 @@ const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *s
>                                                  enum AVFrameSideDataType type);
>  
>  /**
> - * Wrapper around av_frame_side_data_get_c() to workaround the limitation
> + * Get a side data entry of a specific type from an array.
> + *
> + * @param sd    array of side data.
> + * @param nb_sd integer containing the number of entries in the array.
> + * @param type  type of side data to be queried
> + * @param n     relative position of the side data entry.
> + *
> + * @return a pointer to the side data of a given type on success, NULL if there
> + *         is no side data with such type in this set or all the entries were skipped.
> + */
> +const AVFrameSideData *av_frame_side_data_get_nth_c(const AVFrameSideData * const *sd,
> +                                                    const int nb_sd,
> +                                                    enum AVFrameSideDataType type,
> +                                                    int n
> +);
> +
> +/**
> + * Wrappers around av_frame_side_data_get{_nth}_c() and to workaround the limitation
>   * that for any type T the conversion from T * const * to const T * const *
>   * is not performed automatically in C.
>   * @see av_frame_side_data_get_c()
> @@ -1198,6 +1225,16 @@ const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd,
>                                      nb_sd, type);
>  }
>  
> +static inline
> +const AVFrameSideData *av_frame_side_data_get_nth(AVFrameSideData * const *sd,
> +                                                  const int nb_sd,
> +                                                  enum AVFrameSideDataType type,
> +                                                  int n)
> +{
> +    return av_frame_side_data_get_nth_c((const AVFrameSideData * const *)sd,
> +                                        nb_sd, type, n);
> +}
> +
>  /**
>   * Remove and free all side data instances of the given type from an array.
>   */
> diff --git a/libavutil/side_data.c b/libavutil/side_data.c
> index 17965f2d3c..bfe408e611 100644
> --- a/libavutil/side_data.c
> +++ b/libavutil/side_data.c
> @@ -301,13 +301,21 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
>      return 0;
>  }
>  
> -const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd,
> +const AVFrameSideData *av_frame_side_data_get_nth_c(const AVFrameSideData * const *sd,
>                                                  const int nb_sd,
> -                                                enum AVFrameSideDataType type)
> +                                                enum AVFrameSideDataType type,
> +                                                int n)
>  {
>      for (int i = 0; i < nb_sd; i++) {
> -        if (sd[i]->type == type)
> +        if (sd[i]->type == type && --n < 0)
>              return sd[i];
>      }
>      return NULL;
>  }
> +
> +const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd,
> +                                                const int nb_sd,
> +                                                enum AVFrameSideDataType type)
> +{
> +    return av_frame_side_data_get_nth_c(sd, nb_sd, type, 0);
> +}
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-03-10 10:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 11:55 Leandro Santiago
2025-03-10 10:52 ` Leandro Santiago [this message]
2025-03-10 14:57 ` Andreas Rheinhardt
2025-03-10 15:19   ` James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee2009f3-5568-4eaf-a765-1a8674befc50@gmail.com \
    --to=leandrosansilva@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git