From 3e16a6a2e773c68e18346030eaa6efce0ab927ec Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 15 Jan 2016 00:02:43 +1100 Subject: [PATCH] glbasefilter: add a class function on set_caps (from GL) This is simply a convenience to avoid duplicating the thread marshalling on set_caps. --- gst-libs/gst/gl/gstglbasefilter.c | 46 +++++++++++++++++++++++++++++-- gst-libs/gst/gl/gstglbasefilter.h | 5 ++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/gl/gstglbasefilter.c b/gst-libs/gst/gl/gstglbasefilter.c index c5d330ebf6..2e3da4540c 100644 --- a/gst-libs/gst/gl/gstglbasefilter.c +++ b/gst-libs/gst/gl/gstglbasefilter.c @@ -50,9 +50,9 @@ 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, const GValue * value, GParamSpec * pspec); static void gst_gl_base_filter_get_property (GObject * object, guint prop_id, @@ -67,6 +67,8 @@ static gboolean gst_gl_base_filter_query (GstBaseTransform * trans, static void gst_gl_base_filter_reset (GstGLBaseFilter * filter); static gboolean gst_gl_base_filter_start (GstBaseTransform * bt); static gboolean gst_gl_base_filter_stop (GstBaseTransform * bt); +static gboolean gst_gl_base_filter_set_caps (GstBaseTransform * bt, + GstCaps * incaps, GstCaps * outcaps); static gboolean gst_gl_base_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query); @@ -85,10 +87,12 @@ gst_gl_base_filter_class_init (GstGLBaseFilterClass * klass) gobject_class = (GObjectClass *) klass; element_class = GST_ELEMENT_CLASS (klass); + gobject_class->finalize = gst_gl_base_filter_finalize; gobject_class->set_property = gst_gl_base_filter_set_property; gobject_class->get_property = gst_gl_base_filter_get_property; GST_BASE_TRANSFORM_CLASS (klass)->query = gst_gl_base_filter_query; + GST_BASE_TRANSFORM_CLASS (klass)->set_caps = gst_gl_base_filter_set_caps; GST_BASE_TRANSFORM_CLASS (klass)->start = gst_gl_base_filter_start; GST_BASE_TRANSFORM_CLASS (klass)->stop = gst_gl_base_filter_stop; GST_BASE_TRANSFORM_CLASS (klass)->decide_allocation = @@ -112,6 +116,17 @@ gst_gl_base_filter_init (GstGLBaseFilter * filter) filter->priv = GST_GL_BASE_FILTER_GET_PRIVATE (filter); } +static void +gst_gl_base_filter_finalize (GObject * object) +{ + GstGLBaseFilter *filter = GST_GL_BASE_FILTER (object); + + gst_caps_replace (&filter->in_caps, NULL); + gst_caps_replace (&filter->out_caps, NULL); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + static void gst_gl_base_filter_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) @@ -325,6 +340,16 @@ gst_gl_base_filter_gl_stop (GstGLContext * context, gpointer data) filter->priv->gl_started = FALSE; } +static void +_gl_set_caps (GstGLContext * context, GstGLBaseFilter * filter) +{ + GstGLBaseFilterClass *filter_class = GST_GL_BASE_FILTER_GET_CLASS (filter); + + if (filter_class->gl_set_caps) + filter->priv->gl_result = + filter_class->gl_set_caps (filter, filter->in_caps, filter->out_caps); +} + static gboolean gst_gl_base_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query) @@ -369,6 +394,11 @@ gst_gl_base_filter_decide_allocation (GstBaseTransform * trans, goto error; } + gst_gl_context_thread_add (filter->context, + (GstGLContextThreadFunc) _gl_set_caps, filter); + if (!filter->priv->gl_result) + goto error; + return GST_BASE_TRANSFORM_CLASS (parent_class)->decide_allocation (trans, query); @@ -387,6 +417,18 @@ error: } } +static gboolean +gst_gl_base_filter_set_caps (GstBaseTransform * bt, GstCaps * incaps, + GstCaps * outcaps) +{ + GstGLBaseFilter *filter = GST_GL_BASE_FILTER (bt); + + gst_caps_replace (&filter->in_caps, incaps); + gst_caps_replace (&filter->out_caps, outcaps); + + return TRUE; +} + static GstStateChangeReturn gst_gl_base_filter_change_state (GstElement * element, GstStateChange transition) diff --git a/gst-libs/gst/gl/gstglbasefilter.h b/gst-libs/gst/gl/gstglbasefilter.h index 5ed398097f..84f7a96e3a 100644 --- a/gst-libs/gst/gl/gstglbasefilter.h +++ b/gst-libs/gst/gl/gstglbasefilter.h @@ -55,6 +55,9 @@ struct _GstGLBaseFilter GstGLDisplay *display; GstGLContext *context; + GstCaps *in_caps; + GstCaps *out_caps; + /* */ gpointer _padding[GST_PADDING]; @@ -66,6 +69,7 @@ struct _GstGLBaseFilter * @base_transform_class: parent class * @gl_start: called in the GL thread to setup the element GL state. * @gl_stop: called in the GL thread to setup the element GL state. + * @gl_set_caps: called in the GL thread when caps are set on @filter. */ struct _GstGLBaseFilterClass { @@ -74,6 +78,7 @@ struct _GstGLBaseFilterClass gboolean (*gl_start) (GstGLBaseFilter *filter); void (*gl_stop) (GstGLBaseFilter *filter); + gboolean (*gl_set_caps) (GstGLBaseFilter *filter, GstCaps * incaps, GstCaps * outcaps); gpointer _padding[GST_PADDING]; };