Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > f0a9f2b9c81d34eadc43f527947c0b70 > files > 197

libgstreamer0.7-devel-0.7.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>The chain function</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="GStreamer Plugin Writer's Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Building a Filter"
HREF="part-building.html"><LINK
REL="PREVIOUS"
TITLE="Explicit caps"
HREF="section-pads-explicitcaps.html"><LINK
REL="NEXT"
TITLE="
    What are states?
  "
HREF="chapter-statemanage-states.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
> Plugin Writer's Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="section-pads-explicitcaps.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="chapter-statemanage-states.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="chapter-building-chainfn"
></A
>Chapter 5. The chain function</H1
><P
>&#13;    The chain function is the function in which all data processing takes
    place. In the case of a simple filter, <CODE
CLASS="function"
>_chain ()</CODE
>
    functions are mostly lineair functions - so for each incoming buffer,
    one buffer will go out, too. Below is a very simple implementation of
    a chain function:
  </P
><PRE
CLASS="programlisting"
>&#13;static void
gst_my_filter_chain (GstPad  *pad,
		     GstData *data)
{
  GstMyFilter *filter = GST_MY_FILTER (gst_pad_get_parent (pad));
  GstBuffer *buf = GST_BUFFER (data);

  if (!filter-&#62;silent)
    g_print ("Have data of size %u bytes!\n", GST_BUFFER_SIZE (buf));

  gst_pad_push (filter-&#62;srcpad, GST_DATA (buf));
}
  </PRE
><P
>&#13;    Obviously, the above doesn't do much useful. Instead of printing that the
    data is in, you would normally process the data there. Remember, however,
    that buffers are not always writable. In more advanced elements (the ones
    that do event processing), the incoming data might not even be a buffer.
  </P
><PRE
CLASS="programlisting"
>&#13;static void
gst_my_filter_chain (GstPad  *pad,
                     GstData *data)
{
  GstMyFilter *filter = GST_MY_FILTER (gst_pad_get_parent (pad));
  GstBuffer *buf, *outbuf;

  if (GST_IS_EVENT (data)) {
    GstEvent *event = GST_EVENT (data);

    switch (GST_EVENT_TYPE (event)) {
      case GST_EVENT_EOS:
        /* end-of-stream, we should close down all stream leftovers here */
        gst_my_filter_stop_processing (filter);
        /* fall-through to default event handling */
      default:
        gst_pad_event_default (pad, event);
        break;
    }
    return;
  }

  buf = GST_BUFFER (data);
  outbuf = gst_my_filter_process_data (buf);
  gst_buffer_unref (buf);
  if (!outbuf) {
    /* something went wrong - signal an error */
    gst_element_error (GST_ELEMENT (filter), STREAM, FAILED, (NULL), (NULL));
    return;
  }

  gst_pad_push (filter-&#62;srcpad, GST_DATA (outbuf));
}
  </PRE
><P
>&#13;    In some cases, it might be useful for an element to have control over the
    input data rate, too. In that case, you probably want to write a so-called
    <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>loop-based</I
></SPAN
> element. Source elements (with only source
    pads) can also be <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>get-based</I
></SPAN
> elements. These concepts
    will be explained in the advanced section of this guide, and in the section
    that specifically discusses source pads.
  </P
></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="section-pads-explicitcaps.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="chapter-statemanage-states.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Explicit caps</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="part-building.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>What are states?</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>