add a member dmafd in buffer struct. we can use it represents dma-buf. Signed-off-by: Ming Qian <ming.q...@nxp.com> --- libavutil/buffer.c | 12 ++++++++++++ libavutil/buffer.h | 14 ++++++++++++++ libavutil/buffer_internal.h | 1 + 3 files changed, 27 insertions(+)
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 -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".