plugins: fix allocation of DMABUF memory.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 2 Mar 2015 10:12:53 +0000 (11:12 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 2 Mar 2015 12:41:29 +0000 (13:41 +0100)
The dmabuf allocator would close the DMABUF handle passed in the init
function gst_dmabuf_allocator_alloc(). So, we need to dup() it so that
to avoid a double close, ultimately in the underlying driver that owns
the DMABUF handle.

gst/vaapi/gstvaapivideomemory.c

index 96a4b1e..3583530 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "gst/vaapi/sysdeps.h"
+#include <unistd.h>
 #include <gst/vaapi/gstvaapisurface_drm.h>
 #include <gst/vaapi/gstvaapisurfacepool.h>
 #include <gst/vaapi/gstvaapiimagepool.h>
@@ -773,6 +774,7 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta)
   GstVaapiSurface *surface;
   GstVaapiSurfaceProxy *proxy;
   GstVaapiBufferProxy *dmabuf_proxy;
+  gint dmabuf_fd;
   const GstVideoInfo *vip;
   guint flags;
 
@@ -803,8 +805,11 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta)
   gst_vaapi_video_meta_set_surface_proxy (meta, proxy);
   gst_vaapi_surface_proxy_unref (proxy);
 
-  mem = gst_dmabuf_allocator_alloc (allocator,
-      gst_vaapi_buffer_proxy_get_handle (dmabuf_proxy),
+  dmabuf_fd = gst_vaapi_buffer_proxy_get_handle (dmabuf_proxy);
+  if (dmabuf_fd < 0 || (dmabuf_fd = dup (dmabuf_fd)) < 0)
+    goto error_create_dmabuf_handle;
+
+  mem = gst_dmabuf_allocator_alloc (allocator, dmabuf_fd,
       gst_vaapi_buffer_proxy_get_size (dmabuf_proxy));
   if (!mem)
     goto error_create_dmabuf_memory;
@@ -834,6 +839,12 @@ error_create_dmabuf_proxy:
     gst_vaapi_surface_proxy_unref (proxy);
     return NULL;
   }
+error_create_dmabuf_handle:
+  {
+    GST_ERROR ("failed to duplicate DMABUF handle");
+    gst_vaapi_buffer_proxy_unref (dmabuf_proxy);
+    return NULL;
+  }
 error_create_dmabuf_memory:
   {
     GST_ERROR ("failed to create DMABUF memory");