mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-21 21:46:22 +00:00
plugin-development: syntax highlighting in code snippets
Signed-off-by: Carlos Eduardo R. B. Fonseca <cadubentzen@gmail.com> https://bugzilla.gnome.org/show_bug.cgi?id=788029
This commit is contained in:
parent
6fa607b01c
commit
14193ec3d7
3 changed files with 78 additions and 73 deletions
|
@ -291,44 +291,46 @@ access:
|
||||||
The following example will show how a `_get_range
|
The following example will show how a `_get_range
|
||||||
()`-function can be implemented in a source element:
|
()`-function can be implemented in a source element:
|
||||||
|
|
||||||
#include "filter.h"
|
```c
|
||||||
static GstFlowReturn
|
#include "filter.h"
|
||||||
gst_my_filter_get_range (GstPad * pad,
|
static GstFlowReturn
|
||||||
GstObject * parent,
|
gst_my_filter_get_range (GstPad * pad,
|
||||||
guint64 offset,
|
GstObject * parent,
|
||||||
guint length,
|
guint64 offset,
|
||||||
GstBuffer ** buf);
|
guint length,
|
||||||
|
GstBuffer ** buf);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstMyFilter, gst_my_filter, GST_TYPE_ELEMENT);
|
G_DEFINE_TYPE (GstMyFilter, gst_my_filter, GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_my_filter_init (GstMyFilter * filter)
|
gst_my_filter_init (GstMyFilter * filter)
|
||||||
{
|
{
|
||||||
|
|
||||||
[..]
|
[..]
|
||||||
|
|
||||||
gst_pad_set_getrange_function (filter->srcpad,
|
gst_pad_set_getrange_function (filter->srcpad,
|
||||||
gst_my_filter_get_range);
|
gst_my_filter_get_range);
|
||||||
|
|
||||||
[..]
|
[..]
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_my_filter_get_range (GstPad * pad,
|
gst_my_filter_get_range (GstPad * pad,
|
||||||
GstObject * parent,
|
GstObject * parent,
|
||||||
guint64 offset,
|
guint64 offset,
|
||||||
guint length,
|
guint length,
|
||||||
GstBuffer ** buf)
|
GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
GstMyFilter *filter = GST_MY_FILTER (parent);
|
GstMyFilter *filter = GST_MY_FILTER (parent);
|
||||||
|
|
||||||
[.. here, you would fill *buf ..]
|
[.. here, you would fill *buf ..]
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
In practice, many elements that could theoretically do random access,
|
In practice, many elements that could theoretically do random access,
|
||||||
may in practice often be activated in push-mode scheduling anyway, since
|
may in practice often be activated in push-mode scheduling anyway, since
|
||||||
|
|
|
@ -262,20 +262,22 @@ a new pad from this template using `gst_pad_new_from_static_template
|
||||||
()`, you will need to declare the pad template as a global variable. More on
|
()`, you will need to declare the pad template as a global variable. More on
|
||||||
this subject in [Specifying the pads][pads].
|
this subject in [Specifying the pads][pads].
|
||||||
|
|
||||||
static GstStaticPadTemplate sink_factory = [..],
|
```c
|
||||||
src_factory = [..];
|
static GstStaticPadTemplate sink_factory = [..],
|
||||||
|
src_factory = [..];
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_my_filter_class_init (GstMyFilterClass * klass)
|
gst_my_filter_class_init (GstMyFilterClass * klass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
[..]
|
[..]
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
gst_element_class_add_pad_template (element_class,
|
gst_element_class_add_pad_template (element_class,
|
||||||
gst_static_pad_template_get (&sink_factory));
|
gst_static_pad_template_get (&sink_factory));
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The last argument in a template is its type or list of supported types.
|
The last argument in a template is its type or list of supported types.
|
||||||
In this example, we use 'ANY', which means that this element will accept
|
In this example, we use 'ANY', which means that this element will accept
|
||||||
|
|
|
@ -77,49 +77,50 @@ from one state to another.
|
||||||
Do not g\_assert for unhandled state changes; this is taken care of by
|
Do not g\_assert for unhandled state changes; this is taken care of by
|
||||||
the GstElement base class.
|
the GstElement base class.
|
||||||
|
|
||||||
static GstStateChangeReturn
|
```c
|
||||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition);
|
static GstStateChangeReturn
|
||||||
|
gst_my_filter_change_state (GstElement *element, GstStateChange transition);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_my_filter_class_init (GstMyFilterClass *klass)
|
gst_my_filter_class_init (GstMyFilterClass *klass)
|
||||||
{
|
{
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
element_class->change_state = gst_my_filter_change_state;
|
element_class->change_state = gst_my_filter_change_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static GstStateChangeReturn
|
static GstStateChangeReturn
|
||||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
|
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
|
||||||
{
|
{
|
||||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||||
GstMyFilter *filter = GST_MY_FILTER (element);
|
GstMyFilter *filter = GST_MY_FILTER (element);
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||||
if (!gst_my_filter_allocate_memory (filter))
|
if (!gst_my_filter_allocate_memory (filter))
|
||||||
return GST_STATE_CHANGE_FAILURE;
|
return GST_STATE_CHANGE_FAILURE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||||
if (ret == GST_STATE_CHANGE_FAILURE)
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
gst_my_filter_free_memory (filter);
|
gst_my_filter_free_memory (filter);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
```
|
||||||
Note that upwards (NULL=\>READY, READY=\>PAUSED, PAUSED=\>PLAYING) and
|
Note that upwards (NULL=\>READY, READY=\>PAUSED, PAUSED=\>PLAYING) and
|
||||||
downwards (PLAYING=\>PAUSED, PAUSED=\>READY, READY=\>NULL) state changes
|
downwards (PLAYING=\>PAUSED, PAUSED=\>READY, READY=\>NULL) state changes
|
||||||
are handled in two separate blocks with the downwards state change
|
are handled in two separate blocks with the downwards state change
|
||||||
|
|
Loading…
Reference in a new issue