Commit 14040a1d authored by James Almer's avatar James Almer

avutil/buffer: change public function and struct size parameter types to size_t

Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 3e3c408e
...@@ -15,6 +15,10 @@ libavutil: 2017-10-21 ...@@ -15,6 +15,10 @@ libavutil: 2017-10-21
API changes, most recent first: API changes, most recent first:
2021-03-10 - xxxxxxxxxx - lavu 56.68.100 - buffer.h
Change AVBufferRef related function and struct size parameter and fields
type to size_t at next major bump.
2021-03-04 - xxxxxxxxxx - lavc 58.128.101 - avcodec.h 2021-03-04 - xxxxxxxxxx - lavc 58.128.101 - avcodec.h
Enable err_recognition to be set for encoders. Enable err_recognition to be set for encoders.
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "mem.h" #include "mem.h"
#include "thread.h" #include "thread.h"
AVBufferRef *av_buffer_create(uint8_t *data, int size, AVBufferRef *av_buffer_create(uint8_t *data, buffer_size_t size,
void (*free)(void *opaque, uint8_t *data), void (*free)(void *opaque, uint8_t *data),
void *opaque, int flags) void *opaque, int flags)
{ {
...@@ -64,7 +64,7 @@ void av_buffer_default_free(void *opaque, uint8_t *data) ...@@ -64,7 +64,7 @@ void av_buffer_default_free(void *opaque, uint8_t *data)
av_free(data); av_free(data);
} }
AVBufferRef *av_buffer_alloc(int size) AVBufferRef *av_buffer_alloc(buffer_size_t size)
{ {
AVBufferRef *ret = NULL; AVBufferRef *ret = NULL;
uint8_t *data = NULL; uint8_t *data = NULL;
...@@ -80,7 +80,7 @@ AVBufferRef *av_buffer_alloc(int size) ...@@ -80,7 +80,7 @@ AVBufferRef *av_buffer_alloc(int size)
return ret; return ret;
} }
AVBufferRef *av_buffer_allocz(int size) AVBufferRef *av_buffer_allocz(buffer_size_t size)
{ {
AVBufferRef *ret = av_buffer_alloc(size); AVBufferRef *ret = av_buffer_alloc(size);
if (!ret) if (!ret)
...@@ -166,7 +166,7 @@ int av_buffer_make_writable(AVBufferRef **pbuf) ...@@ -166,7 +166,7 @@ int av_buffer_make_writable(AVBufferRef **pbuf)
return 0; return 0;
} }
int av_buffer_realloc(AVBufferRef **pbuf, int size) int av_buffer_realloc(AVBufferRef **pbuf, buffer_size_t size)
{ {
AVBufferRef *buf = *pbuf; AVBufferRef *buf = *pbuf;
uint8_t *tmp; uint8_t *tmp;
...@@ -242,8 +242,8 @@ int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src) ...@@ -242,8 +242,8 @@ int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src)
return 0; return 0;
} }
AVBufferPool *av_buffer_pool_init2(int size, void *opaque, AVBufferPool *av_buffer_pool_init2(buffer_size_t size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size), AVBufferRef* (*alloc)(void *opaque, buffer_size_t size),
void (*pool_free)(void *opaque)) void (*pool_free)(void *opaque))
{ {
AVBufferPool *pool = av_mallocz(sizeof(*pool)); AVBufferPool *pool = av_mallocz(sizeof(*pool));
...@@ -263,7 +263,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque, ...@@ -263,7 +263,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
return pool; return pool;
} }
AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)) AVBufferPool *av_buffer_pool_init(buffer_size_t size, AVBufferRef* (*alloc)(buffer_size_t size))
{ {
AVBufferPool *pool = av_mallocz(sizeof(*pool)); AVBufferPool *pool = av_mallocz(sizeof(*pool));
if (!pool) if (!pool)
......
...@@ -25,8 +25,11 @@ ...@@ -25,8 +25,11 @@
#ifndef AVUTIL_BUFFER_H #ifndef AVUTIL_BUFFER_H
#define AVUTIL_BUFFER_H #define AVUTIL_BUFFER_H
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "version.h"
/** /**
* @defgroup lavu_buffer AVBuffer * @defgroup lavu_buffer AVBuffer
* @ingroup lavu_data * @ingroup lavu_data
...@@ -90,7 +93,11 @@ typedef struct AVBufferRef { ...@@ -90,7 +93,11 @@ typedef struct AVBufferRef {
/** /**
* Size of data in bytes. * Size of data in bytes.
*/ */
#if FF_API_BUFFER_SIZE_T
int size; int size;
#else
size_t size;
#endif
} AVBufferRef; } AVBufferRef;
/** /**
...@@ -98,13 +105,21 @@ typedef struct AVBufferRef { ...@@ -98,13 +105,21 @@ typedef struct AVBufferRef {
* *
* @return an AVBufferRef of given size or NULL when out of memory * @return an AVBufferRef of given size or NULL when out of memory
*/ */
#if FF_API_BUFFER_SIZE_T
AVBufferRef *av_buffer_alloc(int size); AVBufferRef *av_buffer_alloc(int size);
#else
AVBufferRef *av_buffer_alloc(size_t size);
#endif
/** /**
* Same as av_buffer_alloc(), except the returned buffer will be initialized * Same as av_buffer_alloc(), except the returned buffer will be initialized
* to zero. * to zero.
*/ */
#if FF_API_BUFFER_SIZE_T
AVBufferRef *av_buffer_allocz(int size); AVBufferRef *av_buffer_allocz(int size);
#else
AVBufferRef *av_buffer_allocz(size_t size);
#endif
/** /**
* Always treat the buffer as read-only, even when it has only one * Always treat the buffer as read-only, even when it has only one
...@@ -127,7 +142,11 @@ AVBufferRef *av_buffer_allocz(int size); ...@@ -127,7 +142,11 @@ AVBufferRef *av_buffer_allocz(int size);
* *
* @return an AVBufferRef referring to data on success, NULL on failure. * @return an AVBufferRef referring to data on success, NULL on failure.
*/ */
#if FF_API_BUFFER_SIZE_T
AVBufferRef *av_buffer_create(uint8_t *data, int size, AVBufferRef *av_buffer_create(uint8_t *data, int size,
#else
AVBufferRef *av_buffer_create(uint8_t *data, size_t size,
#endif
void (*free)(void *opaque, uint8_t *data), void (*free)(void *opaque, uint8_t *data),
void *opaque, int flags); void *opaque, int flags);
...@@ -195,7 +214,11 @@ int av_buffer_make_writable(AVBufferRef **buf); ...@@ -195,7 +214,11 @@ int av_buffer_make_writable(AVBufferRef **buf);
* reference to it (i.e. the one passed to this function). In all other cases * 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. * a new buffer is allocated and the data is copied.
*/ */
#if FF_API_BUFFER_SIZE_T
int av_buffer_realloc(AVBufferRef **buf, int size); int av_buffer_realloc(AVBufferRef **buf, int size);
#else
int av_buffer_realloc(AVBufferRef **buf, size_t size);
#endif
/** /**
* Ensure dst refers to the same data as src. * Ensure dst refers to the same data as src.
...@@ -262,7 +285,11 @@ typedef struct AVBufferPool AVBufferPool; ...@@ -262,7 +285,11 @@ typedef struct AVBufferPool AVBufferPool;
* (av_buffer_alloc()). * (av_buffer_alloc()).
* @return newly created buffer pool on success, NULL on error. * @return newly created buffer pool on success, NULL on error.
*/ */
#if FF_API_BUFFER_SIZE_T
AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
#else
AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size));
#endif
/** /**
* Allocate and initialize a buffer pool with a more complex allocator. * Allocate and initialize a buffer pool with a more complex allocator.
...@@ -279,8 +306,13 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); ...@@ -279,8 +306,13 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size));
* data. May be NULL. * data. May be NULL.
* @return newly created buffer pool on success, NULL on error. * @return newly created buffer pool on success, NULL on error.
*/ */
#if FF_API_BUFFER_SIZE_T
AVBufferPool *av_buffer_pool_init2(int size, void *opaque, AVBufferPool *av_buffer_pool_init2(int size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, int size), AVBufferRef* (*alloc)(void *opaque, int size),
#else
AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque,
AVBufferRef* (*alloc)(void *opaque, size_t size),
#endif
void (*pool_free)(void *opaque)); void (*pool_free)(void *opaque));
/** /**
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
struct AVBuffer { struct AVBuffer {
uint8_t *data; /**< data described by this buffer */ uint8_t *data; /**< data described by this buffer */
int size; /**< size of data in bytes */ buffer_size_t size; /**< size of data in bytes */
/** /**
* number of existing AVBufferRef instances referring to this buffer * number of existing AVBufferRef instances referring to this buffer
...@@ -89,10 +89,10 @@ struct AVBufferPool { ...@@ -89,10 +89,10 @@ struct AVBufferPool {
*/ */
atomic_uint refcount; atomic_uint refcount;
int size; buffer_size_t size;
void *opaque; void *opaque;
AVBufferRef* (*alloc)(int size); AVBufferRef* (*alloc)(buffer_size_t size);
AVBufferRef* (*alloc2)(void *opaque, int size); AVBufferRef* (*alloc2)(void *opaque, buffer_size_t size);
void (*pool_free)(void *opaque); void (*pool_free)(void *opaque);
}; };
......
...@@ -299,4 +299,11 @@ int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t time ...@@ -299,4 +299,11 @@ int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t time
#define FF_PSEUDOPAL 0 #define FF_PSEUDOPAL 0
#endif #endif
// Temporary typedef to simplify porting all AVBufferRef users to size_t
#if FF_API_BUFFER_SIZE_T
typedef int buffer_size_t;
#else
typedef size_t buffer_size_t;
#endif
#endif /* AVUTIL_INTERNAL_H */ #endif /* AVUTIL_INTERNAL_H */
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 56 #define LIBAVUTIL_VERSION_MAJOR 56
#define LIBAVUTIL_VERSION_MINOR 67 #define LIBAVUTIL_VERSION_MINOR 68
#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
...@@ -132,6 +132,9 @@ ...@@ -132,6 +132,9 @@
#ifndef FF_API_CHILD_CLASS_NEXT #ifndef FF_API_CHILD_CLASS_NEXT
#define FF_API_CHILD_CLASS_NEXT (LIBAVUTIL_VERSION_MAJOR < 57) #define FF_API_CHILD_CLASS_NEXT (LIBAVUTIL_VERSION_MAJOR < 57)
#endif #endif
#ifndef FF_API_BUFFER_SIZE_T
#define FF_API_BUFFER_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57)
#endif
#ifndef FF_API_D2STR #ifndef FF_API_D2STR
#define FF_API_D2STR (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_D2STR (LIBAVUTIL_VERSION_MAJOR < 58)
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment