2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gsttype.c: Media-type management functions
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* probably should set up a hash table for the type id's, since currently
|
|
|
|
* it's a rather pathetic linear search. Eventually there may be dozens
|
|
|
|
* of id's, but in reality there are only so many instances of lookup, so
|
|
|
|
* I'm not overly worried yet...
|
|
|
|
*/
|
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
#include "gstbytestream.h"
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gsttype.h"
|
2003-02-10 20:32:32 +00:00
|
|
|
#include "gstregistrypool.h"
|
2002-07-08 19:07:30 +00:00
|
|
|
#include "gstobject.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
/* global list of registered types */
|
2001-08-21 20:16:48 +00:00
|
|
|
static GList *_gst_types;
|
|
|
|
static guint16 _gst_maxtype;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_type_factory_class_init (GstTypeFactoryClass *klass);
|
|
|
|
static void gst_type_factory_init (GstTypeFactory *factory);
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
static void gst_type_factory_unload_thyself (GstPluginFeature *feature);
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
static GstPluginFeatureClass *parent_class = NULL;
|
2002-04-11 20:35:18 +00:00
|
|
|
/* static guint gst_type_factory_signals[LAST_SIGNAL] = { 0 }; */
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
GType
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_get_type (void)
|
2001-08-21 20:16:48 +00:00
|
|
|
{
|
|
|
|
static GType typefactory_type = 0;
|
|
|
|
|
|
|
|
if (!typefactory_type) {
|
|
|
|
static const GTypeInfo typefactory_info = {
|
|
|
|
sizeof (GstTypeFactoryClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GClassInitFunc) gst_type_factory_class_init,
|
2001-08-21 20:16:48 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstTypeFactory),
|
|
|
|
0,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GInstanceInitFunc) gst_type_factory_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2001-08-21 20:16:48 +00:00
|
|
|
};
|
|
|
|
typefactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
|
|
|
|
"GstTypeFactory", &typefactory_info, 0);
|
|
|
|
}
|
|
|
|
return typefactory_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_class_init (GstTypeFactoryClass *klass)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2001-08-21 20:16:48 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
GstPluginFeatureClass *gstpluginfeature_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstobject_class = (GstObjectClass*)klass;
|
|
|
|
gstpluginfeature_class = (GstPluginFeatureClass*) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gstpluginfeature_class->unload_thyself = GST_DEBUG_FUNCPTR (gst_type_factory_unload_thyself);
|
2001-08-21 20:16:48 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
_gst_types = NULL;
|
|
|
|
_gst_maxtype = 1; /* type 0 is undefined */
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_init (GstTypeFactory *factory)
|
2001-08-21 20:16:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-10-21 18:00:31 +00:00
|
|
|
/**
|
2002-04-11 20:35:18 +00:00
|
|
|
* gst_type_factory_new:
|
2001-10-21 18:00:31 +00:00
|
|
|
* @definition: the definition to use
|
|
|
|
*
|
|
|
|
* Creata a new typefactory from the given definition.
|
|
|
|
*
|
|
|
|
* Returns: the new typefactory
|
|
|
|
*/
|
2001-08-21 20:16:48 +00:00
|
|
|
GstTypeFactory*
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_new (GstTypeDefinition *definition)
|
2001-08-21 20:16:48 +00:00
|
|
|
{
|
|
|
|
GstTypeFactory *factory;
|
|
|
|
|
|
|
|
g_return_val_if_fail (definition != NULL, NULL);
|
|
|
|
g_return_val_if_fail (definition->name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (definition->mime != NULL, NULL);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = gst_type_factory_find (definition->name);
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
if (!factory) {
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = GST_TYPE_FACTORY (g_object_new (GST_TYPE_TYPE_FACTORY, NULL));
|
2001-08-21 20:16:48 +00:00
|
|
|
}
|
|
|
|
|
2002-05-08 20:40:48 +00:00
|
|
|
|
|
|
|
GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (definition->name);
|
2001-08-21 20:16:48 +00:00
|
|
|
factory->mime = g_strdup (definition->mime);
|
|
|
|
factory->exts = g_strdup (definition->exts);
|
|
|
|
factory->typefindfunc = definition->typefindfunc;
|
|
|
|
|
|
|
|
return factory;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_register:
|
|
|
|
* @factory: the type factory to register
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Register a new type factory to the system.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
|
|
|
* Returns: the new type id
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
guint16
|
|
|
|
gst_type_register (GstTypeFactory *factory)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
guint16 id;
|
|
|
|
GstType *type;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, 0);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
/* GST_CAT_INFO (GST_CAT_TYPES,"type register %s", factory->mime); */
|
2000-11-11 15:13:50 +00:00
|
|
|
id = gst_type_find_by_mime (factory->mime);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
if (!id) {
|
2000-11-11 15:13:50 +00:00
|
|
|
type = g_new0 (GstType, 1);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
type->id = _gst_maxtype++;
|
|
|
|
type->mime = factory->mime;
|
|
|
|
type->exts = factory->exts;
|
2001-08-21 20:16:48 +00:00
|
|
|
type->factories = NULL;
|
2001-03-07 21:52:56 +00:00
|
|
|
_gst_types = g_list_prepend (_gst_types, type);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
id = type->id;
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2000-01-30 09:03:00 +00:00
|
|
|
} else {
|
2000-11-11 15:13:50 +00:00
|
|
|
type = gst_type_find_by_id (id);
|
2000-01-30 09:03:00 +00:00
|
|
|
/* now we want to try to merge the types and return the original */
|
|
|
|
|
|
|
|
/* FIXME: do extension merging here, not that easy */
|
|
|
|
|
|
|
|
/* if there is no existing typefind function, try to use new one */
|
2000-12-15 16:43:26 +00:00
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_TYPES,"gsttype: %s(%p) gave new mime type '%s', id %d",
|
2001-08-21 20:16:48 +00:00
|
|
|
GST_OBJECT_NAME (factory), factory, type->mime, type->id);
|
|
|
|
type->factories = g_slist_prepend (type->factories, factory);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
static guint16
|
|
|
|
gst_type_find_by_mime_func (const gchar *mime)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2000-08-28 20:20:55 +00:00
|
|
|
GList *walk;
|
2000-01-30 09:03:00 +00:00
|
|
|
GstType *type;
|
|
|
|
gint typelen,mimelen;
|
|
|
|
gchar *search, *found;
|
|
|
|
|
2000-12-12 19:29:43 +00:00
|
|
|
g_return_val_if_fail (mime != NULL, 0);
|
|
|
|
|
2000-08-28 20:20:55 +00:00
|
|
|
walk = _gst_types;
|
2003-06-29 14:05:49 +00:00
|
|
|
/* GST_CAT_DEBUG (GST_CAT_TYPES,"searching for '%s'",mime); */
|
2000-11-11 15:13:50 +00:00
|
|
|
mimelen = strlen (mime);
|
2000-01-30 09:03:00 +00:00
|
|
|
while (walk) {
|
|
|
|
type = (GstType *)walk->data;
|
|
|
|
search = type->mime;
|
2003-06-29 14:05:49 +00:00
|
|
|
/* GST_CAT_DEBUG (GST_CAT_TYPES,"checking against '%s'",search); */
|
2000-11-11 15:13:50 +00:00
|
|
|
typelen = strlen (search);
|
2000-01-30 09:03:00 +00:00
|
|
|
while ((search - type->mime) < typelen) {
|
2000-11-11 15:13:50 +00:00
|
|
|
found = strstr (search, mime);
|
2000-01-30 09:03:00 +00:00
|
|
|
/* if the requested mime is in the list */
|
|
|
|
if (found) {
|
|
|
|
if ((*(found + mimelen) == ' ') ||
|
|
|
|
(*(found + mimelen) == ',') ||
|
|
|
|
(*(found + mimelen) == '\0')) {
|
|
|
|
return type->id;
|
|
|
|
} else {
|
|
|
|
search = found + mimelen;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
search += mimelen;
|
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_find_by_mime:
|
|
|
|
* @mime: the mime type to find
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Find the type id of a given mime type.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
|
|
|
* Returns: the type id
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
guint16
|
|
|
|
gst_type_find_by_mime (const gchar *mime)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
|
|
|
return gst_type_find_by_mime_func (mime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_type_find_by_ext:
|
|
|
|
* @ext: the extension to find
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Find the type id of a given extention.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
|
|
|
* Returns: the type id
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
guint16
|
|
|
|
gst_type_find_by_ext (const gchar *ext)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2001-12-14 22:59:21 +00:00
|
|
|
/* FIXME */
|
2000-11-11 15:13:50 +00:00
|
|
|
g_warning ("gsttype: find_by_ext not implemented");
|
|
|
|
return 0;
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_find_by_id:
|
|
|
|
* @id: the type id to lookup
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Find the type of a given type id.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
|
|
|
* Returns: the type
|
|
|
|
*/
|
|
|
|
GstType*
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_type_find_by_id (guint16 id)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GList *walk = _gst_types;
|
|
|
|
GstType *type;
|
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
type = (GstType *)walk->data;
|
|
|
|
if (type->id == id)
|
|
|
|
return type;
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_get_list:
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Return a list of all registered types.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
|
|
|
* Returns: a list of GstTypes
|
|
|
|
*/
|
2002-04-19 19:49:41 +00:00
|
|
|
const GList*
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_type_get_list (void)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
return _gst_types;
|
|
|
|
}
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
2002-04-11 20:35:18 +00:00
|
|
|
* gst_type_factory_find:
|
2001-08-21 20:16:48 +00:00
|
|
|
* @name: the name of the typefactory to find
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
2001-08-21 20:16:48 +00:00
|
|
|
* Return the TypeFactory with the given name.
|
2000-11-11 15:13:50 +00:00
|
|
|
*
|
2001-08-21 20:16:48 +00:00
|
|
|
* Returns: a GstTypeFactory with the given name;
|
2000-11-11 15:13:50 +00:00
|
|
|
*/
|
2001-08-21 20:16:48 +00:00
|
|
|
GstTypeFactory*
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_find (const gchar *name)
|
2000-11-11 15:13:50 +00:00
|
|
|
{
|
2002-05-08 20:40:48 +00:00
|
|
|
GstPluginFeature *feature;
|
|
|
|
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
feature = gst_registry_pool_find_feature (name, GST_TYPE_TYPE_FACTORY);
|
|
|
|
if (feature)
|
|
|
|
return GST_TYPE_FACTORY (feature);
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_factory_unload_thyself (GstPluginFeature *feature)
|
2001-08-21 20:16:48 +00:00
|
|
|
{
|
|
|
|
GstTypeFactory *factory;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_if_fail (GST_IS_TYPE_FACTORY (feature));
|
2001-08-21 20:16:48 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = GST_TYPE_FACTORY (feature);
|
2001-08-21 20:16:48 +00:00
|
|
|
|
|
|
|
if (factory->typefindfunc)
|
2002-04-11 20:35:18 +00:00
|
|
|
factory->typefindfunc = gst_type_type_find_dummy;
|
2001-08-21 20:16:48 +00:00
|
|
|
}
|
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
GstCaps*
|
|
|
|
gst_type_type_find_dummy (GstByteStream *bs, gpointer priv)
|
2001-09-10 19:46:01 +00:00
|
|
|
{
|
2003-01-23 19:03:02 +00:00
|
|
|
GstCaps *res = NULL;
|
2001-09-10 19:46:01 +00:00
|
|
|
GstTypeFactory *factory = (GstTypeFactory *)priv;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_TYPES,"gsttype: need to load typefind function for %s", factory->mime);
|
2001-09-10 19:46:01 +00:00
|
|
|
|
2001-10-21 18:00:31 +00:00
|
|
|
if (gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory))) {
|
2003-01-23 19:03:02 +00:00
|
|
|
if (factory->typefindfunc == gst_type_type_find_dummy) {
|
|
|
|
/* looks like we didn't get a real typefind function */
|
|
|
|
g_warning ("could not load valid typefind function for %s\n", factory->mime);
|
|
|
|
}
|
|
|
|
else if (factory->typefindfunc) {
|
2003-10-01 13:11:45 +00:00
|
|
|
res = factory->typefindfunc (bs, priv);
|
2001-10-21 18:00:31 +00:00
|
|
|
}
|
2001-09-10 19:46:01 +00:00
|
|
|
}
|
|
|
|
|
2003-01-23 19:03:02 +00:00
|
|
|
return res;
|
2001-09-10 19:46:01 +00:00
|
|
|
}
|