diff mbox series

[FFmpeg-devel,v1,1/2] avutil/buffer: support represents dma-buf

Message ID 20211112083601.6804-1-ming.qian@nxp.com
State New
Headers show
Series [FFmpeg-devel,v1,1/2] avutil/buffer: support represents dma-buf
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Ming Qian Nov. 12, 2021, 8:36 a.m. UTC
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(+)
diff mbox series

Patch

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 54590be56604..6aacd9c2c08a 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -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;
diff --git a/libavutil/buffer.h b/libavutil/buffer.h
index e1ef5b7f07fc..b86aaf87efc0 100644
--- a/libavutil/buffer.h
+++ b/libavutil/buffer.h
@@ -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.
  *
diff --git a/libavutil/buffer_internal.h b/libavutil/buffer_internal.h
index bdff1b5b32ca..22aa54a246b8 100644
--- a/libavutil/buffer_internal.h
+++ b/libavutil/buffer_internal.h
@@ -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