[FFmpeg-devel] [PATCH v3 3/8] avutil/frame: add av_frame_side_data_remove_by_props()

Niklas Haas ffmpeg at haasn.xyz
Mon Dec 23 14:48:44 EET 2024


From: Niklas Haas <git at haasn.dev>

As discussed in the previous commit, we often need a convenient way of
stripping all side data related to a certain aspect of the frame. This helper
accomplishes just that.

I considered also adding a way to match only side data matching *all*
properties, but I think this is sufficiently useless in practise to not warrant
inclusion in the API.
---
 doc/APIchanges      |  3 +++
 libavutil/frame.c   | 16 ++++++++++++++++
 libavutil/frame.h   | 13 +++++++++++++
 libavutil/version.h |  2 +-
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index f6c4b6797e..4fa4db142f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-12-xx - xxxxxxxxxx - lavu 59.53.100 - frame.h
+  Add av_frame_side_data_remove_by_props().
+
 2024-12-xx - xxxxxxxxxx - lavu 59.52.100 - frame.h
   Add AV_SIDE_DATA_PROP_SIZE_DEPENDENT and AV_FRAME_DATA_PROP_COLOR_DEPENDENT.
 
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 1dced3b52b..342079b5a1 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -961,6 +961,22 @@ void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
     remove_side_data(sd, nb_sd, type);
 }
 
+void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd,
+                                        int props)
+{
+    for (int i = *nb_sd - 1; i >= 0; i--) {
+        AVFrameSideData *entry = ((*sd)[i]);
+        const AVSideDataDescriptor *desc = av_frame_side_data_desc(entry->type);
+        if (!desc || !(desc->props & props))
+            continue;
+
+        free_side_data(&entry);
+
+        ((*sd)[i]) = ((*sd)[*nb_sd - 1]);
+        (*nb_sd)--;
+    }
+}
+
 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
                                         enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8345010e22..5dfcd85c47 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1013,6 +1013,11 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  */
 void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
 
+/**
+ * Remove and free all side data instances that match any of the given
+ * side data properties. (See enum AVSideDataProps)
+ */
+void av_frame_remove_side_data_by_props(AVFrame *frame, int props);
 
 /**
  * Flags for frame cropping.
@@ -1183,6 +1188,14 @@ const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd,
  */
 void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
                                enum AVFrameSideDataType type);
+
+/**
+ * Remove and free all side data instances that match any of the given
+ * side data properties. (See enum AVSideDataProps)
+ */
+void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd,
+                                        int props);
+
 /**
  * @}
  */
diff --git a/libavutil/version.h b/libavutil/version.h
index 0eb07e5e3d..b430555c88 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  52
+#define LIBAVUTIL_VERSION_MINOR  53
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.47.0



More information about the ffmpeg-devel mailing list