docs: syntax in event handling example in chainfn.md

Signed-off-by: cadubentzen <cadubentzen@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788023
This commit is contained in:
cadubentzen 2017-09-21 16:56:14 -03:00 committed by Mathieu Duponchelle
parent 020bf14d03
commit 6fa607b01c

View file

@ -52,57 +52,59 @@ want to additionally specify an event handling function, which will be
called when stream-events are sent (such as caps, end-of-stream, called when stream-events are sent (such as caps, end-of-stream,
newsegment, tags, etc.). newsegment, tags, etc.).
static void ```c
gst_my_filter_init (GstMyFilter * filter) static void
{ gst_my_filter_init (GstMyFilter * filter)
[..] {
gst_pad_set_event_function (filter->sinkpad, [..]
gst_my_filter_sink_event); gst_pad_set_event_function (filter->sinkpad,
[..] gst_my_filter_sink_event);
} [..]
}
static gboolean static gboolean
gst_my_filter_sink_event (GstPad *pad, gst_my_filter_sink_event (GstPad *pad,
GstObject *parent, GstObject *parent,
GstEvent *event) GstEvent *event)
{ {
GstMyFilter *filter = GST_MY_FILTER (parent); GstMyFilter *filter = GST_MY_FILTER (parent);
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS: case GST_EVENT_CAPS:
/* we should handle the format here */ /* we should handle the format here */
break; break;
case GST_EVENT_EOS: case GST_EVENT_EOS:
/* end-of-stream, we should close down all stream leftovers here */ /* end-of-stream, we should close down all stream leftovers here */
gst_my_filter_stop_processing (filter); gst_my_filter_stop_processing (filter);
break; break;
default: default:
break; break;
} }
return gst_pad_event_default (pad, parent, event); return gst_pad_event_default (pad, parent, event);
} }
static GstFlowReturn static GstFlowReturn
gst_my_filter_chain (GstPad *pad, gst_my_filter_chain (GstPad *pad,
GstObject *parent, GstObject *parent,
GstBuffer *buf) GstBuffer *buf)
{ {
GstMyFilter *filter = GST_MY_FILTER (parent); GstMyFilter *filter = GST_MY_FILTER (parent);
GstBuffer *outbuf; GstBuffer *outbuf;
outbuf = gst_my_filter_process_data (filter, buf); outbuf = gst_my_filter_process_data (filter, buf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
if (!outbuf) { if (!outbuf) {
/* something went wrong - signal an error */ /* something went wrong - signal an error */
GST_ELEMENT_ERROR (GST_ELEMENT (filter), STREAM, FAILED, (NULL), (NULL)); GST_ELEMENT_ERROR (GST_ELEMENT (filter), STREAM, FAILED, (NULL), (NULL));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
return gst_pad_push (filter->srcpad, outbuf); return gst_pad_push (filter->srcpad, outbuf);
} }
```
In some cases, it might be useful for an element to have control over 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 the input data rate, too. In that case, you probably want to write a