Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > d620e9f76c810e9fbdaebc304909c8fc > files > 293

lib64gstreamer0.10-devel-0.10.36-7.mga4.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Providing random access</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79;charset=UTF-8"><LINK
REL="HOME"
TITLE="GStreamer Plugin Writer's Guide (0.10.36)"
HREF="index.html"><LINK
REL="UP"
TITLE="Different scheduling modes"
HREF="chapter-scheduling.html"><LINK
REL="PREVIOUS"
TITLE="Pads driving the pipeline"
HREF="section-scheduling-loop.html"><LINK
REL="NEXT"
TITLE="Types and Properties"
HREF="chapter-building-types.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
> Plugin Writer's Guide (0.10.36)</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="section-scheduling-loop.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 11. Different scheduling modes</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="chapter-building-types.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="section-scheduling-randomxs"
>11.3. Providing random access</A
></H1
><P
>&#13;      In the previous section, we have talked about how elements (or pads)
      that are assigned to drive the pipeline using their own task, have
      random access over their sinkpads. This means that all elements linked
      to those pads (recursively) need to provide random access functions.
      Requesting random access is done using the function
      <CODE
CLASS="function"
>gst_pad_pull_range ()</CODE
>, which requests a buffer of
      a specified size and offset. Source pads implementing and assigned to
      do random access will have a <CODE
CLASS="function"
>_get_range ()</CODE
>-function
      set using <CODE
CLASS="function"
>gst_pad_set_getrange_function ()</CODE
>, and
      that function will be called when the peer pad requests some data. The
      element is then responsible for seeking to the right offset and
      providing the requested data. Several elements can implement random
      access:
    </P
><P
></P
><UL
><LI
><P
>&#13;          Data sources, such as a file source, that can provide data from any
          offset with reasonable low latency.
        </P
></LI
><LI
><P
>&#13;          Filters that would like to provide a pull-based-like scheduling
          mode over the whole pipeline. Note that elements assigned to do
          random access-based scheduling are themselves responsible for
          assigning this scheduling mode to their upstream peers! <SPAN
CLASS="application"
>GStreamer</SPAN
>
          will not do that for you.
        </P
></LI
><LI
><P
>&#13;          Parsers who can easily provide this by skipping a small part of
          their input and are thus essentially "forwarding" random access
          requests literally without any own processing involved. Examples
          include tag readers (e.g. ID3) or single output parsers, such as
          a WAVE parser.
        </P
></LI
></UL
><P
>&#13;      The following example will show how a <CODE
CLASS="function"
>_get_range
      ()</CODE
>-function can be implemented in a source element:
    </P
><PRE
CLASS="programlisting"
>&#13;#include "filter.h"
static GstFlowReturn
		gst_my_filter_get_range	(GstPad     * pad,
					 guint64      offset,
					 guint        length,
					 GstBuffer ** buf);

GST_BOILERPLATE (GstMyFilter, gst_my_filter, GstElement, GST_TYPE_ELEMENT);



static void
gst_my_filter_init (GstMyFilter * filter)
{
  GstElementClass *klass = GST_ELEMENT_GET_CLASS (filter);

  filter-&#62;srcpad = gst_pad_new_from_template (
        gst_element_class_get_pad_template (klass, "src"), "src");
  gst_pad_set_getrange_function (filter-&#62;srcpad,
      gst_my_filter_get_range);
  gst_element_add_pad (GST_ELEMENT (filter), filter-&#62;srcpad);

[..]
}

static gboolean
gst_my_filter_get_range (GstPad     * pad,
			 guint64      offset,
			 guint        length,
			 GstBuffer ** buf)
{

  GstMyFilter *filter = GST_MY_FILTER (GST_OBJECT_PARENT (pad));

  [.. here, you would fill *buf ..]

  return GST_FLOW_OK;
}

</PRE
><P
>&#13;      In practice, many elements that could theoretically do random access,
      may in practice often be assigned to do push-based scheduling anyway,
      since there is no downstream element able to start its own task.
      Therefore, in practice, those elements should implement both a
      <CODE
CLASS="function"
>_get_range ()</CODE
>-function and a <CODE
CLASS="function"
>_chain
      ()</CODE
>-function (for filters and parsers) or a <CODE
CLASS="function"
>_get_range
      ()</CODE
>-function and be prepared to start their own task by
      providing <CODE
CLASS="function"
>_activate_* ()</CODE
>-functions (for
      source elements), so that <SPAN
CLASS="application"
>GStreamer</SPAN
> can decide for the optimal
      scheduling mode and have it just work fine in practice.
    </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-scheduling-loop.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-building-types.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Pads driving the pipeline</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="chapter-scheduling.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Types and Properties</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>