diff options
author | Matt Fischer <matt.fischer@garmin.com> | 2017-01-10 19:23:58 -0600 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2017-12-02 14:49:39 -0500 |
commit | 9f65c316e4898781757bebfbed9b46fbb6a7f7bb (patch) | |
tree | d3a5f4bded495e23c2ec2096fd663c14ff68bcd4 /gst-libs | |
parent | d01297e115e475760764d9caa4eb37b5f7f9f31a (diff) |
gldownload: Add dmabuf exporting
This patch adds code to gldownload to export the image as a
dmabuf if requested. The element now exposes memory:DMABuf as
a cap feature, and if it is selected, the element exports the
texture to an EGL image and then a dmabuf. It also implements a
fallback to system memory download in case the exportation failed.
https://bugzilla.gnome.org/show_bug.cgi?id=776927
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/gl/egl/gsteglimage.c | 59 | ||||
-rw-r--r-- | gst-libs/gst/gl/egl/gsteglimage.h | 2 |
2 files changed, 61 insertions, 0 deletions
diff --git a/gst-libs/gst/gl/egl/gsteglimage.c b/gst-libs/gst/gl/egl/gsteglimage.c index 92b3862b1..fdd603807 100644 --- a/gst-libs/gst/gl/egl/gsteglimage.c +++ b/gst-libs/gst/gl/egl/gsteglimage.c @@ -469,4 +469,63 @@ gst_egl_image_from_dmabuf (GstGLContext * context, return gst_egl_image_new_wrapped (context, img, format, NULL, (GstEGLImageDestroyNotify) _destroy_egl_image); } + +gboolean +gst_egl_image_export_dmabuf (GstEGLImage * image, int *fd, gint * stride, + gsize * offset) +{ + EGLBoolean (*gst_eglExportDMABUFImageQueryMESA) (EGLDisplay dpy, + EGLImageKHR image, int *fourcc, int *num_planes, + EGLuint64KHR * modifiers); + EGLBoolean (*gst_eglExportDMABUFImageMESA) (EGLDisplay dpy, EGLImageKHR image, + int *fds, EGLint * strides, EGLint * offsets); + GstGLDisplayEGL *display_egl; + EGLDisplay egl_display = EGL_DEFAULT_DISPLAY; + int num_planes = 0; + int egl_fd = 0; + EGLint egl_stride = 0; + EGLint egl_offset = 0; + + gst_eglExportDMABUFImageQueryMESA = + gst_gl_context_get_proc_address (image->context, + "eglExportDMABUFImageQueryMESA"); + gst_eglExportDMABUFImageMESA = + gst_gl_context_get_proc_address (image->context, + "eglExportDMABUFImageMESA"); + + if (!gst_eglExportDMABUFImageQueryMESA || !gst_eglExportDMABUFImageMESA) + return FALSE; + + display_egl = + (GstGLDisplayEGL *) gst_gl_display_egl_from_gl_display (image-> + context->display); + if (!display_egl) { + GST_WARNING_OBJECT (image->context, + "Failed to retrieve GstGLDisplayEGL from %" GST_PTR_FORMAT, + image->context->display); + return FALSE; + } + egl_display = + (EGLDisplay) gst_gl_display_get_handle (GST_GL_DISPLAY (display_egl)); + gst_object_unref (display_egl); + + if (!gst_eglExportDMABUFImageQueryMESA (egl_display, image->image, + NULL, &num_planes, NULL)) + return FALSE; + + /* Don't allow multi-plane dmabufs */ + if (num_planes > 1) + return FALSE; + + if (!gst_eglExportDMABUFImageMESA (egl_display, image->image, &egl_fd, + &egl_stride, &egl_offset)) + return FALSE; + + *fd = egl_fd; + *stride = egl_stride; + *offset = egl_offset; + + return TRUE; +} + #endif /* GST_GL_HAVE_DMABUF */ diff --git a/gst-libs/gst/gl/egl/gsteglimage.h b/gst-libs/gst/gl/egl/gsteglimage.h index cfd8f008a..b96cc2d3d 100644 --- a/gst-libs/gst/gl/egl/gsteglimage.h +++ b/gst-libs/gst/gl/egl/gsteglimage.h @@ -88,6 +88,8 @@ GstEGLImage * gst_egl_image_from_dmabuf (GstGLContext * GstVideoInfo * in_info, gint plane, gsize offset); +GST_EXPORT +gboolean gst_egl_image_export_dmabuf (GstEGLImage *image, int *fd, gint *stride, gsize *offset); #endif /** |