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"
40 #define GST_CAT_DEFAULT GST_CAT_PLUGIN_LOADING
42 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
43 static void gst_plugin_feature_init (GstPluginFeature * feature);
44 static void gst_plugin_feature_finalize (GObject * object);
46 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
48 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
49 GstObjectClass *parent_class = NULL;
52 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
54 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
56 G_OBJECT_CLASS (klass)->finalize =
57 GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
61 gst_plugin_feature_init (GstPluginFeature * feature)
67 gst_plugin_feature_finalize (GObject * object)
69 GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
71 GST_DEBUG ("finalizing feature %p", feature);
72 g_free (feature->name);
73 g_free (feature->plugin_name);
75 G_OBJECT_CLASS (parent_class)->finalize (object);
79 * gst_plugin_feature_load:
80 * @feature: the plugin feature to check
82 * Loads the plugin containing @feature if it's not already loaded. @feature is
83 * unaffected; use the return value instead.
85 * Normally this function is used like this:
88 * GstPluginFeature *loaded_feature;
89 * loaded_feature = gst_plugin_feature_load (feature);
90 * // presumably, we're no longer interested in the potentially-unloaded feature
91 * gst_object_unref (feature);
92 * feature = loaded_feature;
95 * Returns: A reference to the loaded feature, or NULL on error.
98 gst_plugin_feature_load (GstPluginFeature * feature)
101 GstPluginFeature *real_feature;
103 g_return_val_if_fail (feature != NULL, FALSE);
104 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
106 GST_DEBUG ("loading plugin for feature %p", feature);
110 GST_DEBUG ("loading plugin %s", feature->plugin_name);
111 plugin = gst_plugin_load_by_name (feature->plugin_name);
113 g_critical ("Failed to load plugin containing feature '%s'.",
114 GST_PLUGIN_FEATURE_NAME (feature));
117 GST_DEBUG ("loaded plugin %s", feature->plugin_name);
118 gst_object_unref (plugin);
121 gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
123 if (real_feature == NULL) {
125 ("Loaded plugin containing feature '%s', but feature disappeared.",
127 } else if (!real_feature->loaded) {
128 GST_INFO ("Tried to load plugin containing feature '%s', but feature was "
129 "not found.", real_feature->name);
137 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
138 GstTypeNameData * data)
140 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
142 || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
146 * gst_plugin_feature_set_name:
147 * @feature: a feature
148 * @name: the name to set
150 * Sets the name of a plugin feature. The name uniquely identifies a feature
151 * within all features of the same type. Renaming a plugin feature is not
152 * allowed. A copy is made of the name so you should free the supplied @name
153 * after calling this function.
156 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
158 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
159 g_return_if_fail (name != NULL);
162 g_return_if_fail (strcmp (feature->name, name) == 0);
164 feature->name = g_strdup (name);
166 gst_object_set_name (GST_OBJECT (feature), feature->name);
170 * gst_plugin_feature_get_name:
171 * @feature: a feature
173 * Gets the name of a plugin feature.
177 G_CONST_RETURN gchar *
178 gst_plugin_feature_get_name (GstPluginFeature * feature)
180 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
182 return feature->name;
186 * gst_plugin_feature_set_rank:
187 * @feature: feature to rank
188 * @rank: rank value - higher number means more priority rank
190 * Specifies a rank for a plugin feature, so that autoplugging uses
191 * the most appropriate feature.
194 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
196 g_return_if_fail (feature != NULL);
197 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
199 feature->rank = rank;
203 * gst_plugin_feature_get_rank:
204 * @feature: a feature
206 * Gets the rank of a plugin feature.
208 * Returns: The rank of the feature
211 gst_plugin_feature_get_rank (GstPluginFeature * feature)
213 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
215 return feature->rank;
219 * gst_plugin_feature_list_free:
220 * @list: list of #GstPluginFeature
222 * Unrefs each member of @list, then frees the list.
225 gst_plugin_feature_list_free (GList * list)
229 for (g = list; g; g = g->next) {
230 GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
232 gst_object_unref (feature);
238 * gst_plugin_feature_check_version:
239 * @feature: a feature
240 * @min_major: minimum required major version
241 * @min_minor: minimum required minor version
242 * @min_micro: minimum required micro version
244 * Checks whether the given plugin feature is at least
245 * the required version
247 * Returns: #TRUE if the plugin feature has at least
248 * the required version, otherwise #FALSE.
251 gst_plugin_feature_check_version (GstPluginFeature * feature,
252 guint min_major, guint min_minor, guint min_micro)
254 GstRegistry *registry;
256 gboolean ret = FALSE;
258 g_return_val_if_fail (feature != NULL, FALSE);
259 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
261 GST_DEBUG ("Looking up plugin '%s' containing plugin feature '%s'",
262 feature->plugin_name, feature->name);
264 registry = gst_registry_get_default ();
265 plugin = gst_registry_find_plugin (registry, feature->plugin_name);
268 const gchar *ver_str;
269 guint major, minor, micro;
271 ver_str = gst_plugin_get_version (plugin);
272 g_return_val_if_fail (ver_str != NULL, FALSE);
274 if (sscanf (ver_str, "%u.%u.%u", &major, &minor, µ) == 3) {
275 if (major > min_major)
277 else if (major < min_major)
279 else if (minor > min_minor)
281 else if (minor < min_minor)
283 else if (micro > min_micro)
286 ret = (micro == min_micro);
288 GST_DEBUG ("Checking whether %u.%u.%u >= %u.%u.%u? %s", major, minor,
289 micro, min_major, min_minor, min_micro, (ret) ? "yes" : "no");
291 GST_WARNING ("Could not parse version string '%s' of plugin '%s'",
292 ver_str, feature->plugin_name);
295 gst_object_unref (plugin);
297 GST_DEBUG ("Could not find plugin '%s'", feature->plugin_name);