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 /libs/gst/controller | |
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
Diffstat (limited to 'libs/gst/controller')
-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 |
4 files changed, 286 insertions, 0 deletions
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', |