@@ -36,6 +36,7 @@ static AVBufferRef *buffer_create(AVBuffer *buf, uint8_t *data, size_t size,
buf->size = size;
buf->free = free ? free : av_buffer_default_free;
buf->opaque = opaque;
+ buf->dmafd = -1;
atomic_init(&buf->refcount, 1);
@@ -48,6 +49,7 @@ static AVBufferRef *buffer_create(AVBuffer *buf, uint8_t *data, size_t size,
ref->buffer = buf;
ref->data = data;
ref->size = size;
+ ref->dmafd = -1;
return ref;
}
@@ -180,6 +182,16 @@ int av_buffer_make_writable(AVBufferRef **pbuf)
return 0;
}
+int av_buffer_set_dma_buf(AVBufferRef *buf, int fd)
+{
+ if (!buf || !buf->buffer)
+ return AVERROR(EINVAL);
+
+ buf->dmafd = buf->buffer->dmafd = fd;
+
+ return 0;
+}
+
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
{
AVBufferRef *buf = *pbuf;
@@ -92,6 +92,11 @@ typedef struct AVBufferRef {
* Size of data in bytes.
*/
size_t size;
+
+ /**
+ * The fd of dma-buf
+ */
+ int dmafd;
} AVBufferRef;
/**
@@ -181,6 +186,15 @@ int av_buffer_get_ref_count(const AVBufferRef *buf);
*/
int av_buffer_make_writable(AVBufferRef **buf);
+/**
+ * Set dma-buf fd to a given buffer reference.
+ * @param buf buffer reference to set dma-buf,
+ * it should be create from dma-buf mmapped address.
+ * @param fd dma-buf fd
+ * @return 0 on success, a negative AVERROR on failure.
+ */
+int av_buffer_set_dma_buf(AVBufferRef *buf, int fd);
+
/**
* Reallocate a given buffer.
*
@@ -39,6 +39,7 @@
struct AVBuffer {
uint8_t *data; /**< data described by this buffer */
size_t size; /**< size of data in bytes */
+ int dmafd; /**< fd of dma-buf */
/**
* number of existing AVBufferRef instances referring to this buffer
add a member dmafd in buffer struct. we can use it represents dma-buf. Signed-off-by: Ming Qian <ming.qian@nxp.com> --- libavutil/buffer.c | 12 ++++++++++++ libavutil/buffer.h | 14 ++++++++++++++ libavutil/buffer_internal.h | 1 + 3 files changed, 27 insertions(+)