From ceda9dc1aaee32686b6c62ce8a43916e1407af4b Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 12 Jan 2017 21:35:25 +1100 Subject: [PATCH] gl/utils: also take care of the local GL context in query functions Simplifies a deduplicates a lot of code in elements retrieving/setting the local OpenGL context. --- ext/gl/gstglbasemixer.c | 109 +++--------------------- ext/gl/gstglimagesink.c | 37 +------- ext/gl/gstglstereosplit.c | 110 +++--------------------- ext/gl/gstgltestsrc.c | 70 ++------------- ext/gl/gstglutils.h | 1 - gst-libs/gst/gl/gstglbasefilter.c | 78 ++--------------- gst-libs/gst/gl/gstglutils.c | 160 ++++++++++++++++++++++++++--------- gst-libs/gst/gl/gstglutils.h | 8 +- gst-libs/gst/gl/gstglutils_private.h | 32 +++++++ 9 files changed, 197 insertions(+), 408 deletions(-) create mode 100644 gst-libs/gst/gl/gstglutils_private.h diff --git a/ext/gl/gstglbasemixer.c b/ext/gl/gstglbasemixer.c index 2611f3d..6e6e949 100644 --- a/ext/gl/gstglbasemixer.c +++ b/ext/gl/gstglbasemixer.c @@ -145,39 +145,12 @@ gst_gl_base_mixer_sink_event (GstAggregator * agg, GstAggregatorPad * bpad, static gboolean _find_local_gl_context (GstGLBaseMixer * mix) { - GstQuery *query; - GstContext *context; - const GstStructure *s; - - if (mix->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (mix), GST_PAD_SRC, + &mix->context)) return TRUE; - - query = gst_query_new_context ("gst.gl.local_context"); - if (!mix->context && gst_gl_run_query (GST_ELEMENT (mix), query, GST_PAD_SRC)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &mix->context, - NULL); - } - } - if (!mix->context - && gst_gl_run_query (GST_ELEMENT (mix), query, GST_PAD_SINK)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &mix->context, - NULL); - } - } - - GST_DEBUG_OBJECT (mix, "found local context %p", mix->context); - - gst_query_unref (query); - - if (mix->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (mix), GST_PAD_SINK, + &mix->context)) return TRUE; - return FALSE; } @@ -296,39 +269,9 @@ gst_gl_base_mixer_sink_query (GstAggregator * agg, GstAggregatorPad * bpad, } case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - - ret = gst_gl_handle_context_query ((GstElement *) mix, query, - &mix->display, &mix->priv->other_context); - if (mix->display) - gst_gl_display_filter_gl_api (mix->display, - mix_class->supported_gl_api); - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, mix->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - ret = mix->context != NULL; - } - GST_LOG_OBJECT (mix, "context query of type %s %i", context_type, ret); - - if (ret) - return ret; - + if (gst_gl_handle_context_query ((GstElement *) mix, query, + mix->display, mix->context, mix->priv->other_context)) + return TRUE; break; } default: @@ -508,46 +451,14 @@ gst_gl_base_mixer_src_activate_mode (GstAggregator * aggregator, static gboolean gst_gl_base_mixer_src_query (GstAggregator * agg, GstQuery * query) { - gboolean res = FALSE; GstGLBaseMixer *mix = GST_GL_BASE_MIXER (agg); - GstGLBaseMixerClass *mix_class = GST_GL_BASE_MIXER_GET_CLASS (mix); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - - res = gst_gl_handle_context_query ((GstElement *) mix, query, - &mix->display, &mix->priv->other_context); - if (mix->display) - gst_gl_display_filter_gl_api (mix->display, - mix_class->supported_gl_api); - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, mix->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - res = mix->context != NULL; - } - GST_LOG_OBJECT (mix, "context query of type %s %i", context_type, res); - - if (res) - return res; - + if (gst_gl_handle_context_query ((GstElement *) mix, query, + mix->display, mix->context, mix->priv->other_context)) + return TRUE; break; } default: diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c index 15ab284..79ef08e 100644 --- a/ext/gl/gstglimagesink.c +++ b/ext/gl/gstglimagesink.c @@ -1080,39 +1080,10 @@ gst_glimage_sink_query (GstBaseSink * bsink, GstQuery * query) switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - - res = gst_gl_handle_context_query ((GstElement *) glimage_sink, query, - &glimage_sink->display, &glimage_sink->other_context); - if (glimage_sink->display) - gst_gl_display_filter_gl_api (glimage_sink->display, SUPPORTED_GL_APIS); - - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, - glimage_sink->context, NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - res = glimage_sink->context != NULL; - } - GST_LOG_OBJECT (glimage_sink, "context query of type %s %i", context_type, - res); - - if (res) - return res; + if (gst_gl_handle_context_query ((GstElement *) glimage_sink, query, + glimage_sink->display, glimage_sink->context, + glimage_sink->other_context)) + return TRUE; break; } case GST_QUERY_DRAIN: diff --git a/ext/gl/gstglstereosplit.c b/ext/gl/gstglstereosplit.c index 38836ad..5650ab4 100644 --- a/ext/gl/gstglstereosplit.c +++ b/ext/gl/gstglstereosplit.c @@ -247,8 +247,8 @@ strip_mview_fields (GstCaps * incaps, GstVideoMultiviewFlags keep_flags) GstVideoMultiviewFlags flags, mask; gst_structure_remove_field (st, "multiview-mode"); - if (gst_structure_get_flagset (st, "multiview-flags", (guint*) &flags, - (guint*) &mask)) { + if (gst_structure_get_flagset (st, "multiview-flags", (guint *) & flags, + (guint *) & mask)) { flags &= keep_flags; mask = keep_flags; gst_structure_set (st, "multiview-flags", @@ -414,40 +414,12 @@ fail: static gboolean _find_local_gl_context (GstGLStereoSplit * split) { - GstQuery *query; - GstContext *context; - const GstStructure *s; - - if (split->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (split), GST_PAD_SRC, + &split->context)) return TRUE; - - query = gst_query_new_context ("gst.gl.local_context"); - if (!split->context - && gst_gl_run_query (GST_ELEMENT (split), query, GST_PAD_SRC)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &split->context, - NULL); - } - } - if (!split->context - && gst_gl_run_query (GST_ELEMENT (split), query, GST_PAD_SINK)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &split->context, - NULL); - } - } - - GST_DEBUG_OBJECT (split, "found local context %p", split->context); - - gst_query_unref (query); - - if (split->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (split), GST_PAD_SINK, + &split->context)) return TRUE; - return FALSE; } @@ -626,38 +598,9 @@ stereosplit_src_query (GstPad * pad, GstObject * parent, GstQuery * query) switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - gboolean ret; - - ret = gst_gl_handle_context_query ((GstElement *) split, query, - &split->display, &split->other_context); - if (split->display) - gst_gl_display_filter_gl_api (split->display, SUPPORTED_GL_APIS); - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, split->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - ret = split->context != NULL; - } - GST_LOG_OBJECT (split, "context query of type %s %i", context_type, ret); - - if (ret) - return ret; + if (gst_gl_handle_context_query ((GstElement *) split, query, + split->display, split->context, split->other_context)) + return TRUE; return gst_pad_query_default (pad, parent, query); } @@ -684,38 +627,9 @@ stereosplit_sink_query (GstPad * pad, GstObject * parent, GstQuery * query) switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - gboolean ret; - - ret = gst_gl_handle_context_query ((GstElement *) split, query, - &split->display, &split->other_context); - if (split->display) - gst_gl_display_filter_gl_api (split->display, SUPPORTED_GL_APIS); - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, split->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - ret = split->context != NULL; - } - GST_LOG_OBJECT (split, "context query of type %s %i", context_type, ret); - - if (ret) - return ret; + if (gst_gl_handle_context_query ((GstElement *) split, query, + split->display, split->context, split->other_context)) + return TRUE; return gst_pad_query_default (pad, parent, query); } diff --git a/ext/gl/gstgltestsrc.c b/ext/gl/gstgltestsrc.c index 11ecc1d..51c709d 100644 --- a/ext/gl/gstgltestsrc.c +++ b/ext/gl/gstgltestsrc.c @@ -326,39 +326,9 @@ gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query) switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - - res = gst_gl_handle_context_query ((GstElement *) src, query, - &src->display, &src->other_context); - if (src->display) - gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS); - - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, src->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - res = src->context != NULL; - } - GST_LOG_OBJECT (src, "context query of type %s %i", context_type, res); - - if (res) - return res; - + if (gst_gl_handle_context_query ((GstElement *) src, query, + src->display, src->context, src->other_context)) + return TRUE; break; } case GST_QUERY_CONVERT: @@ -584,39 +554,9 @@ gst_gl_test_src_stop (GstBaseSrc * basesrc) static gboolean _find_local_gl_context (GstGLTestSrc * src) { - GstQuery *query; - GstContext *context; - const GstStructure *s; - - if (src->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (src), GST_PAD_SRC, + &src->context)) return TRUE; - - query = gst_query_new_context ("gst.gl.local_context"); - if (!src->context && gst_gl_run_query (GST_ELEMENT (src), query, GST_PAD_SRC)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &src->context, - NULL); - } - } - if (!src->context - && gst_gl_run_query (GST_ELEMENT (src), query, GST_PAD_SINK)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &src->context, - NULL); - } - } - - GST_DEBUG_OBJECT (src, "found local context %p", src->context); - - gst_query_unref (query); - - if (src->context) - return TRUE; - return FALSE; } diff --git a/ext/gl/gstglutils.h b/ext/gl/gstglutils.h index ee8d363..ee7d4c6 100644 --- a/ext/gl/gstglutils.h +++ b/ext/gl/gstglutils.h @@ -25,7 +25,6 @@ G_BEGIN_DECLS -GST_EXPORT gboolean gst_gl_context_gen_shader (GstGLContext * context, const gchar * shader_vertex_source, const gchar * shader_fragment_source, GstGLShader ** shader); diff --git a/gst-libs/gst/gl/gstglbasefilter.c b/gst-libs/gst/gl/gstglbasefilter.c index e950d79..de921cf 100644 --- a/gst-libs/gst/gl/gstglbasefilter.c +++ b/gst-libs/gst/gl/gstglbasefilter.c @@ -25,6 +25,7 @@ #include #include +#include /** * SECTION:gstglbasefilter @@ -62,8 +63,7 @@ enum #define gst_gl_base_filter_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstGLBaseFilter, gst_gl_base_filter, GST_TYPE_BASE_TRANSFORM, GST_DEBUG_CATEGORY_INIT (gst_gl_base_filter_debug, - "glbasefilter", 0, "glbasefilter element"); - ); + "glbasefilter", 0, "glbasefilter element");); static void gst_gl_base_filter_finalize (GObject * object); static void gst_gl_base_filter_set_property (GObject * object, guint prop_id, @@ -192,40 +192,12 @@ gst_gl_base_filter_set_context (GstElement * element, GstContext * context) static gboolean _find_local_gl_context (GstGLBaseFilter * filter) { - GstQuery *query; - GstContext *context; - const GstStructure *s; - - if (filter->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (filter), GST_PAD_SRC, + &filter->context)) return TRUE; - - query = gst_query_new_context ("gst.gl.local_context"); - if (!filter->context - && gst_gl_run_query (GST_ELEMENT (filter), query, GST_PAD_SRC)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &filter->context, - NULL); - } - } - if (!filter->context - && gst_gl_run_query (GST_ELEMENT (filter), query, GST_PAD_SINK)) { - gst_query_parse_context (query, &context); - if (context) { - s = gst_context_get_structure (context); - gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, &filter->context, - NULL); - } - } - - GST_DEBUG_OBJECT (filter, "found local context %p", filter->context); - - gst_query_unref (query); - - if (filter->context) + if (gst_gl_query_local_gl_context (GST_ELEMENT (filter), GST_PAD_SINK, + &filter->context)) return TRUE; - return FALSE; } @@ -234,7 +206,6 @@ gst_gl_base_filter_query (GstBaseTransform * trans, GstPadDirection direction, GstQuery * query) { GstGLBaseFilter *filter = GST_GL_BASE_FILTER (trans); - GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (filter); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_ALLOCATION: @@ -249,40 +220,9 @@ gst_gl_base_filter_query (GstBaseTransform * trans, GstPadDirection direction, } case GST_QUERY_CONTEXT: { - const gchar *context_type; - GstContext *context, *old_context; - gboolean ret; - - ret = gst_gl_handle_context_query ((GstElement *) filter, query, - &filter->display, &filter->priv->other_context); - if (filter->display) - gst_gl_display_filter_gl_api (filter->display, - filter_class->supported_gl_api); - - gst_query_parse_context_type (query, &context_type); - - if (g_strcmp0 (context_type, "gst.gl.local_context") == 0) { - GstStructure *s; - - gst_query_parse_context (query, &old_context); - - if (old_context) - context = gst_context_copy (old_context); - else - context = gst_context_new ("gst.gl.local_context", FALSE); - - s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, filter->context, - NULL); - gst_query_set_context (query, context); - gst_context_unref (context); - - ret = filter->context != NULL; - } - GST_LOG_OBJECT (filter, "context query of type %s %i", context_type, ret); - - if (ret) - return ret; + if (gst_gl_handle_context_query ((GstElement *) filter, query, + filter->display, filter->context, filter->priv->other_context)) + return TRUE; break; } default: diff --git a/gst-libs/gst/gl/gstglutils.c b/gst-libs/gst/gl/gstglutils.c index 0b7d55d..b41ed8f 100644 --- a/gst-libs/gst/gl/gstglutils.c +++ b/gst-libs/gst/gl/gstglutils.c @@ -35,6 +35,7 @@ #include "gl.h" #include "gstglutils.h" +#include "gstglutils_private.h" #if GST_GL_HAVE_WINDOW_X11 #include @@ -49,6 +50,24 @@ #define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0)) #define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0)) +#ifndef GST_DISABLE_GST_DEBUG +GST_DEBUG_CATEGORY_STATIC (gst_gl_utils_debug); +static GstDebugCategory * +_init_gl_utils_debug_category (void) +{ + static volatile gsize _init = 0; + + if (g_once_init_enter (&_init)) { + GST_DEBUG_CATEGORY_INIT (gst_gl_utils_debug, "glutils", 0, + "OpenGL Utilities"); + g_once_init_leave (&_init, 1); + } + + return gst_gl_utils_debug; +} + +#define GST_CAT_DEFAULT _init_gl_utils_debug_category() +#endif static gboolean gst_gl_display_found (GstElement * element, GstGLDisplay * display) @@ -349,21 +368,24 @@ gst_gl_handle_set_context (GstElement * element, GstContext * context, gboolean gst_gl_handle_context_query (GstElement * element, GstQuery * query, - GstGLDisplay ** display, GstGLContext ** other_context) + GstGLDisplay * display, GstGLContext * gl_context, + GstGLContext * other_context) { - gboolean res = FALSE; const gchar *context_type; GstContext *context, *old_context; - g_return_val_if_fail (element != NULL, FALSE); - g_return_val_if_fail (query != NULL, FALSE); - g_return_val_if_fail (display != NULL, FALSE); - g_return_val_if_fail (other_context != NULL, FALSE); + g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); + g_return_val_if_fail (GST_IS_QUERY (query), FALSE); + g_return_val_if_fail (display == NULL || GST_IS_GL_DISPLAY (display), FALSE); + g_return_val_if_fail (gl_context == NULL + || GST_IS_GL_CONTEXT (gl_context), FALSE); + g_return_val_if_fail (other_context == NULL + || GST_IS_GL_CONTEXT (other_context), FALSE); + GST_LOG_OBJECT (element, "handle context query %" GST_PTR_FORMAT, query); gst_query_parse_context_type (query, &context_type); - if (g_strcmp0 (context_type, GST_GL_DISPLAY_CONTEXT_TYPE) == 0) { - + if (display && g_strcmp0 (context_type, GST_GL_DISPLAY_CONTEXT_TYPE) == 0) { gst_query_parse_context (query, &old_context); if (old_context) @@ -371,16 +393,17 @@ gst_gl_handle_context_query (GstElement * element, GstQuery * query, else context = gst_context_new (GST_GL_DISPLAY_CONTEXT_TYPE, TRUE); - gst_context_set_gl_display (context, *display); + gst_context_set_gl_display (context, display); gst_query_set_context (query, context); gst_context_unref (context); + GST_DEBUG_OBJECT (element, "successfully set %" GST_PTR_FORMAT + " on %" GST_PTR_FORMAT, display, query); - res = *display != NULL; + return TRUE; } #if GST_GL_HAVE_WINDOW_X11 - else if (g_strcmp0 (context_type, "gst.x11.display.handle") == 0) { + else if (display && g_strcmp0 (context_type, "gst.x11.display.handle") == 0) { GstStructure *s; - Display *x11_display = NULL; gst_query_parse_context (query, &old_context); @@ -389,24 +412,29 @@ gst_gl_handle_context_query (GstElement * element, GstQuery * query, else context = gst_context_new ("gst.x11.display.handle", TRUE); - if (*display - && ((*display)->type & GST_GL_DISPLAY_TYPE_X11) == - GST_GL_DISPLAY_TYPE_X11) - x11_display = (Display *) gst_gl_display_get_handle (*display); + if (gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_X11) { + Display *x11_display = (Display *) gst_gl_display_get_handle (display); - s = gst_context_writable_structure (context); - gst_structure_set (s, "display", G_TYPE_POINTER, x11_display, NULL); + if (x11_display) { + s = gst_context_writable_structure (context); + gst_structure_set (s, "display", G_TYPE_POINTER, x11_display, NULL); - gst_query_set_context (query, context); - gst_context_unref (context); + gst_query_set_context (query, context); + gst_context_unref (context); - res = x11_display != NULL; + GST_DEBUG_OBJECT (element, "successfully set x11 display %p (from %" + GST_PTR_FORMAT ") on %" GST_PTR_FORMAT, x11_display, display, + query); + + return TRUE; + } + } } #endif #if GST_GL_HAVE_WINDOW_WAYLAND - else if (g_strcmp0 (context_type, "GstWaylandDisplayHandleContextType") == 0) { + else if (display + && g_strcmp0 (context_type, "GstWaylandDisplayHandleContextType") == 0) { GstStructure *s; - struct wl_display *wayland_display = NULL; gst_query_parse_context (query, &old_context); @@ -415,22 +443,27 @@ gst_gl_handle_context_query (GstElement * element, GstQuery * query, else context = gst_context_new ("GstWaylandDisplayHandleContextType", TRUE); - if (*display - && ((*display)->type & GST_GL_DISPLAY_TYPE_WAYLAND) == - GST_GL_DISPLAY_TYPE_WAYLAND) - wayland_display = - (struct wl_display *) gst_gl_display_get_handle (*display); + if (gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_WAYLAND) { + struct wl_display *wayland_display = + (struct wl_display *) gst_gl_display_get_handle (display); - s = gst_context_writable_structure (context); - gst_structure_set (s, "display", G_TYPE_POINTER, wayland_display, NULL); + if (wayland_display) { + s = gst_context_writable_structure (context); + gst_structure_set (s, "display", G_TYPE_POINTER, wayland_display, NULL); - gst_query_set_context (query, context); - gst_context_unref (context); + gst_query_set_context (query, context); + gst_context_unref (context); + + GST_DEBUG_OBJECT (element, "successfully set wayland display %p (from %" + GST_PTR_FORMAT ") on %" GST_PTR_FORMAT, wayland_display, display, + query); - res = wayland_display != NULL; + return TRUE; + } + } } #endif - else if (g_strcmp0 (context_type, "gst.gl.app_context") == 0) { + else if (other_context && g_strcmp0 (context_type, "gst.gl.app_context") == 0) { GstStructure *s; gst_query_parse_context (query, &old_context); @@ -441,14 +474,65 @@ gst_gl_handle_context_query (GstElement * element, GstQuery * query, context = gst_context_new ("gst.gl.app_context", TRUE); s = gst_context_writable_structure (context); - gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, *other_context, NULL); + gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, other_context, NULL); + gst_query_set_context (query, context); + gst_context_unref (context); + + GST_DEBUG_OBJECT (element, "successfully set application GL context %" + GST_PTR_FORMAT " on %" GST_PTR_FORMAT, other_context, query); + + return TRUE; + } else if (gl_context + && g_strcmp0 (context_type, "gst.gl.local_context") == 0) { + GstStructure *s; + + gst_query_parse_context (query, &old_context); + + if (old_context) + context = gst_context_copy (old_context); + else + context = gst_context_new ("gst.gl.local_context", TRUE); + + s = gst_context_writable_structure (context); + gst_structure_set (s, "context", GST_TYPE_GL_CONTEXT, gl_context, NULL); gst_query_set_context (query, context); gst_context_unref (context); - res = *other_context != NULL; + GST_DEBUG_OBJECT (element, "successfully set GL context %" + GST_PTR_FORMAT " on %" GST_PTR_FORMAT, gl_context, query); + + return TRUE; + } + + return FALSE; +} + +gboolean +gst_gl_query_local_gl_context (GstElement * element, GstPadDirection direction, + GstGLContext ** context_ptr) +{ + GstQuery *query; + GstContext *context; + const GstStructure *s; + + g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE); + g_return_val_if_fail (context_ptr != NULL, FALSE); + + if (*context_ptr) + return TRUE; + + query = gst_query_new_context ("gst.gl.local_context"); + if (gst_gl_run_query (GST_ELEMENT (element), query, direction)) { + gst_query_parse_context (query, &context); + if (context) { + s = gst_context_get_structure (context); + gst_structure_get (s, "context", GST_TYPE_GL_CONTEXT, context_ptr, NULL); + } } - return res; + gst_query_unref (query); + + return *context_ptr != NULL; } gsize @@ -471,8 +555,6 @@ gst_gl_get_plane_data_size (GstVideoInfo * info, GstVideoAlignment * align, return plane_size; } -/* find the difference between the start of the plane and where the video - * data starts in the plane */ gsize gst_gl_get_plane_start (GstVideoInfo * info, GstVideoAlignment * valign, guint plane) diff --git a/gst-libs/gst/gl/gstglutils.h b/gst-libs/gst/gl/gstglutils.h index 942371e..e1207aa 100644 --- a/gst-libs/gst/gl/gstglutils.h +++ b/gst-libs/gst/gl/gstglutils.h @@ -36,11 +36,11 @@ gboolean gst_gl_handle_set_context (GstElement * element, GstContext * context, GstGLDisplay ** display, GstGLContext ** other_context); GST_EXPORT gboolean gst_gl_handle_context_query (GstElement * element, GstQuery * query, - GstGLDisplay ** display, GstGLContext ** other_context); - + GstGLDisplay * display, GstGLContext * context, GstGLContext * other_context); GST_EXPORT -gboolean gst_gl_run_query (GstElement * element, - GstQuery * query, GstPadDirection direction); +gboolean gst_gl_query_local_gl_context (GstElement * element, GstPadDirection direction, + GstGLContext ** context_ptr); + GST_EXPORT gsize gst_gl_get_plane_data_size (GstVideoInfo * info, GstVideoAlignment * align, guint plane); diff --git a/gst-libs/gst/gl/gstglutils_private.h b/gst-libs/gst/gl/gstglutils_private.h new file mode 100644 index 0000000..9321d8d --- /dev/null +++ b/gst-libs/gst/gl/gstglutils_private.h @@ -0,0 +1,32 @@ +/* + * GStreamer + * Copyright (C) 2017 Matthew Waters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_GL_UTILS_PRIVATE_H__ +#define __GST_GL_UTILS_PRIVATE_H__ + +#include + +G_BEGIN_DECLS + +gboolean gst_gl_run_query (GstElement * element, GstQuery * query, GstPadDirection direction); + +G_END_DECLS + +#endif /* __GST_GL_UTILS_H__ */ -- 2.7.4