The flag is documented but did not exist. So introduce it as it can be useful.
Signed-off-by: James Almer <jamr...@gmail.com> --- libavutil/frame.c | 17 ++++++++--------- libavutil/frame.h | 5 +++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index ab0d8f535f..10b59545f0 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -868,21 +868,20 @@ AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, AVFrameSideData *sd_dst = NULL; AVBufferRef *buf = *pbuf; + if ((flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) && !(buf = av_buffer_ref(*pbuf))) + return NULL; if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, type); if ((!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) && (sd_dst = (AVFrameSideData *)av_frame_side_data_get(*sd, *nb_sd, type))) { sd_dst = replace_side_data_from_buf(sd_dst, buf, flags); - if (sd_dst) - *pbuf = NULL; - return sd_dst; - } - - sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); - if (!sd_dst) - return NULL; + } else + sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); - *pbuf = NULL; + if (sd_dst && !(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) + *pbuf = NULL; + else if (!sd_dst && (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) + av_buffer_unref(&buf); return sd_dst; } diff --git a/libavutil/frame.h b/libavutil/frame.h index 929dbb885e..cfaa53695e 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1078,6 +1078,11 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); * Applies only for side data types without the AV_SIDE_DATA_PROP_MULTI prop. */ #define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1) +/** + * Create a new reference to the passed in buffer instead of taking ownership + * of it. + */ +#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2) /** * Add new side data entry to an array. -- 2.47.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".