[FFmpeg-cvslog] avutil/frame: use the same data information as the source entry when cloning side data

James Almer git at videolan.org
Sat Mar 30 15:24:18 EET 2024


ffmpeg | branch: release/7.0 | James Almer <jamrial at gmail.com> | Thu Mar 28 13:52:46 2024 -0300| [799a7200ee608df7ac415c90900a7e48b845c945] | committer: James Almer

avutil/frame: use the same data information as the source entry when cloning side data

src->{data,size} does not need to match src->buf->{data,size}.

Signed-off-by: James Almer <jamrial at gmail.com>
(cherry picked from commit f8fbec8686d49a74aa6e96d55c5c738ae8aa8e49)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=799a7200ee608df7ac415c90900a7e48b845c945
---

 libavutil/frame.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d7a32cdc92..eb04a65c90 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -711,16 +711,14 @@ AVBufferRef *av_frame_get_plane_buffer(const AVFrame *frame, int plane)
     return NULL;
 }
 
-static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd,
-                                               int *nb_sd,
-                                               enum AVFrameSideDataType type,
-                                               AVBufferRef *buf)
+static AVFrameSideData *add_side_data_from_buf_ext(AVFrameSideData ***sd,
+                                                   int *nb_sd,
+                                                   enum AVFrameSideDataType type,
+                                                   AVBufferRef *buf, uint8_t *data,
+                                                   size_t size)
 {
     AVFrameSideData *ret, **tmp;
 
-    if (!buf)
-        return NULL;
-
     // *nb_sd + 1 needs to fit into an int and a size_t.
     if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX))
         return NULL;
@@ -735,8 +733,8 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd,
         return NULL;
 
     ret->buf = buf;
-    ret->data = ret->buf->data;
-    ret->size = buf->size;
+    ret->data = data;
+    ret->size = size;
     ret->type = type;
 
     (*sd)[(*nb_sd)++] = ret;
@@ -744,6 +742,17 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd,
     return ret;
 }
 
+static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd,
+                                               int *nb_sd,
+                                               enum AVFrameSideDataType type,
+                                               AVBufferRef *buf)
+{
+    if (!buf)
+        return NULL;
+
+    return add_side_data_from_buf_ext(sd, nb_sd, type, buf, buf->data, buf->size);
+}
+
 AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
                                                  enum AVFrameSideDataType type,
                                                  AVBufferRef *buf)
@@ -799,7 +808,8 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
     if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
         remove_side_data(sd, nb_sd, src->type);
 
-    sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf);
+    sd_dst = add_side_data_from_buf_ext(sd, nb_sd, src->type, buf,
+                                        src->data, src->size);
     if (!sd_dst) {
         av_buffer_unref(&buf);
         return AVERROR(ENOMEM);



More information about the ffmpeg-cvslog mailing list