[FFmpeg-devel,v1,04/12] avutil/frame: split side_data_from_buf to base and AVFrame func

Message ID 20230331162205.428735-5-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:21 p.m. UTC
---
 libavutil/frame.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
  

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 24038cc0fa..ab1a4e7f6a 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -648,23 +648,23 @@  FF_ENABLE_DEPRECATION_WARNINGS
     return NULL;
 }
 
-AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
-                                                 enum AVFrameSideDataType type,
-                                                 AVBufferRef *buf)
+static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set,
+                                                      enum AVFrameSideDataType type,
+                                                      AVBufferRef *buf)
 {
     AVFrameSideData *ret, **tmp;
 
     if (!buf)
         return NULL;
 
-    if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
+    if (set->nb_side_data > INT_MAX / sizeof(*set->side_data) - 1)
         return NULL;
 
-    tmp = av_realloc(frame->side_data,
-                     (frame->nb_side_data + 1) * sizeof(*frame->side_data));
+    tmp = av_realloc(set->side_data,
+                     (set->nb_side_data + 1) * sizeof(*set->side_data));
     if (!tmp)
         return NULL;
-    frame->side_data = tmp;
+    set->side_data = tmp;
 
     ret = av_mallocz(sizeof(*ret));
     if (!ret)
@@ -675,7 +675,23 @@  AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
     ret->size = buf->size;
     ret->type = type;
 
-    frame->side_data[frame->nb_side_data++] = ret;
+    set->side_data[set->nb_side_data++] = ret;
+
+    return ret;
+}
+
+AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
+                                                 enum AVFrameSideDataType type,
+                                                 AVBufferRef *buf)
+{
+    AVFrameSideDataSet set = {
+        .side_data    = frame->side_data,
+        .nb_side_data = frame->nb_side_data,
+    };
+    AVFrameSideData *ret = add_side_data_to_set_from_buf(&set, type, buf);
+
+    frame->side_data = set.side_data;
+    frame->nb_side_data = set.nb_side_data;
 
     return ret;
 }