v4l2: allocator: Don't close foreign dmabuf
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 25 Jul 2023 19:14:11 +0000 (15:14 -0400)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 21 Aug 2023 22:52:57 +0000 (23:52 +0100)
Imported dmabuf are not being duped, so they should never be closed. Instead,
we ensure their live time by having strong reference on their original
buffer. This should fix potential flickering due to dmabuf being closed
too early.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5217>

subprojects/gst-plugins-good/sys/v4l2/gstv4l2allocator.c

index f04bae1444f9e01f576f5b119f8ca5897d6ab967..059039e5307620075ecc6abaed564a02f1a88eb9 100644 (file)
@@ -357,7 +357,6 @@ gst_v4l2_allocator_release (GstV4l2Allocator * allocator, GstV4l2Memory * mem)
 
   switch (allocator->memory) {
     case V4L2_MEMORY_DMABUF:
-      close (mem->dmafd);
       mem->dmafd = -1;
       break;
     case V4L2_MEMORY_USERPTR:
@@ -396,8 +395,7 @@ gst_v4l2_allocator_free (GstAllocator * gallocator, GstMemory * gmem)
         obj->munmap (mem->data, group->planes[mem->plane].length);
     }
 
-    /* This apply for both mmap with expbuf, and dmabuf imported memory */
-    if (mem->dmafd >= 0)
+    if (allocator->memory == V4L2_MEMORY_MMAP && mem->dmafd >= 0)
       close (mem->dmafd);
   }