diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-10-18 01:57:28 +0300 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2018-03-01 23:37:18 +0300 |
commit | 6731f60598963da357ff77dafe9e5e903629bde9 (patch) | |
tree | f0330ba2d1d9f18b263dc6f53f0858855024392e /libavutil/frame.c | |
parent | 1be4c8579024bd44265ce2f63c6a090aa1b21bc4 (diff) |
frame: add an av_frame_new_side_data_from_buf function
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'libavutil/frame.c')
-rw-r--r-- | libavutil/frame.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/libavutil/frame.c b/libavutil/frame.c index 662a7e5ab5..61c45f0f53 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); - #if FF_API_FRAME_GET_SET MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp) MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration) @@ -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 *ref = av_buffer_ref(sd_src->buf); + sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); if (!sd_dst) { + av_buffer_unref(&ref); wipe_side_data(dst); return AVERROR(ENOMEM); } @@ -642,9 +639,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; @@ -652,17 +649,17 @@ 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; tmp = av_realloc(frame->side_data, (frame->nb_side_data + 1) * sizeof(*frame->side_data)); if (!tmp) - goto fail; + return NULL; frame->side_data = tmp; ret = av_mallocz(sizeof(*ret)); if (!ret) - goto fail; + return NULL; ret->buf = buf; ret->data = ret->buf->data; @@ -672,17 +669,18 @@ 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) { - - return frame_new_side_data(frame, type, av_buffer_alloc(size)); + AVFrameSideData *ret; + AVBufferRef *buf = av_buffer_alloc(size); + ret = av_frame_new_side_data_from_buf(frame, type, buf); + if (!ret) + av_buffer_unref(&buf); + return ret; } AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, |