2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpluginfeature.c: Abstract base class for all plugin features
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * SECTION:gstpluginfeature
25 * @short_description: Base class for contents of a GstPlugin
26 * @see_also: #GstPlugin
28 * This is a base class for anything that can be added to a #GstPlugin.
31 #include "gst_private.h"
33 #include "gstpluginfeature.h"
34 #include "gstplugin.h"
35 #include "gstregistry.h"
41 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
43 static void gst_plugin_feature_finalize (GObject * object);
45 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
47 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
50 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
52 G_OBJECT_CLASS (klass)->finalize = gst_plugin_feature_finalize;
56 gst_plugin_feature_init (GstPluginFeature * feature)
58 /* do nothing, needed because of G_DEFINE_TYPE */
62 gst_plugin_feature_finalize (GObject * object)
64 GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (object);
66 GST_DEBUG ("finalizing feature %p: '%s'", feature,
67 GST_PLUGIN_FEATURE_NAME (feature));
69 if (feature->plugin != NULL) {
70 g_object_remove_weak_pointer ((GObject *) feature->plugin,
71 (gpointer *) & feature->plugin);
74 G_OBJECT_CLASS (gst_plugin_feature_parent_class)->finalize (object);
78 * gst_plugin_feature_load:
79 * @feature: (transfer none): the plugin feature to check
81 * Loads the plugin containing @feature if it's not already loaded. @feature is
82 * unaffected; use the return value instead.
84 * Normally this function is used like this:
86 * GstPluginFeature *loaded_feature;
88 * loaded_feature = gst_plugin_feature_load (feature);
89 * // presumably, we're no longer interested in the potentially-unloaded feature
90 * gst_object_unref (feature);
91 * feature = loaded_feature;
94 * Returns: (transfer full): a reference to the loaded feature, or NULL on error
97 gst_plugin_feature_load (GstPluginFeature * feature)
100 GstPluginFeature *real_feature;
102 g_return_val_if_fail (feature != NULL, FALSE);
103 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
105 GST_DEBUG ("loading plugin for feature %p; '%s'", feature,
106 GST_PLUGIN_FEATURE_NAME (feature));
108 return gst_object_ref (feature);
110 GST_DEBUG ("loading plugin %s", feature->plugin_name);
111 plugin = gst_plugin_load_by_name (feature->plugin_name);
115 GST_DEBUG ("loaded plugin %s", feature->plugin_name);
116 gst_object_unref (plugin);
119 gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
121 if (real_feature == NULL)
123 else if (!real_feature->loaded)
131 GST_WARNING ("Failed to load plugin containing feature '%s'.",
132 GST_PLUGIN_FEATURE_NAME (feature));
138 ("Loaded plugin containing feature '%s', but feature disappeared.",
144 GST_INFO ("Tried to load plugin containing feature '%s', but feature was "
145 "not found.", real_feature->name);
151 * gst_plugin_feature_type_name_filter:
152 * @feature: the #GstPluginFeature
153 * @data: (in): the type and name to check against
155 * Compares type and name of plugin feature. Can be used with gst_filter_run().
157 * Returns: TRUE if equal.
159 #ifndef GST_REMOVE_DEPRECATED
160 #ifdef GST_DISABLE_DEPRECATED
166 gboolean gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
167 GstTypeNameData * data);
170 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
171 GstTypeNameData * data)
173 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
175 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
177 || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
179 #endif /* GST_REMOVE_DEPRECATED */
182 * gst_plugin_feature_set_name:
183 * @feature: a feature
184 * @name: the name to set
186 * Sets the name of a plugin feature. The name uniquely identifies a feature
187 * within all features of the same type. Renaming a plugin feature is not
188 * allowed. A copy is made of the name so you should free the supplied @name
189 * after calling this function.
192 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
194 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
195 g_return_if_fail (name != NULL);
197 if (G_UNLIKELY (feature->name)) {
198 g_return_if_fail (strcmp (feature->name, name) == 0);
200 gst_object_set_name (GST_OBJECT (feature), name);
201 feature->name = GST_OBJECT_NAME (GST_OBJECT (feature));
206 * gst_plugin_feature_get_name:
207 * @feature: a feature
209 * Gets the name of a plugin feature.
214 gst_plugin_feature_get_name (GstPluginFeature * feature)
216 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
218 return feature->name;
222 * gst_plugin_feature_set_rank:
223 * @feature: feature to rank
224 * @rank: rank value - higher number means more priority rank
226 * Specifies a rank for a plugin feature, so that autoplugging uses
227 * the most appropriate feature.
230 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
232 g_return_if_fail (feature != NULL);
233 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
235 feature->rank = rank;
239 * gst_plugin_feature_get_rank:
240 * @feature: a feature
242 * Gets the rank of a plugin feature.
244 * Returns: The rank of the feature
247 gst_plugin_feature_get_rank (GstPluginFeature * feature)
249 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
251 return feature->rank;
255 * gst_plugin_feature_list_free:
256 * @list: (transfer full) (element-type Gst.PluginFeature): list
257 * of #GstPluginFeature
259 * Unrefs each member of @list, then frees the list.
262 gst_plugin_feature_list_free (GList * list)
266 for (g = list; g; g = g->next) {
267 GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (g->data);
269 gst_object_unref (feature);
275 * gst_plugin_feature_list_copy:
276 * @list: (transfer none) (element-type Gst.PluginFeature): list
277 * of #GstPluginFeature
279 * Copies the list of features. Caller should call @gst_plugin_feature_list_free
280 * when done with the list.
282 * Returns: (transfer full) (element-type Gst.PluginFeature): a copy of @list,
283 * with each feature's reference count incremented.
288 gst_plugin_feature_list_copy (GList * list)
290 GList *new_list = NULL;
292 if (G_LIKELY (list)) {
295 new_list = g_list_alloc ();
296 new_list->data = g_object_ref ((GObject *) list->data);
297 new_list->prev = NULL;
301 last->next = g_list_alloc ();
302 last->next->prev = last;
304 last->data = g_object_ref ((GObject *) list->data);
314 * gst_plugin_feature_list_debug:
315 * @list: (transfer none) (element-type Gst.PluginFeature): a #GList of
318 * Debug the plugin feature names in @list.
323 gst_plugin_feature_list_debug (GList * list)
325 #ifndef GST_DISABLE_GST_DEBUG
328 gst_plugin_feature_get_name ((GstPluginFeature *) list->data));
335 * gst_plugin_feature_check_version:
336 * @feature: a feature
337 * @min_major: minimum required major version
338 * @min_minor: minimum required minor version
339 * @min_micro: minimum required micro version
341 * Checks whether the given plugin feature is at least
342 * the required version
344 * Returns: #TRUE if the plugin feature has at least
345 * the required version, otherwise #FALSE.
348 gst_plugin_feature_check_version (GstPluginFeature * feature,
349 guint min_major, guint min_minor, guint min_micro)
351 GstRegistry *registry;
353 gboolean ret = FALSE;
355 g_return_val_if_fail (feature != NULL, FALSE);
356 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
358 GST_DEBUG ("Looking up plugin '%s' containing plugin feature '%s'",
359 feature->plugin_name, feature->name);
361 registry = gst_registry_get_default ();
362 plugin = gst_registry_find_plugin (registry, feature->plugin_name);
365 const gchar *ver_str;
366 guint major, minor, micro, nano;
369 ver_str = gst_plugin_get_version (plugin);
370 g_return_val_if_fail (ver_str != NULL, FALSE);
372 nscan = sscanf (ver_str, "%u.%u.%u.%u", &major, &minor, µ, &nano);
373 GST_DEBUG ("version string '%s' parsed to %d values", ver_str, nscan);
376 if (major > min_major)
378 else if (major < min_major)
380 else if (minor > min_minor)
382 else if (minor < min_minor)
384 else if (micro > min_micro)
386 /* micro is 1 smaller but we have a nano version, this is the upcoming
387 * release of the requested version and we're ok then */
388 else if (nscan == 4 && nano > 0 && (micro + 1 == min_micro))
391 ret = (micro == min_micro);
393 GST_DEBUG ("Checking whether %u.%u.%u >= %u.%u.%u? %s", major, minor,
394 micro, min_major, min_minor, min_micro, (ret) ? "yes" : "no");
396 GST_WARNING ("Could not parse version string '%s' of plugin '%s'",
397 ver_str, feature->plugin_name);
400 gst_object_unref (plugin);
402 GST_DEBUG ("Could not find plugin '%s'", feature->plugin_name);
409 * gst_plugin_feature_rank_compare_func:
410 * @p1: a #GstPluginFeature
411 * @p2: a #GstPluginFeature
413 * Compares the two given #GstPluginFeature instances. This function can be
414 * used as a #GCompareFunc when sorting by rank and then by name.
416 * Returns: negative value if the rank of p1 > the rank of p2 or the ranks are
417 * equal but the name of p1 comes before the name of p2; zero if the rank
418 * and names are equal; positive value if the rank of p1 < the rank of p2 or the
419 * ranks are equal but the name of p2 comes after the name of p1
424 gst_plugin_feature_rank_compare_func (gconstpointer p1, gconstpointer p2)
426 GstPluginFeature *f1, *f2;
429 f1 = (GstPluginFeature *) p1;
430 f2 = (GstPluginFeature *) p2;
432 diff = f2->rank - f1->rank;
436 diff = strcmp (f2->name, f1->name);