mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 11:11:08 +00:00
72 lines
2.1 KiB
XML
72 lines
2.1 KiB
XML
|
|
<!-- ############ chapter ############# -->
|
|
|
|
<chapter id="chapter-building-eventfn">
|
|
<title>The event function</title>
|
|
<para>
|
|
The event function notifies you of special events that happen in
|
|
the datastream (such as caps, end-of-stream, newsegment, tags, etc.).
|
|
Events can travel both upstream and downstream, so you can receive them
|
|
on sink pads as well as source pads.
|
|
</para>
|
|
<para>
|
|
Below follows a very simple event function that we install on the sink
|
|
pad of our element.
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
static gboolean gst_my_filter_sink_event (GstPad *pad,
|
|
GstObject *parent,
|
|
GstEvent *event);
|
|
|
|
[..]
|
|
|
|
static void
|
|
gst_my_filter_init (GstMyFilter * filter)
|
|
{
|
|
[..]
|
|
/* configure event function on the pad before adding
|
|
* the pad to the element */
|
|
gst_pad_set_event_function (filter->sinkpad,
|
|
gst_my_filter_sink_event);
|
|
[..]
|
|
}
|
|
|
|
static gboolean
|
|
gst_my_filter_sink_event (GstPad *pad,
|
|
GstObject *parent,
|
|
GstEvent *event)
|
|
{
|
|
gboolean ret;
|
|
GstMyFilter *filter = GST_MY_FILTER (parent);
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
case GST_EVENT_CAPS:
|
|
/* we should handle the format here */
|
|
|
|
/* push the event downstream */
|
|
ret = gst_pad_push_event (filter->srcpad, event);
|
|
break;
|
|
case GST_EVENT_EOS:
|
|
/* end-of-stream, we should close down all stream leftovers here */
|
|
gst_my_filter_stop_processing (filter);
|
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
break;
|
|
default:
|
|
/* just call the default handler */
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
It is a good idea to call the default event handler
|
|
<function>gst_pad_event_default ()</function> for unknown events.
|
|
Depending on the event type, the default handler will forward
|
|
the event or simply unref it. The CAPS event is by default not
|
|
forwarded so we need to do this in the event handler ourselves.
|
|
</para>
|
|
</chapter>
|