X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fbuffer.h;h=63ab87eb720d148a7fe96e7b681f3b01fde6779f;hb=ef6a9e5e311f09fa8032974fa4d0c1e166a959bb;hp=73b6bd0b148e6e6018845a0df928d8d20cef115a;hpb=67d466d09b105b2b1d3d8da4c21d8975925741ae;p=ffmpeg diff --git a/libavutil/buffer.h b/libavutil/buffer.h index 73b6bd0b148..63ab87eb720 100644 --- a/libavutil/buffer.h +++ b/libavutil/buffer.h @@ -25,8 +25,11 @@ #ifndef AVUTIL_BUFFER_H #define AVUTIL_BUFFER_H +#include #include +#include "version.h" + /** * @defgroup lavu_buffer AVBuffer * @ingroup lavu_data @@ -90,7 +93,7 @@ typedef struct AVBufferRef { /** * Size of data in bytes. */ - int size; + size_t size; } AVBufferRef; /** @@ -98,13 +101,13 @@ typedef struct AVBufferRef { * * @return an AVBufferRef of given size or NULL when out of memory */ -AVBufferRef *av_buffer_alloc(int size); +AVBufferRef *av_buffer_alloc(size_t size); /** * Same as av_buffer_alloc(), except the returned buffer will be initialized * to zero. */ -AVBufferRef *av_buffer_allocz(int size); +AVBufferRef *av_buffer_allocz(size_t size); /** * Always treat the buffer as read-only, even when it has only one @@ -127,7 +130,7 @@ AVBufferRef *av_buffer_allocz(int size); * * @return an AVBufferRef referring to data on success, NULL on failure. */ -AVBufferRef *av_buffer_create(uint8_t *data, int size, +AVBufferRef *av_buffer_create(uint8_t *data, size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags); @@ -195,7 +198,23 @@ int av_buffer_make_writable(AVBufferRef **buf); * reference to it (i.e. the one passed to this function). In all other cases * a new buffer is allocated and the data is copied. */ -int av_buffer_realloc(AVBufferRef **buf, int size); +int av_buffer_realloc(AVBufferRef **buf, size_t 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); /** * @} @@ -246,7 +265,7 @@ typedef struct AVBufferPool AVBufferPool; * (av_buffer_alloc()). * @return newly created buffer pool on success, NULL on error. */ -AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); +AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size)); /** * Allocate and initialize a buffer pool with a more complex allocator. @@ -254,16 +273,17 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); * @param size size of each buffer in this pool * @param opaque arbitrary user data used by the allocator * @param alloc a function that will be used to allocate new buffers when the - * pool is empty. + * pool is empty. May be NULL, then the default allocator will be + * used (av_buffer_alloc()). * @param pool_free a function that will be called immediately before the pool * is freed. I.e. after av_buffer_pool_uninit() is called * by the caller and all the frames are returned to the pool * and freed. It is intended to uninitialize the user opaque - * data. + * data. May be NULL. * @return newly created buffer pool on success, NULL on error. */ -AVBufferPool *av_buffer_pool_init2(int size, void *opaque, - AVBufferRef* (*alloc)(void *opaque, int size), +AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque, + AVBufferRef* (*alloc)(void *opaque, size_t size), void (*pool_free)(void *opaque)); /** @@ -284,6 +304,19 @@ void av_buffer_pool_uninit(AVBufferPool **pool); */ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool); +/** + * Query the original opaque parameter of an allocated buffer in the pool. + * + * @param ref a buffer reference to a buffer returned by av_buffer_pool_get. + * @return the opaque parameter set by the buffer allocator function of the + * buffer pool. + * + * @note the opaque parameter of ref is used by the buffer pool implementation, + * therefore you have to use this function to access the original opaque + * parameter of an allocated buffer. + */ +void *av_buffer_pool_buffer_get_opaque(AVBufferRef *ref); + /** * @} */