tests: fix tests when compiling with glib_checks=disabled
[platform/upstream/gstreamer.git] / gst / gstpluginfeature.c
index 0ca7ab5..831236e 100644 (file)
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
  * SECTION:gstpluginfeature
+ * @title: GstPluginfeature
  * @short_description: Base class for contents of a GstPlugin
  * @see_also: #GstPlugin
  *
@@ -45,13 +46,10 @@ static void gst_plugin_feature_finalize (GObject * object);
 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
 
 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
-static GstObjectClass *parent_class = NULL;
 
 static void
 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
 {
-  parent_class = g_type_class_peek_parent (klass);
-
   G_OBJECT_CLASS (klass)->finalize = gst_plugin_feature_finalize;
 }
 
@@ -66,31 +64,35 @@ gst_plugin_feature_finalize (GObject * object)
 {
   GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (object);
 
-  GST_DEBUG ("finalizing feature %p: '%s'", feature,
-      GST_PLUGIN_FEATURE_NAME (feature));
-  g_free (feature->name);
+  GST_DEBUG ("finalizing feature %p: '%s'", feature, GST_OBJECT_NAME (feature));
+
+  if (feature->plugin != NULL) {
+    g_object_remove_weak_pointer ((GObject *) feature->plugin,
+        (gpointer *) & feature->plugin);
+  }
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gst_plugin_feature_parent_class)->finalize (object);
 }
 
 /**
  * gst_plugin_feature_load:
- * @feature: the plugin feature to check
+ * @feature: (transfer none): the plugin feature to check
  *
  * Loads the plugin containing @feature if it's not already loaded. @feature is
  * unaffected; use the return value instead.
  *
  * Normally this function is used like this:
- * |[
+ * |[<!-- language="C" -->
  * GstPluginFeature *loaded_feature;
- * 
+ *
  * loaded_feature = gst_plugin_feature_load (feature);
  * // presumably, we're no longer interested in the potentially-unloaded feature
  * gst_object_unref (feature);
  * feature = loaded_feature;
  * ]|
  *
- * Returns: A reference to the loaded feature, or NULL on error.
+ * Returns: (transfer full) (nullable): a reference to the loaded
+ * feature, or %NULL on error
  */
 GstPluginFeature *
 gst_plugin_feature_load (GstPluginFeature * feature)
@@ -102,7 +104,7 @@ gst_plugin_feature_load (GstPluginFeature * feature)
   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
 
   GST_DEBUG ("loading plugin for feature %p; '%s'", feature,
-      GST_PLUGIN_FEATURE_NAME (feature));
+      GST_OBJECT_NAME (feature));
   if (feature->loaded)
     return gst_object_ref (feature);
 
@@ -114,8 +116,8 @@ gst_plugin_feature_load (GstPluginFeature * feature)
   GST_DEBUG ("loaded plugin %s", feature->plugin_name);
   gst_object_unref (plugin);
 
-  real_feature =
-      gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
+  real_feature = gst_registry_lookup_feature (gst_registry_get (),
+      GST_OBJECT_NAME (feature));
 
   if (real_feature == NULL)
     goto disappeared;
@@ -128,120 +130,105 @@ gst_plugin_feature_load (GstPluginFeature * feature)
 load_failed:
   {
     GST_WARNING ("Failed to load plugin containing feature '%s'.",
-        GST_PLUGIN_FEATURE_NAME (feature));
+        GST_OBJECT_NAME (feature));
     return NULL;
   }
 disappeared:
   {
     GST_INFO
         ("Loaded plugin containing feature '%s', but feature disappeared.",
-        feature->name);
+        GST_OBJECT_NAME (feature));
     return NULL;
   }
 not_found:
   {
     GST_INFO ("Tried to load plugin containing feature '%s', but feature was "
-        "not found.", real_feature->name);
+        "not found.", GST_OBJECT_NAME (real_feature));
     return NULL;
   }
 }
 
 /**
- * gst_plugin_feature_type_name_filter:
- * @feature: the #GstPluginFeature
- * @data: the type and name to check against
- *
- * Compares type and name of plugin feature. Can be used with gst_filter_run().
+ * gst_plugin_feature_set_rank:
+ * @feature: feature to rank
+ * @rank: rank value - higher number means more priority rank
  *
- * Returns: TRUE if equal.
+ * Specifies a rank for a plugin feature, so that autoplugging uses
+ * the most appropriate feature.
  */
-gboolean
-gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
-    GstTypeNameData * data)
+void
+gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
 {
-  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
+  g_return_if_fail (feature != NULL);
+  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
 
-  return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
-      (data->name == NULL
-          || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
+  feature->rank = rank;
 }
 
 /**
- * gst_plugin_feature_set_name:
+ * gst_plugin_feature_get_rank:
  * @feature: a feature
- * @name: the name to set
  *
- * Sets the name of a plugin feature. The name uniquely identifies a feature
- * within all features of the same type. Renaming a plugin feature is not
- * allowed. A copy is made of the name so you should free the supplied @name
- * after calling this function.
+ * Gets the rank of a plugin feature.
+ *
+ * Returns: The rank of the feature
  */
-void
-gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
+guint
+gst_plugin_feature_get_rank (GstPluginFeature * feature)
 {
-  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
-  g_return_if_fail (name != NULL);
+  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
 
-  if (feature->name) {
-    g_return_if_fail (strcmp (feature->name, name) == 0);
-  } else {
-    feature->name = g_strdup (name);
-  }
-  gst_object_set_name (GST_OBJECT_CAST (feature), feature->name);
+  return feature->rank;
 }
 
 /**
- * gst_plugin_feature_get_name:
+ * gst_plugin_feature_get_plugin:
  * @feature: a feature
  *
- * Gets the name of a plugin feature.
+ * Get the plugin that provides this feature.
  *
- * Returns: the name
+ * Returns: (transfer full) (nullable): the plugin that provides this
+ *     feature, or %NULL.  Unref with gst_object_unref() when no
+ *     longer needed.
  */
-G_CONST_RETURN gchar *
-gst_plugin_feature_get_name (GstPluginFeature * feature)
+GstPlugin *
+gst_plugin_feature_get_plugin (GstPluginFeature * feature)
 {
   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
 
-  return feature->name;
-}
-
-/**
- * gst_plugin_feature_set_rank:
- * @feature: feature to rank
- * @rank: rank value - higher number means more priority rank
- *
- * Specifies a rank for a plugin feature, so that autoplugging uses
- * the most appropriate feature.
- */
-void
-gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
-{
-  g_return_if_fail (feature != NULL);
-  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
+  if (feature->plugin == NULL)
+    return NULL;
 
-  feature->rank = rank;
+  return (GstPlugin *) gst_object_ref (feature->plugin);
 }
 
 /**
- * gst_plugin_feature_get_rank:
+ * gst_plugin_feature_get_plugin_name:
  * @feature: a feature
  *
- * Gets the rank of a plugin feature.
+ * Get the name of the plugin that provides this feature.
  *
- * Returns: The rank of the feature
+ * Returns: (nullable): the name of the plugin that provides this
+ *     feature, or %NULL if the feature is not associated with a
+ *     plugin.
+ *
+ * Since: 1.2
  */
-guint
-gst_plugin_feature_get_rank (GstPluginFeature * feature)
+const gchar *
+gst_plugin_feature_get_plugin_name (GstPluginFeature * feature)
 {
-  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
+  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
 
-  return feature->rank;
+  if (feature->plugin == NULL)
+    return NULL;
+
+  return gst_plugin_get_name (feature->plugin);
 }
 
 /**
  * gst_plugin_feature_list_free:
- * @list: list of #GstPluginFeature
+ * @list: (transfer full) (element-type Gst.PluginFeature): list
+ *     of #GstPluginFeature
  *
  * Unrefs each member of @list, then frees the list.
  */
@@ -260,14 +247,14 @@ gst_plugin_feature_list_free (GList * list)
 
 /**
  * gst_plugin_feature_list_copy:
- * @list: list of #GstPluginFeature
+ * @list: (transfer none) (element-type Gst.PluginFeature): list
+ *     of #GstPluginFeature
  *
  * Copies the list of features. Caller should call @gst_plugin_feature_list_free
  * when done with the list.
  *
- * Returns: a copy of @list, with each feature's reference count incremented.
- *
- * Since: 0.10.26
+ * Returns: (transfer full) (element-type Gst.PluginFeature): a copy of @list,
+ *     with each feature's reference count incremented.
  */
 GList *
 gst_plugin_feature_list_copy (GList * list)
@@ -278,7 +265,7 @@ gst_plugin_feature_list_copy (GList * list)
     GList *last;
 
     new_list = g_list_alloc ();
-    new_list->data = g_object_ref ((GObject *) list->data);
+    new_list->data = gst_object_ref (list->data);
     new_list->prev = NULL;
     last = new_list;
     list = list->next;
@@ -286,7 +273,7 @@ gst_plugin_feature_list_copy (GList * list)
       last->next = g_list_alloc ();
       last->next->prev = last;
       last = last->next;
-      last->data = g_object_ref ((GObject *) list->data);
+      last->data = gst_object_ref (list->data);
       list = list->next;
     }
     last->next = NULL;
@@ -296,6 +283,25 @@ gst_plugin_feature_list_copy (GList * list)
 }
 
 /**
+ * gst_plugin_feature_list_debug:
+ * @list: (transfer none) (element-type Gst.PluginFeature): a #GList of
+ *     plugin features
+ *
+ * Debug the plugin feature names in @list.
+ */
+void
+gst_plugin_feature_list_debug (GList * list)
+{
+#ifndef GST_DISABLE_GST_DEBUG
+  while (list) {
+    GST_DEBUG ("%s",
+        gst_plugin_feature_get_name ((GstPluginFeature *) list->data));
+    list = list->next;
+  }
+#endif
+}
+
+/**
  * gst_plugin_feature_check_version:
  * @feature: a feature
  * @min_major: minimum required major version
@@ -305,8 +311,8 @@ gst_plugin_feature_list_copy (GList * list)
  * Checks whether the given plugin feature is at least
  *  the required version
  *
- * Returns: #TRUE if the plugin feature has at least
- *  the required version, otherwise #FALSE.
+ * Returns: %TRUE if the plugin feature has at least
+ *  the required version, otherwise %FALSE.
  */
 gboolean
 gst_plugin_feature_check_version (GstPluginFeature * feature,
@@ -320,9 +326,9 @@ gst_plugin_feature_check_version (GstPluginFeature * feature,
   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
 
   GST_DEBUG ("Looking up plugin '%s' containing plugin feature '%s'",
-      feature->plugin_name, feature->name);
+      feature->plugin_name, GST_OBJECT_NAME (feature));
 
-  registry = gst_registry_get_default ();
+  registry = gst_registry_get ();
   plugin = gst_registry_find_plugin (registry, feature->plugin_name);
 
   if (plugin) {
@@ -347,7 +353,7 @@ gst_plugin_feature_check_version (GstPluginFeature * feature,
         ret = FALSE;
       else if (micro > min_micro)
         ret = TRUE;
-      /* micro is 1 smaller but we have a nano version, this is the upcomming
+      /* micro is 1 smaller but we have a nano version, this is the upcoming
        * release of the requested version and we're ok then */
       else if (nscan == 4 && nano > 0 && (micro + 1 == min_micro))
         ret = TRUE;
@@ -368,3 +374,34 @@ gst_plugin_feature_check_version (GstPluginFeature * feature,
 
   return ret;
 }
+
+/**
+ * gst_plugin_feature_rank_compare_func:
+ * @p1: a #GstPluginFeature
+ * @p2: a #GstPluginFeature
+ *
+ * Compares the two given #GstPluginFeature instances. This function can be
+ * used as a #GCompareFunc when sorting by rank and then by name.
+ *
+ * Returns: negative value if the rank of p1 > the rank of p2 or the ranks are
+ * equal but the name of p1 comes before the name of p2; zero if the rank
+ * and names are equal; positive value if the rank of p1 < the rank of p2 or the
+ * ranks are equal but the name of p2 comes before the name of p1
+ */
+gint
+gst_plugin_feature_rank_compare_func (gconstpointer p1, gconstpointer p2)
+{
+  GstPluginFeature *f1, *f2;
+  gint diff;
+
+  f1 = (GstPluginFeature *) p1;
+  f2 = (GstPluginFeature *) p2;
+
+  diff = f2->rank - f1->rank;
+  if (diff != 0)
+    return diff;
+
+  diff = strcmp (GST_OBJECT_NAME (f1), GST_OBJECT_NAME (f2));
+
+  return diff;
+}