controller: improve control binding handling

Change _set_control_binding to _add_control_binding and take ownership. Add a
_remove_control_binding function.
This commit is contained in:
Stefan Sauer 2012-01-20 14:42:31 +01:00
parent c227d51fa9
commit dd9f0481ea
9 changed files with 113 additions and 80 deletions

View file

@ -1485,8 +1485,9 @@ gst_object_sync_values
gst_object_has_active_control_bindings
gst_object_set_control_bindings_disabled
gst_object_set_control_binding_disabled
gst_object_set_control_binding
gst_object_add_control_binding
gst_object_get_control_binding
gst_object_remove_control_binding
gst_object_get_value
gst_object_get_value_array
gst_object_get_control_rate

View file

@ -117,7 +117,7 @@
* </para></listitem>
* <listitem><para>
* Attach the #GstControlSource on the controller to a property.
* gst_object_set_control_binding (object, gst_control_binding_new (objetct, "prop1", csource));
* gst_object_add_control_binding (object, gst_control_binding_new (objetct, "prop1", csource));
* </para></listitem>
* <listitem><para>
* Set the control values
@ -1204,41 +1204,39 @@ gst_object_set_control_binding_disabled (GstObject * object,
/**
* gst_object_set_control_binding:
* gst_object_add_control_binding:
* @object: the controller object
* @binding: the #GstControlBinding that should be used for the property
* @binding: (transfer full): the #GstControlBinding that should be used
*
* Sets the #GstControlBinding. If there already was a #GstControlBinding
* for this property it will be replaced. Use %NULL for @binding to unset it.
* for this property it will be replaced.
* The @object will take ownership of the @binding.
*
* Returns: %FALSE if the given property isn't handled by the controller or
* %TRUE if everything worked as expected.
* Returns: %FALSE if the given @binding has not been setup for this object or
* %TRUE otherwise.
*/
gboolean
gst_object_set_control_binding (GstObject * object, GstControlBinding * binding)
gst_object_add_control_binding (GstObject * object, GstControlBinding * binding)
{
GstControlBinding *old;
gboolean ret = FALSE;
g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
g_return_val_if_fail ((!binding || GST_IS_CONTROL_BINDING (binding)), FALSE);
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
g_return_val_if_fail (g_type_is_a (binding->pspec->owner_type,
G_OBJECT_TYPE (object)), FALSE);
GST_OBJECT_LOCK (object);
if ((old = gst_object_find_control_binding (object, binding->name))) {
GST_DEBUG_OBJECT (object, "controlled property %s removed", old->name);
object->control_bindings = g_list_remove (object->control_bindings, old);
g_object_unref (old);
GST_DEBUG_OBJECT (object, "controlled property %s removed", binding->name);
ret = TRUE;
}
if (binding) {
object->control_bindings =
g_list_prepend (object->control_bindings, g_object_ref (binding));
GST_DEBUG_OBJECT (object, "controlled property %s added", binding->name);
ret = TRUE;
gst_object_unparent (GST_OBJECT_CAST (old));
}
object->control_bindings = g_list_prepend (object->control_bindings, binding);
gst_object_set_parent (GST_OBJECT_CAST (binding), object);
GST_DEBUG_OBJECT (object, "controlled property %s added", binding->name);
GST_OBJECT_UNLOCK (object);
return ret;
return TRUE;
}
/**
@ -1269,6 +1267,39 @@ gst_object_get_control_binding (GstObject * object, const gchar * property_name)
return binding;
}
/**
* gst_object_remove_control_binding:
* @object: the object
* @binding: the binding
*
* Removes the corresponding #GstControlBinding. If it was the
* last ref of the binding, it will be disposed.
*
* Returns: %TRUE if the binding could be removed.
*/
gboolean
gst_object_remove_control_binding (GstObject * object,
GstControlBinding * binding)
{
GList *node;
gboolean ret = FALSE;
g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
GST_OBJECT_LOCK (object);
if ((node = g_list_find (object->control_bindings, binding))) {
GST_DEBUG_OBJECT (object, "controlled property %s removed", binding->name);
object->control_bindings =
g_list_delete_link (object->control_bindings, node);
gst_object_unparent (GST_OBJECT_CAST (binding));
ret = TRUE;
}
GST_OBJECT_UNLOCK (object);
return ret;
}
/**
* gst_object_get_value:
* @object: the object that has controlled properties

View file

@ -235,27 +235,28 @@ gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
#include <gst/gstcontrolbinding.h>
#include <gst/gstcontrolsource.h>
GstClockTime gst_object_suggest_next_sync (GstObject * object);
gboolean gst_object_sync_values (GstObject * object, GstClockTime timestamp);
GstClockTime gst_object_suggest_next_sync (GstObject * object);
gboolean gst_object_sync_values (GstObject * object, GstClockTime timestamp);
gboolean gst_object_has_active_control_bindings (GstObject *object);
void gst_object_set_control_bindings_disabled (GstObject *object, gboolean disabled);
void gst_object_set_control_binding_disabled (GstObject *object,
const gchar * property_name,
gboolean disabled);
void gst_object_set_control_binding_disabled (GstObject *object,
const gchar * property_name,
gboolean disabled);
gboolean gst_object_set_control_binding (GstObject * object, GstControlBinding * binding);
gboolean gst_object_add_control_binding (GstObject * object, GstControlBinding * binding);
GstControlBinding *
gst_object_get_control_binding (GstObject *object, const gchar * property_name);
gst_object_get_control_binding (GstObject *object, const gchar * property_name);
gboolean gst_object_remove_control_binding (GstObject * object, GstControlBinding * binding);
GValue * gst_object_get_value (GstObject * object, const gchar * property_name,
GstClockTime timestamp);
gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name,
GstClockTime timestamp, GstClockTime interval,
guint n_values, GValue *values);
GValue * gst_object_get_value (GstObject * object, const gchar * property_name,
GstClockTime timestamp);
gboolean gst_object_get_value_array (GstObject * object, const gchar * property_name,
GstClockTime timestamp, GstClockTime interval,
guint n_values, GValue *values);
GstClockTime gst_object_get_control_rate (GstObject * object);
void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate);
GstClockTime gst_object_get_control_rate (GstObject * object);
void gst_object_set_control_rate (GstObject * object, GstClockTime control_rate);
G_END_DECLS

View file

@ -111,7 +111,7 @@ main (gint argc, gchar * argv[])
/* create and configure control source */
csource = gst_interpolation_control_source_new ();
gst_object_set_control_binding (GST_OBJECT (src),
gst_object_add_control_binding (GST_OBJECT (src),
gst_control_binding_new (GST_OBJECT (src), "freq",
GST_CONTROL_SOURCE (csource)));
g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);

View file

@ -469,26 +469,26 @@ GST_START_TEST (controller_param_twice)
cb = gst_control_binding_new (GST_OBJECT (elem), "int",
GST_CONTROL_SOURCE (cs));
fail_unless (cb != NULL, NULL);
cb = gst_object_ref (cb);
res = gst_object_set_control_binding (GST_OBJECT (elem), cb);
res = gst_object_add_control_binding (GST_OBJECT (elem), cb);
fail_unless (res, NULL);
/* setting it again will just unset the old and set it again
* this might cause some trouble with binding the control source again
*/
res = gst_object_set_control_binding (GST_OBJECT (elem), cb);
res = gst_object_add_control_binding (GST_OBJECT (elem), cb);
fail_unless (res, NULL);
#if 0 /* FIXME(ensonic): need new API */
/* it should have been added at least once, let remove it */
res = gst_object_remove_control_binding (GST_OBJECT (elem), "int");
/* it should have been added now, let remove it */
res = gst_object_remove_control_binding (GST_OBJECT (elem), cb);
fail_unless (res, NULL);
/* removing it again should not work */
res = gst_object_remove_control_binding (GST_OBJECT (elem), "int");
res = gst_object_remove_control_binding (GST_OBJECT (elem), cb);
fail_unless (!res, NULL);
#endif
gst_object_unref (cb);
gst_object_unref (cs);
gst_object_unref (elem);
}
@ -530,7 +530,7 @@ GST_START_TEST (controller_controlsource_refcounts)
cb = gst_control_binding_new (GST_OBJECT (elem), "int", cs);
fail_unless (cb != NULL, NULL);
fail_unless_equals_int (G_OBJECT (cs)->ref_count, 2);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem), cb));
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem), cb));
test_cb = gst_object_get_control_binding (GST_OBJECT (elem), "int");
fail_unless (test_cb != NULL, NULL);
@ -542,7 +542,6 @@ GST_START_TEST (controller_controlsource_refcounts)
gst_object_unref (test_cs);
gst_object_unref (test_cb);
gst_object_unref (cs);
gst_object_unref (cb);
gst_object_unref (elem);
}
@ -585,7 +584,7 @@ GST_START_TEST (controller_sync1)
csource = gst_test_control_source_new ();
fail_unless (csource != NULL, NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int",
(GstControlSource *) csource)));
@ -611,10 +610,10 @@ GST_START_TEST (controller_sync2)
csource = gst_test_control_source_new ();
fail_unless (csource != NULL, NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int",
(GstControlSource *) csource)));
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "double",
(GstControlSource *) csource)));

View file

@ -285,7 +285,7 @@ GST_START_TEST (controller_controlsource_empty1)
csource = (GstControlSource *) gst_interpolation_control_source_new ();
fail_unless (csource != NULL, NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int",
(GstControlSource *) csource)));
@ -311,7 +311,7 @@ GST_START_TEST (controller_controlsource_empty2)
csource = gst_interpolation_control_source_new ();
fail_unless (csource != NULL, NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int",
(GstControlSource *) csource)));
@ -349,7 +349,7 @@ GST_START_TEST (controller_interpolation_none)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -401,7 +401,7 @@ GST_START_TEST (controller_interpolation_linear)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -441,7 +441,7 @@ GST_START_TEST (controller_interpolation_cubic)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "double", cs)));
/* set interpolation mode */
@ -490,7 +490,7 @@ GST_START_TEST (controller_interpolation_cubic_too_few_cp)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "double", cs)));
/* set interpolation mode */
@ -532,7 +532,7 @@ GST_START_TEST (controller_interpolation_unset)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -588,7 +588,7 @@ GST_START_TEST (controller_interpolation_unset_all)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -636,7 +636,7 @@ GST_START_TEST (controller_interpolation_linear_value_array)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -690,7 +690,7 @@ GST_START_TEST (controller_interpolation_linear_invalid_values)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "float", cs)));
/* set interpolation mode */
@ -742,7 +742,7 @@ GST_START_TEST (controller_interpolation_linear_default_values)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -813,10 +813,10 @@ GST_START_TEST (controller_interpolation_linear_disabled)
cs2 = (GstControlSource *) csource2;
fail_unless (csource1 != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs1)));
fail_unless (csource2 != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "double", cs2)));
/* set interpolation mode */
@ -938,7 +938,7 @@ GST_START_TEST (controller_interpolation_set_from_list)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -983,7 +983,7 @@ GST_START_TEST (controller_interpolation_linear_before_ts0)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -1030,7 +1030,7 @@ GST_START_TEST (controller_interpolation_linear_enums)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "enum", cs)));
/* set interpolation mode */
@ -1074,7 +1074,7 @@ GST_START_TEST (controller_timed_value_count)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* set interpolation mode */
@ -1115,7 +1115,7 @@ GST_START_TEST (controller_lfo_sine)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1169,7 +1169,7 @@ GST_START_TEST (controller_lfo_sine_timeshift)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1223,7 +1223,7 @@ GST_START_TEST (controller_lfo_square)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1277,7 +1277,7 @@ GST_START_TEST (controller_lfo_saw)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1331,7 +1331,7 @@ GST_START_TEST (controller_lfo_rsaw)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1385,7 +1385,7 @@ GST_START_TEST (controller_lfo_triangle)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* configure lfo */
@ -1439,7 +1439,7 @@ GST_START_TEST (controller_lfo_none)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
/* now pull in values for some timestamps */
@ -1491,7 +1491,7 @@ GST_START_TEST (controller_trigger_exact)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
fail_if (gst_control_source_get_value (cs, 0 * GST_SECOND, &raw_val));
@ -1537,7 +1537,7 @@ GST_START_TEST (controller_trigger_tolerance)
cs = (GstControlSource *) csource;
fail_unless (csource != NULL);
fail_unless (gst_object_set_control_binding (GST_OBJECT (elem),
fail_unless (gst_object_add_control_binding (GST_OBJECT (elem),
gst_control_binding_new (GST_OBJECT (elem), "int", cs)));
g_object_set (csource, "tolerance", G_GINT64_CONSTANT (10), NULL);

View file

@ -48,10 +48,10 @@ main (gint argc, gchar ** argv)
csource1 = gst_interpolation_control_source_new ();
csource2 = gst_interpolation_control_source_new ();
gst_object_set_control_binding (GST_OBJECT_CAST (src),
gst_object_add_control_binding (GST_OBJECT_CAST (src),
gst_control_binding_new (GST_OBJECT_CAST (src), "volume",
GST_CONTROL_SOURCE (csource1)));
gst_object_set_control_binding (GST_OBJECT_CAST (src),
gst_object_add_control_binding (GST_OBJECT_CAST (src),
gst_control_binding_new (GST_OBJECT_CAST (src), "freq",
GST_CONTROL_SOURCE (csource2)));

View file

@ -192,7 +192,7 @@ test_interpolation (void)
tvcs = (GstTimedValueControlSource *) ics;
cs = (GstControlSource *) ics;
gst_object_set_control_binding (e, gst_control_binding_new (e, "int", cs));
gst_object_add_control_binding (e, gst_control_binding_new (e, "int", cs));
gst_timed_value_control_source_set (tvcs, 0 * GST_SECOND, 0.0);
gst_timed_value_control_source_set (tvcs, 10 * GST_SECOND, 1.0);
@ -275,7 +275,7 @@ test_lfo (void)
lfocs = gst_lfo_control_source_new ();
cs = (GstControlSource *) lfocs;
gst_object_set_control_binding (e, gst_control_binding_new (e, "int", cs));
gst_object_add_control_binding (e, gst_control_binding_new (e, "int", cs));
g_object_set (lfocs,
"frequency", (gdouble) 0.05,
@ -381,7 +381,7 @@ test_chained_lfo (void)
lfocs1 = gst_lfo_control_source_new ();
cs1 = (GstControlSource *) lfocs1;
gst_object_set_control_binding (e, gst_control_binding_new (e, "int", cs1));
gst_object_add_control_binding (e, gst_control_binding_new (e, "int", cs1));
g_object_set (lfocs1,
"waveform", GST_LFO_WAVEFORM_SINE,
@ -391,7 +391,7 @@ test_chained_lfo (void)
lfocs2 = gst_lfo_control_source_new ();
cs2 = (GstControlSource *) lfocs2;
gst_object_set_control_binding ((GstObject *) lfocs1,
gst_object_add_control_binding ((GstObject *) lfocs1,
gst_control_binding_new ((GstObject *) lfocs1, "amplitude", cs2));
g_object_set (lfocs2,

View file

@ -598,6 +598,7 @@ EXPORTS
gst_mini_object_unref
gst_mini_object_weak_ref
gst_mini_object_weak_unref
gst_object_add_control_binding
gst_object_check_uniqueness
gst_object_default_deep_notify
gst_object_default_error
@ -614,8 +615,8 @@ EXPORTS
gst_object_has_ancestor
gst_object_ref
gst_object_ref_sink
gst_object_remove_control_binding
gst_object_replace
gst_object_set_control_binding
gst_object_set_control_binding_disabled
gst_object_set_control_bindings_disabled
gst_object_set_control_rate