2011-12-20 21:36:18 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
|
|
|
|
*
|
|
|
|
* gstcontrolbinding.c: Attachment for control sources
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-12-20 21:36:18 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* SECTION:gstcontrolbinding
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstControlBinding
|
2011-12-20 21:36:18 +00:00
|
|
|
* @short_description: attachment for control source sources
|
|
|
|
*
|
2013-01-10 10:33:42 +00:00
|
|
|
* A base class for value mapping objects that attaches control sources to gobject
|
|
|
|
* properties. Such an object is taking one or more #GstControlSource instances,
|
|
|
|
* combines them and maps the resulting value to the type and value range of the
|
|
|
|
* bound property.
|
2011-12-20 21:36:18 +00:00
|
|
|
*/
|
2012-04-13 06:10:19 +00:00
|
|
|
/* FIXME(ensonic): should we make gst_object_add_control_binding() internal
|
|
|
|
* - we create the control_binding for a certain object anyway
|
|
|
|
* - we could call gst_object_add_control_binding() at the end of
|
|
|
|
* gst_control_binding_constructor()
|
|
|
|
* - the weak-ref on object is not nice, as is the same as gst_object_parent()
|
|
|
|
* once the object is added to the parent
|
2012-04-25 07:47:10 +00:00
|
|
|
*
|
2013-03-07 08:15:14 +00:00
|
|
|
* - another option would be to defer what is done in _constructor to when
|
2012-04-25 07:47:10 +00:00
|
|
|
* the parent is set (need to listen to the signal then)
|
|
|
|
* then basically I could
|
|
|
|
* a) remove the obj arg and wait the binding to be added or
|
|
|
|
* b) add the binding from constructor, unref object there and make obj
|
|
|
|
* writeonly
|
2012-04-13 06:10:19 +00:00
|
|
|
*/
|
2011-12-20 21:36:18 +00:00
|
|
|
|
|
|
|
#include "gst_private.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include "gstcontrolbinding.h"
|
|
|
|
|
2011-12-22 22:48:30 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2011-12-20 21:36:18 +00:00
|
|
|
#define GST_CAT_DEFAULT control_binding_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
#define _do_init \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gstcontrolbinding", 0, \
|
|
|
|
"dynamic parameter control source attachment");
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
static GObject *gst_control_binding_constructor (GType type,
|
|
|
|
guint n_construct_params, GObjectConstructParam * construct_params);
|
|
|
|
static void gst_control_binding_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_control_binding_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_control_binding_dispose (GObject * object);
|
|
|
|
static void gst_control_binding_finalize (GObject * object);
|
|
|
|
|
2012-01-21 19:03:52 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstControlBinding, gst_control_binding,
|
2012-01-20 07:27:57 +00:00
|
|
|
GST_TYPE_OBJECT, _do_init);
|
2011-12-20 21:36:18 +00:00
|
|
|
|
2016-10-13 16:20:58 +00:00
|
|
|
struct _GstControlBindingPrivate
|
|
|
|
{
|
|
|
|
GWeakRef object;
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_OBJECT,
|
|
|
|
PROP_NAME,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[PROP_LAST];
|
|
|
|
|
2011-12-20 21:36:18 +00:00
|
|
|
static void
|
|
|
|
gst_control_binding_class_init (GstControlBindingClass * klass)
|
|
|
|
{
|
2012-01-24 20:53:14 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2016-10-13 16:20:58 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstControlBindingPrivate));
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
gobject_class->constructor = gst_control_binding_constructor;
|
|
|
|
gobject_class->set_property = gst_control_binding_set_property;
|
|
|
|
gobject_class->get_property = gst_control_binding_get_property;
|
|
|
|
gobject_class->dispose = gst_control_binding_dispose;
|
|
|
|
gobject_class->finalize = gst_control_binding_finalize;
|
|
|
|
|
|
|
|
properties[PROP_OBJECT] =
|
|
|
|
g_param_spec_object ("object", "Object",
|
|
|
|
"The object of the property", GST_TYPE_OBJECT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
properties[PROP_NAME] =
|
|
|
|
g_param_spec_string ("name", "Name", "The name of the property", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (gobject_class, PROP_LAST, properties);
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_init (GstControlBinding * binding)
|
2011-12-20 21:36:18 +00:00
|
|
|
{
|
2016-10-13 16:20:58 +00:00
|
|
|
binding->ABI.abi.priv =
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (binding, GST_TYPE_CONTROL_BINDING,
|
|
|
|
GstControlBindingPrivate);
|
|
|
|
g_weak_ref_init (&binding->ABI.abi.priv->object, NULL);
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
static GObject *
|
|
|
|
gst_control_binding_constructor (GType type, guint n_construct_params,
|
|
|
|
GObjectConstructParam * construct_params)
|
|
|
|
{
|
2012-06-15 23:43:30 +00:00
|
|
|
GstControlBinding *binding;
|
2012-01-24 20:53:14 +00:00
|
|
|
GParamSpec *pspec;
|
2016-10-13 16:20:58 +00:00
|
|
|
GstObject *object;
|
2012-01-24 20:53:14 +00:00
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
binding =
|
|
|
|
GST_CONTROL_BINDING (G_OBJECT_CLASS (gst_control_binding_parent_class)
|
2012-01-24 20:53:14 +00:00
|
|
|
->constructor (type, n_construct_params, construct_params));
|
|
|
|
|
2016-10-13 16:20:58 +00:00
|
|
|
object = g_weak_ref_get (&binding->ABI.abi.priv->object);
|
|
|
|
if (!object) {
|
|
|
|
GST_WARNING_OBJECT (object, "no object set");
|
|
|
|
return (GObject *) binding;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (object, "trying to put property '%s' under control",
|
2012-06-15 23:43:30 +00:00
|
|
|
binding->name);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
/* check if the object has a property of that name */
|
|
|
|
if ((pspec =
|
2016-10-13 16:20:58 +00:00
|
|
|
g_object_class_find_property (G_OBJECT_GET_CLASS (object),
|
2012-06-15 23:43:30 +00:00
|
|
|
binding->name))) {
|
2016-10-13 16:20:58 +00:00
|
|
|
GST_DEBUG_OBJECT (object, " psec->flags : 0x%08x", pspec->flags);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
/* check if this param is witable && controlable && !construct-only */
|
|
|
|
if ((pspec->flags & (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY)) ==
|
|
|
|
(G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE)) {
|
2012-06-15 23:43:30 +00:00
|
|
|
binding->pspec = pspec;
|
2013-02-08 20:21:48 +00:00
|
|
|
} else {
|
2016-10-13 16:20:58 +00:00
|
|
|
GST_WARNING_OBJECT (object,
|
2013-02-08 20:21:48 +00:00
|
|
|
"property '%s' on class '%s' needs to "
|
|
|
|
"be writeable, controlable and not construct_only", binding->name,
|
2016-10-13 16:20:58 +00:00
|
|
|
G_OBJECT_TYPE_NAME (object));
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-10-13 16:20:58 +00:00
|
|
|
GST_WARNING_OBJECT (object, "class '%s' has no property '%s'",
|
|
|
|
G_OBJECT_TYPE_NAME (object), binding->name);
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
2016-10-13 16:20:58 +00:00
|
|
|
|
|
|
|
gst_object_unref (object);
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
return (GObject *) binding;
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_control_binding_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstControlBinding *self = GST_CONTROL_BINDING (object);
|
|
|
|
|
2012-04-13 06:10:19 +00:00
|
|
|
/* we did not took a reference */
|
2016-10-13 16:20:58 +00:00
|
|
|
g_object_remove_weak_pointer ((GObject *) self->__object,
|
|
|
|
(gpointer *) & self->__object);
|
|
|
|
self->__object = NULL;
|
|
|
|
g_weak_ref_clear (&self->ABI.abi.priv->object);
|
2012-04-05 19:56:05 +00:00
|
|
|
|
|
|
|
((GObjectClass *) gst_control_binding_parent_class)->dispose (object);
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_control_binding_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstControlBinding *self = GST_CONTROL_BINDING (object);
|
|
|
|
|
|
|
|
g_free (self->name);
|
2012-04-05 19:56:05 +00:00
|
|
|
|
|
|
|
((GObjectClass *) gst_control_binding_parent_class)->finalize (object);
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_control_binding_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstControlBinding *self = GST_CONTROL_BINDING (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_OBJECT:
|
2012-04-13 06:10:19 +00:00
|
|
|
/* do not ref to avoid a ref cycle */
|
2016-10-13 16:20:58 +00:00
|
|
|
self->__object = g_value_get_object (value);
|
|
|
|
g_object_add_weak_pointer ((GObject *) self->__object,
|
|
|
|
(gpointer *) & self->__object);
|
|
|
|
|
|
|
|
g_weak_ref_set (&self->ABI.abi.priv->object, self->__object);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case PROP_NAME:
|
|
|
|
self->name = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_control_binding_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstControlBinding *self = GST_CONTROL_BINDING (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_OBJECT:
|
2016-10-13 16:20:58 +00:00
|
|
|
g_value_take_object (value, g_weak_ref_get (&self->ABI.abi.priv->object));
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, self->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 21:36:18 +00:00
|
|
|
/* functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_control_binding_sync_values:
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2011-12-20 21:36:18 +00:00
|
|
|
* @object: the object that has controlled properties
|
|
|
|
* @timestamp: the time that should be processed
|
|
|
|
* @last_sync: the last time this was called
|
|
|
|
*
|
|
|
|
* Sets the property of the @object, according to the #GstControlSources that
|
|
|
|
* handle them and for the given timestamp.
|
|
|
|
*
|
|
|
|
* If this function fails, it is most likely the application developers fault.
|
|
|
|
* Most probably the control sources are not setup correctly.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the controller value could be applied to the object
|
|
|
|
* property, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_sync_values (GstControlBinding * binding,
|
|
|
|
GstObject * object, GstClockTime timestamp, GstClockTime last_sync)
|
2011-12-20 21:36:18 +00:00
|
|
|
{
|
2012-01-21 19:03:52 +00:00
|
|
|
GstControlBindingClass *klass;
|
|
|
|
gboolean ret = FALSE;
|
2011-12-20 21:36:18 +00:00
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
|
2011-12-20 21:36:18 +00:00
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
if (binding->disabled)
|
2011-12-20 21:36:18 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
klass = GST_CONTROL_BINDING_GET_CLASS (binding);
|
2011-12-20 21:36:18 +00:00
|
|
|
|
2012-01-21 19:03:52 +00:00
|
|
|
if (G_LIKELY (klass->sync_values != NULL)) {
|
2012-06-15 23:43:30 +00:00
|
|
|
ret = klass->sync_values (binding, object, timestamp, last_sync);
|
2011-12-20 21:36:18 +00:00
|
|
|
} else {
|
2012-06-15 23:43:30 +00:00
|
|
|
GST_WARNING_OBJECT (binding, "missing sync_values implementation");
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
2012-01-21 19:03:52 +00:00
|
|
|
return ret;
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:48:30 +00:00
|
|
|
/**
|
|
|
|
* gst_control_binding_get_value:
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2011-12-22 22:48:30 +00:00
|
|
|
* @timestamp: the time the control-change should be read from
|
|
|
|
*
|
|
|
|
* Gets the value for the given controlled property at the requested time.
|
|
|
|
*
|
2014-06-11 22:21:34 +00:00
|
|
|
* Returns: (nullable): the GValue of the property at the given time,
|
|
|
|
* or %NULL if the property isn't controlled.
|
2011-12-22 22:48:30 +00:00
|
|
|
*/
|
|
|
|
GValue *
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_get_value (GstControlBinding * binding,
|
|
|
|
GstClockTime timestamp)
|
2011-12-22 22:48:30 +00:00
|
|
|
{
|
2012-01-21 19:03:52 +00:00
|
|
|
GstControlBindingClass *klass;
|
|
|
|
GValue *ret = NULL;
|
2011-12-22 22:48:30 +00:00
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), NULL);
|
2011-12-22 22:48:30 +00:00
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
klass = GST_CONTROL_BINDING_GET_CLASS (binding);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (klass->get_value != NULL)) {
|
2012-06-15 23:43:30 +00:00
|
|
|
ret = klass->get_value (binding, timestamp);
|
2012-01-01 13:28:54 +00:00
|
|
|
} else {
|
2012-06-15 23:43:30 +00:00
|
|
|
GST_WARNING_OBJECT (binding, "missing get_value implementation");
|
2011-12-22 22:48:30 +00:00
|
|
|
}
|
2012-01-21 19:03:52 +00:00
|
|
|
return ret;
|
2011-12-22 22:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-30 07:17:06 +00:00
|
|
|
* gst_control_binding_get_value_array: (skip)
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2011-12-22 22:48:30 +00:00
|
|
|
* @timestamp: the time that should be processed
|
|
|
|
* @interval: the time spacing between subsequent values
|
|
|
|
* @n_values: the number of values
|
2014-05-30 07:17:06 +00:00
|
|
|
* @values: (array length=n_values): array to put control-values in
|
2011-12-22 22:48:30 +00:00
|
|
|
*
|
2012-04-25 07:47:10 +00:00
|
|
|
* Gets a number of values for the given controlled property starting at the
|
2011-12-22 22:48:30 +00:00
|
|
|
* requested time. The array @values need to hold enough space for @n_values of
|
|
|
|
* the same type as the objects property's type.
|
|
|
|
*
|
|
|
|
* This function is useful if one wants to e.g. draw a graph of the control
|
|
|
|
* curve or apply a control curve sample by sample.
|
|
|
|
*
|
2017-01-16 14:26:16 +00:00
|
|
|
* The values are unboxed and ready to be used. The similar function
|
2012-04-25 07:47:10 +00:00
|
|
|
* gst_control_binding_get_g_value_array() returns the array as #GValues and is
|
2013-02-01 20:59:41 +00:00
|
|
|
* more suitable for bindings.
|
2012-04-25 07:47:10 +00:00
|
|
|
*
|
2011-12-22 22:48:30 +00:00
|
|
|
* Returns: %TRUE if the given array could be filled, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_get_value_array (GstControlBinding * binding,
|
2011-12-22 22:48:30 +00:00
|
|
|
GstClockTime timestamp, GstClockTime interval, guint n_values,
|
2012-04-25 07:47:10 +00:00
|
|
|
gpointer values)
|
2011-12-22 22:48:30 +00:00
|
|
|
{
|
2012-01-21 19:03:52 +00:00
|
|
|
GstControlBindingClass *klass;
|
|
|
|
gboolean ret = FALSE;
|
2011-12-22 22:48:30 +00:00
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
|
2011-12-22 22:48:30 +00:00
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
|
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
|
|
|
|
g_return_val_if_fail (values, FALSE);
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
klass = GST_CONTROL_BINDING_GET_CLASS (binding);
|
2011-12-22 22:48:30 +00:00
|
|
|
|
2012-01-21 19:03:52 +00:00
|
|
|
if (G_LIKELY (klass->get_value_array != NULL)) {
|
2012-06-15 23:43:30 +00:00
|
|
|
ret =
|
|
|
|
klass->get_value_array (binding, timestamp, interval, n_values, values);
|
2012-01-01 13:28:54 +00:00
|
|
|
} else {
|
2012-06-15 23:43:30 +00:00
|
|
|
GST_WARNING_OBJECT (binding, "missing get_value_array implementation");
|
2011-12-22 22:48:30 +00:00
|
|
|
}
|
2012-01-21 19:03:52 +00:00
|
|
|
return ret;
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 18:10:11 +00:00
|
|
|
#define CONVERT_ARRAY(type,TYPE) \
|
|
|
|
{ \
|
|
|
|
g##type *v = g_new (g##type,n_values); \
|
2012-06-15 23:43:30 +00:00
|
|
|
ret = gst_control_binding_get_value_array (binding, timestamp, interval, \
|
2012-04-25 18:10:11 +00:00
|
|
|
n_values, v); \
|
|
|
|
if (ret) { \
|
|
|
|
for (i = 0; i < n_values; i++) { \
|
|
|
|
g_value_init (&values[i], G_TYPE_##TYPE); \
|
|
|
|
g_value_set_##type (&values[i], v[i]); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
g_free (v); \
|
|
|
|
}
|
|
|
|
|
2012-04-25 07:47:10 +00:00
|
|
|
/**
|
|
|
|
* gst_control_binding_get_g_value_array:
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2012-04-25 07:47:10 +00:00
|
|
|
* @timestamp: the time that should be processed
|
|
|
|
* @interval: the time spacing between subsequent values
|
|
|
|
* @n_values: the number of values
|
2014-05-30 07:17:06 +00:00
|
|
|
* @values: (array length=n_values): array to put control-values in
|
2012-04-25 07:47:10 +00:00
|
|
|
*
|
|
|
|
* Gets a number of #GValues for the given controlled property starting at the
|
|
|
|
* requested time. The array @values need to hold enough space for @n_values of
|
|
|
|
* #GValue.
|
|
|
|
*
|
|
|
|
* This function is useful if one wants to e.g. draw a graph of the control
|
|
|
|
* curve or apply a control curve sample by sample.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the given array could be filled, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_get_g_value_array (GstControlBinding * binding,
|
2012-04-25 07:47:10 +00:00
|
|
|
GstClockTime timestamp, GstClockTime interval, guint n_values,
|
|
|
|
GValue * values)
|
|
|
|
{
|
|
|
|
GstControlBindingClass *klass;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
|
2012-04-25 07:47:10 +00:00
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
|
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
|
|
|
|
g_return_val_if_fail (values, FALSE);
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
klass = GST_CONTROL_BINDING_GET_CLASS (binding);
|
2012-04-25 07:47:10 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (klass->get_g_value_array != NULL)) {
|
|
|
|
ret =
|
2012-06-15 23:43:30 +00:00
|
|
|
klass->get_g_value_array (binding, timestamp, interval, n_values,
|
|
|
|
values);
|
2012-04-25 07:47:10 +00:00
|
|
|
} else {
|
2012-04-25 18:10:11 +00:00
|
|
|
guint i;
|
|
|
|
GType type, base;
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (binding));
|
2012-04-25 18:10:11 +00:00
|
|
|
while ((type = g_type_parent (type)))
|
|
|
|
base = type;
|
|
|
|
|
2012-06-15 23:43:30 +00:00
|
|
|
GST_INFO_OBJECT (binding, "missing get_g_value_array implementation, we're "
|
2012-04-25 18:10:11 +00:00
|
|
|
"emulating it");
|
|
|
|
switch (base) {
|
|
|
|
case G_TYPE_INT:
|
|
|
|
CONVERT_ARRAY (int, INT);
|
|
|
|
break;
|
|
|
|
case G_TYPE_UINT:
|
|
|
|
CONVERT_ARRAY (uint, UINT);
|
|
|
|
break;
|
|
|
|
case G_TYPE_LONG:
|
|
|
|
CONVERT_ARRAY (long, LONG);
|
|
|
|
break;
|
|
|
|
case G_TYPE_ULONG:
|
|
|
|
CONVERT_ARRAY (ulong, ULONG);
|
|
|
|
break;
|
|
|
|
case G_TYPE_INT64:
|
|
|
|
CONVERT_ARRAY (int64, INT64);
|
|
|
|
break;
|
|
|
|
case G_TYPE_UINT64:
|
|
|
|
CONVERT_ARRAY (uint64, UINT64);
|
|
|
|
break;
|
|
|
|
case G_TYPE_FLOAT:
|
|
|
|
CONVERT_ARRAY (float, FLOAT);
|
|
|
|
break;
|
|
|
|
case G_TYPE_DOUBLE:
|
|
|
|
CONVERT_ARRAY (double, DOUBLE);
|
|
|
|
break;
|
|
|
|
case G_TYPE_BOOLEAN:
|
|
|
|
CONVERT_ARRAY (boolean, BOOLEAN);
|
|
|
|
break;
|
|
|
|
case G_TYPE_ENUM:
|
|
|
|
{
|
|
|
|
gint *v = g_new (gint, n_values);
|
2012-06-15 23:43:30 +00:00
|
|
|
ret = gst_control_binding_get_value_array (binding, timestamp, interval,
|
2012-04-25 18:10:11 +00:00
|
|
|
n_values, v);
|
|
|
|
if (ret) {
|
|
|
|
for (i = 0; i < n_values; i++) {
|
|
|
|
g_value_init (&values[i], type);
|
|
|
|
g_value_set_enum (&values[i], v[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("incomplete implementation for paramspec type '%s'",
|
2012-06-15 23:43:30 +00:00
|
|
|
G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (binding)));
|
|
|
|
GST_CONTROL_BINDING_PSPEC (binding) = NULL;
|
2012-04-25 18:10:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-25 07:47:10 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-20 21:36:18 +00:00
|
|
|
/**
|
|
|
|
* gst_control_binding_set_disabled:
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2011-12-20 21:36:18 +00:00
|
|
|
* @disabled: boolean that specifies whether to disable the controller
|
|
|
|
* or not.
|
|
|
|
*
|
|
|
|
* This function is used to disable a control binding for some time, i.e.
|
|
|
|
* gst_object_sync_values() will do nothing.
|
|
|
|
*/
|
|
|
|
void
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_set_disabled (GstControlBinding * binding,
|
|
|
|
gboolean disabled)
|
2011-12-20 21:36:18 +00:00
|
|
|
{
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_if_fail (GST_IS_CONTROL_BINDING (binding));
|
|
|
|
binding->disabled = disabled;
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_control_binding_is_disabled:
|
2012-06-15 23:43:30 +00:00
|
|
|
* @binding: the control binding
|
2011-12-20 21:36:18 +00:00
|
|
|
*
|
|
|
|
* Check if the control binding is disabled.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the binding is inactive
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-15 23:43:30 +00:00
|
|
|
gst_control_binding_is_disabled (GstControlBinding * binding)
|
2011-12-20 21:36:18 +00:00
|
|
|
{
|
2012-06-15 23:43:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), TRUE);
|
2014-11-28 13:17:54 +00:00
|
|
|
return ! !binding->disabled;
|
2011-12-20 21:36:18 +00:00
|
|
|
}
|