コード例 #1
0
static void
_gst_egl_image_free (GstMiniObject * object)
{
  GstEGLImage *image = GST_EGL_IMAGE (object);

  if (image->context) {
    gst_gl_context_thread_add (GST_GL_CONTEXT (image->context),
        (GstGLContextThreadFunc) _gst_egl_image_free_thread, image);
    gst_object_unref (image->context);
  }
}
コード例 #2
0
static gboolean
_gl_mem_create (GstGLMemoryEGL * gl_mem, GError ** error)
{
    GstGLContext *context = gl_mem->mem.mem.context;
    GstGLContextEGL *ctx_egl = GST_GL_CONTEXT_EGL (context);
    const GstGLFuncs *gl = context->gl_vtable;
    GstGLBaseMemoryAllocatorClass *alloc_class;

    if (!gst_gl_context_check_feature (GST_GL_CONTEXT (context),
                                       "EGL_KHR_image_base")) {
        g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
                     "EGL_KHR_image_base is not supported");
        return FALSE;
    }

    alloc_class = GST_GL_BASE_MEMORY_ALLOCATOR_CLASS (parent_class);
    if (!alloc_class->create ((GstGLBaseMemory *) gl_mem, error))
        return FALSE;

    if (gl_mem->image == NULL) {
        EGLImageKHR image = ctx_egl->eglCreateImageKHR (ctx_egl->egl_display,
                            ctx_egl->egl_context, EGL_GL_TEXTURE_2D_KHR,
                            (EGLClientBuffer) (guintptr) gl_mem->mem.tex_id, NULL);

        GST_TRACE ("Generating EGLImage handle:%p from a texture:%u",
                   gl_mem->image, gl_mem->mem.tex_id);

        if (eglGetError () != EGL_SUCCESS) {
            g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
                         "Failed to create EGLImage");
            return FALSE;
        }

        gl_mem->image = gst_egl_image_new_wrapped (context, image, 0, 0,
                        NULL, (GstEGLImageDestroyNotify) _destroy_egl_image);
    } else {
        gl->ActiveTexture (GL_TEXTURE0 + gl_mem->mem.plane);
        gl->BindTexture (GL_TEXTURE_2D, gl_mem->mem.tex_id);
        gl->EGLImageTargetTexture2D (GL_TEXTURE_2D,
                                     gst_egl_image_get_image (GST_EGL_IMAGE (gl_mem->image)));
    }

    return TRUE;
}