mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 14:36:24 +00:00
gl/examples: update for other-context property removal
This commit is contained in:
parent
567185a277
commit
c1f3cc9f1c
3 changed files with 58 additions and 28 deletions
|
@ -623,7 +623,7 @@ _gst_context_query (GstElement * element,
|
||||||
GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
|
GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
|
||||||
"posting need context message");
|
"posting need context message");
|
||||||
msg = gst_message_new_need_context (GST_OBJECT_CAST (element),
|
msg = gst_message_new_need_context (GST_OBJECT_CAST (element),
|
||||||
GST_GL_DISPLAY_CONTEXT_TYPE);
|
display_type);
|
||||||
gst_element_post_message (element, msg);
|
gst_element_post_message (element, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,11 +650,12 @@ gst_gl_display_context_query (GstElement * element, GstGLDisplay ** display_ptr)
|
||||||
query =
|
query =
|
||||||
_gst_context_query (element, display_ptr, GST_GL_DISPLAY_CONTEXT_TYPE);
|
_gst_context_query (element, display_ptr, GST_GL_DISPLAY_CONTEXT_TYPE);
|
||||||
gst_query_parse_context (query, &ctxt);
|
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);
|
gst_context_get_gl_display (ctxt, display_ptr);
|
||||||
if (*display_ptr)
|
|
||||||
goto out;
|
if (*display_ptr)
|
||||||
}
|
goto out;
|
||||||
|
|
||||||
#if GST_GL_HAVE_WINDOW_X11
|
#if GST_GL_HAVE_WINDOW_X11
|
||||||
gst_query_unref (query);
|
gst_query_unref (query);
|
||||||
query = _gst_context_query (element, display_ptr, "gst.x11.display.handle");
|
query = _gst_context_query (element, display_ptr, "gst.x11.display.handle");
|
||||||
|
@ -668,9 +669,11 @@ gst_gl_display_context_query (GstElement * element, GstGLDisplay ** display_ptr)
|
||||||
&& display) {
|
&& display) {
|
||||||
*display_ptr =
|
*display_ptr =
|
||||||
(GstGLDisplay *) gst_gl_display_x11_new_with_display (display);
|
(GstGLDisplay *) gst_gl_display_x11_new_with_display (display);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*display_ptr)
|
||||||
|
goto out;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
|
@ -74,16 +74,6 @@ Pipeline::configure ()
|
||||||
g_signal_connect (m_bus, "sync-message", G_CALLBACK (sync_bus_call), this);
|
g_signal_connect (m_bus, "sync-message", G_CALLBACK (sync_bus_call), this);
|
||||||
gst_object_unref (m_bus);
|
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);
|
gst_element_set_state (GST_ELEMENT (this->m_pipeline), GST_STATE_PAUSED);
|
||||||
GstState state = GST_STATE_PAUSED;
|
GstState state = GST_STATE_PAUSED;
|
||||||
if (gst_element_get_state (GST_ELEMENT (this->m_pipeline),
|
if (gst_element_get_state (GST_ELEMENT (this->m_pipeline),
|
||||||
|
@ -225,6 +215,11 @@ gboolean Pipeline::sync_bus_call (GstBus * bus, GstMessage * msg, Pipeline * p)
|
||||||
GstContext *display_context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
|
GstContext *display_context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
|
||||||
gst_context_set_gl_display (display_context, p->display);
|
gst_context_set_gl_display (display_context, p->display);
|
||||||
gst_element_set_context (GST_ELEMENT (msg->src), display_context);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/gl/gl.h>
|
#include <gst/gl/gl.h>
|
||||||
|
|
||||||
|
static GstGLContext *sdl_context;
|
||||||
|
static GstGLDisplay *sdl_gl_display;
|
||||||
|
|
||||||
/* rotation angle for the triangle. */
|
/* rotation angle for the triangle. */
|
||||||
float rtri = 0.0f;
|
float rtri = 0.0f;
|
||||||
|
|
||||||
|
@ -229,6 +232,39 @@ end_stream_cb (GstBus * bus, GstMessage * msg, GMainLoop * loop)
|
||||||
g_main_loop_quit (loop);
|
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
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -246,13 +282,10 @@ main (int argc, char **argv)
|
||||||
GMainLoop *loop = NULL;
|
GMainLoop *loop = NULL;
|
||||||
GstPipeline *pipeline = NULL;
|
GstPipeline *pipeline = NULL;
|
||||||
GstBus *bus = NULL;
|
GstBus *bus = NULL;
|
||||||
GstElement *glfilter = NULL;
|
|
||||||
GstElement *fakesink = NULL;
|
GstElement *fakesink = NULL;
|
||||||
GstState state;
|
GstState state;
|
||||||
GAsyncQueue *queue_input_buf = NULL;
|
GAsyncQueue *queue_input_buf = NULL;
|
||||||
GAsyncQueue *queue_output_buf = NULL;
|
GAsyncQueue *queue_output_buf = NULL;
|
||||||
GstGLDisplay *display;
|
|
||||||
GstGLContext *sdl_context;
|
|
||||||
const gchar *platform;
|
const gchar *platform;
|
||||||
|
|
||||||
/* Initialize SDL for video output */
|
/* Initialize SDL for video output */
|
||||||
|
@ -284,22 +317,24 @@ main (int argc, char **argv)
|
||||||
sdl_dc = wglGetCurrentDC ();
|
sdl_dc = wglGetCurrentDC ();
|
||||||
wglMakeCurrent (0, 0);
|
wglMakeCurrent (0, 0);
|
||||||
platform = "wgl";
|
platform = "wgl";
|
||||||
display = gst_gl_display_new ();
|
sdl_gl_display = gst_gl_display_new ();
|
||||||
#else
|
#else
|
||||||
SDL_VERSION (&info.version);
|
SDL_VERSION (&info.version);
|
||||||
SDL_GetWMInfo (&info);
|
SDL_GetWMInfo (&info);
|
||||||
/* FIXME: This display is different to the one that SDL uses to create the
|
/* 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
|
* 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_win = info.info.x11.window;
|
||||||
sdl_gl_context = glXGetCurrentContext ();
|
sdl_gl_context = glXGetCurrentContext ();
|
||||||
glXMakeCurrent (sdl_display, None, 0);
|
glXMakeCurrent (sdl_display, None, 0);
|
||||||
platform = "glx";
|
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
|
#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);
|
gst_gl_platform_from_string (platform), GST_GL_API_OPENGL);
|
||||||
|
|
||||||
pipeline =
|
pipeline =
|
||||||
|
@ -312,13 +347,10 @@ main (int argc, char **argv)
|
||||||
g_signal_connect (bus, "message::error", G_CALLBACK (end_stream_cb), loop);
|
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::warning", G_CALLBACK (end_stream_cb), loop);
|
||||||
g_signal_connect (bus, "message::eos", 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);
|
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
|
/* NULL to PAUSED state pipeline to make sure the gst opengl context is created and
|
||||||
* shared with the sdl one */
|
* shared with the sdl one */
|
||||||
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
|
||||||
|
|
Loading…
Reference in a new issue