gst/gsterror.c: Add another error string used in a few existing plugins.
[platform/upstream/gstreamer.git] / gst / gstpluginfeature.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstpluginfeature.c: Abstract base class for all plugin features
6  *
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.
11  *
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.
16  *
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.
21  */
22 /**
23  * SECTION:gstpluginfeature
24  * @short_description: Base class for contents of a GstPlugin
25  * @see_also: #GstPlugin
26  *
27  * This is a base class for anything that can be added to a #GstPlugin.
28  */
29
30 #include "gst_private.h"
31
32 #include "gstpluginfeature.h"
33 #include "gstplugin.h"
34 #include "gstregistry.h"
35 #include "gstinfo.h"
36
37 #include <string.h>
38
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);
42
43 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
44
45 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
46 GstObjectClass *parent_class = NULL;
47
48 static void
49 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
50 {
51   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
52
53   G_OBJECT_CLASS (klass)->finalize =
54       GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
55 }
56
57 static void
58 gst_plugin_feature_init (GstPluginFeature * feature)
59 {
60
61 }
62
63 static void
64 gst_plugin_feature_finalize (GObject * object)
65 {
66   GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
67
68   GST_DEBUG ("finalizing feature %p", feature);
69   g_free (feature->name);
70   g_free (feature->plugin_name);
71
72   G_OBJECT_CLASS (parent_class)->finalize (object);
73 }
74
75 /**
76  * gst_plugin_feature_load:
77  * @feature: the plugin feature to check
78  *
79  * Loads the plugin containing @feature if it's not already loaded. @feature is
80  * unaffected; use the return value instead.
81  *
82  * Normally this function is used like this:
83  *
84  * <programlisting>
85  * GstPluginFeature *loaded_feature;
86  * loaded_feature = gst_plugin_feature_load (feature);
87  * // presumably, we're no longer interested in the potentially-unloaded feature
88  * gst_object_unref (feature);
89  * feature = loaded_feature;
90  * </programlisting>
91  *
92  * Returns: A reference to the loaded feature, or NULL on error.
93  */
94 GstPluginFeature *
95 gst_plugin_feature_load (GstPluginFeature * feature)
96 {
97   GstPlugin *plugin;
98   GstPluginFeature *real_feature;
99
100   g_return_val_if_fail (feature != NULL, FALSE);
101   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
102
103   GST_DEBUG ("loading plugin for feature %p", feature);
104   if (feature->loaded)
105     return feature;
106
107   GST_DEBUG ("loading plugin %s", feature->plugin_name);
108   plugin = gst_plugin_load_by_name (feature->plugin_name);
109   if (!plugin) {
110     g_critical ("Failed to load plugin containing feature '%s'.",
111         GST_PLUGIN_FEATURE_NAME (feature));
112     return NULL;
113   }
114   GST_DEBUG ("loaded plugin %s", feature->plugin_name);
115   gst_object_unref (plugin);
116
117   real_feature =
118       gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
119
120   if (real_feature == NULL) {
121     GST_INFO
122         ("Loaded plugin containing feature '%s', but feature disappeared.",
123         feature->name);
124   } else if (!real_feature->loaded) {
125     GST_INFO ("Tried to load plugin containing feature '%s', but feature was "
126         "not found.", real_feature->name);
127     return NULL;
128   }
129
130   return real_feature;
131 }
132
133 gboolean
134 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
135     GstTypeNameData * data)
136 {
137   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
138       (data->name == NULL
139           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
140 }
141
142 /**
143  * gst_plugin_feature_set_name:
144  * @feature: a feature
145  * @name: the name to set
146  *
147  * Sets the name of a plugin feature. The name uniquely identifies a feature
148  * within all features of the same type. Renaming a plugin feature is not 
149  * allowed. A copy is made of the name so you should free the supplied @name
150  * after calling this function.
151  */
152 void
153 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
154 {
155   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
156   g_return_if_fail (name != NULL);
157
158   if (feature->name) {
159     g_return_if_fail (strcmp (feature->name, name) == 0);
160   } else {
161     feature->name = g_strdup (name);
162   }
163   gst_object_set_name (GST_OBJECT (feature), feature->name);
164 }
165
166 /**
167  * gst_plugin_feature_get_name:
168  * @feature: a feature
169  *
170  * Gets the name of a plugin feature.
171  *
172  * Returns: the name
173  */
174 G_CONST_RETURN gchar *
175 gst_plugin_feature_get_name (GstPluginFeature * feature)
176 {
177   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
178
179   return feature->name;
180 }
181
182 /**
183  * gst_plugin_feature_set_rank:
184  * @feature: feature to rank
185  * @rank: rank value - higher number means more priority rank
186  *
187  * Specifies a rank for a plugin feature, so that autoplugging uses
188  * the most appropriate feature.
189  */
190 void
191 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
192 {
193   g_return_if_fail (feature != NULL);
194   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
195
196   feature->rank = rank;
197 }
198
199 /**
200  * gst_plugin_feature_get rank:
201  * @feature: a feature
202  *
203  * Gets the rank of a plugin feature.
204  *
205  * Returns: The rank of the feature
206  */
207 guint
208 gst_plugin_feature_get_rank (GstPluginFeature * feature)
209 {
210   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
211
212   return feature->rank;
213 }
214
215 /**
216  * gst_plugin_feature_list_free:
217  * @list: list of #GstPluginFeature
218  *
219  * Unrefs each member of @list, then frees the list.
220  */
221 void
222 gst_plugin_feature_list_free (GList * list)
223 {
224   GList *g;
225
226   for (g = list; g; g = g->next) {
227     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
228
229     gst_object_unref (feature);
230   }
231   g_list_free (list);
232 }