## GstBin

GstBin — Base class for elements that contain other elements

## Synopsis

    #include <gst/gst.h>

                GstBin;
    enum        GstBinFlags;
    GstElement* gst_bin_new                     (const gchar *name);
    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_many             (GstBin *bin,
                                                 GstElement *element_1,
                                                 ...);
    GstElement* gst_bin_get_by_name             (GstBin *bin,
                                                 const gchar *name);
    GstElement* gst_bin_get_by_name_recurse_up  (GstBin *bin,
                                                 const gchar *name);
    const GList* gst_bin_get_list               (GstBin *bin);
    GstElement* gst_bin_get_by_interface        (GstBin *bin,
                                                 GType interface);
    GList*      gst_bin_get_all_by_interface    (GstBin *bin,
                                                 GType interface);
    gboolean    gst_bin_iterate                 (GstBin *bin);
    void        gst_bin_use_clock               (GstBin *bin,
                                                 GstClock *clock);
    GstClock*   gst_bin_get_clock               (GstBin *bin);
    void        gst_bin_auto_clock              (GstBin *bin);
    GstElementStateReturn gst_bin_sync_children_state
                                                (GstBin *bin);
    void        gst_bin_child_state_change      (GstBin *bin,
                                                 GstElementState oldstate,
                                                 GstElementState newstate,
                                                 GstElement *child);

## Object Hierarchy

      GObject
       +----GstObject
             +----GstElement
                   +----GstBin
                         +----GstPipeline
                         +----GstThread

## Implemented Interfaces

GstBin implements

## Signal Prototypes

    "element-added"
                void        user_function      (GstBin *gstbin,
                                                GstElement *arg1,
                                                gpointer user_data);
    "element-removed"
                void        user_function      (GstBin *gstbin,
                                                GstElement *arg1,
                                                gpointer user_data);
    "iterate"   gboolean    user_function      (GstBin *gstbin,
                                                gpointer user_data);

## Description

GstBin is the simplest of the container elements, allowing elements to become children of itself. Pads from the child elements can be ghosted to the bin, making the bin itself look transparently like any other element, allowing for deep nesting of predefined sub-pipelines.

A new GstBin is created with `gst_bin_new()`. Use a GstPipeline instead if you want to create a toplevel bin because a normal bin doesn't have a scheduler of its own.

After the bin has been created you will typically add elements to it with `gst_bin_add()`. You can remove elements with `gst_bin_remove()`.

An element can be retrieved from a bin with `gst_bin_get_by_name()`, using the elements name. `gst_bin_get_by_name_recurse_up()` is mainly used for internal purposes and will query the parent bins when the element is not found in the current bin.

The list of elements in a bin can be retrieved with `gst_bin_get_list()`.

After the bin has been set to the PLAYING state (with `gst_element_set_state()`), `gst_bin_iterate()` is used to process the elements in the bin.

The "element_added" signal is fired whenever a new element is added to the bin.

The "element_removed" signal is fired whenever an element is removed from the bin.

`gst_bin_destroy()` is used to destroy the bin.

To control the selection of the clock in a bin, you can use the following methods: `gst_bin_auto_clock()` to let the bin select a clock automatically, `gst_bin_get_clock()` to get the current clock of the bin and `gst_bin_use_clock()` to specify a clock explicitly. Note that the default behaviour is to automatically select a clock from one of the clock providers in the bin.

## Details

### GstBin

    typedef struct _GstBin GstBin;

### enum GstBinFlags

    typedef enum {
      GST_BIN_FLAG_MANAGER		= GST_ELEMENT_FLAG_LAST,
      GST_BIN_SELF_SCHEDULABLE,
      GST_BIN_FLAG_PREFER_COTHREADS,
      GST_BIN_FLAG_FIXED_CLOCK,
      GST_BIN_STATE_LOCKED,
      GST_BIN_FLAG_LAST		= GST_ELEMENT_FLAG_LAST + 5
    } GstBinFlags;

GstBinFlags are a set of flags specific to bins. Most are set/used internally. They can be checked using the `GST_FLAG_IS_SET()` macro, and (un)set using `GST_FLAG_SET()` and `GST_FLAG_UNSET()`.

`GST_BIN_FLAG_MANAGER` | this bin is a manager of child elements, i.e. a pipeline or thread.
`GST_BIN_SELF_SCHEDULABLE` | the bin iterates itself.
`GST_BIN_FLAG_PREFER_COTHREADS` | we prefer to have cothreads when its an option, over chain-based.
`GST_BIN_FLAG_FIXED_CLOCK` | bin has one clock that cannot be changed.
`GST_BIN_STATE_LOCKED` | indicator that we are in a non-recursive state-change on the bin, or that kids should not change parent state. Both are internally used to prevent infinitely recursive loops of state changes. Since they are mutually exclusive and serve the same purpose, we use the same flag for them.
`GST_BIN_FLAG_LAST` | the last enum in the series of flags in a bin, derived classes can use this as first value in a list of flags.

### gst_bin_new ()

    GstElement* gst_bin_new                     (const gchar *name);

Create a new bin with given name.

`name` : | name of new bin
Returns : | new bin

### gst_bin_add ()

    void        gst_bin_add                     (GstBin *bin,
                                                 GstElement *element);

Adds the given element to the bin. Sets the element's parent, and thus takes ownership of the element. An element can only be added to one bin.

`bin` : | GstBin to add element to
`element` : | GstElement to add to bin

### gst_bin_add_many ()

    void        gst_bin_add_many                (GstBin *bin,
                                                 GstElement *element_1,
                                                 ...);

Adds a NULL-terminated list of elements to a bin. This function is equivalent to calling #`gst_bin_add()` for each member of the list.

`bin` : | the bin to add the elements to
`element_1` : | the first element to add to the bin
`...` : | additional elements to add to the bin

### gst_bin_remove ()

    void        gst_bin_remove                  (GstBin *bin,
                                                 GstElement *element);

Remove the element from its associated bin, unparenting it as well. Unparenting the element means that the element will be dereferenced, so if the bin holds the only reference to the element, the element will be freed in the process of removing it from the bin. If you want the element to still exist after removing, you need to call gst_object_ref before removing it from the bin.

`bin` : | GstBin to remove element from
`element` : | GstElement to remove

### gst_bin_remove_many ()

    void        gst_bin_remove_many             (GstBin *bin,
                                                 GstElement *element_1,
                                                 ...);

Remove a list of elements from a bin. This function is equivalent to calling gst_bin_remove with each member of the list.

`bin` : | the bin to remove the elements from
`element_1` : | the first element to remove from the bin
`...` : | NULL-terminated list of elements to remove from the bin

### gst_bin_get_by_name ()

    GstElement* gst_bin_get_by_name             (GstBin *bin,
                                                 const gchar *name);

Get the element with the given name from this bin.

`bin` : | Gstbin to search
`name` : | the element name to search for
Returns : | the element with the given name

### gst_bin_get_by_name_recurse_up ()

    GstElement* gst_bin_get_by_name_recurse_up  (GstBin *bin,
                                                 const gchar *name);

Get the element with the given name from this bin. If the element is not found, a recursion is performed on the parent bin.

`bin` : | Gstbin to search
`name` : | the element name to search for
Returns : | the element with the given name

### gst_bin_get_list ()

    const GList* gst_bin_get_list               (GstBin *bin);

Get the list of elements in this bin.

`bin` : | Gstbin to get the list from
Returns : | a GList of elements

### gst_bin_get_by_interface ()

    GstElement* gst_bin_get_by_interface        (GstBin *bin,
                                                 GType interface);

Looks for the first element inside the bin that implements the given interface. If such an element is found, it returns the element. You can cast this element to the given interface afterwards. If you want all elements that implement the interface, use `gst_bin_get_all_by_interface()`. The function recurses bins inside bins.

`bin` : | bin to find element in
`interface` : | interface to be implemented by interface
Returns : | An element inside the bin implementing the interface.

### gst_bin_get_all_by_interface ()

    GList*      gst_bin_get_all_by_interface    (GstBin *bin,
                                                 GType interface);

Looks for all elements inside the bin that implements the given interface. You can safely cast all returned elements to the given interface. The function recurses bins inside bins. You need to free the list using `g_list_free()` after use.

`bin` : | bin to find elements in
`interface` : | interface to be implemented by interface
Returns : | An element inside the bin implementing the interface.

### gst_bin_iterate ()

    gboolean    gst_bin_iterate                 (GstBin *bin);

Iterates over the elements in this bin.

`bin` : | aGstBin to iterate.
Returns : | TRUE if the bin did something useful. This value can be used to determine it the bin is in EOS.

### gst_bin_use_clock ()

    void        gst_bin_use_clock               (GstBin *bin,
                                                 GstClock *clock);

Force the bin to use the given clock. Use NULL to force it to use no clock at all.

`bin` : | the bin to set the clock for
`clock` : | the clock to use.

### gst_bin_get_clock ()

    GstClock*   gst_bin_get_clock               (GstBin *bin);

Gets the current clock of the (scheduler of the) bin.

`bin` : | a GstBin to get the clock of
Returns : | the GstClock of the bin

### gst_bin_auto_clock ()

    void        gst_bin_auto_clock              (GstBin *bin);

Let the bin select a clock automatically.

`bin` : | the bin to autoclock

### gst_bin_sync_children_state ()

    GstElementStateReturn gst_bin_sync_children_state
                                                (GstBin *bin);

Tries to set the state of the children of this bin to the same state of the bin by calling gst_element_set_state for each child not already having a synchronized state.

Returns: The worst return value of any gst_element_set_state. So if one child

`bin` : | Gstbin to sync state
Returns : | GST_STATE_FAILURE while all others return GST_STATE_SUCCESS this function returns GST_STATE_FAILURE.

### gst_bin_child_state_change ()

    void        gst_bin_child_state_change      (GstBin *bin,
                                                 GstElementState oldstate,
                                                 GstElementState newstate,
                                                 GstElement *child);

An internal function to inform the parent bin about a state change of a child.

`bin` : | GstBin with the child
`oldstate` : | The old child state
`newstate` : | The new child state
`child` : | GstElement that signaled an changed state

## Signals

### The "element-added" signal

    void        user_function                  (GstBin *gstbin,
                                                GstElement *arg1,
                                                gpointer user_data);

Will be emmited if a new element was removed/added to this bin.

`gstbin` : | the object which received the signal.
`arg1` : | the element that was added to the bin
`user_data` : | user data set when the signal handler was connected.

### The "element-removed" signal

    void        user_function                  (GstBin *gstbin,
                                                GstElement *arg1,
                                                gpointer user_data);

Will be emmited if an element was removed from this bin.

`gstbin` : | the object which received the signal.
`arg1` : | the element that was removed from the bin
`user_data` : | user data set when the signal handler was connected.

### The "iterate" signal

    gboolean    user_function                  (GstBin *gstbin,
                                                gpointer user_data);

This signal is emitted when a bin iterates, either automatically or due to a #`gst_bin_iterate()` call. The return value is used to determine if the object method handler processed any data. In most normal cases, a user-provided signal handler should return FALSE.

`gstbin` : | the object which received the signal.
`user_data` : | user data set when the signal handler was connected.
Returns : | TRUE if the state of the bin was advanced.