diff mbox series

[FFmpeg-devel,v3,06/12] avutil/frame: add helper for getting side data from set

Message ID 20230817214858.184010-7-jeebjp@gmail.com
State New
Headers show
Series encoder AVCodecContext configuration side data | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jan Ekström Aug. 17, 2023, 9:48 p.m. UTC
---
 libavutil/frame.c | 22 +++++++++++++++++-----
 libavutil/frame.h | 12 ++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 27ccbc52c7..d8910a2120 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -880,16 +880,28 @@  AVFrameSideData *av_side_data_set_new_item(AVFrameSideDataSet *set,
     return ret;
 }
 
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
-                                        enum AVFrameSideDataType type)
+AVFrameSideData *av_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_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 b9d7c76461..0cafc9c51f 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1083,6 +1083,18 @@  AVFrameSideData *av_side_data_set_new_item(AVFrameSideDataSet *set,
                                            size_t size,
                                            unsigned int allow_duplicates);
 
+/**
+ * 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_side_data_set_get_item(const AVFrameSideDataSet set,
+                                           enum AVFrameSideDataType type);
+
 /**
  * @}
  */