pluginfeature: store pointer to plugin in addition to the plugin name
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 24 Apr 2011 08:53:39 +0000 (09:53 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 24 Apr 2011 10:27:19 +0000 (11:27 +0100)
So we can reliably remove plugin features for a specific plugin later.

https://bugzilla.gnome.org/show_bug.cgi?id=604094

gst/gstelementfactory.c
gst/gstpluginfeature.c
gst/gstpluginfeature.h
gst/gstregistrychunks.c
gst/gsttypefind.c

index 31b74b0..109ff57 100644 (file)
@@ -307,8 +307,12 @@ gst_element_register (GstPlugin * plugin, const gchar * name, guint rank,
 
   if (plugin && plugin->desc.name) {
     GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name;
+    GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
+    g_object_add_weak_pointer ((GObject *) plugin,
+        (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
   } else {
     GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
+    GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
   }
   gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
   GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
index 2c44034..696988c 100644 (file)
@@ -67,6 +67,11 @@ gst_plugin_feature_finalize (GObject * object)
       GST_PLUGIN_FEATURE_NAME (feature));
   g_free (feature->name);
 
+  if (feature->plugin != NULL) {
+    g_object_remove_weak_pointer ((GObject *) feature->plugin,
+        (gpointer *) & feature->plugin);
+  }
+
   G_OBJECT_CLASS (gst_plugin_feature_parent_class)->finalize (object);
 }
 
index ee615d9..b731a86 100644 (file)
@@ -84,9 +84,10 @@ struct _GstPluginFeature {
   guint          rank;
 
   const gchar   *plugin_name;
+  GstPlugin     *plugin;      /* weak ref */
 
   /*< private >*/
-  gpointer _gst_reserved[GST_PADDING];
+  gpointer _gst_reserved[GST_PADDING - 1];
 };
 
 struct _GstPluginFeatureClass {
index e308174..d30d400 100644 (file)
@@ -527,15 +527,18 @@ fail:
  */
 static gboolean
 gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
-    gchar * end, const gchar * plugin_name)
+    gchar * end, GstPlugin * plugin)
 {
   GstRegistryChunkPluginFeature *pf = NULL;
   GstPluginFeature *feature = NULL;
   const gchar *const_str, *type_name;
+  const gchar *plugin_name;
   gchar *str, *feature_name;
   GType type;
   guint i;
 
+  plugin_name = plugin->desc.name;
+
   /* unpack plugin feature strings */
   unpack_string_nocopy (*in, type_name, end, fail);
 
@@ -681,9 +684,13 @@ gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
   feature->rank = pf->rank;
 
   feature->plugin_name = plugin_name;
+  feature->plugin = plugin;
+  g_object_add_weak_pointer ((GObject *) plugin,
+      (gpointer *) & feature->plugin);
 
   gst_registry_add_feature (registry, feature);
-  GST_DEBUG ("Added feature %s", feature->name);
+  GST_DEBUG ("Added feature %s, plugin %p %s", feature->name, plugin,
+      plugin_name);
 
   return TRUE;
 
@@ -836,7 +843,7 @@ _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
   /* Load plugin features */
   for (i = 0; i < n; i++) {
     if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
-                plugin->desc.name))) {
+                plugin))) {
       GST_ERROR ("Error while loading binary feature for plugin '%s'",
           GST_STR_NULL (plugin->desc.name));
       gst_registry_remove_plugin (registry, plugin);
index e4254e1..3827265 100644 (file)
@@ -99,8 +99,12 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
   factory->user_data_notify = data_notify;
   if (plugin && plugin->desc.name) {
     GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; /* interned string */
+    GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
+    g_object_add_weak_pointer ((GObject *) plugin,
+        (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
   } else {
     GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
+    GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
   }
   GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;