Bins

A Bin is a container element. You can add elements to a bin. Since a bin is an GstElement itself, it can also be added to another bin.

Bins allow you to combine linked elements into one logical element. You do not deal with the individual elements anymore but with just one element, the bin. We will see that this is extremely powerful when you are going to construct complex pipelines since it allows you to break up the pipeline in smaller chunks.

The bin will also manage the elements contained in it. It will figure out how the data will flow in the bin and generate an optimal plan for that data flow. Plan generation is one of the most complicated procedures in GStreamer.

Figure 1. Visualisation of a GstBin element with some elements in it

There are two standard bins available to the GStreamer programmer:

Creating a bin

Bins are created in the same way that other elements are created. ie. using an element factory, or any of the associated convenience functions:


  GstElement *bin, *thread, *pipeline;
  
  /* create a new bin called 'mybin'. this bin will be only for organizational purposes; a normal
     GstBin doesn't affect plan generation */
  bin = gst_element_factory_make ("bin", "mybin");

  /* create a new thread, and give it a unique name */
  thread = gst_element_factory_make ("thread", NULL);

  /* the core bins (GstBin, GstThread, GstPipeline) also have convenience APIs,
     gst_<bintype>_new (). these are equivalent to the gst_element_factory_make () syntax. */
  pipeline = gst_pipeline_new ("pipeline_name");