* [FFmpeg-devel] [PATCH] avutil/frame: add new functions to get frame side data
@ 2025-03-04 11:55 Leandro Santiago
0 siblings, 0 replies; only message in thread
From: Leandro Santiago @ 2025-03-04 11:55 UTC (permalink / raw)
To: ffmpeg-devel
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);
+}
--
2.48.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-03-04 11:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-04 11:55 [FFmpeg-devel] [PATCH] avutil/frame: add new functions to get frame side data Leandro Santiago
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