summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2014-09-15 15:25:09 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2015-01-28 17:35:16 +0100
commit011f9bd6cbdacc8b4cc8546aa24f505d3fa17a08 (patch)
tree3f8a3e07709aea877ede1c4b9785e74f2d2c1e12
parentdd37fc4999bea6afd8b85846491d7f35ec2befda (diff)
downloadgst-vaapi-011f9bd6cbdacc8b4cc8546aa24f505d3fa17a08.tar.gz
surface: add support for dma_buf imports.
Add new gst_vaapi_surface_new_with_dma_buf_handle() helper function to allow for creating VA surfaces from a foreign DRM PRIME fd. The resulting VA surface owns the supplied buffer handle. https://bugzilla.gnome.org/show_bug.cgi?id=735362
-rw-r--r--gst-libs/gst/vaapi/gstvaapisurface_drm.c53
-rw-r--r--gst-libs/gst/vaapi/gstvaapisurface_drm.h5
2 files changed, 58 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapisurface_drm.c b/gst-libs/gst/vaapi/gstvaapisurface_drm.c
index bebbea1e..d0898a52 100644
--- a/gst-libs/gst/vaapi/gstvaapisurface_drm.c
+++ b/gst-libs/gst/vaapi/gstvaapisurface_drm.c
@@ -97,3 +97,56 @@ gst_vaapi_surface_get_gem_buf_handle (GstVaapiSurface * surface)
return gst_vaapi_surface_get_drm_buf_handle (surface,
GST_VAAPI_BUFFER_MEMORY_TYPE_GEM_BUF);
}
+
+static void
+fill_video_info (GstVideoInfo * vip, GstVideoFormat format, guint width,
+ guint height, gsize offset[GST_VIDEO_MAX_PLANES],
+ gint stride[GST_VIDEO_MAX_PLANES])
+{
+ guint i;
+
+ gst_video_info_init (vip);
+ gst_video_info_set_format (vip, format, width, height);
+ for (i = 0; i < GST_VIDEO_INFO_N_PLANES (vip); i++) {
+ GST_VIDEO_INFO_PLANE_OFFSET (vip, i) = offset[i];
+ GST_VIDEO_INFO_PLANE_STRIDE (vip, i) = stride[i];
+ }
+}
+
+/**
+ * gst_vaapi_surface_new_with_dma_buf_handle:
+ * @display: a #GstVaapiDisplay
+ * @fd: the DRM PRIME file descriptor
+ * @size: the underlying DRM buffer size
+ * @format: the desired surface format
+ * @width: the desired surface width in pixels
+ * @height: the desired surface height in pixels
+ * @offset: the offsets to each plane
+ * @stride: the pitches for each plane
+ *
+ * Creates a new #GstVaapiSurface with an external DRM PRIME file
+ * descriptor. The newly created VA surfaces owns the supplied buffer
+ * handle.
+ *
+ * Return value: the newly allocated #GstVaapiSurface object, or %NULL
+ * if creation from DRM PRIME fd failed, or is not supported
+ */
+GstVaapiSurface *
+gst_vaapi_surface_new_with_dma_buf_handle (GstVaapiDisplay * display,
+ gint fd, guint size, GstVideoFormat format, guint width, guint height,
+ gsize offset[GST_VIDEO_MAX_PLANES], gint stride[GST_VIDEO_MAX_PLANES])
+{
+ GstVaapiBufferProxy *proxy;
+ GstVaapiSurface *surface;
+ GstVideoInfo vi;
+
+ proxy = gst_vaapi_buffer_proxy_new ((gintptr) fd,
+ GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF, size, NULL, NULL);
+ if (!proxy)
+ return NULL;
+
+ fill_video_info (&vi, format, width, height, offset, stride);
+ surface = gst_vaapi_surface_new_from_buffer_proxy (display, proxy, &vi);
+ gst_vaapi_buffer_proxy_unref (proxy);
+ return surface;
+}
diff --git a/gst-libs/gst/vaapi/gstvaapisurface_drm.h b/gst-libs/gst/vaapi/gstvaapisurface_drm.h
index cfbccbe1..eee010c5 100644
--- a/gst-libs/gst/vaapi/gstvaapisurface_drm.h
+++ b/gst-libs/gst/vaapi/gstvaapisurface_drm.h
@@ -34,6 +34,11 @@ gst_vaapi_surface_get_dma_buf_handle (GstVaapiSurface * surface);
GstVaapiBufferProxy *
gst_vaapi_surface_get_gem_buf_handle (GstVaapiSurface * surface);
+GstVaapiSurface *
+gst_vaapi_surface_new_with_dma_buf_handle (GstVaapiDisplay * display,
+ gint fd, guint size, GstVideoFormat format, guint width, guint height,
+ gsize offset[GST_VIDEO_MAX_PLANES], gint stride[GST_VIDEO_MAX_PLANES]);
+
G_END_DECLS
#endif /* GST_VAAPI_SURFACE_DRM_H */