mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-20 21:16:24 +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
|
||||
()`-function can be implemented in a source element:
|
||||
|
||||
#include "filter.h"
|
||||
static GstFlowReturn
|
||||
gst_my_filter_get_range (GstPad * pad,
|
||||
GstObject * parent,
|
||||
guint64 offset,
|
||||
guint length,
|
||||
GstBuffer ** buf);
|
||||
```c
|
||||
#include "filter.h"
|
||||
static GstFlowReturn
|
||||
gst_my_filter_get_range (GstPad * pad,
|
||||
GstObject * parent,
|
||||
guint64 offset,
|
||||
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
|
||||
gst_my_filter_init (GstMyFilter * filter)
|
||||
{
|
||||
static void
|
||||
gst_my_filter_init (GstMyFilter * filter)
|
||||
{
|
||||
|
||||
[..]
|
||||
[..]
|
||||
|
||||
gst_pad_set_getrange_function (filter->srcpad,
|
||||
gst_my_filter_get_range);
|
||||
gst_pad_set_getrange_function (filter->srcpad,
|
||||
gst_my_filter_get_range);
|
||||
|
||||
[..]
|
||||
}
|
||||
[..]
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_my_filter_get_range (GstPad * pad,
|
||||
GstObject * parent,
|
||||
guint64 offset,
|
||||
guint length,
|
||||
GstBuffer ** buf)
|
||||
{
|
||||
static GstFlowReturn
|
||||
gst_my_filter_get_range (GstPad * pad,
|
||||
GstObject * parent,
|
||||
guint64 offset,
|
||||
guint length,
|
||||
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,
|
||||
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
|
||||
this subject in [Specifying the pads][pads].
|
||||
|
||||
static GstStaticPadTemplate sink_factory = [..],
|
||||
src_factory = [..];
|
||||
```c
|
||||
static GstStaticPadTemplate sink_factory = [..],
|
||||
src_factory = [..];
|
||||
|
||||
static void
|
||||
gst_my_filter_class_init (GstMyFilterClass * klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
[..]
|
||||
static void
|
||||
gst_my_filter_class_init (GstMyFilterClass * klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
[..]
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&src_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&sink_factory));
|
||||
}
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&src_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&sink_factory));
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
|
|
|
@ -77,49 +77,50 @@ from one state to another.
|
|||
Do not g\_assert for unhandled state changes; this is taken care of by
|
||||
the GstElement base class.
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition);
|
||||
```c
|
||||
static GstStateChangeReturn
|
||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition);
|
||||
|
||||
static void
|
||||
gst_my_filter_class_init (GstMyFilterClass *klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
static void
|
||||
gst_my_filter_class_init (GstMyFilterClass *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
|
||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
|
||||
{
|
||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||
GstMyFilter *filter = GST_MY_FILTER (element);
|
||||
static GstStateChangeReturn
|
||||
gst_my_filter_change_state (GstElement *element, GstStateChange transition)
|
||||
{
|
||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
||||
GstMyFilter *filter = GST_MY_FILTER (element);
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
if (!gst_my_filter_allocate_memory (filter))
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
if (!gst_my_filter_allocate_memory (filter))
|
||||
return GST_STATE_CHANGE_FAILURE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||
return ret;
|
||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||
return ret;
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
gst_my_filter_free_memory (filter);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
gst_my_filter_free_memory (filter);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
Note that upwards (NULL=\>READY, READY=\>PAUSED, PAUSED=\>PLAYING) and
|
||||
downwards (PLAYING=\>PAUSED, PAUSED=\>READY, READY=\>NULL) state changes
|
||||
are handled in two separate blocks with the downwards state change
|
||||
|
|
Loading…
Reference in a new issue