<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Cothreads</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="Queues" HREF="chapter-queues.html"><LINK REL="NEXT" TITLE="Loop-based elements" HREF="section-loop-based.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="chapter-queues.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-loop-based.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="chapter-cothreads" ></A >Chapter 23. Cothreads</H1 ><P > Cothreads are user-space threads that greatly reduce context switching overhead introduced by regular kernel threads. Cothreads are also used to handle the more complex elements. They differ from other user-space threading libraries in that they are scheduled explictly by GStreamer. </P ><P > A cothread is created by a <CODE CLASS="classname" >GstBin</CODE > whenever an element is found inside the bin that has one or more of the following properties: <P ></P ><UL ><LI ><P > The element is loop-based instead of chain-based </P ></LI ><LI ><P > The element has multiple input pads </P ></LI ><LI ><P > The element has the MULTI_IN flag set </P ></LI ></UL > The <CODE CLASS="classname" >GstBin</CODE > will create a cothread context for all the elements in the bin so that the elements will interact in cooperative multithreading. </P ><P > Before proceding to the concept of loop-based elements we will first explain the chain-based elements. </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-chain-based" >23.1. Chain-based elements</A ></H1 ><P > Chain based elements receive a buffer of data and are supposed to handle the data and perform a gst_pad_push. </P ><P > The basic main function of a chain-based element is like: </P ><PRE CLASS="programlisting" > static void chain_function (GstPad *pad, GstBuffer *buffer) { GstBuffer *outbuffer; .... // process the buffer, create a new outbuffer ... gst_pad_push (srcpad, outbuffer); } </PRE ><P > Chain based function are mainly used for elements that have a one to one relation between their input and output behaviour. An example of such an element can be a simple video blur filter. The filter takes a buffer in, performs the blur operation on it and sends out the resulting buffer. </P ><P > Another element, for example, is a volume filter. The filter takes audio samples as input, performs the volume effect and sends out the resulting buffer. </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="chapter-queues.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-loop-based.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Queues</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" >Loop-based elements</TD ></TR ></TABLE ></DIV ></BODY ></HTML >