From bccdda84b73653c96672161905ba60a9ed9b6557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 21 Apr 2016 12:57:30 +0200 Subject: [PATCH] plugins: rework set_context() vmethod definition In bug 757598 was added the set_context() vmethod chain up in GstVaapiPluginBase. But it is buggy, since the parent_class address is assigned to the last element which called gst_vaapi_plugin_base_class_init(). No error has shown up since none of the element's base classes redefined set_context() vmethod from GstElement, so always the correct function was called. Still this code is wrong and this patch make it right. Since set_context() is the same code, a macro is used to implement that code in all the gst-vaapi elements. https://bugzilla.gnome.org/show_bug.cgi?id=765368 --- gst/vaapi/gstvaapidecode.c | 2 ++ gst/vaapi/gstvaapiencode.c | 3 +++ gst/vaapi/gstvaapipluginbase.c | 29 ++++++++++++++--------------- gst/vaapi/gstvaapipluginbase.h | 15 +++++++++++++++ gst/vaapi/gstvaapipostproc.c | 3 +++ gst/vaapi/gstvaapisink.c | 3 +++ 6 files changed, 40 insertions(+), 15 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 8dfb133e08..6b24c2d326 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -160,6 +160,7 @@ static const GstVaapiDecoderMap vaapi_decode_map[] = { }; static GstElementClass *parent_class = NULL; +GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT (parent_class); static gboolean gst_vaapidecode_update_sink_caps (GstVaapiDecode * decode, GstCaps * caps); @@ -1263,6 +1264,7 @@ gst_vaapidecode_class_init (GstVaapiDecodeClass * klass) longname = g_strdup ("VA-API decoder"); } + element_class->set_context = gst_vaapi_base_set_context; gst_element_class_set_static_metadata (element_class, longname, "Codec/Decoder/Video", GST_PLUGIN_DESC, "Gwenole Beauchesne , " diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index 78ab5521d3..9d79fd10af 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -44,6 +44,8 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstVaapiEncode, gst_vaapiencode, GST_TYPE_VIDEO_ENCODER, GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES); +GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT (gst_vaapiencode_parent_class); + enum { PROP_0, @@ -629,6 +631,7 @@ gst_vaapiencode_class_init (GstVaapiEncodeClass * klass) object_class->finalize = gst_vaapiencode_finalize; + element_class->set_context = gst_vaapi_base_set_context; element_class->change_state = GST_DEBUG_FUNCPTR (gst_vaapiencode_change_state); diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index 055bf7e3cc..e762e1eec6 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -35,8 +35,6 @@ /* Default debug category is from the subclass */ #define GST_CAT_DEFAULT (plugin->debug_category) -static gpointer plugin_parent_class = NULL; - /* GstVideoContext interface */ static void plugin_set_display (GstVaapiPluginBase * plugin, GstVaapiDisplay * display) @@ -57,18 +55,25 @@ plugin_set_display (GstVaapiPluginBase * plugin, GstVaapiDisplay * display) gst_vaapi_display_unref (display); } -static void -plugin_set_context (GstElement * element, GstContext * context) +/** + * gst_vaapi_plugin_base_set_context: + * @plugin: a #GstVaapiPluginBase instance + * @context: a #GstContext to set + * + * This is a common set_context() element's vmethod for all the + * GStreamer VA-API elements. + * + * It normally should be used through the macro + * #GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT() + **/ +void +gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin, + GstContext * context) { - GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); - GstElementClass *element_class = GST_ELEMENT_CLASS (plugin_parent_class); GstVaapiDisplay *display = NULL; if (gst_vaapi_video_context_get_display (context, &display)) plugin_set_display (plugin, display); - - if (element_class->set_context) - element_class->set_context (element, context); } void @@ -180,14 +185,8 @@ error_create_proxy: void gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - klass->has_interface = default_has_interface; klass->display_changed = default_display_changed; - - plugin_parent_class = g_type_class_peek_parent (klass); - - element_class->set_context = GST_DEBUG_FUNCPTR (plugin_set_context); } void diff --git a/gst/vaapi/gstvaapipluginbase.h b/gst/vaapi/gstvaapipluginbase.h index ce76d519fc..d51a5dc850 100644 --- a/gst/vaapi/gstvaapipluginbase.h +++ b/gst/vaapi/gstvaapipluginbase.h @@ -102,6 +102,16 @@ typedef struct _GstVaapiPluginBaseClass GstVaapiPluginBaseClass; (gst_vaapi_display_replace(&GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin), \ (new_display))) +#define GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT(parent_class) \ + static void \ + gst_vaapi_base_set_context (GstElement * element, GstContext * context) \ + { \ + GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); \ + \ + gst_vaapi_plugin_base_set_context (plugin, context); \ + GST_ELEMENT_CLASS (parent_class)->set_context (element, context); \ + } + struct _GstVaapiPluginBase { /*< private >*/ @@ -220,6 +230,11 @@ GstFlowReturn gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin, GstBuffer * inbuf, GstBuffer ** outbuf_ptr); +G_GNUC_INTERNAL +void +gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin, + GstContext * context); + G_GNUC_INTERNAL void gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin, diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index 0aecace810..a5f8a3304f 100644 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -96,6 +96,8 @@ G_DEFINE_TYPE_WITH_CODE (GstVaapiPostproc, gst_vaapipostproc, G_IMPLEMENT_INTERFACE (GST_TYPE_COLOR_BALANCE, gst_vaapipostproc_colorbalance_init)); +GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT (gst_vaapipostproc_parent_class); + static GstVideoFormat native_formats[] = { GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_I420 }; @@ -1522,6 +1524,7 @@ gst_vaapipostproc_class_init (GstVaapiPostprocClass * klass) trans_class->prepare_output_buffer = gst_vaapipostproc_prepare_output_buffer; + element_class->set_context = gst_vaapi_base_set_context; gst_element_class_set_static_metadata (element_class, "VA-API video postprocessing", "Filter/Converter/Video;Filter/Converter/Video/Scaler;" diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index 8d7b6e0ca4..c7b0ca0a01 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -107,6 +107,8 @@ G_DEFINE_TYPE_WITH_CODE (GstVaapiSink, G_IMPLEMENT_INTERFACE (GST_TYPE_NAVIGATION, gst_vaapisink_navigation_iface_init)); +GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT (gst_vaapisink_parent_class); + enum { HANDOFF_SIGNAL, @@ -1663,6 +1665,7 @@ gst_vaapisink_class_init (GstVaapiSinkClass * klass) videosink_class->show_frame = GST_DEBUG_FUNCPTR (gst_vaapisink_show_frame); + element_class->set_context = gst_vaapi_base_set_context; element_class->set_bus = gst_vaapisink_set_bus; gst_element_class_set_static_metadata (element_class, "VA-API sink", "Sink/Video", GST_PLUGIN_DESC,