[FFmpeg-devel] [RFC PATCH] avutil/frame: fix remove_side_data

Zhao Zhili quinkblack at foxmail.com
Sat Nov 2 18:16:30 EET 2019


From: Zhao Zhili <zhilizhao at tencent.com>

remove_side_data is supposed to remove a single instance by design.
Since new_side_data() doesn't forbid add multiple instance of the
same type, remove_side_data should deal with that.
---
 libavutil/frame.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index dcf1fc3d17..10d06dd29f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -805,15 +805,20 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src)
 void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
 {
     int i;
-
-    for (i = 0; i < frame->nb_side_data; i++) {
-        AVFrameSideData *sd = frame->side_data[i];
-        if (sd->type == type) {
-            free_side_data(&frame->side_data[i]);
-            frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
-            frame->nb_side_data--;
+    int found;
+
+    do {
+        found = 0;
+        for (i = 0; i < frame->nb_side_data; i++) {
+            AVFrameSideData *sd = frame->side_data[i];
+            if (sd->type == type) {
+                free_side_data(&frame->side_data[i]);
+                frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
+                frame->nb_side_data--;
+                found = 1;
+            }
         }
-    }
+    } while (found);
 }
 
 const char *av_frame_side_data_name(enum AVFrameSideDataType type)
-- 
2.17.1





More information about the ffmpeg-devel mailing list