add two apis: gst_element_connect_elements_many (elem1, elem2, ...)

Original commit message from CVS:
* add two apis:
* gst_element_connect_elements_many (elem1, elem2, ...)
- calls gst_element_connect_elements() in order
- should be called gst_element_connect_many, but we need to rename gst_element_connect_elements first
- simplifies common-case code
* gst_bin_add_many (bin, elem1, ...)
- calls gst_bin_add on all of the elems
- again, simplifying common code
This commit is contained in:
Andy Wingo 2002-02-21 14:44:27 +00:00
parent 5f1c9c689c
commit cbc6f66cf4
6 changed files with 103 additions and 45 deletions

View file

@ -1,52 +1,47 @@
#include <stdlib.h>
#include <gst/gst.h>
int main(int argc,char *argv[])
int main (int argc, char *argv[])
{
GstElement *bin, *filesrc, *decoder, *osssink;
gst_init(&argc,&argv);
gst_init (&argc, &argv);
if (argc != 2) {
g_print("usage: %s <mp3 file>\n", argv[0]);
exit(-1);
g_print ("usage: %s <mp3 file>\n", argv[0]);
exit (-1);
}
/* create a new bin to hold the elements */
bin = gst_pipeline_new("pipeline");
bin = gst_pipeline_new ("pipeline");
/* create a disk reader */
filesrc = gst_elementfactory_make("filesrc", "disk_source");
g_object_set(G_OBJECT(filesrc),"location", argv[1],NULL);
filesrc = gst_elementfactory_make ("filesrc", "disk_source");
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
/* now it's time to get the decoder */
decoder = gst_elementfactory_make("mad","parse");
decoder = gst_elementfactory_make ("mad", "parse");
if (!decoder) {
g_print ("could not find plugin \"mad\"");
return -1;
}
/* and an audio sink */
osssink = gst_elementfactory_make("osssink", "play_audio");
osssink = gst_elementfactory_make ("osssink", "play_audio");
/* add objects to the main pipeline */
gst_bin_add(GST_BIN(bin), filesrc);
gst_bin_add(GST_BIN(bin), decoder);
gst_bin_add(GST_BIN(bin), osssink);
/* connect src to sink */
gst_pad_connect(gst_element_get_pad(filesrc,"src"),
gst_element_get_pad(decoder,"sink"));
gst_pad_connect(gst_element_get_pad(decoder,"src"),
gst_element_get_pad(osssink,"sink"));
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, osssink, NULL);
/* connect the elements */
gst_element_connect_elements_many (filesrc, decoder, osssink, NULL);
/* start playing */
gst_element_set_state(bin, GST_STATE_PLAYING);
gst_element_set_state (bin, GST_STATE_PLAYING);
while (gst_bin_iterate(GST_BIN(bin)));
while (gst_bin_iterate (GST_BIN (bin)));
/* stop the bin */
gst_element_set_state(bin, GST_STATE_NULL);
gst_element_set_state (bin, GST_STATE_NULL);
exit(0);
exit (0);
}

View file

@ -333,6 +333,36 @@ gst_bin_unset_element_sched (GstElement * element)
}
/**
* gst_element_connect_elements_many:
* @element_1: the first element to add to the bin
* @...: NULL-terminated list of elements to add to the bin
*
* Add a list of elements to a bin. Uses #gst_bin_add.
**/
/* API FIXME: this should be called gst_element_connect_many, and connect_elements
* should just be connect */
void
gst_bin_add_many (GstBin *bin, GstElement *element_1, ...)
{
va_list args;
g_return_if_fail (bin != NULL);
g_return_if_fail (element_1 != NULL);
g_return_if_fail (GST_IS_BIN (bin));
g_return_if_fail (GST_IS_ELEMENT (element_1));
va_start (args, element_1);
while (element_1) {
gst_bin_add (bin, element_1);
element_1 = va_arg (args, GstElement*);
}
va_end (args);
}
/**
* gst_bin_add:
* @bin: #GstBin to add element to

View file

@ -105,6 +105,7 @@ GstElement* gst_bin_new (const gchar *name);
/* add and remove elements from the bin */
void gst_bin_add (GstBin *bin, GstElement *element);
void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...);
void gst_bin_remove (GstBin *bin, GstElement *element);
/* retrieve a single element or the list of children */

View file

@ -824,12 +824,12 @@ gst_element_get_compatible_pad_filtered (GstElement *element, GstPad *pad, GstCa
*
* Returns: the pad to which a connection can be made
*/
GstPad*
gst_element_get_compatible_pad (GstElement *element, GstPad *pad)
{
return gst_element_get_compatible_pad_filtered (element, pad, NULL);
}
/**
* gst_element_connect_elements:
* @src: the element containing source pad
@ -927,6 +927,41 @@ gst_element_connect_elements_filtered (GstElement *src, GstElement *dest,
return FALSE;
}
/**
* gst_element_connect_elements_many:
* @element_1: the first element in the connection chain
* @element_2: the second element in the connection chain
* @...: NULL-terminated list of elements to connect in order
*
* Chain together a series of elements. Uses #gst_element_connect_elements.
*
* Returns: TRUE on success, FALSE otherwise.
**/
/* API FIXME: this should be called gst_element_connect_many, and connect_elements
* should just be connect */
gboolean
gst_element_connect_elements_many (GstElement *element_1, GstElement *element_2, ...)
{
va_list args;
g_return_val_if_fail (element_1 != NULL && element_2 != NULL, FALSE);
g_return_val_if_fail (GST_IS_ELEMENT (element_1) && GST_IS_ELEMENT (element_2), FALSE);
va_start (args, element_2);
while (element_2) {
if (!gst_element_connect_elements (element_1, element_2))
return FALSE;
element_1 = element_2;
element_2 = va_arg (args, GstElement*);
}
va_end (args);
return TRUE;
}
/**
* gst_element_connect_elements:
* @src: element containing source pad
@ -946,6 +981,7 @@ gst_element_connect_elements (GstElement *src, GstElement *dest)
{
return gst_element_connect_elements_filtered (src, dest, NULL);
}
/**
* gst_element_connect_filtered:
* @src: element containing source pad

View file

@ -224,6 +224,7 @@ gboolean gst_element_connect_filtered (GstElement *src, const gchar *srcpadname
void gst_element_disconnect (GstElement *src, const gchar *srcpadname,
GstElement *dest, const gchar *destpadname);
void gst_element_disconnect_elements (GstElement *src, GstElement *dest);
gboolean gst_element_connect_elements_many (GstElement *element_1, GstElement *element_2, ...);
void gst_element_set_eos (GstElement *element);

View file

@ -1,52 +1,47 @@
#include <stdlib.h>
#include <gst/gst.h>
int main(int argc,char *argv[])
int main (int argc, char *argv[])
{
GstElement *bin, *filesrc, *decoder, *osssink;
gst_init(&argc,&argv);
gst_init (&argc, &argv);
if (argc != 2) {
g_print("usage: %s <mp3 file>\n", argv[0]);
exit(-1);
g_print ("usage: %s <mp3 file>\n", argv[0]);
exit (-1);
}
/* create a new bin to hold the elements */
bin = gst_pipeline_new("pipeline");
bin = gst_pipeline_new ("pipeline");
/* create a disk reader */
filesrc = gst_elementfactory_make("filesrc", "disk_source");
g_object_set(G_OBJECT(filesrc),"location", argv[1],NULL);
filesrc = gst_elementfactory_make ("filesrc", "disk_source");
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
/* now it's time to get the decoder */
decoder = gst_elementfactory_make("mad","parse");
decoder = gst_elementfactory_make ("mad", "parse");
if (!decoder) {
g_print ("could not find plugin \"mad\"");
return -1;
}
/* and an audio sink */
osssink = gst_elementfactory_make("osssink", "play_audio");
osssink = gst_elementfactory_make ("osssink", "play_audio");
/* add objects to the main pipeline */
gst_bin_add(GST_BIN(bin), filesrc);
gst_bin_add(GST_BIN(bin), decoder);
gst_bin_add(GST_BIN(bin), osssink);
/* connect src to sink */
gst_pad_connect(gst_element_get_pad(filesrc,"src"),
gst_element_get_pad(decoder,"sink"));
gst_pad_connect(gst_element_get_pad(decoder,"src"),
gst_element_get_pad(osssink,"sink"));
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, osssink, NULL);
/* connect the elements */
gst_element_connect_elements_many (filesrc, decoder, osssink, NULL);
/* start playing */
gst_element_set_state(bin, GST_STATE_PLAYING);
gst_element_set_state (bin, GST_STATE_PLAYING);
while (gst_bin_iterate(GST_BIN(bin)));
while (gst_bin_iterate (GST_BIN (bin)));
/* stop the bin */
gst_element_set_state(bin, GST_STATE_NULL);
gst_element_set_state (bin, GST_STATE_NULL);
exit(0);
exit (0);
}