diff mbox series

[FFmpeg-devel] avutil/buffer: separate public and internal flags inside AVBuffers

Message ID 20200601160435.9689-1-jamrial@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel] avutil/buffer: separate public and internal flags inside AVBuffers
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

James Almer June 1, 2020, 4:04 p.m. UTC
It's better to not mix user provided flags and internal flags set by
AVBufferRef helper functions.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/buffer.c          |  7 +++----
 libavutil/buffer_internal.h | 13 +++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

Comments

Anton Khirnov June 5, 2020, 10:04 a.m. UTC | #1
Quoting James Almer (2020-06-01 18:04:35)
> It's better to not mix user provided flags and internal flags set by
> AVBufferRef helper functions.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---

Looks ok
diff mbox series

Patch

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 6d9cb7428e..7ff6adc2ec 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -44,8 +44,7 @@  AVBufferRef *av_buffer_create(uint8_t *data, int size,
 
     atomic_init(&buf->refcount, 1);
 
-    if (flags & AV_BUFFER_FLAG_READONLY)
-        buf->flags |= BUFFER_FLAG_READONLY;
+    buf->flags = flags;
 
     ref = av_mallocz(sizeof(*ref));
     if (!ref) {
@@ -185,14 +184,14 @@  int av_buffer_realloc(AVBufferRef **pbuf, int size)
             return AVERROR(ENOMEM);
         }
 
-        buf->buffer->flags |= BUFFER_FLAG_REALLOCATABLE;
+        buf->buffer->flags_internal |= BUFFER_FLAG_REALLOCATABLE;
         *pbuf = buf;
 
         return 0;
     } else if (buf->size == size)
         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) {
         /* cannot realloc, allocate a new reallocable buffer and copy data */
         AVBufferRef *new = NULL;
diff --git a/libavutil/buffer_internal.h b/libavutil/buffer_internal.h
index 54b67047e5..70d2615a06 100644
--- a/libavutil/buffer_internal.h
+++ b/libavutil/buffer_internal.h
@@ -25,14 +25,10 @@ 
 #include "buffer.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.
  */
-#define BUFFER_FLAG_REALLOCATABLE (1 << 1)
+#define BUFFER_FLAG_REALLOCATABLE (1 << 0)
 
 struct AVBuffer {
     uint8_t *data; /**< data described by this buffer */
@@ -54,9 +50,14 @@  struct AVBuffer {
     void *opaque;
 
     /**
-     * A combination of BUFFER_FLAG_*
+     * A combination of AV_BUFFER_FLAG_*
      */
     int flags;
+
+    /**
+     * A combination of BUFFER_FLAG_*
+     */
+    int flags_internal;
 };
 
 typedef struct BufferPoolEntry {