Table of Contents
You can define the dparams you need anywhere within your element but will usually need to do so in only a couple of places:
In the element init function, just after the call to gst_dpman_new
Whenever a new pad is created so that parameters can affect data going into or out of a specific pad. An example of this would be a mixer element where a seperate volume parameter is needed on every pad.
There are three different ways the dparams subsystem can pass parameters into your element. Which one you use will depend on how that parameter is used within your element. Each of these methods has its own function to define a required dparam:
gst_dpman_add_required_dparam_direct
gst_dpman_add_required_dparam_callback
gst_dpman_add_required_dparam_array
These functions will return TRUE if the required dparam was added successfully.
The following function will be used as an example.
gboolean gst_dpman_add_required_dparam_direct (GstDParamManager *dpman, GParamSpec *param_spec, gboolean is_log, gboolean is_rate, gpointer update_data)
The common parameters to these functions are:
GstDParamManager *dpman the element's dparam manager
GParamSpec *param_spec the param spec which defines the required dparam
gboolean is_log whether this dparam value should be interpreted on a log scale (such as a frequency or a decibel value)
gboolean is_rate whether this dparam value is a proportion of the sample rate. For example with a sample rate of 44100, 0.5 would be 22050 Hz and 0.25 would be 11025 Hz.
This method is the simplest and has the lowest overhead for parameters which change less frequently than the sample rate. First you need somewhere to store the parameter - this will usually be in your element's stuct.
struct _GstExample { GstElement element; ... GstDParamManager *dpman; gfloat volume; ... };
Then to define the required dparam just call gst_dpman_add_required_dparam_direct and pass in the location of the parameter to change. In this case the location is &(example->volume).
gst_dpman_add_required_dparam_direct ( example->dpman, g_param_spec_float("volume","Volume","Volume of the audio", 0.0, 1.0, 0.8, G_PARAM_READWRITE), FALSE, FALSE, &(example->volume) );
You can now use example->volume anywhere in your element knowing that it will always contain the correct value to use.