<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Threads</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="Advanced GStreamer concepts" HREF="part-advanced.html"><LINK REL="PREVIOUS" TITLE="Advanced GStreamer concepts" HREF="part-advanced.html"><LINK REL="NEXT" TITLE="When would you want to use a thread?" HREF="section-threads-when.html"></HEAD ><BODY CLASS="chapter" 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="part-advanced.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-threads-when.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="chapter-threads" ></A >Chapter 21. Threads</H1 ><P > GStreamer has support for multithreading through the use of the <CODE CLASS="classname" >GstThread</CODE > object. This object is in fact a special <CODE CLASS="classname" >GstBin</CODE > that will become a thread when started. </P ><P > To construct a new thread you will perform something like: </P ><P > <PRE CLASS="programlisting" > GstElement *my_thread; /* create the thread object */ my_thread = gst_thread_new ("my_thread"); /* you could have used gst_element_factory_make ("thread", "my_thread"); */ g_return_if_fail (my_thread != NULL); /* add some plugins */ gst_bin_add (GST_BIN (my_thread), GST_ELEMENT (funky_src)); gst_bin_add (GST_BIN (my_thread), GST_ELEMENT (cool_effect)); /* link the elements here... */ ... /* start playing */ gst_element_set_state (GST_ELEMENT (my_thread), GST_STATE_PLAYING); </PRE > </P ><P > The above program will create a thread with two elements in it. As soon as it is set to the PLAYING state, the thread will start to iterate itself. You never need to explicitly iterate a thread. </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-threads-constraints" >21.1. Constraints placed on the pipeline by the GstThread</A ></H1 ><P > Within the pipeline, everything is the same as in any other bin. The difference lies at the thread boundary, at the link between the thread and the outside world (containing bin). Since GStreamer is fundamentally buffer-oriented rather than byte-oriented, the natural solution to this problem is an element that can "buffer" the buffers between the threads, in a thread-safe fashion. This element is the queue, described more fully in <A HREF="chapter-queues.html" >Chapter 22</A >. It doesn't matter if the queue is placed in the containing bin or in the thread itself, but it needs to be present on one side or the other to enable inter-thread communication. </P ></DIV ></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="part-advanced.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-threads-when.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Advanced <SPAN CLASS="application" >GStreamer</SPAN > concepts</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="part-advanced.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >When would you want to use a thread?</TD ></TR ></TABLE ></DIV ></BODY ></HTML >