diff mbox

[FFmpeg-devel,v2] frame: add an av_frame_new_side_data_from_buf function

Message ID 20171017225728.25132-1-atomnuker@gmail.com
State Superseded
Headers show

Commit Message

Rostislav Pehlivanov Oct. 17, 2017, 10:57 p.m. UTC
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
---
 libavutil/frame.c | 38 ++++++++++++++++++++------------------
 libavutil/frame.h | 13 +++++++++++++
 2 files changed, 33 insertions(+), 18 deletions(-)

Comments

Rostislav Pehlivanov Dec. 26, 2017, 3:09 p.m. UTC | #1
On 17 October 2017 at 23:57, Rostislav Pehlivanov <atomnuker@gmail.com>
wrote:

> Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
> ---
>  libavutil/frame.c | 38 ++++++++++++++++++++------------------
>  libavutil/frame.h | 13 +++++++++++++
>  2 files changed, 33 insertions(+), 18 deletions(-)
>
>
I'll push this tonight if there are no more objections.
Michael Niedermayer Dec. 27, 2017, 2:02 a.m. UTC | #2
On Tue, Oct 17, 2017 at 11:57:28PM +0100, Rostislav Pehlivanov wrote:
> Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
> ---
>  libavutil/frame.c | 38 ++++++++++++++++++++------------------
>  libavutil/frame.h | 13 +++++++++++++
>  2 files changed, 33 insertions(+), 18 deletions(-)

this seems not to build (anymore) as is, or i did something silly

libavutil/frame.c: In function ‘av_frame_new_side_data_from_buf’:
libavutil/frame.c:661:9: error: label ‘fail’ used but not defined
         goto fail;
         ^

[...]
diff mbox

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d5fd2932e3..b5a2b2f842 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -26,11 +26,6 @@ 
 #include "mem.h"
 #include "samplefmt.h"
 
-
-static AVFrameSideData *frame_new_side_data(AVFrame *frame,
-                                            enum AVFrameSideDataType type,
-                                            AVBufferRef *buf);
-
 MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
@@ -356,8 +351,10 @@  FF_ENABLE_DEPRECATION_WARNINGS
             }
             memcpy(sd_dst->data, sd_src->data, sd_src->size);
         } else {
-            sd_dst = frame_new_side_data(dst, sd_src->type, av_buffer_ref(sd_src->buf));
+            AVBufferRef *buf = av_buffer_ref(sd_src->buf);
+            sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, buf);
             if (!sd_dst) {
+                av_buffer_unref(&buf);
                 wipe_side_data(dst);
                 return AVERROR(ENOMEM);
             }
@@ -636,9 +633,9 @@  AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
     return NULL;
 }
 
-static AVFrameSideData *frame_new_side_data(AVFrame *frame,
-                                            enum AVFrameSideDataType type,
-                                            AVBufferRef *buf)
+AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
+                                                 enum AVFrameSideDataType type,
+                                                 AVBufferRef *buf)
 {
     AVFrameSideData *ret, **tmp;
 
@@ -646,7 +643,11 @@  static AVFrameSideData *frame_new_side_data(AVFrame *frame,
         return NULL;
 
     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
-        goto fail;
+        return NULL;
+
+    ret = av_mallocz(sizeof(*ret));
+    if (!ret)
+        return NULL;
 
     tmp = av_realloc(frame->side_data,
                      (frame->nb_side_data + 1) * sizeof(*frame->side_data));
@@ -654,10 +655,6 @@  static AVFrameSideData *frame_new_side_data(AVFrame *frame,
         goto fail;
     frame->side_data = tmp;
 
-    ret = av_mallocz(sizeof(*ret));
-    if (!ret)
-        goto fail;
-
     ret->buf = buf;
     ret->data = ret->buf->data;
     ret->size = buf->size;
@@ -666,17 +663,22 @@  static AVFrameSideData *frame_new_side_data(AVFrame *frame,
     frame->side_data[frame->nb_side_data++] = ret;
 
     return ret;
-fail:
-    av_buffer_unref(&buf);
-    return NULL;
 }
 
 AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
                                         enum AVFrameSideDataType type,
                                         int size)
 {
+    AVBufferRef *buf = av_buffer_alloc(size);
+    if (!buf)
+        return NULL;
 
-    return frame_new_side_data(frame, type, av_buffer_alloc(size));
+    AVFrameSideData *ret = av_frame_new_side_data_from_buf(frame, type, buf);
+    if (!ref) {
+        av_buffer_unref(&buf);
+        return NULL;
+    }
+    return ret;
 }
 
 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
diff --git a/libavutil/frame.h b/libavutil/frame.h
index abe4f4fd17..bc01b4f0dd 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -762,6 +762,19 @@  AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
                                         enum AVFrameSideDataType type,
                                         int size);
 
+/**
+ * Add a new side data to a frame from an existing AVBufferRef
+ *
+ * @param frame a frame to which the side data should be added
+ * @param type type of the added side data
+ * @param buf the AVBufferRef to add as side data
+ *
+ * @return newly added side data on success, NULL on error
+ */
+AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
+                                                 enum AVFrameSideDataType type,
+                                                 AVBufferRef *buf);
+
 /**
  * @return a pointer to the side data of a given type on success, NULL if there
  * is no side data with such type in this frame.