I’m trying to make gstreamer use the opengl context created by Unity and can’t get it to work.
https://gstreamer.freedesktop.org/documentation/additional/design/opengl.html?gi-language=c provides an example to share a context with gstreamer so I’ve created:
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfacesPtr) {
g_unityContext = eglGetCurrentContext();
g_unityDisplay = eglGetCurrentDisplay();
...
}
And a bus call
static gboolean
sync_bus_call(GstBus *bus, GstMessage *msg, gpointer data)
{
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_NEED_CONTEXT: {
const gchar *context_type;
GstContext *context = NULL;
gst_message_parse_context_type(msg, &context_type);
Logger::logFormat("got need context %s\n", context_type);
if (g_strcmp0(context_type, "gst.gl.app_context") == 0) {
context = gst_context_new("gst.gl.app_context", TRUE);
GstStructure *s = gst_context_writable_structure(context);
gst_structure_set(s, "context", GST_TYPE_GL_CONTEXT, g_gstContext, NULL);
// Assign to the element that requested it
gst_element_set_context(GST_ELEMENT(msg->src), context);
gst_context_unref(context);
}
break;
}
default:
break;
}
return FALSE; // let other messages pass
}
This fails and gives
wrapped context could not retrieve config. The application may be missing a call to gst_gl_context_fill_info() or the specific platform implemention is not implemented for retrieving the config from a wrapped OpenGL context.
So I need to call gst_gl_context_fill_infosure I can do that…
void InitGStreamerInstance(GStreamerInstance *instance) {
...
if(!g_gstContext) {
g_gstDisplayEGL = gst_gl_display_egl_new_with_egl_display(g_unityDisplay);
g_gstDisplay = GST_GL_DISPLAY(g_gstDisplayEGL);
g_gstContext = gst_gl_context_new_wrapped(
g_gstDisplay,
(guintptr)g_unityContext,
GST_GL_PLATFORM_EGL,
GST_GL_API_GLES2
);
GError *error = nullptr;
Logger::log("Filling info...");
if (!gst_gl_context_fill_info(g_gstContext, &error)) {
Logger::logFormat("gst_gl_context_fill_info failed: %s", error ? error->message : "unknown error");
if (error) g_error_free(error);
}
}
}
Which gives
Filling info…
gst_gl_context_fill_info failed: unknown error
Which couldn’t be any more helpful. Clearly I’m doing something wrong here. What?