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.
23 #include "gst_private.h"
25 #include "gstpluginfeature.h"
26 #include "gstplugin.h"
27 #include "gstregistry.h"
32 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
33 static void gst_plugin_feature_init (GstPluginFeature * feature);
34 static void gst_plugin_feature_finalize (GObject * object);
36 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
38 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
39 GstObjectClass *parent_class = NULL;
42 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
44 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
46 G_OBJECT_CLASS (klass)->finalize =
47 GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
51 gst_plugin_feature_init (GstPluginFeature * feature)
57 gst_plugin_feature_finalize (GObject * object)
59 GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
61 GST_DEBUG ("finalizing feature %p", feature);
62 g_free (feature->name);
63 g_free (feature->plugin_name);
65 G_OBJECT_CLASS (parent_class)->finalize (object);
69 * gst_plugin_feature_load:
70 * @feature: the plugin feature to check
72 * Check if the plugin containing the feature is loaded,
73 * if not, the plugin will be loaded.
75 * Returns: The new feature
78 gst_plugin_feature_load (GstPluginFeature * feature)
81 GstPluginFeature *real_feature;
83 g_return_val_if_fail (feature != NULL, FALSE);
84 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
86 GST_DEBUG ("loading plugin for feature %p", feature);
90 GST_DEBUG ("loading plugin %s", feature->plugin_name);
91 plugin = gst_plugin_load_by_name (feature->plugin_name);
93 g_critical ("Failed to load plugin containing feature '%s'.",
94 GST_PLUGIN_FEATURE_NAME (feature));
97 GST_DEBUG ("loaded plugin %s", feature->plugin_name);
98 gst_object_unref (plugin);
101 gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
103 if (real_feature == NULL) {
105 ("Loaded plugin containing feature '%s', but feature disappeared.",
108 gst_object_unref (feature);
114 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
115 GstTypeNameData * data)
117 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
119 || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
123 * gst_plugin_feature_set_name:
124 * @feature: a feature
125 * @name: the name to set
127 * Sets the name of a plugin feature. The name uniquely identifies a feature
128 * within all features of the same type. Renaming a plugin feature is not
129 * allowed. A copy is made of the name so you should free the supplied @name
130 * after calling this function.
133 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
135 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
136 g_return_if_fail (name != NULL);
139 g_return_if_fail (strcmp (feature->name, name) == 0);
141 feature->name = g_strdup (name);
143 gst_object_set_name (GST_OBJECT (feature), feature->name);
147 * gst_plugin_feature_get_name:
148 * @feature: a feature
150 * Gets the name of a plugin feature.
154 G_CONST_RETURN gchar *
155 gst_plugin_feature_get_name (GstPluginFeature * feature)
157 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
159 return feature->name;
163 * gst_plugin_feature_set_rank:
164 * @feature: feature to rank
165 * @rank: rank value - higher number means more priority rank
167 * Specifies a rank for a plugin feature, so that autoplugging uses
168 * the most appropriate feature.
171 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
173 g_return_if_fail (feature != NULL);
174 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
176 feature->rank = rank;
180 * gst_plugin_feature_get rank:
181 * @feature: a feature
183 * Gets the rank of a plugin feature.
185 * Returns: The rank of the feature
188 gst_plugin_feature_get_rank (GstPluginFeature * feature)
190 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
192 return feature->rank;
196 gst_plugin_feature_list_free (GList * list)
200 for (g = list; g; g = g->next) {
201 GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
203 gst_object_unref (feature);