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 * SECTION:gstpluginfeature
24 * @short_description: Base class for contents of a GstPlugin
25 * @see_also: #GstPlugin
27 * This is a base class for anything that can be added to a #GstPlugin.
30 #include "gst_private.h"
32 #include "gstpluginfeature.h"
33 #include "gstplugin.h"
34 #include "gstregistry.h"
39 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
40 static void gst_plugin_feature_init (GstPluginFeature * feature);
41 static void gst_plugin_feature_finalize (GObject * object);
43 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
45 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
46 GstObjectClass *parent_class = NULL;
49 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
51 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
53 G_OBJECT_CLASS (klass)->finalize =
54 GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
58 gst_plugin_feature_init (GstPluginFeature * feature)
64 gst_plugin_feature_finalize (GObject * object)
66 GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
68 GST_DEBUG ("finalizing feature %p", feature);
69 g_free (feature->name);
70 g_free (feature->plugin_name);
72 G_OBJECT_CLASS (parent_class)->finalize (object);
76 * gst_plugin_feature_load:
77 * @feature: the plugin feature to check
79 * Check if the plugin containing the feature is loaded,
80 * if not, the plugin will be loaded.
82 * Returns: The new feature
85 gst_plugin_feature_load (GstPluginFeature * feature)
88 GstPluginFeature *real_feature;
90 g_return_val_if_fail (feature != NULL, FALSE);
91 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
93 GST_DEBUG ("loading plugin for feature %p", feature);
97 GST_DEBUG ("loading plugin %s", feature->plugin_name);
98 plugin = gst_plugin_load_by_name (feature->plugin_name);
100 g_critical ("Failed to load plugin containing feature '%s'.",
101 GST_PLUGIN_FEATURE_NAME (feature));
104 GST_DEBUG ("loaded plugin %s", feature->plugin_name);
105 gst_object_unref (plugin);
108 gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
110 if (real_feature == NULL) {
112 ("Loaded plugin containing feature '%s', but feature disappeared.",
115 gst_object_unref (feature);
121 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
122 GstTypeNameData * data)
124 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
126 || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
130 * gst_plugin_feature_set_name:
131 * @feature: a feature
132 * @name: the name to set
134 * Sets the name of a plugin feature. The name uniquely identifies a feature
135 * within all features of the same type. Renaming a plugin feature is not
136 * allowed. A copy is made of the name so you should free the supplied @name
137 * after calling this function.
140 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
142 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
143 g_return_if_fail (name != NULL);
146 g_return_if_fail (strcmp (feature->name, name) == 0);
148 feature->name = g_strdup (name);
150 gst_object_set_name (GST_OBJECT (feature), feature->name);
154 * gst_plugin_feature_get_name:
155 * @feature: a feature
157 * Gets the name of a plugin feature.
161 G_CONST_RETURN gchar *
162 gst_plugin_feature_get_name (GstPluginFeature * feature)
164 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
166 return feature->name;
170 * gst_plugin_feature_set_rank:
171 * @feature: feature to rank
172 * @rank: rank value - higher number means more priority rank
174 * Specifies a rank for a plugin feature, so that autoplugging uses
175 * the most appropriate feature.
178 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
180 g_return_if_fail (feature != NULL);
181 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
183 feature->rank = rank;
187 * gst_plugin_feature_get rank:
188 * @feature: a feature
190 * Gets the rank of a plugin feature.
192 * Returns: The rank of the feature
195 gst_plugin_feature_get_rank (GstPluginFeature * feature)
197 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
199 return feature->rank;
203 gst_plugin_feature_list_free (GList * list)
207 for (g = list; g; g = g->next) {
208 GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
210 gst_object_unref (feature);