[FFmpeg-devel,v1,07/12] avutil/frame: add helper for extending a set of side data

Message ID 20230331162205.428735-8-jeebjp@gmail.com
State New
Headers
Series encoder AVCodecContext configuration side data |

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jan Ekström March 31, 2023, 4:22 p.m. UTC
---
 libavutil/frame.c | 21 +++++++++++++++++++++
 libavutil/frame.h | 11 +++++++++++
 2 files changed, 32 insertions(+)
  

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 3386cda627..ec4e44a11f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -720,6 +720,27 @@  AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
     return ret;
 }
 
+int av_extend_side_data_set(AVFrameSideDataSet *dst,
+                            const AVFrameSideDataSet src)
+{
+    for (int i = 0; i < src.nb_side_data; i++) {
+        const AVFrameSideData *sd_src = src.side_data[i];
+        AVFrameSideData *sd_dst =
+            av_new_side_data_to_set(dst, sd_src->type,
+                                    sd_src->size);
+        if (!sd_dst) {
+            av_side_data_set_wipe(dst);
+            return AVERROR(ENOMEM);
+        }
+
+        memcpy(sd_dst->data, sd_src->data, sd_src->size);
+
+        av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
+    }
+
+    return 0;
+}
+
 AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
                                            enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8aa50e3ad8..da8ac3237b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1011,6 +1011,17 @@  AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
                                          enum AVFrameSideDataType type,
                                          size_t size);
 
+/**
+ * Add multiple side data entries to a set in one go.
+ *
+ * @param dst a set to which the side data should be added
+ * @param src a set from which the side data should be copied from
+ *
+ * @return negative error code on failure, >=0 on success.
+ */
+int av_extend_side_data_set(AVFrameSideDataSet *dst,
+                            const AVFrameSideDataSet src);
+
 /**
  * @param set a set to which the side data should be added
  * @param type type of the added side data