The typefind function now returns a GstCaps structure instead of a gboolean. modified some plugins to this new behaviour

Original commit message from CVS:
The typefind function now returns a GstCaps structure instead of a gboolean.
modified some plugins to this new behaviour
Fixed autoplugging for the mpg123 case. When an element is selected in
autoplugging and the caps do not match, another element is selected until the
caps match. only examples/autoplug works because gstmediaplay uses a threaded
setup that does not seem to work with the current scheduling.
This commit is contained in:
Wim Taymans 2000-12-17 16:24:14 +00:00
parent e40c284572
commit 510430d10f
7 changed files with 73 additions and 25 deletions

View file

@ -17,7 +17,7 @@
* Boston, MA 02111-1307, USA.
*/
#define GST_DEBUG_ENABLED
//#define GST_DEBUG_ENABLED
#include "gstbin.h"
#include "gstdebug.h"
@ -592,7 +592,6 @@ gst_bin_src_wrapper (int argc,char *argv[])
return 0;
}
/*
static void
gst_bin_pullregionfunc_proxy (GstPad *pad,
gulong offset,

View file

@ -22,6 +22,7 @@
#include "gstcaps.h"
#include "gsttype.h"
#include "gstpropsprivate.h"
void
_gst_caps_initialize (void)
{
@ -62,6 +63,7 @@ gst_caps_new (gchar *mime)
caps = g_new0 (GstCaps, 1);
caps->id = get_type_for_mime (mime);
caps->properties = NULL;
return caps;
}
@ -118,10 +120,22 @@ gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
if (fromcaps->id != tocaps->id)
return FALSE;
if (fromcaps->properties && tocaps->properties) {
return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
if (tocaps->properties) {
GstPropsEntry *entry = (GstPropsEntry *)tocaps->properties;
if (fromcaps->properties) {
return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
}
else {
g_print ("gstcaps: no source caps\n");
return FALSE;
}
}
else {
// assume it accepts everything
g_print ("gstcaps: no caps\n");
return TRUE;
}
else return TRUE;
}

View file

@ -626,6 +626,8 @@ gst_pad_connect (GstPad *srcpad,
else
g_print ("gstpad: connecting compatible pads\n");
}
else
g_print ("gstpad: could not check capabilities of pads\n");
/* first set peers */
srcpad->peer = sinkpad;

View file

@ -138,7 +138,8 @@ gst_pipeline_typefind (GstPipeline *pipeline, GstElement *element)
{
gboolean found = FALSE;
GstElement *typefind;
guint16 type_id = 0;
GstCaps *caps = NULL;
guint type_id = 0;
g_print("GstPipeline: typefind for element \"%s\" %p\n",
gst_element_get_name(element), &found);
@ -155,7 +156,6 @@ gst_pipeline_typefind (GstPipeline *pipeline, GstElement *element)
gst_bin_add (GST_BIN (pipeline), typefind);
gst_bin_create_plan (GST_BIN (pipeline));
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY);
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
// keep pushing buffers... the have_type signal handler will set the found flag
@ -166,11 +166,11 @@ gst_pipeline_typefind (GstPipeline *pipeline, GstElement *element)
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
if (found) {
GstType *type;
type_id = gst_util_get_int_arg (GTK_OBJECT (typefind), "type");
type = gst_type_find_by_id (type_id);
caps = gst_util_get_pointer_arg (GTK_OBJECT (typefind), "caps");
gst_pad_set_caps (gst_element_get_pad (element, "src"), gst_caps_new (type->mime));
gst_pad_set_caps (gst_element_get_pad (element, "src"), caps);
type_id = caps->id;
}
gst_pad_disconnect (gst_element_get_pad (element, "src"),
@ -196,16 +196,38 @@ gst_pipeline_pads_autoplug_func (GstElement *src, GstPad *pad, GstElement *sink)
// if we have a match, connect the pads
if (sinkpad->direction == GST_PAD_SINK &&
!GST_PAD_CONNECTED(sinkpad) &&
gst_caps_check_compatibility (pad->caps, sinkpad->caps))
!GST_PAD_CONNECTED(sinkpad))
{
gst_pad_connect(pad, sinkpad);
g_print("gstpipeline: autoconnect pad \"%s\" in element %s <-> ", pad->name,
if (gst_caps_check_compatibility (pad->caps, sinkpad->caps)) {
gst_pad_connect(pad, sinkpad);
g_print("gstpipeline: autoconnect pad \"%s\" in element %s <-> ", pad->name,
gst_element_get_name(src));
g_print("pad \"%s\" in element %s\n", sinkpad->name,
g_print("pad \"%s\" in element %s\n", sinkpad->name,
gst_element_get_name(sink));
connected = TRUE;
break;
connected = TRUE;
break;
}
else {
GList *factories;
g_print("gstpipeline: not compatible, find intermediate element\n");
factories = gst_type_get_sink_to_src (pad->caps->id, sinkpad->caps->id);
while (factories) {
GstElementFactory *factory = (GstElementFactory *)factories->data;
GstElement *element = gst_elementfactory_create (factory, factory->name);
g_print ("gstpipeline: trying element \"%s\"\n", element->name);
if (gst_pipeline_pads_autoplug_func (src, pad, element)) {
if (gst_pipeline_pads_autoplug_func (element, gst_element_get_pad (element, "src"), sink)) {
gst_bin_add (gst_object_get_parent (GST_OBJECT(sink)), element);
return TRUE;
}
}
factories = g_list_next (factories);
}
}
}
sinkpads = g_list_next(sinkpads);
}

View file

@ -103,12 +103,14 @@ gst_props_register (GstPropsFactory factory)
g_return_val_if_fail (factory != NULL, NULL);
tag = factory[i++];
if (!tag) return NULL;
props = g_new0 (GstProps, 1);
g_return_val_if_fail (props != NULL, NULL);
props->properties = NULL;
tag = factory[i++];
while (tag) {
GQuark quark;

View file

@ -50,7 +50,7 @@ struct _gst_type_node
typedef struct _gst_type_node gst_type_node;
static gboolean gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv);
static GstCaps* gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv);
/* we keep a (spase) matrix in the hashtable like:
*
@ -538,6 +538,14 @@ gst_type_find_cost (gint src, gint dest)
return MAX_COST;
}
static GList*
gst_type_find_identity (gint typeid)
{
GstType *type = gst_type_find_by_id (typeid);
return (GList *)g_hash_table_lookup (type->converters, GUINT_TO_POINTER (typeid));
}
/**
* gst_type_get_sink_to_src:
* @sinkid: the id of the sink
@ -558,7 +566,7 @@ gst_type_get_sink_to_src (guint16 sinkid, guint16 srcid)
g_print ("gsttype: find %d to %d\n", srcid, sinkid);
if (sinkid == srcid) {
//FIXME return an identity element
return NULL;
return gst_type_find_identity (sinkid);
}
else {
rgnNodes = g_malloc (sizeof (gst_type_node) * _gst_maxtype);
@ -680,7 +688,7 @@ gst_typefactory_save_thyself (GstTypeFactory *factory, xmlNodePtr parent)
return parent;
}
static gboolean
static GstCaps *
gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv)
{
GstType *type = (GstType *)priv;
@ -700,7 +708,8 @@ gst_type_typefind_dummy (GstBuffer *buffer, gpointer priv)
GstTypeFindFunc func = (GstTypeFindFunc) funcs->data;
if (func) {
if (func (buffer, type)) return TRUE;
GstCaps *res = func (buffer, type);
if (res) return res;
}
funcs = g_slist_next (funcs);

View file

@ -27,7 +27,7 @@
/* type of function used to check a stream for equality with type */
typedef gboolean (*GstTypeFindFunc) (GstBuffer *buf,gpointer priv);
typedef GstCaps *(*GstTypeFindFunc) (GstBuffer *buf,gpointer priv);
typedef struct _GstType GstType;
typedef struct _GstTypeFactory GstTypeFactory;