2002-09-27 18:34:33 +00:00
|
|
|
|
|
|
|
<!-- ############ chapter ############# -->
|
|
|
|
|
2004-01-28 15:51:14 +00:00
|
|
|
<chapter id="chapter-building-pads">
|
2002-09-27 18:34:33 +00:00
|
|
|
<title>Specifying the pads</title>
|
|
|
|
<para>
|
2004-01-27 13:33:39 +00:00
|
|
|
As explained before, pads are the port through which data goes in and out
|
|
|
|
of your element, and that makes them a very important item in the process
|
|
|
|
of element creation. In the boilerplate code, we have seen how static pad
|
|
|
|
templates take care of registering pad templates with the element class.
|
2012-09-27 11:57:46 +00:00
|
|
|
Here, we will see how to create actual elements, use an <function>_event
|
|
|
|
()</function>-function to configure for a particular format and how to
|
2005-07-06 12:18:00 +00:00
|
|
|
register functions to let data flow through the element.
|
2002-09-27 18:34:33 +00:00
|
|
|
</para>
|
2004-01-27 13:33:39 +00:00
|
|
|
<para>
|
|
|
|
In the element <function>_init ()</function> function, you create the pad
|
|
|
|
from the pad template that has been registered with the element class in
|
2012-09-27 11:57:46 +00:00
|
|
|
the <function>_class_init ()</function> function. After creating the pad,
|
|
|
|
you have to set a <function>_chain ()</function> function pointer that will
|
|
|
|
receive and process the input data on the sinkpad.
|
|
|
|
You can optionally also set an <function>_event ()</function> function
|
|
|
|
pointer and a <function>_query ()</function> function pointer.
|
2010-02-08 03:42:01 +00:00
|
|
|
Alternatively, pads can also operate in looping mode, which means that they
|
2005-07-06 12:18:00 +00:00
|
|
|
can pull data themselves. More on this topic later. After that, you have
|
|
|
|
to register the pad with the element. This happens like this:
|
2004-01-27 13:33:39 +00:00
|
|
|
</para>
|
2005-07-01 12:43:03 +00:00
|
|
|
<programlisting><!-- example-begin init.func a --><!--
|
|
|
|
#include "filter.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-12-11 18:24:27 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_my_filter_change_state (GstElement * element, GstStateChange transition);
|
2005-07-01 12:43:03 +00:00
|
|
|
|
2012-09-27 11:57:46 +00:00
|
|
|
G_DEFINE_TYPE (GstMyFilter, gst_my_filter, GST_TYPE_ELEMENT);
|
2005-07-01 12:43:03 +00:00
|
|
|
|
|
|
|
static void
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_my_filter_class_init (gpointer klass)
|
2005-07-01 12:43:03 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2012-09-27 11:57:46 +00:00
|
|
|
static GstStaticPadTemplate sink_template =
|
2005-07-01 12:43:03 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("ANY")
|
|
|
|
);
|
2012-09-27 11:57:46 +00:00
|
|
|
static GstStaticPadTemplate src_template =
|
2005-07-01 12:43:03 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE (
|
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("ANY")
|
|
|
|
);
|
|
|
|
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
|
|
|
"An example plugin",
|
|
|
|
"Example/FirstExample",
|
|
|
|
"Shows the basic structure of a plugin",
|
|
|
|
"your name <your.name@your.isp>");
|
|
|
|
|
2005-07-01 12:43:03 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
2005-07-01 12:43:03 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2005-07-01 12:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_my_filter_class_init (GstMyFilterClass * klass)
|
|
|
|
{
|
|
|
|
GST_ELEMENT_CLASS (klass)->change_state = gst_my_filter_change_state;
|
|
|
|
}
|
|
|
|
--><!-- example-end init.func a -->
|
|
|
|
<!-- example-begin init.func c --><!--
|
2012-09-27 11:57:46 +00:00
|
|
|
static GstFlowReturn gst_my_filter_chain (GstPad *pad,
|
|
|
|
GstObject *parent,
|
|
|
|
GstBuffer *buf);
|
|
|
|
static gboolean gst_my_filter_sink_event (GstPad *pad,
|
|
|
|
GstObject *parent,
|
|
|
|
GstEvent *event);
|
|
|
|
static gboolean gst_my_filter_src_query (GstPad *pad,
|
|
|
|
GstObject *parent,
|
|
|
|
GstQuery *query);
|
|
|
|
static gboolean gst_my_filter_sink_query (GstPad *pad,
|
|
|
|
GstObject *parent,
|
|
|
|
GstQuery *query);
|
2005-07-01 12:43:03 +00:00
|
|
|
--><!-- example-end init.func c -->
|
|
|
|
<!-- example-begin init.func d -->
|
2004-01-27 13:33:39 +00:00
|
|
|
|
|
|
|
static void
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_my_filter_init (GstMyFilter *filter)
|
2004-01-27 13:33:39 +00:00
|
|
|
{
|
|
|
|
/* pad through which data comes in to the element */
|
2012-09-27 11:57:46 +00:00
|
|
|
filter->sinkpad = gst_pad_new_from_static_template (
|
|
|
|
&sink_template, "sink");
|
|
|
|
/* pads are configured here with gst_pad_set_*_function () */
|
2005-07-01 12:43:03 +00:00
|
|
|
<!-- example-end init.func d -->
|
|
|
|
<!-- example-begin init.func e --><!--
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_my_filter_chain);
|
|
|
|
gst_pad_set_event_function (filter->sinkpad, gst_my_filter_sink_event);
|
|
|
|
gst_pad_set_query_function (filter->sinkpad, gst_my_filter_sink_query);
|
2005-07-01 12:43:03 +00:00
|
|
|
--><!-- example-end init.func e -->
|
|
|
|
<!-- example-begin init.func f -->
|
2004-01-27 23:08:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
2004-01-27 13:33:39 +00:00
|
|
|
|
|
|
|
/* pad through which data goes out of the element */
|
2012-09-27 11:57:46 +00:00
|
|
|
filter->srcpad = gst_pad_new_from_static_template (
|
|
|
|
&src_template, "src");
|
|
|
|
/* pads are configured here with gst_pad_set_*_function () */
|
2005-07-06 12:18:00 +00:00
|
|
|
<!-- example-end init.func f -->
|
|
|
|
<!-- example-begin init.func g --><!--
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_pad_set_query_function (filter->srcpad, gst_my_filter_src_query);
|
2005-07-06 12:18:00 +00:00
|
|
|
--><!-- example-end init.func g -->
|
|
|
|
<!-- example-begin init.func h -->
|
2004-01-27 23:08:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
2005-07-01 12:43:03 +00:00
|
|
|
|
|
|
|
/* properties initial value */
|
|
|
|
filter->silent = FALSE;
|
2004-01-27 13:33:39 +00:00
|
|
|
}
|
2005-07-06 12:18:00 +00:00
|
|
|
<!-- example-end init.func h --></programlisting>
|
2004-01-28 10:03:51 +00:00
|
|
|
|
2005-07-01 12:43:03 +00:00
|
|
|
<!-- example-begin pads.c --><!--
|
|
|
|
#include "init.func"
|
2004-01-28 10:03:51 +00:00
|
|
|
|
2005-07-01 12:43:03 +00:00
|
|
|
static gboolean
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_my_filter_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2004-01-27 13:33:39 +00:00
|
|
|
{
|
2012-09-27 11:57:46 +00:00
|
|
|
return gst_pad_event_default (pad, parent, event);
|
2004-01-27 13:33:39 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 12:43:03 +00:00
|
|
|
static GstFlowReturn
|
2012-09-27 11:57:46 +00:00
|
|
|
gst_my_filter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2004-01-27 13:33:39 +00:00
|
|
|
{
|
2012-09-27 11:57:46 +00:00
|
|
|
return gst_pad_push (GST_MY_FILTER (parent)->srcpad, buf);
|
2004-01-27 13:33:39 +00:00
|
|
|
}
|
2005-07-01 12:43:03 +00:00
|
|
|
|
2005-12-11 18:24:27 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_my_filter_change_state (GstElement * element, GstStateChange transition)
|
2005-07-01 12:43:03 +00:00
|
|
|
{
|
|
|
|
return GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS,
|
2005-12-11 18:24:27 +00:00
|
|
|
change_state, (element, transition), GST_STATE_CHANGE_SUCCESS);
|
2005-07-01 12:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "register.func"
|
|
|
|
--><!-- example-end pads.c -->
|
2002-09-27 18:34:33 +00:00
|
|
|
</chapter>
|
|
|
|
|