<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Adding elements to a bin</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="GStreamer Application Development Manual" HREF="index.html"><LINK REL="UP" TITLE="Bins" HREF="chapter-bins-api.html"><LINK REL="PREVIOUS" TITLE="Bins" HREF="chapter-bins-api.html"><LINK REL="NEXT" TITLE="Custom bins" HREF="section-bin-custom.html"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" ><SPAN CLASS="application" >GStreamer</SPAN > Application Development Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="chapter-bins-api.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 16. Bins</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-bin-custom.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-bin-adding" >16.2. Adding elements to a bin</A ></H1 ><P > Elements are added to a bin with the following code sample: </P ><PRE CLASS="programlisting" > GstElement *element; GstElement *bin; bin = gst_bin_new ("mybin"); element = gst_element_factory_make ("mpg123", "decoder"); gst_bin_add (GST_BIN (bin), element); ... </PRE ><P > Bins and threads can be added to other bins too. This allows you to create nested bins. Pipelines shouldn't be added to any other element, though. They are toplevel bins and they are directly linked to the scheduler. </P ><P > To get an element from the bin you can use: </P ><PRE CLASS="programlisting" > GstElement *element; element = gst_bin_get_by_name (GST_BIN (bin), "decoder"); ... </PRE ><P > 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. </P ><P > To get a list of elements in a bin, use: </P ><PRE CLASS="programlisting" > 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); } ... </PRE ><P > To remove an element from a bin, use: </P ><PRE CLASS="programlisting" > GstElement *element; gst_bin_remove (GST_BIN (bin), element); ... </PRE ><P > 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. </P ><PRE CLASS="programlisting" > GstElement *filesrc, *decoder, *audiosink; GstBin *bin; /* instantiate the elements and the bins... */ gst_bin_add_many (bin, filesrc, decoder, audiosink, NULL); </PRE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="chapter-bins-api.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="section-bin-custom.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Bins</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="chapter-bins-api.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Custom bins</TD ></TR ></TABLE ></DIV ></BODY ></HTML >