GstEGLImage * gst_egl_image_from_dmabuf (GstGLContext * context, gint dmabuf, GstVideoInfo * in_info, gint plane, gsize offset) { GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context); gint fourcc; gint atti = 0; EGLint attribs[13]; EGLImageKHR img = EGL_NO_IMAGE_KHR; GstVideoGLTextureType type; fourcc = _drm_fourcc_from_info (in_info, plane); type = gst_gl_texture_type_from_format (context, GST_VIDEO_INFO_FORMAT (in_info), plane); GST_DEBUG ("fourcc %.4s (%d) plane %d (%dx%d)", (char *) &fourcc, fourcc, plane, GST_VIDEO_INFO_COMP_WIDTH (in_info, plane), GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane)); attribs[atti++] = EGL_WIDTH; attribs[atti++] = GST_VIDEO_INFO_COMP_WIDTH (in_info, plane); attribs[atti++] = EGL_HEIGHT; attribs[atti++] = GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane); attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT; attribs[atti++] = fourcc; attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT; attribs[atti++] = dmabuf; attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; attribs[atti++] = offset; attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; attribs[atti++] = GST_VIDEO_INFO_PLANE_STRIDE (in_info, plane); attribs[atti] = EGL_NONE; for (int i = 0; i < atti; i++) GST_LOG ("attr %i: %08X", i, attribs[i]); g_assert (atti == 12); img = ctx_egl->eglCreateImage (ctx_egl->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs); if (!img) { GST_WARNING ("eglCreateImage failed: %s", gst_gl_context_egl_get_error_string (eglGetError ())); return NULL; } return gst_egl_image_new_wrapped (context, img, type, GST_VIDEO_GL_TEXTURE_ORIENTATION_X_NORMAL_Y_NORMAL, (GstEGLImageDestroyNotify) _destroy_egl_image, NULL); }
GstMemory * gst_egl_image_memory_from_dmabuf (GstGLContext * context, gint dmabuf, GstVideoInfo * in_info, gint plane, gsize offset) { GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context); GstEGLImageAllocator *allocator; gint fourcc; gint atti = 0; EGLint attribs[13]; EGLImageKHR img = EGL_NO_IMAGE_KHR; allocator = gst_egl_image_allocator_obtain (); fourcc = _drm_fourcc_from_info (in_info, plane); GST_DEBUG ("fourcc %.4s (%d) plane %d (%dx%d)", (char *) &fourcc, fourcc, plane, GST_VIDEO_INFO_COMP_WIDTH (in_info, plane), GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane)); attribs[atti++] = EGL_WIDTH; attribs[atti++] = GST_VIDEO_INFO_COMP_WIDTH (in_info, plane); attribs[atti++] = EGL_HEIGHT; attribs[atti++] = GST_VIDEO_INFO_COMP_HEIGHT (in_info, plane); attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT; attribs[atti++] = fourcc; attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT; attribs[atti++] = dmabuf; attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; attribs[atti++] = offset; attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; attribs[atti++] = GST_VIDEO_INFO_PLANE_STRIDE (in_info, plane); attribs[atti] = EGL_NONE; for (int i = 0; i < atti; i++) GST_LOG ("attr %i: %08X", i, attribs[i]); g_assert (atti == 12); img = ctx_egl->eglCreateImage (ctx_egl->egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attribs); if (!img) { GST_WARNING_OBJECT (allocator, "eglCreateImage failed: %s", gst_gl_context_egl_get_error_string ()); return NULL; } return gst_egl_image_allocator_wrap (allocator, ctx_egl, img, 0, 0, in_info->size, NULL, NULL); }