Commit 0ac0cbcc authored by Nicolas Dufresne's avatar Nicolas Dufresne Committed by Sebastian Dröge

v4l2allocator: Use qdata instead of parenting to DmabufMemory

Parenting V4l2Memory to DmabufMemory was in conflict with recent
optimization in DmabufMemory to avoid dup(), and didn't work with
memory sharing. Instead, use a qdata and it's destroy notify.

https://bugzilla.gnome.org/show_bug.cgi?id=730441
parent 7e40c743
......@@ -204,19 +204,23 @@ _v4l2mem_is_span (GstV4l2Memory * mem1, GstV4l2Memory * mem2, gsize * offset)
return mem1->mem.offset + mem1->mem.size == mem2->mem.offset;
}
static void
_v4l2mem_parent_to_dmabuf (GstV4l2Memory * mem, GstMemory * dma_mem)
{
gst_memory_lock (&mem->mem, GST_LOCK_FLAG_EXCLUSIVE);
dma_mem->parent = gst_memory_ref (&mem->mem);
}
gboolean
gst_is_v4l2_memory (GstMemory * mem)
{
return gst_memory_is_type (mem, GST_V4L2_MEMORY_TYPE);
}
GQuark
gst_v4l2_memory_quark (void)
{
static GQuark quark = 0;
if (quark == 0)
quark = g_quark_from_string ("GstV4l2Memory");
return quark;
}
/*************************************/
/* GstV4l2MemoryGroup implementation */
......@@ -885,7 +889,9 @@ gst_v4l2_allocator_alloc_dmabuf (GstV4l2Allocator * allocator,
dma_mem = gst_dmabuf_allocator_alloc (dmabuf_allocator, dmafd,
mem->mem.maxsize);
_v4l2mem_parent_to_dmabuf (mem, dma_mem);
gst_mini_object_set_qdata (GST_MINI_OBJECT (dma_mem),
GST_V4L2_MEMORY_QUARK, mem, (GDestroyNotify) gst_memory_unref);
group->mem[i] = dma_mem;
group->mems_allocated++;
......
......@@ -42,6 +42,8 @@ G_BEGIN_DECLS
#define GST_V4L2_ALLOCATOR_CAN_ALLOCATE(obj,type) \
(GST_OBJECT_FLAG_IS_SET (obj, GST_V4L2_ALLOCATOR_FLAG_ ## type ## _CREATE_BUFS))
#define GST_V4L2_MEMORY_QUARK gst_v4l2_memory_quark ()
typedef struct _GstV4l2Allocator GstV4l2Allocator;
typedef struct _GstV4l2AllocatorClass GstV4l2AllocatorClass;
typedef struct _GstV4l2MemoryGroup GstV4l2MemoryGroup;
......@@ -109,6 +111,8 @@ GType gst_v4l2_allocator_get_type(void);
gboolean gst_is_v4l2_memory (GstMemory * mem);
GQuark gst_v4l2_memory_quark (void);
gboolean gst_v4l2_allocator_is_active (GstV4l2Allocator * allocator);
guint gst_v4l2_allocator_get_size (GstV4l2Allocator * allocator);
......
......@@ -78,9 +78,10 @@ gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** group)
goto done;
if (gst_is_dmabuf_memory (mem))
mem = mem->parent;
mem = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
GST_V4L2_MEMORY_QUARK);
if (gst_is_v4l2_memory (mem)) {
if (mem && gst_is_v4l2_memory (mem)) {
GstV4l2Memory *vmem = (GstV4l2Memory *) mem;
valid = TRUE;
if (group)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment