2000-01-30 09:03:00 +00:00
|
|
|
/* Gnome-Streamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <string.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* global list of registered types */
|
|
|
|
GList *_gst_types;
|
|
|
|
guint16 _gst_maxtype;
|
|
|
|
|
2000-08-22 21:18:18 +00:00
|
|
|
#define MAX_COST 999999
|
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
struct _gst_type_node
|
|
|
|
{
|
|
|
|
int iNode;
|
|
|
|
int iDist;
|
|
|
|
int iPrev;
|
|
|
|
};
|
2000-11-11 15:13:50 +00:00
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
typedef struct _gst_type_node gst_type_node;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static gboolean gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
/* we keep a (spase) matrix in the hashtable like:
|
|
|
|
*
|
|
|
|
* type_id list of factories hashed by src type_id
|
|
|
|
*
|
|
|
|
* 1 -> (1, factory1, factory2), (3, factory3)
|
|
|
|
* 2 -> NULL
|
|
|
|
* 3 -> (4, factory4)
|
|
|
|
* 4 -> NULL
|
|
|
|
*
|
|
|
|
* That way, we can quickly find all factories that convert
|
|
|
|
* 1 to 2.
|
|
|
|
*
|
|
|
|
**/
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
void
|
|
|
|
_gst_type_initialize (void)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
_gst_types = NULL;
|
|
|
|
_gst_maxtype = 1; /* type 0 is undefined */
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_register:
|
|
|
|
* @factory: the type factory to register
|
|
|
|
*
|
|
|
|
* register a new type factory to the system
|
|
|
|
*
|
|
|
|
* Returns: the new type id
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_type_register (GstTypeFactory *factory)
|
|
|
|
{
|
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
|
|
|
|
2000-11-01 13:49:41 +00:00
|
|
|
//g_print("gsttype: type register %s\n", factory->mime);
|
2000-11-11 15:13:50 +00:00
|
|
|
id = gst_type_find_by_mime (factory->mime);
|
|
|
|
|
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
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
type->id = _gst_maxtype++;
|
|
|
|
type->mime = factory->mime;
|
|
|
|
type->exts = factory->exts;
|
2000-01-30 09:03:00 +00:00
|
|
|
type->typefindfunc = factory->typefindfunc;
|
2000-11-11 15:13:50 +00:00
|
|
|
type->srcs = NULL;
|
|
|
|
type->sinks = NULL;
|
|
|
|
type->converters = g_hash_table_new (NULL, NULL);
|
|
|
|
_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-08-28 20:20:55 +00:00
|
|
|
if ((type->typefindfunc == gst_type_typefind_dummy ||
|
|
|
|
type->typefindfunc == NULL) && factory->typefindfunc)
|
2000-01-30 09:03:00 +00:00
|
|
|
type->typefindfunc = factory->typefindfunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static
|
|
|
|
guint16 gst_type_find_by_mime_func (gchar *mime)
|
|
|
|
{
|
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-08-28 20:20:55 +00:00
|
|
|
walk = _gst_types;
|
2000-01-30 09:03:00 +00:00
|
|
|
// DEBUG("searching for '%s'\n",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;
|
|
|
|
// DEBUG("checking against '%s'\n",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
|
|
|
|
*
|
|
|
|
* find the type id of a given mime type
|
|
|
|
*
|
|
|
|
* Returns: the type id
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_type_find_by_mime (gchar *mime)
|
|
|
|
{
|
2000-08-28 20:20:55 +00:00
|
|
|
guint16 typeid;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
typeid = gst_type_find_by_mime_func (mime);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
|
|
|
if (!typeid) {
|
2000-11-11 15:13:50 +00:00
|
|
|
gst_plugin_load_typefactory (mime);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* find the type id of a given extention
|
|
|
|
*
|
|
|
|
* Returns: the type id
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_type_find_by_ext (gchar *ext)
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* find the type of a given type id
|
|
|
|
*
|
|
|
|
* Returns: the type
|
|
|
|
*/
|
|
|
|
GstType*
|
|
|
|
gst_type_find_by_id (guint16 id)
|
|
|
|
{
|
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
|
|
|
static void
|
|
|
|
gst_type_dump_converter (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *walk = (GList *)value;
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("gsttype: %u, (", GPOINTER_TO_UINT (key));
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
factory = (GstElementFactory *) walk->data;
|
|
|
|
g_print("%s, ", factory->name);
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("NULL)), ");
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_dump:
|
|
|
|
*
|
|
|
|
* dumps the current type system
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_type_dump(void)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *walk = _gst_types;
|
|
|
|
GstType *type;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("gst_type_dump() : \n");
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
type = (GstType *)walk->data;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("gst_type: %d (%s) -> (", type->id, type->mime);
|
|
|
|
g_hash_table_foreach (type->converters, gst_type_dump_converter, NULL);
|
|
|
|
g_print ("NULL)\n");
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_add_src:
|
|
|
|
* @id: the type id to add the source factory to
|
|
|
|
* @src: the source factory for the type
|
|
|
|
*
|
|
|
|
* register the src factory as being a source for the
|
|
|
|
* given type id
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_type_add_src (guint16 id, GstElementFactory *src)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *walk;
|
2000-11-11 15:13:50 +00:00
|
|
|
GstType *type = gst_type_find_by_id (id);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_return_if_fail (type != NULL);
|
|
|
|
g_return_if_fail (src != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
type->srcs = g_list_prepend (type->srcs, src);
|
|
|
|
gst_elementfactory_add_src (src, id);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
// find out if the element has to be indexed in the matrix
|
|
|
|
walk = src->sink_types;
|
|
|
|
|
|
|
|
while (walk) {
|
2000-11-11 15:13:50 +00:00
|
|
|
GstType *type2 = gst_type_find_by_id (GPOINTER_TO_UINT (walk->data));
|
|
|
|
GList *converters = (GList *)g_hash_table_lookup (type2->converters, GUINT_TO_POINTER ((guint)id));
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *orig = converters;
|
|
|
|
|
|
|
|
while (converters) {
|
|
|
|
if (converters->data == src) {
|
|
|
|
break;
|
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
converters = g_list_next (converters);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!converters) {
|
2000-11-11 15:13:50 +00:00
|
|
|
orig = g_list_prepend (orig, src);
|
|
|
|
g_hash_table_insert (type2->converters, GUINT_TO_POINTER ((guint)id), orig);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_add_sink:
|
|
|
|
* @id: the type id to add the sink factory to
|
|
|
|
* @sink: the sink factory for the type
|
|
|
|
*
|
|
|
|
* register the sink factory as being a sink for the
|
|
|
|
* given type id
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_type_add_sink (guint16 id, GstElementFactory *sink)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *walk;
|
2000-11-11 15:13:50 +00:00
|
|
|
GstType *type = gst_type_find_by_id (id);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_return_if_fail (type != NULL);
|
|
|
|
g_return_if_fail (sink != NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
type->sinks = g_list_prepend (type->sinks, sink);
|
|
|
|
gst_elementfactory_add_sink (sink, id);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
// find out if the element has to be indexed in the matrix
|
|
|
|
walk = sink->src_types;
|
|
|
|
|
|
|
|
while (walk) {
|
2000-11-11 15:13:50 +00:00
|
|
|
GList *converters = (GList *)g_hash_table_lookup (type->converters, walk->data);
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *orig = converters;
|
|
|
|
|
|
|
|
while (converters) {
|
|
|
|
if (converters->data == sink) {
|
|
|
|
break;
|
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
converters = g_list_next (converters);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!converters) {
|
2000-11-11 15:13:50 +00:00
|
|
|
orig = g_list_prepend (orig, sink);
|
|
|
|
g_hash_table_insert (type->converters, walk->data, orig);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
walk = g_list_next (walk);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_get_srcs:
|
|
|
|
* @id: the id to fetch the source factories for
|
|
|
|
*
|
|
|
|
* return a list of elementfactories that source
|
|
|
|
* the given type id
|
|
|
|
*
|
|
|
|
* Returns: a list of elementfactories
|
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_type_get_srcs (guint16 id)
|
|
|
|
{
|
|
|
|
GstType *type = gst_type_find_by_id (id);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_return_val_if_fail (type != NULL, NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return type->srcs;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_get_sinks:
|
|
|
|
* @id: the id to fetch the sink factories for
|
|
|
|
*
|
|
|
|
* return a list of elementfactories that sink
|
|
|
|
* the given type id
|
|
|
|
*
|
|
|
|
* Returns: a list of elementfactories
|
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_type_get_sinks (guint16 id)
|
|
|
|
{
|
|
|
|
GstType *type = gst_type_find_by_id (id);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_return_val_if_fail (type != 0, NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return type->sinks;
|
|
|
|
}
|
|
|
|
|
2000-08-21 21:20:38 +00:00
|
|
|
/*
|
|
|
|
* An implementation of Dijkstra's shortest path
|
|
|
|
* algorithm to find the best set of GstElementFactories
|
|
|
|
* to connnect two GstTypes
|
|
|
|
*
|
|
|
|
**/
|
2000-11-11 15:13:50 +00:00
|
|
|
static GList*
|
|
|
|
gst_type_enqueue (GList *queue, gint iNode, gint iDist, gint iPrev)
|
|
|
|
{
|
|
|
|
gst_type_node *node = g_malloc (sizeof (gst_type_node));
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
node->iNode = iNode;
|
|
|
|
node->iDist = iDist;
|
|
|
|
node->iPrev = iPrev;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
queue = g_list_append (queue, node);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static GList*
|
|
|
|
gst_type_dequeue (GList *queue, gint *iNode, gint *iDist, gint *iPrev)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
GList *head;
|
|
|
|
gst_type_node *node;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
head = g_list_first (queue);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
if (head) {
|
|
|
|
node = (gst_type_node *)head->data;
|
|
|
|
*iNode = node->iNode;
|
|
|
|
*iPrev = node->iPrev;
|
|
|
|
*iDist = node->iDist;
|
2000-11-11 15:13:50 +00:00
|
|
|
head = g_list_remove (queue, node);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static GList*
|
|
|
|
construct_path (gst_type_node *rgnNodes, gint chNode)
|
2000-08-21 21:20:38 +00:00
|
|
|
{
|
|
|
|
guint src = chNode;
|
|
|
|
guint current = rgnNodes[chNode].iPrev;
|
|
|
|
GList *factories = NULL;
|
|
|
|
GstType *type;
|
|
|
|
GList *converters;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("gsttype: constructed mime path ");
|
2000-08-22 21:18:18 +00:00
|
|
|
while (current != MAX_COST)
|
2000-08-21 21:20:38 +00:00
|
|
|
{
|
2000-11-11 15:13:50 +00:00
|
|
|
type = gst_type_find_by_id (current);
|
|
|
|
converters = (GList *)g_hash_table_lookup (type->converters, GUINT_TO_POINTER (src));
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("(%d %d)", src, current);
|
|
|
|
factories = g_list_prepend (factories, converters->data);
|
2000-08-21 21:20:38 +00:00
|
|
|
src = current;
|
|
|
|
current = rgnNodes[current].iPrev;
|
|
|
|
}
|
|
|
|
g_print("\n");
|
|
|
|
return factories;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static guint
|
|
|
|
gst_type_find_cost (gint src, gint dest)
|
|
|
|
{
|
|
|
|
GstType *type = gst_type_find_by_id (src);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
GList *converters = (GList *)g_hash_table_lookup (type->converters, GUINT_TO_POINTER (dest));
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-08-28 20:20:55 +00:00
|
|
|
// FIXME do something very clever here...
|
2000-08-21 21:20:38 +00:00
|
|
|
if (converters) return 1;
|
2000-08-22 21:18:18 +00:00
|
|
|
return MAX_COST;
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_get_sink_to_src:
|
|
|
|
* @sinkid: the id of the sink
|
|
|
|
* @srcid: the id of the source
|
|
|
|
*
|
|
|
|
* return a list of elementfactories that convert the source
|
|
|
|
* type id to the sink type id
|
|
|
|
*
|
|
|
|
* Returns: a list of elementfactories
|
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_type_get_sink_to_src (guint16 sinkid, guint16 srcid)
|
|
|
|
{
|
2000-08-21 21:20:38 +00:00
|
|
|
gst_type_node *rgnNodes;
|
|
|
|
GList *queue = NULL;
|
|
|
|
gint iNode, iDist, iPrev, i, iCost;
|
|
|
|
|
|
|
|
if (sinkid == srcid) {
|
|
|
|
//FIXME return an identity element
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
2000-11-11 15:13:50 +00:00
|
|
|
rgnNodes = g_malloc (sizeof (gst_type_node) * _gst_maxtype);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
for (i=0; i< _gst_maxtype; i++) {
|
|
|
|
rgnNodes[i].iNode = i;
|
2000-08-22 21:18:18 +00:00
|
|
|
rgnNodes[i].iDist = MAX_COST;
|
|
|
|
rgnNodes[i].iPrev = MAX_COST;
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
rgnNodes[sinkid].iDist = 0;
|
2000-08-22 21:18:18 +00:00
|
|
|
rgnNodes[sinkid].iPrev = MAX_COST;
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
queue = gst_type_enqueue (queue, sinkid, 0, MAX_COST);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
while (g_list_length (queue) > 0) {
|
2000-08-21 21:20:38 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
queue = gst_type_dequeue (queue, &iNode, &iDist, &iPrev);
|
2000-08-21 21:20:38 +00:00
|
|
|
|
|
|
|
for (i=0; i< _gst_maxtype; i++) {
|
2000-11-11 15:13:50 +00:00
|
|
|
iCost = gst_type_find_cost (iNode, i);
|
2000-08-22 21:18:18 +00:00
|
|
|
if (iCost != MAX_COST) {
|
|
|
|
if((MAX_COST == rgnNodes[i].iDist) ||
|
2000-08-21 21:20:38 +00:00
|
|
|
(rgnNodes[i].iDist > (iCost + iDist))) {
|
|
|
|
rgnNodes[i].iDist = iDist + iCost;
|
|
|
|
rgnNodes[i].iPrev = iNode;
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
queue = gst_type_enqueue (queue, i, iDist + iCost, iNode);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
return construct_path (rgnNodes, srcid);
|
2000-08-21 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_get_list:
|
|
|
|
*
|
|
|
|
* return a list of all registered types
|
|
|
|
*
|
|
|
|
* Returns: a list of GstTypes
|
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_type_get_list (void)
|
|
|
|
{
|
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
|
|
|
/**
|
|
|
|
* gst_type_save_thyself:
|
|
|
|
* @type: the type to save
|
|
|
|
* @parent: the parent node to save into
|
|
|
|
*
|
|
|
|
* save a type into an XML representation
|
|
|
|
*
|
|
|
|
* Returns: the new xmlNodePtr
|
|
|
|
*/
|
|
|
|
xmlNodePtr
|
|
|
|
gst_type_save_thyself (GstType *type, xmlNodePtr parent)
|
|
|
|
{
|
|
|
|
xmlNewChild (parent, NULL, "mime", type->mime);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2000-10-08 22:17:11 +00:00
|
|
|
return parent;
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_type_load_thyself:
|
|
|
|
* @parent: the parent node with the xml information
|
|
|
|
*
|
|
|
|
* load a type from an XML representation
|
|
|
|
*
|
|
|
|
* Returns: the loaded type id
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_type_load_thyself (xmlNodePtr parent)
|
|
|
|
{
|
2000-10-08 22:17:11 +00:00
|
|
|
xmlNodePtr field = parent->childs;
|
2000-08-28 20:20:55 +00:00
|
|
|
guint16 typeid = 0;
|
|
|
|
|
2000-10-08 22:17:11 +00:00
|
|
|
while (field) {
|
2000-11-11 15:13:50 +00:00
|
|
|
if (!strcmp (field->name, "mime")) {
|
|
|
|
typeid = gst_type_find_by_mime (xmlNodeGetContent (field));
|
2000-10-08 22:17:11 +00:00
|
|
|
if (!typeid) {
|
2000-11-11 15:13:50 +00:00
|
|
|
GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
|
2000-10-08 22:17:11 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
factory->mime = g_strdup (xmlNodeGetContent (field));
|
|
|
|
typeid = gst_type_register (factory);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
2000-10-08 22:17:11 +00:00
|
|
|
return typeid;
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
2000-10-08 22:17:11 +00:00
|
|
|
field = field->next;
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return typeid;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_typefactory_save_thyself:
|
|
|
|
* @factory: the type factory to save
|
|
|
|
* @parent: the parent node to save into
|
|
|
|
*
|
|
|
|
* save a typefactory into an XML representation
|
|
|
|
*
|
|
|
|
* Returns: the new xmlNodePtr
|
|
|
|
*/
|
|
|
|
xmlNodePtr
|
|
|
|
gst_typefactory_save_thyself (GstTypeFactory *factory, xmlNodePtr parent)
|
|
|
|
{
|
|
|
|
xmlNewChild (parent, NULL, "mime", factory->mime);
|
2000-08-28 20:20:55 +00:00
|
|
|
if (factory->exts) {
|
2000-11-11 15:13:50 +00:00
|
|
|
xmlNewChild (parent, NULL, "extensions", factory->exts);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
if (factory->typefindfunc) {
|
2000-11-11 15:13:50 +00:00
|
|
|
xmlNewChild (parent, NULL, "typefind", NULL);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv)
|
2000-08-28 20:20:55 +00:00
|
|
|
{
|
|
|
|
GstType *type = (GstType *)priv;
|
|
|
|
guint16 typeid;
|
2000-11-11 15:13:50 +00:00
|
|
|
g_print ("gsttype: need to load typefind function\n");
|
2000-08-28 20:20:55 +00:00
|
|
|
|
|
|
|
type->typefindfunc = NULL;
|
2000-11-11 15:13:50 +00:00
|
|
|
gst_plugin_load_typefactory (type->mime);
|
|
|
|
typeid = gst_type_find_by_mime (type->mime);
|
|
|
|
type = gst_type_find_by_id (typeid);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
|
|
|
if (type->typefindfunc) {
|
2000-11-11 15:13:50 +00:00
|
|
|
return type->typefindfunc (buffer, type);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
/**
|
|
|
|
* gst_typefactory_load_thyself:
|
|
|
|
* @parent: the parent node to load from
|
|
|
|
*
|
|
|
|
* load a typefactory from an XML representation
|
|
|
|
*
|
|
|
|
* Returns: the new typefactory
|
|
|
|
*/
|
|
|
|
GstTypeFactory*
|
|
|
|
gst_typefactory_load_thyself (xmlNodePtr parent)
|
|
|
|
{
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2000-11-11 15:13:50 +00:00
|
|
|
GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
|
2000-08-28 20:20:55 +00:00
|
|
|
xmlNodePtr field = parent->childs;
|
|
|
|
factory->typefindfunc = NULL;
|
|
|
|
|
|
|
|
while (field) {
|
2000-11-11 15:13:50 +00:00
|
|
|
if (!strcmp (field->name, "mime")) {
|
|
|
|
factory->mime = g_strdup (xmlNodeGetContent (field));
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
else if (!strcmp (field->name, "extensions")) {
|
|
|
|
factory->exts = g_strdup (xmlNodeGetContent (field));
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
2000-11-11 15:13:50 +00:00
|
|
|
else if (!strcmp (field->name, "typefind")) {
|
2000-08-28 20:20:55 +00:00
|
|
|
factory->typefindfunc = gst_type_typefind_dummy;
|
|
|
|
}
|
|
|
|
field = field->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|