From d841e0f778ca514b1411a90726b1910d7712badd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 8 Feb 2018 12:24:23 +0100 Subject: [PATCH] pipewiresrc: use the right allocator for dmabuf Use the dmabuf allocator when we get dmabuf memory. https://github.com/PipeWire/pipewire/issues/31 --- src/gst/gstpipewiresrc.c | 11 ++++++++++- src/gst/gstpipewiresrc.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index ec3b75823..86770f1a0 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -42,6 +42,7 @@ #include #include +#include #include #include "gstpipewireclock.h" @@ -211,6 +212,7 @@ gst_pipewire_src_finalize (GObject * object) if (pwsrc->properties) gst_structure_free (pwsrc->properties); g_object_unref (pwsrc->fd_allocator); + g_object_unref (pwsrc->dmabuf_allocator); if (pwsrc->clock) gst_object_unref (pwsrc->clock); g_free (pwsrc->path); @@ -321,6 +323,7 @@ gst_pipewire_src_init (GstPipeWireSrc * src) g_queue_init (&src->queue); src->fd_allocator = gst_fd_allocator_new (); + src->dmabuf_allocator = gst_dmabuf_allocator_new (); src->client_name = pw_get_client_name (); src->buf_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gst_buffer_unref); @@ -400,12 +403,18 @@ on_add_buffer (void *_data, guint id) struct spa_data *d = &b->datas[i]; GstMemory *gmem = NULL; - if (d->type == t->data.MemFd || d->type == t->data.DmaBuf) { + if (d->type == t->data.MemFd) { gmem = gst_fd_allocator_alloc (pwsrc->fd_allocator, dup (d->fd), d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE); gst_memory_resize (gmem, d->mapoffset, d->maxsize); data.offset = d->mapoffset; } + else if(d->type == t->data.DmaBuf) { + gmem = gst_dmabuf_allocator_alloc (pwsrc->dmabuf_allocator, dup (d->fd), + d->mapoffset + d->maxsize); + gst_memory_resize (gmem, d->mapoffset, d->maxsize); + data.offset = d->mapoffset; + } else if (d->type == t->data.MemPtr) { gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, 0, d->maxsize, NULL, NULL); diff --git a/src/gst/gstpipewiresrc.h b/src/gst/gstpipewiresrc.h index 45820b8fb..5769c02dc 100644 --- a/src/gst/gstpipewiresrc.h +++ b/src/gst/gstpipewiresrc.h @@ -77,6 +77,7 @@ struct _GstPipeWireSrc { struct spa_hook stream_listener; GstAllocator *fd_allocator; + GstAllocator *dmabuf_allocator; GstStructure *properties; GHashTable *buf_ids;