diff options
author | Matthew Waters <matthew@centricular.com> | 2016-11-18 13:09:21 +1100 |
---|---|---|
committer | Matthew Waters <matthew@centricular.com> | 2016-11-23 17:15:09 +1100 |
commit | 3eb48964358149f9934656f681402a431b262e5f (patch) | |
tree | f59ae0d4911d79c2c76155b226f8ef228a80bd5e | |
parent | 47fd993d4d160f409301ccc108d943a38358fae1 (diff) |
controllers: add new proxy control binding
Allows proxying the control interface from one property on one GstObject
to another property (of the same type) in another GstObject.
E.g. in a parent-child relationship, one may need to
gst_object_sync_values() on the child and have a binding (set elsewhere)
on the parent update the value.
Note: that this doesn't solve GObject property forwarding and must be
taken care of by the implementation manually or using GBinding.
https://bugzilla.gnome.org/show_bug.cgi?id=774657
-rw-r--r-- | docs/libs/gstreamer-libs-docs.sgml | 1 | ||||
-rw-r--r-- | docs/libs/gstreamer-libs-sections.txt | 17 | ||||
-rw-r--r-- | libs/gst/controller/Makefile.am | 2 | ||||
-rw-r--r-- | libs/gst/controller/gstproxycontrolbinding.c | 199 | ||||
-rw-r--r-- | libs/gst/controller/gstproxycontrolbinding.h | 83 | ||||
-rw-r--r-- | libs/gst/controller/meson.build | 2 | ||||
-rw-r--r-- | tests/check/libs/controller.c | 107 | ||||
-rw-r--r-- | win32/common/libgstcontroller.def | 2 |
8 files changed, 413 insertions, 0 deletions
diff --git a/docs/libs/gstreamer-libs-docs.sgml b/docs/libs/gstreamer-libs-docs.sgml index d11da62ca..bca5d2fa7 100644 --- a/docs/libs/gstreamer-libs-docs.sgml +++ b/docs/libs/gstreamer-libs-docs.sgml @@ -59,6 +59,7 @@ <xi:include href="xml/gstargbcontrolbinding.xml" /> <xi:include href="xml/gstdirectcontrolbinding.xml" /> + <xi:include href="xml/gstproxycontrolbinding.xml" /> <xi:include href="xml/gsttimedvaluecontrolsource.xml" /> <xi:include href="xml/gstinterpolationcontrolsource.xml" /> diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index b833357a8..a0f841378 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -52,6 +52,23 @@ GST_TYPE_DIRECT_CONTROL_BINDING gst_direct_control_binding_get_type </SECTION> +<SECTION> +<FILE>gstproxycontrolbinding</FILE> +<TITLE>GstProxyControlBinding</TITLE> +<INCLUDE>libs/controller/gstdirectcontrolbinding.h</INCLUDE> +gst_proxy_control_binding_new +<SUBSECTION Standard> +GstProxyControlBinding +GstProxyControlBindingClass +GST_PROXY_CONTROL_BINDING +GST_PROXY_CONTROL_BINDING_CLASS +GST_PROXY_CONTROL_BINDING_GET_CLASS +GST_IS_PROXY_CONTROL_BINDING +GST_IS_PROXY_CONTROL_BINDING_CLASS +GST_TYPE_PROXY_CONTROL_BINDING +gst_proxy_control_binding_get_type +</SECTION> + # control source classes <SECTION> diff --git a/libs/gst/controller/Makefile.am b/libs/gst/controller/Makefile.am index 5016ea62b..b20a8e7d9 100644 --- a/libs/gst/controller/Makefile.am +++ b/libs/gst/controller/Makefile.am @@ -7,6 +7,7 @@ libgstcontroller_@GST_API_VERSION@_include_HEADERS = \ gstdirectcontrolbinding.h \ gsttimedvaluecontrolsource.h \ gstinterpolationcontrolsource.h \ + gstproxycontrolbinding.h \ gsttriggercontrolsource.h \ gstlfocontrolsource.h @@ -15,6 +16,7 @@ libgstcontroller_@GST_API_VERSION@_la_SOURCES = \ gstdirectcontrolbinding.c \ gsttimedvaluecontrolsource.c \ gstinterpolationcontrolsource.c \ + gstproxycontrolbinding.c \ gsttriggercontrolsource.c \ gstlfocontrolsource.c diff --git a/libs/gst/controller/gstproxycontrolbinding.c b/libs/gst/controller/gstproxycontrolbinding.c new file mode 100644 index 000000000..ce5cad5d8 --- /dev/null +++ b/libs/gst/controller/gstproxycontrolbinding.c @@ -0,0 +1,199 @@ +/* + * GStreamer + * Copyright (C) 2016 Matthew Waters <matthew@centricular.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +/** + * SECTION:gstproxycontrolbinding + * @short_description: attachment for forwarding control sources + * @see_also: #GstControlBinding + * + * A #GstControlBinding that forwards requests to another #GstControlBinding + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstproxycontrolbinding.h" + +G_DEFINE_TYPE (GstProxyControlBinding, + gst_proxy_control_binding, GST_TYPE_CONTROL_BINDING); + +static void +gst_proxy_control_binding_init (GstProxyControlBinding * self) +{ + g_weak_ref_init (&self->ref_object, NULL); +} + +static void +gst_proxy_control_binding_finalize (GObject * object) +{ + GstProxyControlBinding *self = (GstProxyControlBinding *) object; + + g_weak_ref_clear (&self->ref_object); + g_free (self->property_name); + + G_OBJECT_CLASS (gst_proxy_control_binding_parent_class)->finalize (object); +} + +static gboolean +gst_proxy_control_binding_sync_values (GstControlBinding * binding, + GstObject * object, GstClockTime timestamp, GstClockTime last_sync) +{ + GstProxyControlBinding *self = (GstProxyControlBinding *) + binding; + gboolean ret = TRUE; + GstObject *ref_object; + + ref_object = g_weak_ref_get (&self->ref_object); + if (ref_object) { + GstControlBinding *ref_binding = + gst_object_get_control_binding (ref_object, self->property_name); + if (ref_binding) { + ret = gst_control_binding_sync_values (ref_binding, ref_object, + timestamp, last_sync); + gst_object_unref (ref_binding); + } + gst_object_unref (ref_object); + } + + return ret; +} + +static GValue * +gst_proxy_control_binding_get_value (GstControlBinding * binding, + GstClockTime timestamp) +{ + GstProxyControlBinding *self = (GstProxyControlBinding *) + binding; + GValue *ret = NULL; + GstObject *ref_object; + + ref_object = g_weak_ref_get (&self->ref_object); + if (ref_object) { + GstControlBinding *ref_binding = + gst_object_get_control_binding (ref_object, self->property_name); + if (ref_binding) { + ret = gst_control_binding_get_value (ref_binding, timestamp); + gst_object_unref (ref_binding); + } + gst_object_unref (ref_object); + } + + return ret; +} + +static gboolean +gst_proxy_control_binding_get_value_array (GstControlBinding * binding, + GstClockTime timestamp, GstClockTime interval, guint n_values, + gpointer values) +{ + GstProxyControlBinding *self = (GstProxyControlBinding *) + binding; + gboolean ret = FALSE; + GstObject *ref_object; + + ref_object = g_weak_ref_get (&self->ref_object); + if (ref_object) { + GstControlBinding *ref_binding = + gst_object_get_control_binding (ref_object, self->property_name); + if (ref_binding) { + ret = gst_control_binding_get_value_array (ref_binding, timestamp, + interval, n_values, values); + gst_object_unref (ref_binding); + } + gst_object_unref (ref_object); + } + + return ret; +} + +static gboolean +gst_proxy_control_binding_get_g_value_array (GstControlBinding * + binding, GstClockTime timestamp, GstClockTime interval, guint n_values, + GValue * values) +{ + GstProxyControlBinding *self = (GstProxyControlBinding *) binding; + gboolean ret = FALSE; + GstObject *ref_object; + + ref_object = g_weak_ref_get (&self->ref_object); + if (ref_object) { + GstControlBinding *ref_binding = + gst_object_get_control_binding (ref_object, self->property_name); + if (ref_binding) { + ret = gst_control_binding_get_g_value_array (ref_binding, timestamp, + interval, n_values, values); + gst_object_unref (ref_binding); + } + gst_object_unref (ref_object); + } + + return ret; +} + +static void +gst_proxy_control_binding_class_init (GstProxyControlBindingClass * klass) +{ + GstControlBindingClass *cb_class = GST_CONTROL_BINDING_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + cb_class->sync_values = gst_proxy_control_binding_sync_values; + cb_class->get_value = gst_proxy_control_binding_get_value; + cb_class->get_value_array = gst_proxy_control_binding_get_value_array; + cb_class->get_g_value_array = gst_proxy_control_binding_get_g_value_array; + + gobject_class->finalize = gst_proxy_control_binding_finalize; +} + +/** + * gst_proxy_control_binding_new: + * @object: (transfer none): a #GstObject + * @property_name: the property name in @object to control + * @ref_object: (transfer none): a #GstObject to forward all + * #GstControlBinding requests to + * @ref_property_name: the property_name in @ref_object to control + * + * #GstProxyControlBinding forwards all access to data or sync_values() + * requests from @property_name on @object to the control binding at + * @ref_property_name on @ref_object. + * + * Returns: a new #GstControlBinding that proxies the control interface between + * properties on different #GstObject's + * + * Since: 1.12 + */ +GstControlBinding * +gst_proxy_control_binding_new (GstObject * object, const gchar * property_name, + GstObject * ref_object, const gchar * ref_property_name) +{ + GstProxyControlBinding *cb; + + g_return_val_if_fail (GST_IS_OBJECT (object), NULL); + g_return_val_if_fail (property_name != NULL, NULL); + g_return_val_if_fail (GST_IS_OBJECT (ref_object), NULL); + g_return_val_if_fail (ref_property_name != NULL, NULL); + + cb = g_object_new (GST_TYPE_PROXY_CONTROL_BINDING, "object", object, + "name", property_name, NULL); + + g_weak_ref_set (&cb->ref_object, ref_object); + cb->property_name = g_strdup (ref_property_name); + + return (GstControlBinding *) cb; +} diff --git a/libs/gst/controller/gstproxycontrolbinding.h b/libs/gst/controller/gstproxycontrolbinding.h new file mode 100644 index 000000000..096712d9d --- /dev/null +++ b/libs/gst/controller/gstproxycontrolbinding.h @@ -0,0 +1,83 @@ +/* + * GStreamer + * Copyright (C) 2016 Matthew Waters <matthew@centricular.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_PROXY_CONTROL_BINDING_H__ +#define __GST_PROXY_CONTROL_BINDING_H__ + +#include <gst/gst.h> + +G_BEGIN_DECLS + +GType gst_proxy_control_binding_get_type (void); +#define GST_TYPE_PROXY_CONTROL_BINDING (gst_proxy_control_binding_get_type()) +#define GST_PROXY_CONTROL_BINDING(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PROXY_CONTROL_BINDING,GstProxyControlBinding)) +#define GST_PROXY_CONTROL_BINDING_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PROXY_CONTROL_BINDING,GstProxyControlBindingClass)) +#define GST_IS_PROXY_CONTROL_BINDING(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PROXY_CONTROL_BINDING)) +#define GST_IS_PROXY_CONTROL_BINDING_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PROXY_CONTROL_BINDING)) +#define GST_PROXY_CONTROL_BINDING_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_CONTOL_SOURCE, GstProxyControlBindingClass)) + +typedef struct _GstProxyControlBinding GstProxyControlBinding; +typedef struct _GstProxyControlBindingClass GstProxyControlBindingClass; + +/** + * GstProxyControlBinding: + * + * Opaque #GstProxyControlBinding struct + */ +struct _GstProxyControlBinding +{ + /* <private> */ + GstControlBinding parent; + + GWeakRef ref_object; + gchar *property_name; + + gpointer _padding[GST_PADDING]; +}; + +/** + * GstProxyControlBindingClass: + * + * Opaque #GstProxyControlBindingClass struct + */ +struct _GstProxyControlBindingClass +{ + /* <private> */ + GstControlBindingClass parent_class; + + gpointer _padding[GST_PADDING]; +}; + +GstControlBinding * gst_proxy_control_binding_new (GstObject * object, + const gchar * property_name, + GstObject * ref_object, + const gchar * ref_property_name); + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstProxyControlBinding, gst_object_unref) +#endif +G_END_DECLS + +#endif /* __GST_PROXY_CONTROL_BINDING_H__ */ diff --git a/libs/gst/controller/meson.build b/libs/gst/controller/meson.build index c3c784393..861ada525 100644 --- a/libs/gst/controller/meson.build +++ b/libs/gst/controller/meson.build @@ -3,6 +3,7 @@ gst_controller_sources = [ 'gstdirectcontrolbinding.c', 'gsttimedvaluecontrolsource.c', 'gstinterpolationcontrolsource.c', + 'gstproxycontrolbinding.c', 'gsttriggercontrolsource.c', 'gstlfocontrolsource.c', ] @@ -12,6 +13,7 @@ gst_controller_headers = [ 'gstdirectcontrolbinding.h', 'gsttimedvaluecontrolsource.h', 'gstinterpolationcontrolsource.h', + 'gstproxycontrolbinding.h', 'gsttriggercontrolsource.h', 'gstlfocontrolsource.h', 'controller.h', diff --git a/tests/check/libs/controller.c b/tests/check/libs/controller.c index 3a736cd5d..9fdb760d5 100644 --- a/tests/check/libs/controller.c +++ b/tests/check/libs/controller.c @@ -30,6 +30,7 @@ #include <gst/controller/gstlfocontrolsource.h> #include <gst/controller/gsttriggercontrolsource.h> #include <gst/controller/gstdirectcontrolbinding.h> +#include <gst/controller/gstproxycontrolbinding.h> /* enum for text element */ @@ -1526,6 +1527,111 @@ GST_START_TEST (controller_trigger_tolerance) GST_END_TEST; +GST_START_TEST (controller_proxy) +{ + GstControlBinding *cb, *cb2; + GstControlSource *cs; + GstTimedValueControlSource *tvcs; + GstElement *elem, *elem2; + GstClockTime time; + gint int1, int2; + GValue gval1 = G_VALUE_INIT, gval2 = G_VALUE_INIT; + GValue *val1, *val2; + + elem = gst_element_factory_make ("testobj", NULL); + elem2 = gst_element_factory_make ("testobj", NULL); + + /* proxy control binding from elem to elem2 */ + cb = gst_proxy_control_binding_new (GST_OBJECT (elem), "int", + GST_OBJECT (elem2), "int"); + fail_unless (gst_object_add_control_binding (GST_OBJECT (elem), cb)); + + /* test that no proxy does nothing */ + val1 = gst_control_binding_get_value (cb, 0); + fail_unless (val1 == NULL); + fail_if (gst_control_binding_get_value_array (cb, 0, 0, 1, &int1)); + fail_if (gst_control_binding_get_g_value_array (cb, 0, 0, 1, &gval1)); + + /* new interpolation control source */ + cs = gst_trigger_control_source_new (); + tvcs = (GstTimedValueControlSource *) cs; + + cb2 = gst_direct_control_binding_new (GST_OBJECT (elem2), "int", cs); + fail_unless (gst_object_add_control_binding (GST_OBJECT (elem2), cb2)); + + /* set control values */ + fail_unless (gst_timed_value_control_source_set (tvcs, 0 * GST_SECOND, 0.0)); + fail_unless (gst_timed_value_control_source_set (tvcs, 1 * GST_SECOND, 1.0)); + + /* now pull in values for some timestamps */ + time = 0 * GST_SECOND; + gst_object_sync_values (GST_OBJECT (elem), time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, 0); + val1 = gst_control_binding_get_value (cb, time); + val2 = gst_control_binding_get_value (cb2, time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (val1)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (val2)); + fail_unless (gst_control_binding_get_value_array (cb, time, 0, 1, &int1)); + fail_unless (gst_control_binding_get_value_array (cb2, time, 0, 1, &int2)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, int1); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, int2); + fail_unless (gst_control_binding_get_g_value_array (cb, time, 0, 1, &gval1)); + fail_unless (gst_control_binding_get_g_value_array (cb2, time, 0, 1, &gval2)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (&gval1)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (&gval2)); + g_value_unset (val1); + g_value_unset (val2); + g_free (val1); + g_free (val2); + g_value_unset (&gval1); + g_value_unset (&gval2); + + time = 1 * GST_SECOND; + gst_object_sync_values (GST_OBJECT (elem), time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, 100); + val1 = gst_control_binding_get_value (cb, time); + val2 = gst_control_binding_get_value (cb2, time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (val1)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (val2)); + fail_unless (gst_control_binding_get_value_array (cb, time, 0, 1, &int1)); + fail_unless (gst_control_binding_get_value_array (cb2, time, 0, 1, &int2)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, int1); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, int2); + fail_unless (gst_control_binding_get_g_value_array (cb, time, 0, 1, &gval1)); + fail_unless (gst_control_binding_get_g_value_array (cb2, time, 0, 1, &gval2)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (&gval1)); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, + g_value_get_int (&gval2)); + g_value_unset (val1); + g_value_unset (val2); + g_free (val1); + g_free (val2); + g_value_unset (&gval1); + g_value_unset (&gval2); + + /* test syncing on the original control binding */ + time = 0 * GST_SECOND; + gst_object_sync_values (GST_OBJECT (elem2), time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, 0); + + time = 1 * GST_SECOND; + gst_object_sync_values (GST_OBJECT (elem2), time); + fail_unless_equals_int (GST_TEST_OBJ (elem2)->val_int, 100); + + gst_object_unref (cs); + gst_object_unref (elem); + gst_object_unref (elem2); +} + +GST_END_TEST; + static Suite * gst_controller_suite (void) @@ -1560,6 +1666,7 @@ gst_controller_suite (void) tcase_add_test (tc, controller_lfo_triangle); tcase_add_test (tc, controller_trigger_exact); tcase_add_test (tc, controller_trigger_tolerance); + tcase_add_test (tc, controller_proxy); return s; } diff --git a/win32/common/libgstcontroller.def b/win32/common/libgstcontroller.def index f539777f5..5ccc4c798 100644 --- a/win32/common/libgstcontroller.def +++ b/win32/common/libgstcontroller.def @@ -11,6 +11,8 @@ EXPORTS gst_lfo_control_source_get_type gst_lfo_control_source_new gst_lfo_waveform_get_type + gst_proxy_control_binding_get_type + gst_proxy_control_binding_new gst_timed_value_control_invalidate_cache gst_timed_value_control_source_find_control_point_iter gst_timed_value_control_source_get_all |