diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-06-05 11:17:49 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-09-28 11:33:35 +0200 |
commit | 68918d3b7fda9e75d436a27705c54b77dcb41ba9 (patch) | |
tree | 66fea07125274cf4107ebc07b9dacfeb517f2359 /libavutil/buffer.h | |
parent | 5bbf58ab876279ca1a5a2f30563f271c99b93e62 (diff) | |
download | ffmpeg-68918d3b7fda9e75d436a27705c54b77dcb41ba9.tar.gz |
lavu/buffer: add a convenience function for replacing buffers
A common pattern e.g. in libavcodec is replacing/updating buffer
references: unref old one, ref new one. This function allows simplifying
such code and avoiding unnecessary refs+unrefs if the references are
already equivalent.
Diffstat (limited to 'libavutil/buffer.h')
-rw-r--r-- | libavutil/buffer.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libavutil/buffer.h b/libavutil/buffer.h index c0f3f6cc9a..fd4e381efa 100644 --- a/libavutil/buffer.h +++ b/libavutil/buffer.h @@ -198,6 +198,22 @@ int av_buffer_make_writable(AVBufferRef **buf); int av_buffer_realloc(AVBufferRef **buf, int size); /** + * Ensure dst refers to the same data as src. + * + * When *dst is already equivalent to src, do nothing. Otherwise unreference dst + * and replace it with a new reference to src. + * + * @param dst Pointer to either a valid buffer reference or NULL. On success, + * this will point to a buffer reference equivalent to src. On + * failure, dst will be left untouched. + * @param src A buffer reference to replace dst with. May be NULL, then this + * function is equivalent to av_buffer_unref(dst). + * @return 0 on success + * AVERROR(ENOMEM) on memory allocation failure. + */ +int av_buffer_replace(AVBufferRef **dst, AVBufferRef *src); + +/** * @} */ |