#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);
}
}
+/**
+ * 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
/* 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 */
*
* 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
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
{
return gst_element_connect_elements_filtered (src, dest, NULL);
}
+
/**
* gst_element_connect_filtered:
* @src: element containing source pad
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);
#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);
}