2016-06-04 06:55:52 +00:00
|
|
|
---
|
|
|
|
title: Dynamic Controllable Parameters
|
|
|
|
...
|
|
|
|
|
|
|
|
# Dynamic Controllable Parameters
|
|
|
|
|
2016-06-17 22:41:07 +00:00
|
|
|
## Getting Started
|
2016-06-04 06:55:52 +00:00
|
|
|
|
2017-09-11 18:48:27 +00:00
|
|
|
GStreamer properties are normally set using `g_object_set()`, but timing these
|
|
|
|
calls reliably so that the changes affect certain stream times is close to
|
|
|
|
impossible. The controller subsystem offers a lightweight way to adjust
|
|
|
|
`GObject` properties over stream-time.
|
|
|
|
|
|
|
|
The controller takes time into account; it works by attaching
|
|
|
|
`GstControlSource`s to properties using control-bindings. Control-sources
|
|
|
|
provide values for a given time-stamp that are usually in the range of 0.0 to 1.0.
|
|
|
|
Control-bindings map the control-value to the `GObject` property they are bound
|
|
|
|
to, converting the type and scaling to the target property's value range. At
|
|
|
|
run-time the elements continuously pull value changes for the current
|
|
|
|
stream-time to update the `GObject` properties. GStreamer already includes a
|
|
|
|
few different `GstControlSource`s and control-bindings, but applications can
|
|
|
|
define their own by sub-classing the respective base classes.
|
|
|
|
|
|
|
|
Most parts of the controller mechanism are implemented in `GstObject`.
|
|
|
|
The base classes for `GstControlSource`s and control-bindings are also included
|
|
|
|
in the core library but the existing implementations are contained within
|
|
|
|
the `gstcontroller` library, so you need to include these headers in your
|
|
|
|
application's source file as needed:
|
2016-06-04 06:55:52 +00:00
|
|
|
|
2016-06-06 01:50:32 +00:00
|
|
|
``` c
|
2016-06-04 06:55:52 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/controller/gstinterpolationcontrolsource.h>
|
|
|
|
#include <gst/controller/gstdirectcontrolbinding.h>
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2017-09-11 18:48:27 +00:00
|
|
|
Beyond including the proper headers, your application should link to the
|
|
|
|
`gstreamer-controller` shared library. To get the required compiler and
|
2019-03-25 14:11:04 +00:00
|
|
|
linker flags, you can use:
|
2017-09-11 18:48:27 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
pkg-config --libs --cflags gstreamer-controller-1.0
|
|
|
|
```
|
2016-06-04 06:55:52 +00:00
|
|
|
|
2016-06-17 22:41:07 +00:00
|
|
|
## Setting up parameter control
|
2016-06-04 06:55:52 +00:00
|
|
|
|
|
|
|
If we have our pipeline set up and want to control some parameters, we
|
2019-03-25 14:11:04 +00:00
|
|
|
first need to create a `GstControlSource`. Let's use an interpolation
|
2017-09-11 18:48:27 +00:00
|
|
|
`GstControlSource`:
|
2016-06-04 06:55:52 +00:00
|
|
|
|
2016-06-06 01:50:32 +00:00
|
|
|
``` c
|
2017-09-11 18:48:27 +00:00
|
|
|
csource = gst_interpolation_control_source_new ();
|
|
|
|
g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
|
2016-06-04 06:55:52 +00:00
|
|
|
```
|
|
|
|
|
2017-09-11 18:48:27 +00:00
|
|
|
Now, we need to attach the `GstControlSource` to the gobject property. This
|
2016-06-04 06:55:52 +00:00
|
|
|
is done with a control-binding. One control source can be attached to
|
|
|
|
several object properties (even in different objects) using separate
|
|
|
|
control-bindings.
|
|
|
|
|
2016-06-06 01:50:32 +00:00
|
|
|
``` c
|
2017-09-11 18:48:27 +00:00
|
|
|
gst_object_add_control_binding (object, gst_direct_control_binding_new (object, "prop1", csource));
|
2016-06-04 06:55:52 +00:00
|
|
|
```
|
|
|
|
|
2017-09-11 18:48:27 +00:00
|
|
|
This type `GstControlSource` takes new property values from a list of
|
2016-06-04 06:55:52 +00:00
|
|
|
time-stamped parameter changes. The source can e.g. fill gaps by
|
2017-09-11 18:48:27 +00:00
|
|
|
smoothing parameter changes. This behavior can be configured by setting
|
|
|
|
the mode property of the `GstControlSource`. Other control sources e.g.
|
2016-06-04 06:55:52 +00:00
|
|
|
produce a stream of values by calling `sin()` function. They have
|
2017-09-11 18:48:27 +00:00
|
|
|
parameters to control e.g. the frequency. As `GstControlSource`s are also
|
|
|
|
`GstObject`s, one can attach `GstControlSource`s to these properties too.
|
2016-06-04 06:55:52 +00:00
|
|
|
|
|
|
|
Now we can set some control points. These are time-stamped gdouble
|
|
|
|
values and are usually in the range of 0.0 to 1.0. A value of 1.0 is
|
|
|
|
later mapped to the maximum value in the target properties value range.
|
|
|
|
The values become active when the timestamp is reached. They still stay
|
|
|
|
in the list. If e.g. the pipeline runs a loop (using a segmented seek),
|
2017-09-11 18:48:27 +00:00
|
|
|
the control-curve gets repeated as well.
|
2016-06-04 06:55:52 +00:00
|
|
|
|
2016-06-06 01:50:32 +00:00
|
|
|
``` c
|
2017-09-11 18:48:27 +00:00
|
|
|
GstTimedValueControlSource *tv_csource = (GstTimedValueControlSource *)csource;
|
|
|
|
gst_timed_value_control_source_set (tv_csource, 0 * GST_SECOND, 0.0);
|
|
|
|
gst_timed_value_control_source_set (tv_csource, 1 * GST_SECOND, 1.0);
|
2016-06-04 06:55:52 +00:00
|
|
|
```
|
|
|
|
|
2017-09-11 18:48:27 +00:00
|
|
|
Now everything is ready to play. If we bound the `GstControlSource` to a volume
|
|
|
|
property, we will hear a 1 second fade-in. One word of caution: GStreamer's
|
2017-09-11 21:50:34 +00:00
|
|
|
stock volume element has a `volume` property with a range from 0.0 to 10.0. If
|
2017-09-11 18:48:27 +00:00
|
|
|
the above `GstControlSource` is attached to this property the volume will ramp
|
|
|
|
up to 400%\!
|
|
|
|
|
|
|
|
One final note: the controller subsystem has a built-in live-mode. Even
|
2019-03-25 14:11:04 +00:00
|
|
|
though a property has a `GstControlSource` assigned, one can set the
|
2017-09-11 18:48:27 +00:00
|
|
|
`GObject` property with `g_object_set()`. This is highly useful when binding
|
|
|
|
the `GObject` properties to GUI widgets. When the user adjusts the value with
|
|
|
|
the widget, one can set the `GObject` property and this remains active until
|
|
|
|
the next programmed `GstControlSource` value overrides it. This also works with
|
|
|
|
smoothed parameters but it does not work for `GstControlSource`s that constantly
|
|
|
|
update the property, like `GstLFOControlSource`.
|