plugins: rework set_context() vmethod definition
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 21 Apr 2016 10:57:30 +0000 (12:57 +0200)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Fri, 22 Apr 2016 15:18:18 +0000 (17:18 +0200)
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
gst/vaapi/gstvaapiencode.c
gst/vaapi/gstvaapipluginbase.c
gst/vaapi/gstvaapipluginbase.h
gst/vaapi/gstvaapipostproc.c
gst/vaapi/gstvaapisink.c

index 8dfb133..6b24c2d 100644 (file)
@@ -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 <gwenole.beauchesne@intel.com>, "
index 78ab552..9d79fd1 100644 (file)
@@ -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);
 
index 055bf7e..e762e1e 100644 (file)
@@ -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
index ce76d51..d51a5dc 100644 (file)
@@ -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 >*/
@@ -222,6 +232,11 @@ gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin,
 
 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,
     GstObject * object);
 
index 0aecace..a5f8a33 100644 (file)
@@ -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;"
index 8d7b6e0..c7b0ca0 100644 (file)
@@ -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,