GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
"posting need context message");
msg = gst_message_new_need_context (GST_OBJECT_CAST (element),
- GST_GL_DISPLAY_CONTEXT_TYPE);
+ display_type);
gst_element_post_message (element, msg);
}
query =
_gst_context_query (element, display_ptr, GST_GL_DISPLAY_CONTEXT_TYPE);
gst_query_parse_context (query, &ctxt);
- if (ctxt && gst_context_has_context_type (ctxt, GST_GL_DISPLAY_CONTEXT_TYPE)) {
+ if (ctxt && gst_context_has_context_type (ctxt, GST_GL_DISPLAY_CONTEXT_TYPE))
gst_context_get_gl_display (ctxt, display_ptr);
- if (*display_ptr)
- goto out;
- }
+
+ if (*display_ptr)
+ goto out;
+
#if GST_GL_HAVE_WINDOW_X11
gst_query_unref (query);
query = _gst_context_query (element, display_ptr, "gst.x11.display.handle");
&& display) {
*display_ptr =
(GstGLDisplay *) gst_gl_display_x11_new_with_display (display);
- goto out;
}
}
+
+ if (*display_ptr)
+ goto out;
#endif
out:
g_signal_connect (m_bus, "sync-message", G_CALLBACK (sync_bus_call), this);
gst_object_unref (m_bus);
- /* Retrieve the last gl element */
- GstElement *gl_element =
- gst_bin_get_by_name (GST_BIN (m_pipeline), "gleffects0");
- if (!gl_element) {
- qDebug ("gl element could not be found");
- return;
- }
- g_object_set (G_OBJECT (gl_element), "other-context", this->context, NULL);
- gst_object_unref (gl_element);
-
gst_element_set_state (GST_ELEMENT (this->m_pipeline), GST_STATE_PAUSED);
GstState state = GST_STATE_PAUSED;
if (gst_element_get_state (GST_ELEMENT (this->m_pipeline),
GstContext *display_context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
gst_context_set_gl_display (display_context, p->display);
gst_element_set_context (GST_ELEMENT (msg->src), display_context);
+ } else if (g_strcmp0 (context_type, "gst.gl.app_context") == 0) {
+ GstContext *app_context = gst_context_new ("gst.gl.app_context", TRUE);
+ GstStructure *s = gst_context_writable_structure (app_context);
+ gst_structure_set (s, "context", GST_GL_TYPE_CONTEXT, p->context, NULL);
+ gst_element_set_context (GST_ELEMENT (msg->src), app_context);
}
break;
}
#include <gst/gst.h>
#include <gst/gl/gl.h>
+static GstGLContext *sdl_context;
+static GstGLDisplay *sdl_gl_display;
+
/* rotation angle for the triangle. */
float rtri = 0.0f;
g_main_loop_quit (loop);
}
+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;
+
+ gst_message_parse_context_type (msg, &context_type);
+ g_print ("got need context %s\n", context_type);
+
+ if (g_strcmp0 (context_type, GST_GL_DISPLAY_CONTEXT_TYPE) == 0) {
+ GstContext *display_context =
+ gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
+ gst_context_set_gl_display (display_context, sdl_gl_display);
+ gst_element_set_context (GST_ELEMENT (msg->src), display_context);
+ return TRUE;
+ } else if (g_strcmp0 (context_type, "gst.gl.app_context") == 0) {
+ GstContext *app_context = gst_context_new ("gst.gl.app_context", TRUE);
+ GstStructure *s = gst_context_writable_structure (app_context);
+ gst_structure_set (s, "context", GST_GL_TYPE_CONTEXT, sdl_context,
+ NULL);
+ gst_element_set_context (GST_ELEMENT (msg->src), app_context);
+ return TRUE;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ return FALSE;
+}
+
int
main (int argc, char **argv)
{
GMainLoop *loop = NULL;
GstPipeline *pipeline = NULL;
GstBus *bus = NULL;
- GstElement *glfilter = NULL;
GstElement *fakesink = NULL;
GstState state;
GAsyncQueue *queue_input_buf = NULL;
GAsyncQueue *queue_output_buf = NULL;
- GstGLDisplay *display;
- GstGLContext *sdl_context;
const gchar *platform;
/* Initialize SDL for video output */
sdl_dc = wglGetCurrentDC ();
wglMakeCurrent (0, 0);
platform = "wgl";
- display = gst_gl_display_new ();
+ sdl_gl_display = gst_gl_display_new ();
#else
SDL_VERSION (&info.version);
SDL_GetWMInfo (&info);
/* FIXME: This display is different to the one that SDL uses to create the
* GL context inside SDL_SetVideoMode() above which fails on Intel hardware
*/
- sdl_display = info.info.x11.display;
+ sdl_display = info.info.x11.gfxdisplay;
sdl_win = info.info.x11.window;
sdl_gl_context = glXGetCurrentContext ();
glXMakeCurrent (sdl_display, None, 0);
platform = "glx";
- display = (GstGLDisplay *) gst_gl_display_x11_new_with_display (sdl_display);
+ sdl_gl_display =
+ (GstGLDisplay *) gst_gl_display_x11_new_with_display (sdl_display);
#endif
- sdl_context = gst_gl_context_new_wrapped (display, (guintptr) sdl_gl_context,
+ sdl_context =
+ gst_gl_context_new_wrapped (sdl_gl_display, (guintptr) sdl_gl_context,
gst_gl_platform_from_string (platform), GST_GL_API_OPENGL);
pipeline =
g_signal_connect (bus, "message::error", G_CALLBACK (end_stream_cb), loop);
g_signal_connect (bus, "message::warning", G_CALLBACK (end_stream_cb), loop);
g_signal_connect (bus, "message::eos", G_CALLBACK (end_stream_cb), loop);
+ gst_bus_enable_sync_message_emission (bus);
+ g_signal_connect (bus, "sync-message", G_CALLBACK (sync_bus_call), NULL);
gst_object_unref (bus);
- /* sdl_gl_context is an external OpenGL context with which gst-plugins-gl want to share textures */
- glfilter = gst_bin_get_by_name (GST_BIN (pipeline), "gleffects0");
- g_object_set (G_OBJECT (glfilter), "other-context", sdl_context, NULL);
- gst_object_unref (glfilter);
-
/* NULL to PAUSED state pipeline to make sure the gst opengl context is created and
* shared with the sdl one */
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);