[FFmpeg-devel] [PATCH v2 1/4] frame: handle add side data with the same type
quinkblack at foxmail.com
quinkblack at foxmail.com
Fri Nov 1 14:03:11 EET 2019
From: Zhao Zhili <zhilizhao at tencent.com>
---
libavutil/frame.c | 13 +++++++++++++
libavutil/frame.h | 4 ++++
2 files changed, 17 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index dcf1fc3d17..bb20e99331 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -692,10 +692,23 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
AVBufferRef *buf)
{
AVFrameSideData *ret, **tmp;
+ int i;
if (!buf)
return NULL;
+ for (i = 0; i < frame->nb_side_data; i++) {
+ AVFrameSideData *sd = frame->side_data[i];
+ if (sd->type == type) {
+ av_buffer_unref(&sd->buf);
+ av_dict_free(&sd->metadata);
+ sd->buf = buf;
+ sd->data = buf->data;
+ sd->size = buf->size;
+ return sd;
+ }
+ }
+
if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
return NULL;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..906143f894 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -886,6 +886,8 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane);
/**
* Add a new side data to a frame.
*
+ * @note replace existing side data of the same type
+ *
* @param frame a frame to which the side data should be added
* @param type type of the added side data
* @param size size of the side data
@@ -899,6 +901,8 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
/**
* Add a new side data to a frame from an existing AVBufferRef
*
+ * @note replace existing side data of the same type
+ *
* @param frame a frame to which the side data should be added
* @param type the type of the added side data
* @param buf an AVBufferRef to add as side data. The ownership of
--
2.22.0
More information about the ffmpeg-devel
mailing list