[FFmpeg-devel] [PATCH v5 08/14] avutil/frame: add helper for getting side data from set

Jan Ekström jeebjp at gmail.com
Sun Nov 26 21:58:27 EET 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 e42d9cb758..e4004daa4b 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -929,16 +929,28 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
     }
 }
 
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
-                                        enum AVFrameSideDataType type)
+AVFrameSideData *av_frame_side_data_set_get_entry(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_entry(
+        (const AVFrameSideDataSet){
+            .sd    = frame->side_data,
+            .nb_sd = frame->nb_side_data
+        },
+        type
+    );
+}
+
 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
 {
     int planes;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 9295c868ef..e8517bf6ad 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1101,6 +1101,18 @@ int av_frame_side_data_set_entry_from_sd(AVFrameSideDataSet *dst,
                                          const AVFrameSideData *src,
                                          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_entry(const AVFrameSideDataSet set,
+                                                  enum AVFrameSideDataType type);
+
 /**
  * @}
  */
-- 
2.43.0



More information about the ffmpeg-devel mailing list