Defining Parameter Specificiations

You can define the dparams you need anywhere within your element but will usually need to do so in only a couple of places:

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:

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:

Direct Method

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.

Callback Method

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.

Array Method

This method is quite different from the other two. It could be thought of as a specialised method which should only be used if you need the advantages that it provides. Instead of giving the element a single value it provides an array of values where each item in the array corresponds to a sample of audio in your buffer. There are a couple of reasons why this might be useful.

The array method is currently the least mature of the three methods and is not yet ready to be used in elements, but plugin writers should be aware of its existance for the future.