v4l2allocator: Use qdata instead of parenting to DmabufMemory
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 10 Jul 2014 22:11:20 +0000 (18:11 -0400)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 11 Jul 2014 07:49:27 +0000 (09:49 +0200)
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

sys/v4l2/gstv4l2allocator.c
sys/v4l2/gstv4l2allocator.h
sys/v4l2/gstv4l2bufferpool.c

index 416770b..68ce902 100644 (file)
@@ -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++;
index 54cf1cb..3f7b33d 100644 (file)
@@ -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);
index f5e3bbc..488ade7 100644 (file)
@@ -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)