vl42allocator: Don't dup exported dmabufs
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Fri, 19 Oct 2018 21:37:28 +0000 (17:37 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 24 Oct 2018 10:55:32 +0000 (11:55 +0100)
We can now use the new GstFAllocator to ask the allocator not to close
the wrapped FD. This way the dup is no longer needed.

sys/v4l2/gstv4l2allocator.c

index 5dcfd02..0281fc5 100644 (file)
@@ -852,7 +852,6 @@ gst_v4l2_allocator_alloc_dmabuf (GstV4l2Allocator * allocator,
   for (i = 0; i < group->n_mem; i++) {
     GstV4l2Memory *mem;
     GstMemory *dma_mem;
-    gint dmafd;
 
     if (group->mem[i] == NULL) {
       struct v4l2_exportbuffer expbuf = { 0 };
@@ -882,11 +881,8 @@ gst_v4l2_allocator_alloc_dmabuf (GstV4l2Allocator * allocator,
     g_assert (gst_is_v4l2_memory (group->mem[i]));
     mem = (GstV4l2Memory *) group->mem[i];
 
-    if ((dmafd = dup (mem->dmafd)) < 0)
-      goto dup_failed;
-
-    dma_mem = gst_dmabuf_allocator_alloc (dmabuf_allocator, dmafd,
-        group->planes[i].length);
+    dma_mem = gst_fd_allocator_alloc (dmabuf_allocator, mem->dmafd,
+        group->planes[i].length, GST_FD_MEMORY_FLAG_DONT_CLOSE);
     gst_memory_resize (dma_mem, group->planes[i].data_offset,
         group->planes[i].length - group->planes[i].data_offset);
 
@@ -906,12 +902,6 @@ expbuf_failed:
         g_strerror (errno));
     goto cleanup;
   }
-dup_failed:
-  {
-    GST_ERROR_OBJECT (allocator, "Failed to dup DMABUF descriptor: %s",
-        g_strerror (errno));
-    goto cleanup;
-  }
 cleanup:
   {
     _cleanup_failed_alloc (allocator, group);