[FFmpeg-devel] [PATCH 1/5] libavutil: add convenience accessors for frame side data

Brad Hards bradh at frogmouth.net
Fri Apr 30 14:34:28 EEST 2021


Signed-off-by: Brad Hards <bradh at frogmouth.net>
---
 libavutil/frame.c | 31 +++++++++++++++++++++++++++++++
 libavutil/frame.h | 23 +++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 2ec59b44b1..9f9953c2b4 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -625,6 +625,37 @@ 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;
+}
+
+int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
+{
+    int i;
+    int num = 0;
+    for (i = 0; i < frame->nb_side_data; i++) {
+        if (frame->side_data[i]->type == type) {
+            num += 1;
+        }
+    }
+    return num;
+}
+
 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 ff2540a20f..8e94e3f679 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -839,11 +839,34 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *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.
  */
 void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
 
+/**
+ * Get the number of instances 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 count of instances, which can be 0
+ */
+int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type);
 
 /**
  * Flags for frame cropping.
-- 
2.27.0



More information about the ffmpeg-devel mailing list