This should be used if the you have other values to calculate whenever a parameter changes. If you used the direct method you wouldn't know if a parameter had changed so you would have to recalculate the other values every time you needed them. By using the callback method, other values only have to be recalculated when the dparam value actually changes.
The following code illustrates an instance where you might want to use the callback method. If you had a volume dparam which was represented by a gfloat number, your element may only deal with integer arithmatic. The callback could be used to calculate the integer scaler when the volume changes. First you will need somewhere to store these values.
struct _GstExample { GstElement element; ... GstDParamManager *dpman; gfloat volume_f; gint volume_i; ... };
When the required dparam is defined, the callback function gst_example_update_volume and some user data (which in this case is our element instance) is passed in to the call to gst_dpman_add_required_dparam_callback.
gst_dpman_add_required_dparam_callback ( example->dpman, g_param_spec_float("volume","Volume","Volume of the audio", 0.0, 1.0, 0.8, G_PARAM_READWRITE), FALSE, FALSE, gst_example_update_volume, example );
The callback function needs to conform to this signiture
typedef void (*GstDPMUpdateFunction) (GValue *value, gpointer data);
In our example the callback function looks like this
static void gst_example_update_volume(GValue *value, gpointer data) { GstExample *example = (GstExample*)data; g_return_if_fail(GST_IS_EXAMPLE(example)); example->volume_f = g_value_get_float(value); example->volume_i = example->volume_f * 8192; }
Now example->volume_i can be used elsewhere and it will always contain the correct value.