From 51620950e4c10077c0b1000706900f5ca338d52c Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 13 Mar 2015 09:38:54 +0000 Subject: [PATCH] gl: retreive the gldisplay/app gl context as soon as possible fixes the usage of gst_gl_display_filter_gl_api --- ext/gl/gstglbasemixer.c | 38 ++++++++++++++++ ext/gl/gstglimagesink.c | 12 +++-- ext/gl/gstgltestsrc.c | 37 ++++++++++++++++ gst-libs/gst/gl/gstglbasefilter.c | 74 ++++++++++++++++++------------- gst-libs/gst/gl/gstglfilter.c | 4 -- 5 files changed, 123 insertions(+), 42 deletions(-) diff --git a/ext/gl/gstglbasemixer.c b/ext/gl/gstglbasemixer.c index 20cc3c5771..f2eaa2f271 100644 --- a/ext/gl/gstglbasemixer.c +++ b/ext/gl/gstglbasemixer.c @@ -45,6 +45,8 @@ static void gst_gl_base_mixer_pad_finalize (GObject * object); static void gst_gl_base_mixer_set_context (GstElement * element, GstContext * context); +static GstStateChangeReturn gst_gl_base_mixer_change_state (GstElement * + element, GstStateChange transition); enum { @@ -280,6 +282,7 @@ gst_gl_base_mixer_class_init (GstGLBaseMixerClass * klass) element_class->set_context = GST_DEBUG_FUNCPTR (gst_gl_base_mixer_set_context); + element_class->change_state = gst_gl_base_mixer_change_state; agg_class->sinkpads_type = GST_TYPE_GL_BASE_MIXER_PAD; agg_class->sink_query = gst_gl_base_mixer_sink_query; @@ -692,3 +695,38 @@ gst_gl_base_mixer_stop (GstAggregator * agg) return TRUE; } + +static GstStateChangeReturn +gst_gl_base_mixer_change_state (GstElement * element, GstStateChange transition) +{ + GstGLBaseMixer *mix = GST_GL_BASE_MIXER (element); + GstGLBaseMixerClass *mix_class = GST_GL_BASE_MIXER_GET_CLASS (mix); + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + + GST_DEBUG_OBJECT (mix, "changing state: %s => %s", + gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), + gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition))); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + if (!gst_gl_ensure_element_data (element, &mix->display, + &mix->priv->other_context)) + return GST_STATE_CHANGE_FAILURE; + + gst_gl_display_filter_gl_api (mix->display, mix_class->supported_gl_api); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; + + switch (transition) { + default: + break; + } + + return ret; +} diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c index da8950907f..19289579d1 100644 --- a/ext/gl/gstglimagesink.c +++ b/ext/gl/gstglimagesink.c @@ -610,12 +610,6 @@ _ensure_gl_setup (GstGLImageSink * gl_sink) GST_DEBUG_OBJECT (gl_sink, "Ensuring setup"); - if (!gst_gl_ensure_element_data (gl_sink, &gl_sink->display, - &gl_sink->other_context)) - return FALSE; - - gst_gl_display_filter_gl_api (gl_sink->display, SUPPORTED_GL_APIS); - if (!gl_sink->context) { do { GstGLContext *other_context; @@ -819,7 +813,11 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition) switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: - _ensure_gl_setup (glimage_sink); + if (!gst_gl_ensure_element_data (glimage_sink, &glimage_sink->display, + &glimage_sink->other_context)) + return GST_STATE_CHANGE_FAILURE; + + gst_gl_display_filter_gl_api (glimage_sink->display, SUPPORTED_GL_APIS); break; case GST_STATE_CHANGE_READY_TO_PAUSED: g_atomic_int_set (&glimage_sink->to_quit, 0); diff --git a/ext/gl/gstgltestsrc.c b/ext/gl/gstgltestsrc.c index 5434242e80..dbd5610f13 100644 --- a/ext/gl/gstgltestsrc.c +++ b/ext/gl/gstgltestsrc.c @@ -92,6 +92,8 @@ static gboolean gst_gl_test_src_do_seek (GstBaseSrc * bsrc, static gboolean gst_gl_test_src_query (GstBaseSrc * bsrc, GstQuery * query); static void gst_gl_test_src_set_context (GstElement * element, GstContext * context); +static GstStateChangeReturn gst_gl_test_src_change_state (GstElement * element, + GstStateChange transition); static void gst_gl_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer, GstClockTime * start, GstClockTime * end); @@ -178,6 +180,7 @@ gst_gl_test_src_class_init (GstGLTestSrcClass * klass) gst_static_pad_template_get (&src_factory)); element_class->set_context = gst_gl_test_src_set_context; + element_class->change_state = gst_gl_test_src_change_state; gstbasesrc_class->set_caps = gst_gl_test_src_setcaps; gstbasesrc_class->get_caps = gst_gl_test_src_getcaps; @@ -901,3 +904,37 @@ gst_gl_test_src_callback (gpointer stuff) gst_buffer_unref (src->buffer); src->buffer = NULL; } + +static GstStateChangeReturn +gst_gl_test_src_change_state (GstElement * element, GstStateChange transition) +{ + GstGLTestSrc *src = GST_GL_TEST_SRC (element); + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + + GST_DEBUG_OBJECT (src, "changing state: %s => %s", + gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), + gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition))); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + if (!gst_gl_ensure_element_data (element, &src->display, + &src->other_context)) + return GST_STATE_CHANGE_FAILURE; + + gst_gl_display_filter_gl_api (src->display, SUPPORTED_GL_APIS); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; + + switch (transition) { + default: + break; + } + + return ret; +} diff --git a/gst-libs/gst/gl/gstglbasefilter.c b/gst-libs/gst/gl/gstglbasefilter.c index 5b207eb49b..e61d7f77d6 100644 --- a/gst-libs/gst/gl/gstglbasefilter.c +++ b/gst-libs/gst/gl/gstglbasefilter.c @@ -49,7 +49,8 @@ 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_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -58,6 +59,8 @@ static void gst_gl_base_filter_get_property (GObject * object, guint prop_id, static void gst_gl_base_filter_set_context (GstElement * element, GstContext * context); +static GstStateChangeReturn gst_gl_base_filter_change_state (GstElement * + element, GstStateChange transition); static gboolean gst_gl_base_filter_query (GstBaseTransform * trans, GstPadDirection direction, GstQuery * query); static void gst_gl_base_filter_reset (GstGLBaseFilter * filter); @@ -95,6 +98,7 @@ gst_gl_base_filter_class_init (GstGLBaseFilterClass * klass) gst_gl_base_filter_propose_allocation; element_class->set_context = gst_gl_base_filter_set_context; + element_class->change_state = gst_gl_base_filter_change_state; g_object_class_install_property (gobject_class, PROP_CONTEXT, g_param_spec_object ("context", @@ -191,24 +195,6 @@ _find_local_gl_context (GstGLBaseFilter * filter) return FALSE; } -static gboolean -_ensure_gl_setup (GstGLBaseFilter * filter) -{ - GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (filter); - - if (!gst_gl_ensure_element_data (filter, &filter->display, - &filter->priv->other_context)) { - return FALSE; - } - - gst_gl_display_filter_gl_api (filter->display, - filter_class->supported_gl_api); - - _find_local_gl_context (filter); - - return TRUE; -} - static gboolean gst_gl_base_filter_query (GstBaseTransform * trans, GstPadDirection direction, GstQuery * query) @@ -221,8 +207,7 @@ gst_gl_base_filter_query (GstBaseTransform * trans, GstPadDirection direction, { if (direction == GST_PAD_SINK && gst_base_transform_is_passthrough (trans)) { - if (!_ensure_gl_setup (filter)) - return FALSE; + _find_local_gl_context (filter); return gst_pad_peer_query (GST_BASE_TRANSFORM_SRC_PAD (trans), query); } @@ -303,16 +288,6 @@ gst_gl_base_filter_reset (GstGLBaseFilter * filter) static gboolean gst_gl_base_filter_start (GstBaseTransform * bt) { - GstGLBaseFilter *filter = GST_GL_BASE_FILTER (bt); - GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (filter); - - if (!gst_gl_ensure_element_data (filter, &filter->display, - &filter->priv->other_context)) - return FALSE; - - gst_gl_display_filter_gl_api (filter->display, - filter_class->supported_gl_api); - return TRUE; } @@ -401,3 +376,40 @@ gst_gl_base_filter_propose_allocation (GstBaseTransform * trans, { return FALSE; } + +static GstStateChangeReturn +gst_gl_base_filter_change_state (GstElement * element, + GstStateChange transition) +{ + GstGLBaseFilter *filter = GST_GL_BASE_FILTER (element); + GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (filter); + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + + GST_DEBUG_OBJECT (filter, "changing state: %s => %s", + gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)), + gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition))); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + if (!gst_gl_ensure_element_data (element, &filter->display, + &filter->priv->other_context)) + return GST_STATE_CHANGE_FAILURE; + + gst_gl_display_filter_gl_api (filter->display, + filter_class->supported_gl_api); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; + + switch (transition) { + default: + break; + } + + return ret; +} diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c index 55ded8ad93..cc07954ae6 100644 --- a/gst-libs/gst/gl/gstglfilter.c +++ b/gst-libs/gst/gl/gstglfilter.c @@ -169,10 +169,6 @@ gst_gl_filter_start (GstBaseTransform * bt) { GstGLFilter *filter = GST_GL_FILTER (bt); GstGLFilterClass *filter_class = GST_GL_FILTER_GET_CLASS (filter); - GstGLDisplay *display = GST_GL_BASE_FILTER (bt)->display; - - if (display) - gst_gl_display_filter_gl_api (display, filter_class->supported_gl_api); if (filter_class->onStart) filter_class->onStart (filter);