2 * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
4 * gsttypefindfactory.c: typefinding subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 * SECTION:gsttypefindfactory
23 * @short_description: Information about registered typefind functions
25 * These functions allow querying informations about registered typefind
26 * functions. How to create and register these functions is described in
27 * the section <link linkend="gstreamer-Writing-typefind-functions">
28 * "Writing typefind functions"</link>.
31 * <title>how to write a simple typefinder</title>
40 * my_peek (gpointer data, gint64 offset, guint size)
42 * MyTypeFind *find = (MyTypeFind *) data;
43 * if (offset >= 0 && offset + size <= find->size) {
44 * return find->data + offset;
49 * my_suggest (gpointer data, guint probability, GstCaps *caps)
51 * MyTypeFind *find = (MyTypeFind *) data;
52 * if (probability > find->probability) {
53 * find->probability = probability;
54 * gst_caps_replace (&find->caps, caps);
58 * find_type (guint8 *data, guint size)
60 * GList *walk, *type_list;
61 * MyTypeFind find = {data, size, 0, NULL};
62 * GstTypeFind gst_find = {my_peek, my_suggest, &find, };
64 * walk = type_list = gst_type_find_factory_get_list ();
66 * GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
67 * walk = g_list_next (walk)
68 * gst_type_find_factory_call_function (factory, &gst_find);
70 * g_list_free (type_list);
76 * The above example shows how to write a very simple typefinder that identifies
77 * the given data. You can get quite a bit more complicated than that though.
80 #include "gst_private.h"
82 #include "gsttypefind.h"
83 #include "gsttypefindfactory.h"
84 #include "gstregistry.h"
86 GST_DEBUG_CATEGORY (gst_type_find_debug);
87 #define GST_CAT_DEFAULT gst_type_find_debug
89 static void gst_type_find_factory_class_init (gpointer g_class,
91 static void gst_type_find_factory_init (GTypeInstance * instance,
93 static void gst_type_find_factory_dispose (GObject * object);
95 static GstPluginFeatureClass *parent_class = NULL;
98 gst_type_find_factory_get_type (void)
100 static GType typefind_type = 0;
102 if (!typefind_type) {
103 static const GTypeInfo typefind_info = {
104 sizeof (GstTypeFindFactoryClass),
107 gst_type_find_factory_class_init,
110 sizeof (GstTypeFindFactory),
112 gst_type_find_factory_init,
116 typefind_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
117 "GstTypeFindFactory", &typefind_info, 0);
118 GST_DEBUG_CATEGORY_INIT (gst_type_find_debug, "GST_TYPEFIND",
119 GST_DEBUG_FG_GREEN, "typefinding subsystem");
122 return typefind_type;
126 gst_type_find_factory_class_init (gpointer g_class, gpointer class_data)
128 GObjectClass *object_class = G_OBJECT_CLASS (g_class);
130 parent_class = g_type_class_peek_parent (g_class);
132 object_class->dispose = gst_type_find_factory_dispose;
136 gst_type_find_factory_init (GTypeInstance * instance, gpointer g_class)
138 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (instance);
140 factory->user_data = factory;
144 gst_type_find_factory_dispose (GObject * object)
146 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (object);
149 gst_caps_unref (factory->caps);
150 factory->caps = NULL;
152 if (factory->extensions) {
153 g_strfreev (factory->extensions);
154 factory->extensions = NULL;
159 * gst_type_find_factory_get_list:
161 * Gets the list of all registered typefind factories. You must free the
162 * list using g_list_free.
164 * Returns: the list of all registered typefind factories
167 gst_type_find_factory_get_list (void)
169 return gst_registry_get_feature_list (gst_registry_get_default (),
170 GST_TYPE_TYPE_FIND_FACTORY);
174 * gst_type_find_factory_get_caps:
175 * @factory: a factory
177 * Gets the caps associated with a typefind factory.
179 * Returns: the #GstCaps associated with this factory
182 gst_type_find_factory_get_caps (GstTypeFindFactory * factory)
184 g_return_val_if_fail (GST_IS_TYPE_FIND_FACTORY (factory), NULL);
186 return factory->caps;
190 * gst_type_find_factory_get_extensions:
191 * @factory: a factory
193 * Gets the extensions associated with a typefind factory. The returned
194 * array should not be changed. If you need to change stuff in it, you should
195 * copy it using g_stdupv(). This function may return NULL to indicate
198 * Returns: a NULL-terminated array of extensions associated with this factory
201 gst_type_find_factory_get_extensions (GstTypeFindFactory * factory)
203 g_return_val_if_fail (GST_IS_TYPE_FIND_FACTORY (factory), NULL);
205 return factory->extensions;
209 * gst_type_find_factory_call_function:
210 * @factory: a factory
211 * @find: a properly setup #GstTypeFind entry. The get_data and suggest_type
212 * members must be set.
214 * Calls the typefinding function associated with this factory.
217 gst_type_find_factory_call_function (GstTypeFindFactory * factory,
220 GstTypeFindFactory *new_factory;
222 g_return_if_fail (GST_IS_TYPE_FIND_FACTORY (factory));
223 g_return_if_fail (find != NULL);
224 g_return_if_fail (find->peek != NULL);
225 g_return_if_fail (find->suggest != NULL);
228 GST_TYPE_FIND_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
231 g_assert (new_factory->function != NULL);
233 new_factory->function (find, new_factory->user_data);
234 gst_object_unref (new_factory);