[FFmpeg-devel] [PATCH v4 07/13] avutil/frame: add helper for getting side data from set

Jan Ekström jeebjp at gmail.com
Fri Sep 1 23:38:17 EEST 2023


---
 libavutil/frame.c | 22 +++++++++++++++++-----
 libavutil/frame.h | 12 ++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index f64ddb3645..5f74e0172b 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -879,16 +879,28 @@ AVFrameSideData *av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
     return ret;
 }
 
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
-                                        enum AVFrameSideDataType type)
+AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,
+                                                 enum AVFrameSideDataType type)
 {
-    for (int i = 0; i < frame->nb_side_data; i++) {
-        if (frame->side_data[i]->type == type)
-            return frame->side_data[i];
+    for (int i = 0; i < set.nb_sd; i++) {
+        if (set.sd[i]->type == type)
+            return set.sd[i];
     }
     return NULL;
 }
 
+AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
+                                        enum AVFrameSideDataType type)
+{
+    return av_frame_side_data_set_get_item(
+        (const AVFrameSideDataSet){
+            .sd    = frame->side_data,
+            .nb_sd = frame->nb_side_data
+        },
+        type
+    );
+}
+
 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 5aed08b796..8ecdf82f33 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1085,6 +1085,18 @@ AVFrameSideData *av_frame_side_data_set_new_item(AVFrameSideDataSet *set,
                                                  size_t size,
                                                  unsigned int flags);
 
+/**
+ * Get a side data entry of a specific type from a set.
+ *
+ * @param set the set from which side data should be queried from
+ * @param type type of side data to be queried
+ *
+ * @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.
+ */
+AVFrameSideData *av_frame_side_data_set_get_item(const AVFrameSideDataSet set,
+                                                 enum AVFrameSideDataType type);
+
 /**
  * @}
  */
-- 
2.41.0



More information about the ffmpeg-devel mailing list