Add gst_element_request_compatible_pad and remove gst_element_request_pad.

Original commit message from CVS:
Add gst_element_request_compatible_pad and remove gst_element_request_pad.
Implemented something reasonable for gst_element_request_compatible_pad,
but havn't tested much: it won't work for tee because the pad templates
have no caps, and negotiation is not yet written, so it is assumed that the
tee pads can't connect to anything.
This commit is contained in:
Richard Boulton 2001-01-23 18:42:23 +00:00
parent ba237a38dd
commit d20f0b4bae
3 changed files with 99 additions and 9 deletions

View file

@ -344,19 +344,79 @@ gst_element_get_padtemplate_by_name (GstElement *element, const guchar *name)
return NULL;
}
/**
* gst_element_get_padtemplate_by_compatible:
* @element: element to get padtemplate of
* @templ: a template to find a compatible template for
*
* Generate a padtemplate for this element compatible with the given
* template, ie able to link to it.
*
* Returns: the padtemplate
*/
static GstPadTemplate*
gst_element_get_padtemplate_by_compatible (GstElement *element, GstPadTemplate *compattempl)
{
GstPadTemplate *newtempl = NULL;
GList *padlist;
GST_DEBUG(0,"gst_element_get_padtemplate_by_compatible()\n");
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (compattempl != NULL, NULL);
padlist = gst_element_get_padtemplate_list (element);
while (padlist) {
GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
gboolean compat = FALSE;
// Ignore name
// Ignore presence
// Check direction (must be opposite)
// Check caps
GST_DEBUG(0,"checking direction and caps\n");
if (padtempl->direction == GST_PAD_SRC &&
compattempl->direction == GST_PAD_SINK) {
GST_DEBUG(0,"compatible direction: found src pad template\n");
compat = gst_caps_list_check_compatibility(padtempl->caps,
compattempl->caps);
GST_DEBUG(0,"caps are %scompatible\n", (compat?"":"not "));
} else if (padtempl->direction == GST_PAD_SINK &&
compattempl->direction == GST_PAD_SRC) {
GST_DEBUG(0,"compatible direction: found sink pad template\n");
compat = gst_caps_list_check_compatibility(compattempl->caps,
padtempl->caps);
GST_DEBUG(0,"caps are %scompatible\n", (compat?"":"not "));
}
if (compat) {
newtempl = padtempl;
break;
}
padlist = g_list_next (padlist);
}
return newtempl;
}
/**
* gst_element_request_pad:
* @element: element to request a new pad from
* @templ: the padtemplate specifuing the pad to get.
* @templ: the padtemplate specifying the pad to connect to.
*
* Request a new pad from the element. The template will
* be used to decide what type of pad to create. This function
* is typically used for elements with a padtemplate with presence
* GST_PAD_REQUEST.
*
* Returns: the new pad that was created.
* Returns: the new pad that was created, NULL if no suitable pad can be
* created.
*/
GstPad*
static GstPad*
gst_element_request_pad (GstElement *element, GstPadTemplate *templ)
{
GstPad *newpad = NULL;
@ -374,6 +434,35 @@ gst_element_request_pad (GstElement *element, GstPadTemplate *templ)
return newpad;
}
/**
* gst_element_request_compatible_pad:
* @element: element to request a new pad from
* @templ: a pad template to which the new pad should be able to connect
*
* Request a new pad from the element. The template will
* be used to decide what type of pad to create. This function
* is typically used for elements with a padtemplate with presence
* GST_PAD_REQUEST.
*
* Returns: the new pad that was created.
*/
GstPad*
gst_element_request_compatible_pad (GstElement *element, GstPadTemplate *templ)
{
GstPadTemplate *templ_new;
GstPad *pad = NULL;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (templ != NULL, NULL);
templ_new = gst_element_get_padtemplate_by_compatible (element, templ);
if (templ_new != NULL)
pad = gst_element_request_pad (element, templ_new);
return pad;
}
/**
* gst_element_request_pad_by_name:
* @element: element to request a new pad from

View file

@ -211,7 +211,7 @@ GstPadTemplate* gst_element_get_padtemplate_by_name (GstElement *element, const
void gst_element_add_ghost_pad (GstElement *element, GstPad *pad, gchar *name);
void gst_element_remove_ghost_pad (GstElement *element, GstPad *pad);
GstPad* gst_element_request_pad (GstElement *element, GstPadTemplate *templ);
GstPad* gst_element_request_compatible_pad (GstElement *element, GstPadTemplate *templ);
GstPad* gst_element_request_pad_by_name (GstElement *element, const gchar *name);
void gst_element_connect (GstElement *src, const gchar *srcpadname,

View file

@ -22,15 +22,16 @@ main(int argc, char *argv[])
templ = gst_element_get_padtemplate_by_name (mp3parse, "sink");
templ = gst_padtemplate_create ("src%d", GST_PAD_SRC, GST_PAD_REQUEST, templ->caps);
pad = gst_element_request_pad (element, templ);
pad = gst_element_request_compatible_pad (element, templ);
g_print ("new pad %s\n", gst_pad_get_name (pad));
parent = xmlNewChild (doc->xmlRootNode, NULL, "Padtemplate", NULL);
if (pad != NULL) {
parent = xmlNewChild (doc->xmlRootNode, NULL, "Padtemplate", NULL);
gst_padtemplate_save_thyself (pad->padtemplate, parent);
gst_padtemplate_save_thyself (pad->padtemplate, parent);
xmlDocDump(stdout, doc);
xmlDocDump(stdout, doc);
}
return 0;
}