mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 21:21:12 +00:00
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:
parent
5f1c9c689c
commit
cbc6f66cf4
6 changed files with 103 additions and 45 deletions
|
@ -1,52 +1,47 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GstElement *bin, *filesrc, *decoder, *osssink;
|
GstElement *bin, *filesrc, *decoder, *osssink;
|
||||||
|
|
||||||
gst_init(&argc,&argv);
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
g_print("usage: %s <mp3 file>\n", argv[0]);
|
g_print ("usage: %s <mp3 file>\n", argv[0]);
|
||||||
exit(-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new bin to hold the elements */
|
/* create a new bin to hold the elements */
|
||||||
bin = gst_pipeline_new("pipeline");
|
bin = gst_pipeline_new ("pipeline");
|
||||||
|
|
||||||
/* create a disk reader */
|
/* create a disk reader */
|
||||||
filesrc = gst_elementfactory_make("filesrc", "disk_source");
|
filesrc = gst_elementfactory_make ("filesrc", "disk_source");
|
||||||
g_object_set(G_OBJECT(filesrc),"location", argv[1],NULL);
|
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||||
|
|
||||||
/* now it's time to get the decoder */
|
/* now it's time to get the decoder */
|
||||||
decoder = gst_elementfactory_make("mad","parse");
|
decoder = gst_elementfactory_make ("mad", "parse");
|
||||||
if (!decoder) {
|
if (!decoder) {
|
||||||
g_print ("could not find plugin \"mad\"");
|
g_print ("could not find plugin \"mad\"");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* and an audio sink */
|
/* and an audio sink */
|
||||||
osssink = gst_elementfactory_make("osssink", "play_audio");
|
osssink = gst_elementfactory_make ("osssink", "play_audio");
|
||||||
|
|
||||||
/* add objects to the main pipeline */
|
/* add objects to the main pipeline */
|
||||||
gst_bin_add(GST_BIN(bin), filesrc);
|
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, osssink, NULL);
|
||||||
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"));
|
|
||||||
|
|
||||||
|
/* connect the elements */
|
||||||
|
gst_element_connect_elements_many (filesrc, decoder, osssink, NULL);
|
||||||
|
|
||||||
/* start playing */
|
/* 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 */
|
/* stop the bin */
|
||||||
gst_element_set_state(bin, GST_STATE_NULL);
|
gst_element_set_state (bin, GST_STATE_NULL);
|
||||||
|
|
||||||
exit(0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
gst/gstbin.c
30
gst/gstbin.c
|
@ -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:
|
* gst_bin_add:
|
||||||
* @bin: #GstBin to add element to
|
* @bin: #GstBin to add element to
|
||||||
|
|
|
@ -105,6 +105,7 @@ GstElement* gst_bin_new (const gchar *name);
|
||||||
|
|
||||||
/* add and remove elements from the bin */
|
/* add and remove elements from the bin */
|
||||||
void gst_bin_add (GstBin *bin, GstElement *element);
|
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);
|
void gst_bin_remove (GstBin *bin, GstElement *element);
|
||||||
|
|
||||||
/* retrieve a single element or the list of children */
|
/* retrieve a single element or the list of children */
|
||||||
|
|
|
@ -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
|
* Returns: the pad to which a connection can be made
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GstPad*
|
GstPad*
|
||||||
gst_element_get_compatible_pad (GstElement *element, GstPad *pad)
|
gst_element_get_compatible_pad (GstElement *element, GstPad *pad)
|
||||||
{
|
{
|
||||||
return gst_element_get_compatible_pad_filtered (element, pad, NULL);
|
return gst_element_get_compatible_pad_filtered (element, pad, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_element_connect_elements:
|
* gst_element_connect_elements:
|
||||||
* @src: the element containing source pad
|
* @src: the element containing source pad
|
||||||
|
@ -927,6 +927,41 @@ gst_element_connect_elements_filtered (GstElement *src, GstElement *dest,
|
||||||
return FALSE;
|
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:
|
* gst_element_connect_elements:
|
||||||
* @src: element containing source pad
|
* @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);
|
return gst_element_connect_elements_filtered (src, dest, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_element_connect_filtered:
|
* gst_element_connect_filtered:
|
||||||
* @src: element containing source pad
|
* @src: element containing source pad
|
||||||
|
|
|
@ -224,6 +224,7 @@ gboolean gst_element_connect_filtered (GstElement *src, const gchar *srcpadname
|
||||||
void gst_element_disconnect (GstElement *src, const gchar *srcpadname,
|
void gst_element_disconnect (GstElement *src, const gchar *srcpadname,
|
||||||
GstElement *dest, const gchar *destpadname);
|
GstElement *dest, const gchar *destpadname);
|
||||||
void gst_element_disconnect_elements (GstElement *src, GstElement *dest);
|
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);
|
void gst_element_set_eos (GstElement *element);
|
||||||
|
|
||||||
|
|
|
@ -1,52 +1,47 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GstElement *bin, *filesrc, *decoder, *osssink;
|
GstElement *bin, *filesrc, *decoder, *osssink;
|
||||||
|
|
||||||
gst_init(&argc,&argv);
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
g_print("usage: %s <mp3 file>\n", argv[0]);
|
g_print ("usage: %s <mp3 file>\n", argv[0]);
|
||||||
exit(-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new bin to hold the elements */
|
/* create a new bin to hold the elements */
|
||||||
bin = gst_pipeline_new("pipeline");
|
bin = gst_pipeline_new ("pipeline");
|
||||||
|
|
||||||
/* create a disk reader */
|
/* create a disk reader */
|
||||||
filesrc = gst_elementfactory_make("filesrc", "disk_source");
|
filesrc = gst_elementfactory_make ("filesrc", "disk_source");
|
||||||
g_object_set(G_OBJECT(filesrc),"location", argv[1],NULL);
|
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
||||||
|
|
||||||
/* now it's time to get the decoder */
|
/* now it's time to get the decoder */
|
||||||
decoder = gst_elementfactory_make("mad","parse");
|
decoder = gst_elementfactory_make ("mad", "parse");
|
||||||
if (!decoder) {
|
if (!decoder) {
|
||||||
g_print ("could not find plugin \"mad\"");
|
g_print ("could not find plugin \"mad\"");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* and an audio sink */
|
/* and an audio sink */
|
||||||
osssink = gst_elementfactory_make("osssink", "play_audio");
|
osssink = gst_elementfactory_make ("osssink", "play_audio");
|
||||||
|
|
||||||
/* add objects to the main pipeline */
|
/* add objects to the main pipeline */
|
||||||
gst_bin_add(GST_BIN(bin), filesrc);
|
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, osssink, NULL);
|
||||||
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"));
|
|
||||||
|
|
||||||
|
/* connect the elements */
|
||||||
|
gst_element_connect_elements_many (filesrc, decoder, osssink, NULL);
|
||||||
|
|
||||||
/* start playing */
|
/* 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 */
|
/* stop the bin */
|
||||||
gst_element_set_state(bin, GST_STATE_NULL);
|
gst_element_set_state (bin, GST_STATE_NULL);
|
||||||
|
|
||||||
exit(0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue