plugins: fix allocation of DMABUF memory.

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.
This commit is contained in:
Gwenole Beauchesne 2015-03-02 11:12:53 +01:00
parent 3d8e5e59a7
commit 8b91ddac0b

View file

@ -21,6 +21,7 @@
*/ */
#include "gst/vaapi/sysdeps.h" #include "gst/vaapi/sysdeps.h"
#include <unistd.h>
#include <gst/vaapi/gstvaapisurface_drm.h> #include <gst/vaapi/gstvaapisurface_drm.h>
#include <gst/vaapi/gstvaapisurfacepool.h> #include <gst/vaapi/gstvaapisurfacepool.h>
#include <gst/vaapi/gstvaapiimagepool.h> #include <gst/vaapi/gstvaapiimagepool.h>
@ -773,6 +774,7 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta)
GstVaapiSurface *surface; GstVaapiSurface *surface;
GstVaapiSurfaceProxy *proxy; GstVaapiSurfaceProxy *proxy;
GstVaapiBufferProxy *dmabuf_proxy; GstVaapiBufferProxy *dmabuf_proxy;
gint dmabuf_fd;
const GstVideoInfo *vip; const GstVideoInfo *vip;
guint flags; 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_video_meta_set_surface_proxy (meta, proxy);
gst_vaapi_surface_proxy_unref (proxy); gst_vaapi_surface_proxy_unref (proxy);
mem = gst_dmabuf_allocator_alloc (allocator, dmabuf_fd = gst_vaapi_buffer_proxy_get_handle (dmabuf_proxy);
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)); gst_vaapi_buffer_proxy_get_size (dmabuf_proxy));
if (!mem) if (!mem)
goto error_create_dmabuf_memory; goto error_create_dmabuf_memory;
@ -834,6 +839,12 @@ error_create_dmabuf_proxy:
gst_vaapi_surface_proxy_unref (proxy); gst_vaapi_surface_proxy_unref (proxy);
return NULL; 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: error_create_dmabuf_memory:
{ {
GST_ERROR ("failed to create DMABUF memory"); GST_ERROR ("failed to create DMABUF memory");