Adding elements to a bin

Elements are added to a bin with the following code sample:

  GstElement *element;
  GstElement *bin;
  
  bin = gst_bin_new ("mybin");
  
  element = gst_elementfactory_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.

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 an bin by using the elements 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_element_get_name (element));

    elements = g_list_next (elements);
  }
   ...
    

To remove an element from a bin use:

  GstElement *element;
  
  gst_bin_remove (GST_BIN (bin), element);
   ...