提交 b6c8444e 编写于 作者: J James Almer

avutil/buffer: separate public and internal flags inside AVBuffers

It's better to not mix user provided flags and internal flags set by
AVBufferRef helper functions.
Signed-off-by: NJames Almer <jamrial@gmail.com>
上级 f2ad89be
...@@ -44,8 +44,7 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size, ...@@ -44,8 +44,7 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
atomic_init(&buf->refcount, 1); atomic_init(&buf->refcount, 1);
if (flags & AV_BUFFER_FLAG_READONLY) buf->flags = flags;
buf->flags |= BUFFER_FLAG_READONLY;
ref = av_mallocz(sizeof(*ref)); ref = av_mallocz(sizeof(*ref));
if (!ref) { if (!ref) {
...@@ -185,14 +184,14 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) ...@@ -185,14 +184,14 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
buf->buffer->flags |= BUFFER_FLAG_REALLOCATABLE; buf->buffer->flags_internal |= BUFFER_FLAG_REALLOCATABLE;
*pbuf = buf; *pbuf = buf;
return 0; return 0;
} else if (buf->size == size) } else if (buf->size == size)
return 0; return 0;
if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) || if (!(buf->buffer->flags_internal & BUFFER_FLAG_REALLOCATABLE) ||
!av_buffer_is_writable(buf) || buf->data != buf->buffer->data) { !av_buffer_is_writable(buf) || buf->data != buf->buffer->data) {
/* cannot realloc, allocate a new reallocable buffer and copy data */ /* cannot realloc, allocate a new reallocable buffer and copy data */
AVBufferRef *new = NULL; AVBufferRef *new = NULL;
......
...@@ -25,14 +25,10 @@ ...@@ -25,14 +25,10 @@
#include "buffer.h" #include "buffer.h"
#include "thread.h" #include "thread.h"
/**
* The buffer is always treated as read-only.
*/
#define BUFFER_FLAG_READONLY (1 << 0)
/** /**
* The buffer was av_realloc()ed, so it is reallocatable. * The buffer was av_realloc()ed, so it is reallocatable.
*/ */
#define BUFFER_FLAG_REALLOCATABLE (1 << 1) #define BUFFER_FLAG_REALLOCATABLE (1 << 0)
struct AVBuffer { struct AVBuffer {
uint8_t *data; /**< data described by this buffer */ uint8_t *data; /**< data described by this buffer */
...@@ -54,9 +50,14 @@ struct AVBuffer { ...@@ -54,9 +50,14 @@ struct AVBuffer {
void *opaque; void *opaque;
/** /**
* A combination of BUFFER_FLAG_* * A combination of AV_BUFFER_FLAG_*
*/ */
int flags; int flags;
/**
* A combination of BUFFER_FLAG_*
*/
int flags_internal;
}; };
typedef struct BufferPoolEntry { typedef struct BufferPoolEntry {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册