[FFmpeg-devel] [PATCH] libavutil: additional side_data accessor
Brad Hards
bradh at frogmouth.net
Tue Apr 20 13:07:42 EEST 2021
The existing function allows access the first instance of a given
type. Mostly that is OK, but some types can occur multiple times
(e.g. libx264 can write version info, VANC and UMID related data as
user data unregistered SEI.
This adds API to access additional instances of a given SEI type.
---
libavutil/frame.c | 19 +++++++++++++++++++
libavutil/frame.h | 20 ++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 31a2117b82..662fcfd452 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -748,6 +748,25 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
return NULL;
}
+AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame,
+ enum AVFrameSideDataType type,
+ const int side_data_instance)
+{
+ int i;
+ int n = 0;
+
+ for (i = 0; i < frame->nb_side_data; i++) {
+ if (frame->side_data[i]->type == type) {
+ if (n == side_data_instance) {
+ return frame->side_data[i];
+ } else {
+ n++;
+ }
+ }
+ }
+ return NULL;
+}
+
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
{
const uint8_t *src_data[4];
diff --git a/libavutil/frame.h b/libavutil/frame.h
index a5ed91b20a..76dd14cbd5 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -943,12 +943,32 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
AVBufferRef *buf);
/**
+ * Find the first instance of side data of a given type.
+ *
+ * @param frame a frame to find the side data in
+ * @param type type of the side data to find
+ *
* @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 frame.
*/
AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
enum AVFrameSideDataType type);
+/**
+ * Find a specified instance of side data of a given type.
+ *
+ * @param frame a frame to find the side data in
+ * @param type type of the side data to find
+ * @param side_data_instance instance of the side data to return (0 base).
+ *
+ * @return a pointer to the n'th instance of side data of a given type on
+ * success, NULL if there are less than side_data_instance instances of the
+ * given type.
+ */
+AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame,
+ enum AVFrameSideDataType type,
+ const int side_data_instance);
+
/**
* Remove and free all side data instances of the given type.
*/
--
2.27.0
More information about the ffmpeg-devel
mailing list