surface: add support for dma_buf exports.

Use the new VA buffer export APIs to allow for a VA surface to be
exposed as a plain PRIME fd. This is in view to simplifying interop
with EGL or OpenCL for instance.

https://bugzilla.gnome.org/show_bug.cgi?id=735364
This commit is contained in:
Gwenole Beauchesne 2014-09-15 11:48:05 +02:00
parent 250260cc36
commit 073d6d59e1
5 changed files with 133 additions and 0 deletions

View file

@ -69,6 +69,7 @@ libgstvaapi_source_c = \
gstvaapiprofile.c \
gstvaapisubpicture.c \
gstvaapisurface.c \
gstvaapisurface_drm.c \
gstvaapisurfacepool.c \
gstvaapisurfaceproxy.c \
gstvaapitexture.c \
@ -98,6 +99,7 @@ libgstvaapi_source_h = \
gstvaapiprofile.h \
gstvaapisubpicture.h \
gstvaapisurface.h \
gstvaapisurface_drm.h \
gstvaapisurfacepool.h \
gstvaapisurfaceproxy.h \
gstvaapitexture.h \

View file

@ -21,6 +21,8 @@
*/
#include "sysdeps.h"
#include <va/va_drmcommon.h>
#include "gstvaapicompat.h"
#include "gstvaapibufferproxy.h"
#include "gstvaapibufferproxy_priv.h"
#include "gstvaapiutils.h"
@ -40,6 +42,9 @@ from_GstVaapiBufferMemoryType (guint type)
guint va_type;
switch (type) {
case GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF:
va_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
break;
default:
va_type = 0;
break;
@ -53,6 +58,9 @@ to_GstVaapiBufferMemoryType (guint va_type)
guint type;
switch (va_type) {
case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME:
type = GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF;
break;
default:
type = 0;
break;

View file

@ -57,6 +57,16 @@ G_BEGIN_DECLS
typedef struct _GstVaapiBufferProxy GstVaapiBufferProxy;
/**
* GstVaapiBufferMemoryType:
* @GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF: DRM PRIME buffer memory type.
*
* Set of underlying VA buffer memory types.
*/
typedef enum {
GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF = 1,
} GstVaapiBufferMemoryType;
GstVaapiBufferProxy *
gst_vaapi_buffer_proxy_new (guintptr handle, guint type, gsize size,
GDestroyNotify destroy_func, gpointer user_data);

View file

@ -0,0 +1,77 @@
/*
* gstvaapisurface_drm.c - VA surface abstraction (DRM interop)
*
* Copyright (C) 2014 Intel Corporation
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "sysdeps.h"
#include "gstvaapisurface_drm.h"
#include "gstvaapisurface_priv.h"
#include "gstvaapiimage_priv.h"
#include "gstvaapibufferproxy_priv.h"
static GstVaapiBufferProxy *
gst_vaapi_surface_get_drm_buf_handle (GstVaapiSurface * surface, guint type)
{
GstVaapiBufferProxy *proxy;
GstVaapiImage *image;
image = gst_vaapi_surface_derive_image (surface);
if (!image)
goto error_derive_image;
proxy =
gst_vaapi_buffer_proxy_new_from_object (GST_VAAPI_OBJECT (surface),
image->internal_image.buf, type, gst_vaapi_object_unref, image);
if (!proxy)
goto error_alloc_export_buffer;
return proxy;
/* ERRORS */
error_derive_image:
GST_ERROR ("failed to extract image handle from surface");
return NULL;
error_alloc_export_buffer:
GST_ERROR ("failed to allocate export buffer proxy");
gst_vaapi_object_unref (image);
return NULL;
}
/**
* gst_vaapi_surface_get_dma_buf_handle:
* @surface: a #GstVaapiSurface
*
* If the underlying VA driver implementation supports it, this
* function allows for returning a suitable dma_buf (DRM) buffer
* handle as a #GstVaapiBufferProxy instance. The resulting buffer
* handle is live until the last reference to the proxy gets
* released. Besides, any further change to the parent VA @surface may
* fail.
*
* Return value: the underlying buffer as a #GstVaapiBufferProxy
* instance.
*/
GstVaapiBufferProxy *
gst_vaapi_surface_get_dma_buf_handle (GstVaapiSurface * surface)
{
g_return_val_if_fail (surface != NULL, NULL);
return gst_vaapi_surface_get_drm_buf_handle (surface,
GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF);
}

View file

@ -0,0 +1,36 @@
/*
* gstvaapisurface_drm.h - VA surface abstraction (DRM interop)
*
* Copyright (C) 2014 Intel Corporation
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef GST_VAAPI_SURFACE_DRM_H
#define GST_VAAPI_SURFACE_DRM_H
#include <gst/vaapi/gstvaapisurface.h>
#include <gst/vaapi/gstvaapibufferproxy.h>
G_BEGIN_DECLS
GstVaapiBufferProxy *
gst_vaapi_surface_get_dma_buf_handle (GstVaapiSurface * surface);
G_END_DECLS
#endif /* GST_VAAPI_SURFACE_DRM_H */