2 * Copyright (C) 2001 RidgeRun (http://www.ridgerun.com/)
3 * Written by Erik Walthinsen <omega@ridgerun.com>
5 * gstindexfactory.c: Index for mappings and other data
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:gstindexfactory
25 * @short_description: Create GstIndexes from a factory
26 * @see_also: #GstIndex
28 * GstIndexFactory is used to dynamically create GstIndex implementations.
32 #include "gst_private.h"
36 #include "gstindexfactory.h"
37 #include "gstmarshal.h"
38 #include "gstregistry.h"
40 static void gst_index_factory_class_init (GstIndexFactoryClass * klass);
41 static void gst_index_factory_init (GstIndexFactory * factory);
42 static void gst_index_factory_finalize (GObject * object);
44 static GstPluginFeatureClass *factory_parent_class = NULL;
46 /* static guint gst_index_factory_signals[LAST_SIGNAL] = { 0 }; */
49 gst_index_factory_get_type (void)
51 static GType indexfactory_type = 0;
53 if (G_UNLIKELY (indexfactory_type == 0)) {
54 static const GTypeInfo indexfactory_info = {
55 sizeof (GstIndexFactoryClass),
58 (GClassInitFunc) gst_index_factory_class_init,
61 sizeof (GstIndexFactory),
63 (GInstanceInitFunc) gst_index_factory_init,
67 indexfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
68 "GstIndexFactory", &indexfactory_info, 0);
70 return indexfactory_type;
74 gst_index_factory_class_init (GstIndexFactoryClass * klass)
76 GObjectClass *gobject_class;
77 GstObjectClass *gstobject_class;
78 GstPluginFeatureClass *gstpluginfeature_class;
80 gobject_class = (GObjectClass *) klass;
81 gstobject_class = (GstObjectClass *) klass;
82 gstpluginfeature_class = (GstPluginFeatureClass *) klass;
84 factory_parent_class = g_type_class_peek_parent (klass);
86 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_index_factory_finalize);
90 gst_index_factory_init (GstIndexFactory * factory)
95 gst_index_factory_finalize (GObject * object)
97 GstIndexFactory *factory = GST_INDEX_FACTORY (object);
99 g_free (factory->longdesc);
101 G_OBJECT_CLASS (factory_parent_class)->finalize (object);
106 * gst_index_factory_new:
107 * @name: name of indexfactory to create
108 * @longdesc: long description of indexfactory to create
109 * @type: the GType of the GstIndex element of this factory
111 * Create a new indexfactory with the given parameters
113 * Returns: a new #GstIndexFactory.
116 gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
118 GstIndexFactory *factory;
120 g_return_val_if_fail (name != NULL, NULL);
121 factory = GST_INDEX_FACTORY (g_object_new (GST_TYPE_INDEX_FACTORY, NULL));
123 GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
124 if (factory->longdesc)
125 g_free (factory->longdesc);
126 factory->longdesc = g_strdup (longdesc);
127 factory->type = type;
133 * gst_index_factory_destroy:
134 * @factory: factory to destroy
136 * Removes the index from the global list.
139 gst_index_factory_destroy (GstIndexFactory * factory)
141 g_return_if_fail (factory != NULL);
143 /* we don't free the struct bacause someone might have a handle to it.. */
147 * gst_index_factory_find:
148 * @name: name of indexfactory to find
150 * Search for an indexfactory of the given name.
152 * Returns: #GstIndexFactory if found, NULL otherwise
155 gst_index_factory_find (const gchar * name)
157 GstPluginFeature *feature;
159 g_return_val_if_fail (name != NULL, NULL);
161 GST_DEBUG ("gstindex: find \"%s\"", name);
163 feature = gst_registry_find_feature (gst_registry_get_default (), name,
164 GST_TYPE_INDEX_FACTORY);
166 return GST_INDEX_FACTORY (feature);
172 * gst_index_factory_create:
173 * @factory: the factory used to create the instance
175 * Create a new #GstIndex instance from the
176 * given indexfactory.
178 * Returns: A new #GstIndex instance.
181 gst_index_factory_create (GstIndexFactory * factory)
183 GstIndexFactory *newfactory;
184 GstIndex *new = NULL;
186 g_return_val_if_fail (factory != NULL, NULL);
189 GST_INDEX_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
191 if (newfactory == NULL)
194 new = GST_INDEX (g_object_new (newfactory->type, NULL));
196 gst_object_unref (newfactory);
202 * gst_index_factory_make:
203 * @name: the name of the factory used to create the instance
205 * Create a new #GstIndex instance from the
206 * indexfactory with the given name.
208 * Returns: A new #GstIndex instance.
211 gst_index_factory_make (const gchar * name)
213 GstIndexFactory *factory;
215 g_return_val_if_fail (name != NULL, NULL);
217 factory = gst_index_factory_find (name);
222 return gst_index_factory_create (factory);