Elements are added to a bin with the following code sample:
GstElement *element;
GstElement *bin;
bin = gst_bin_new ("mybin");
element = gst_element_factory_make ("mpg123", "decoder");
gst_bin_add (GST_BIN (bin), element);
...
Bins and threads can be added to other bins too. This allows you to create nested bins. Note that it doesn't make very much sense to add a GstPipeline to anything, as it's a toplevel bin that needs to be explicitly iterated.
To get an element from the bin you can use:
GstElement *element;
element = gst_bin_get_by_name (GST_BIN (bin), "decoder");
...
You can see that the name of the element becomes very handy for retrieving the element from a bin by using the element's name. gst_bin_get_by_name () will recursively search nested bins.
To get a list of elements in a bin, use:
GList *elements;
elements = gst_bin_get_list (GST_BIN (bin));
while (elements) {
GstElement *element = GST_ELEMENT (elements->data);
g_print ("element in bin: %s\n", GST_OBJECT_NAME (GST_OBJECT (element)));
elements = g_list_next (elements);
}
...
To remove an element from a bin, use:
GstElement *element;
gst_bin_remove (GST_BIN (bin), element);
...
To add many elements to a bin at the same time, use the gst_bin_add_many () function. Remember to pass NULL as the last argument.
GstElement *filesrc, *decoder, *audiosink;
GstBin *bin;
/* instantiate the elements and the bins... */
gst_bin_add_many (bin, filesrc, decoder, audiosink, NULL);