2012-01-21 19:03:52 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
|
|
|
|
*
|
2012-01-30 18:17:00 +00:00
|
|
|
* gstdirectcontrolbinding.c: Direct attachment for control sources
|
2012-01-21 19:03:52 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2012-01-21 19:03:52 +00:00
|
|
|
*/
|
|
|
|
/**
|
2012-01-30 18:17:00 +00:00
|
|
|
* SECTION:gstdirectcontrolbinding
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstDirectControlBinding
|
2013-02-01 20:59:41 +00:00
|
|
|
* @short_description: direct attachment for control sources
|
2012-01-21 19:03:52 +00:00
|
|
|
*
|
2013-02-01 20:59:41 +00:00
|
|
|
* A value mapping object that attaches control sources to gobject properties. It
|
2016-10-13 16:01:14 +00:00
|
|
|
* will map the control values directly to the target property range. If a
|
|
|
|
* non-absolute direct control binding is used, the value range [0.0 ... 1.0]
|
|
|
|
* is mapped to full target property range, and all values outside the range
|
|
|
|
* will be clipped. An absolute control binding will not do any value
|
|
|
|
* transformations.
|
2012-01-21 19:03:52 +00:00
|
|
|
*/
|
2018-08-25 21:56:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
#include "gstdirectcontrolbinding.h"
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-06-28 08:42:08 +00:00
|
|
|
#include <gst/math-compat.h>
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT control_binding_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
2015-05-27 09:29:41 +00:00
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
static GObject *gst_direct_control_binding_constructor (GType type,
|
2012-01-24 20:53:14 +00:00
|
|
|
guint n_construct_params, GObjectConstructParam * construct_params);
|
2012-01-30 18:17:00 +00:00
|
|
|
static void gst_direct_control_binding_set_property (GObject * object,
|
2012-01-24 20:53:14 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2012-01-30 18:17:00 +00:00
|
|
|
static void gst_direct_control_binding_get_property (GObject * object,
|
2012-01-24 20:53:14 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2012-01-30 18:17:00 +00:00
|
|
|
static void gst_direct_control_binding_dispose (GObject * object);
|
|
|
|
static void gst_direct_control_binding_finalize (GObject * object);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
static gboolean gst_direct_control_binding_sync_values (GstControlBinding *
|
2012-01-21 19:03:52 +00:00
|
|
|
_self, GstObject * object, GstClockTime timestamp, GstClockTime last_sync);
|
2012-01-30 18:17:00 +00:00
|
|
|
static GValue *gst_direct_control_binding_get_value (GstControlBinding * _self,
|
2012-01-21 19:03:52 +00:00
|
|
|
GstClockTime timestamp);
|
2012-01-30 18:17:00 +00:00
|
|
|
static gboolean gst_direct_control_binding_get_value_array (GstControlBinding *
|
2012-01-21 19:03:52 +00:00
|
|
|
_self, GstClockTime timestamp, GstClockTime interval, guint n_values,
|
2012-04-25 07:47:10 +00:00
|
|
|
gpointer values);
|
|
|
|
static gboolean gst_direct_control_binding_get_g_value_array (GstControlBinding
|
|
|
|
* _self, GstClockTime timestamp, GstClockTime interval, guint n_values,
|
2012-01-21 19:03:52 +00:00
|
|
|
GValue * values);
|
|
|
|
|
|
|
|
#define _do_init \
|
2012-01-30 18:17:00 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gstdirectcontrolbinding", 0, \
|
2012-01-21 19:03:52 +00:00
|
|
|
"dynamic parameter control source attachment");
|
|
|
|
|
2012-04-12 12:59:52 +00:00
|
|
|
#define gst_direct_control_binding_parent_class parent_class
|
2012-01-30 18:17:00 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstDirectControlBinding, gst_direct_control_binding,
|
2012-01-21 19:03:52 +00:00
|
|
|
GST_TYPE_CONTROL_BINDING, _do_init);
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_CS,
|
2015-05-27 09:29:41 +00:00
|
|
|
PROP_ABSOLUTE,
|
2012-01-24 20:53:14 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[PROP_LAST];
|
|
|
|
|
|
|
|
/* mapping functions */
|
|
|
|
|
2012-09-07 00:02:10 +00:00
|
|
|
#define DEFINE_CONVERT(type,Type,TYPE,ROUNDING_OP) \
|
2012-01-24 20:53:14 +00:00
|
|
|
static void \
|
2012-04-25 07:47:10 +00:00
|
|
|
convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) \
|
2012-01-24 20:53:14 +00:00
|
|
|
{ \
|
|
|
|
GParamSpec##Type *pspec = G_PARAM_SPEC_##TYPE (((GstControlBinding *)self)->pspec); \
|
|
|
|
g##type v; \
|
|
|
|
\
|
|
|
|
s = CLAMP (s, 0.0, 1.0); \
|
2013-08-07 17:17:28 +00:00
|
|
|
v = (g##type) ROUNDING_OP (pspec->minimum * (1-s)) + (g##type) ROUNDING_OP (pspec->maximum * s); \
|
2012-01-24 20:53:14 +00:00
|
|
|
g_value_set_##type (d, v); \
|
2012-04-25 07:47:10 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void \
|
|
|
|
convert_value_to_##type (GstDirectControlBinding *self, gdouble s, gpointer d_) \
|
|
|
|
{ \
|
|
|
|
GParamSpec##Type *pspec = G_PARAM_SPEC_##TYPE (((GstControlBinding *)self)->pspec); \
|
|
|
|
g##type *d = (g##type *)d_; \
|
|
|
|
\
|
|
|
|
s = CLAMP (s, 0.0, 1.0); \
|
2013-08-07 17:17:28 +00:00
|
|
|
*d = (g##type) ROUNDING_OP (pspec->minimum * (1-s)) + (g##type) ROUNDING_OP (pspec->maximum * s); \
|
2015-05-27 09:29:41 +00:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void \
|
|
|
|
abs_convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) \
|
|
|
|
{ \
|
|
|
|
g##type v; \
|
|
|
|
v = (g##type) ROUNDING_OP (s); \
|
|
|
|
g_value_set_##type (d, v); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void \
|
|
|
|
abs_convert_value_to_##type (GstDirectControlBinding *self, gdouble s, gpointer d_) \
|
|
|
|
{ \
|
|
|
|
g##type *d = (g##type *)d_; \
|
|
|
|
*d = (g##type) ROUNDING_OP (s); \
|
2012-01-24 20:53:14 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 00:02:10 +00:00
|
|
|
DEFINE_CONVERT (int, Int, INT, rint);
|
|
|
|
DEFINE_CONVERT (uint, UInt, UINT, rint);
|
|
|
|
DEFINE_CONVERT (long, Long, LONG, rint);
|
|
|
|
DEFINE_CONVERT (ulong, ULong, ULONG, rint);
|
|
|
|
DEFINE_CONVERT (int64, Int64, INT64, rint);
|
|
|
|
DEFINE_CONVERT (uint64, UInt64, UINT64, rint);
|
|
|
|
DEFINE_CONVERT (float, Float, FLOAT, /*NOOP*/);
|
|
|
|
DEFINE_CONVERT (double, Double, DOUBLE, /*NOOP*/);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
static void
|
2012-04-25 07:47:10 +00:00
|
|
|
convert_g_value_to_boolean (GstDirectControlBinding * self, gdouble s,
|
|
|
|
GValue * d)
|
2012-01-24 20:53:14 +00:00
|
|
|
{
|
|
|
|
s = CLAMP (s, 0.0, 1.0);
|
|
|
|
g_value_set_boolean (d, (gboolean) (s + 0.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-25 07:47:10 +00:00
|
|
|
convert_value_to_boolean (GstDirectControlBinding * self, gdouble s,
|
|
|
|
gpointer d_)
|
|
|
|
{
|
|
|
|
gboolean *d = (gboolean *) d_;
|
|
|
|
|
|
|
|
s = CLAMP (s, 0.0, 1.0);
|
|
|
|
*d = (gboolean) (s + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
convert_g_value_to_enum (GstDirectControlBinding * self, gdouble s, GValue * d)
|
2012-01-24 20:53:14 +00:00
|
|
|
{
|
|
|
|
GParamSpecEnum *pspec =
|
|
|
|
G_PARAM_SPEC_ENUM (((GstControlBinding *) self)->pspec);
|
|
|
|
GEnumClass *e = pspec->enum_class;
|
|
|
|
gint v;
|
|
|
|
|
|
|
|
s = CLAMP (s, 0.0, 1.0);
|
|
|
|
v = s * (e->n_values - 1);
|
|
|
|
g_value_set_enum (d, e->values[v].value);
|
|
|
|
}
|
|
|
|
|
2012-04-25 07:47:10 +00:00
|
|
|
static void
|
|
|
|
convert_value_to_enum (GstDirectControlBinding * self, gdouble s, gpointer d_)
|
|
|
|
{
|
|
|
|
GParamSpecEnum *pspec =
|
|
|
|
G_PARAM_SPEC_ENUM (((GstControlBinding *) self)->pspec);
|
|
|
|
GEnumClass *e = pspec->enum_class;
|
|
|
|
gint *d = (gint *) d_;
|
|
|
|
|
|
|
|
s = CLAMP (s, 0.0, 1.0);
|
|
|
|
*d = e->values[(gint) (s * (e->n_values - 1))].value;
|
|
|
|
}
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
/* vmethods */
|
|
|
|
|
2012-01-21 19:03:52 +00:00
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_class_init (GstDirectControlBindingClass * klass)
|
2012-01-21 19:03:52 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstControlBindingClass *control_binding_class =
|
|
|
|
GST_CONTROL_BINDING_CLASS (klass);
|
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
gobject_class->constructor = gst_direct_control_binding_constructor;
|
|
|
|
gobject_class->set_property = gst_direct_control_binding_set_property;
|
|
|
|
gobject_class->get_property = gst_direct_control_binding_get_property;
|
|
|
|
gobject_class->dispose = gst_direct_control_binding_dispose;
|
|
|
|
gobject_class->finalize = gst_direct_control_binding_finalize;
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
control_binding_class->sync_values = gst_direct_control_binding_sync_values;
|
|
|
|
control_binding_class->get_value = gst_direct_control_binding_get_value;
|
2012-01-21 19:03:52 +00:00
|
|
|
control_binding_class->get_value_array =
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_get_value_array;
|
2012-04-25 07:47:10 +00:00
|
|
|
control_binding_class->get_g_value_array =
|
|
|
|
gst_direct_control_binding_get_g_value_array;
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
properties[PROP_CS] =
|
|
|
|
g_param_spec_object ("control-source", "ControlSource",
|
|
|
|
"The control source",
|
2013-09-10 15:39:30 +00:00
|
|
|
GST_TYPE_CONTROL_SOURCE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
2015-05-27 09:29:41 +00:00
|
|
|
properties[PROP_ABSOLUTE] =
|
|
|
|
g_param_spec_boolean ("absolute", "Absolute",
|
|
|
|
"Whether the control values are absolute",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
g_object_class_install_properties (gobject_class, PROP_LAST, properties);
|
2012-01-21 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_init (GstDirectControlBinding * self)
|
2012-01-21 19:03:52 +00:00
|
|
|
{
|
2020-07-14 04:03:18 +00:00
|
|
|
self->last_value = G_MAXDOUBLE;
|
2012-01-21 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
static GObject *
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_constructor (GType type, guint n_construct_params,
|
2012-01-24 20:53:14 +00:00
|
|
|
GObjectConstructParam * construct_params)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self;
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
self =
|
2012-04-12 12:59:52 +00:00
|
|
|
GST_DIRECT_CONTROL_BINDING (G_OBJECT_CLASS (parent_class)->constructor
|
|
|
|
(type, n_construct_params, construct_params));
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
if (GST_CONTROL_BINDING_PSPEC (self)) {
|
|
|
|
GType type, base;
|
|
|
|
|
|
|
|
base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (self));
|
|
|
|
g_value_init (&self->cur_value, type);
|
|
|
|
while ((type = g_type_parent (type)))
|
|
|
|
base = type;
|
|
|
|
|
|
|
|
GST_DEBUG (" using type %s", g_type_name (base));
|
|
|
|
|
2012-09-10 10:12:02 +00:00
|
|
|
/* select mapping function */
|
2015-05-27 09:29:41 +00:00
|
|
|
|
|
|
|
#define SET_CONVERT_FUNCTION(type) \
|
2015-06-29 09:41:27 +00:00
|
|
|
if (self->ABI.abi.want_absolute) { \
|
2015-05-27 09:29:41 +00:00
|
|
|
self->convert_g_value = abs_convert_g_value_to_##type; \
|
|
|
|
self->convert_value = abs_convert_value_to_##type; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
self->convert_g_value = convert_g_value_to_##type; \
|
|
|
|
self->convert_value = convert_value_to_##type; \
|
|
|
|
} \
|
|
|
|
self->byte_size = sizeof (g##type);
|
|
|
|
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
switch (base) {
|
|
|
|
case G_TYPE_INT:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (int);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_UINT:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (uint);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_LONG:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (long);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_ULONG:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (ulong);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_INT64:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (int64);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_UINT64:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (uint64);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_FLOAT:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (float);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_DOUBLE:
|
2015-05-27 09:29:41 +00:00
|
|
|
SET_CONVERT_FUNCTION (double);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_BOOLEAN:
|
2012-04-25 07:47:10 +00:00
|
|
|
self->convert_g_value = convert_g_value_to_boolean;
|
|
|
|
self->convert_value = convert_value_to_boolean;
|
|
|
|
self->byte_size = sizeof (gboolean);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
case G_TYPE_ENUM:
|
2012-04-25 07:47:10 +00:00
|
|
|
self->convert_g_value = convert_g_value_to_enum;
|
|
|
|
self->convert_value = convert_value_to_enum;
|
|
|
|
self->byte_size = sizeof (gint);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING ("incomplete implementation for paramspec type '%s'",
|
|
|
|
G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (self)));
|
|
|
|
GST_CONTROL_BINDING_PSPEC (self) = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (GObject *) self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_set_property (GObject * object, guint prop_id,
|
2012-01-24 20:53:14 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_CS:
|
2012-04-05 19:07:55 +00:00
|
|
|
self->cs = g_value_dup_object (value);
|
2012-01-24 20:53:14 +00:00
|
|
|
break;
|
2015-05-27 09:29:41 +00:00
|
|
|
case PROP_ABSOLUTE:
|
2015-06-29 09:41:27 +00:00
|
|
|
self->ABI.abi.want_absolute = g_value_get_boolean (value);
|
2015-05-27 09:29:41 +00:00
|
|
|
break;
|
2012-01-24 20:53:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_get_property (GObject * object, guint prop_id,
|
2012-01-24 20:53:14 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
|
2012-01-24 20:53:14 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_CS:
|
|
|
|
g_value_set_object (value, self->cs);
|
|
|
|
break;
|
2015-05-27 09:29:41 +00:00
|
|
|
case PROP_ABSOLUTE:
|
2015-06-29 09:41:27 +00:00
|
|
|
g_value_set_boolean (value, self->ABI.abi.want_absolute);
|
2015-05-27 09:29:41 +00:00
|
|
|
break;
|
2012-01-24 20:53:14 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 19:03:52 +00:00
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_dispose (GObject * object)
|
2012-01-21 19:03:52 +00:00
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
if (self->cs)
|
|
|
|
gst_object_replace ((GstObject **) & self->cs, NULL);
|
2012-04-12 12:59:52 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2012-01-21 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_finalize (GObject * object)
|
2012-01-21 19:03:52 +00:00
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2016-02-02 15:35:34 +00:00
|
|
|
if (G_IS_VALUE (&self->cur_value))
|
|
|
|
g_value_unset (&self->cur_value);
|
2012-04-12 12:59:52 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2012-01-21 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_sync_values (GstControlBinding * _self,
|
2012-01-21 19:03:52 +00:00
|
|
|
GstObject * object, GstClockTime timestamp, GstClockTime last_sync)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
|
2012-01-21 19:03:52 +00:00
|
|
|
gdouble src_val;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
|
2012-01-24 20:53:14 +00:00
|
|
|
g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (object, "property '%s' at ts=%" GST_TIME_FORMAT,
|
|
|
|
_self->name, GST_TIME_ARGS (timestamp));
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
ret = gst_control_source_get_value (self->cs, timestamp, &src_val);
|
2012-01-21 19:03:52 +00:00
|
|
|
if (G_LIKELY (ret)) {
|
|
|
|
GST_LOG_OBJECT (object, " new value %lf", src_val);
|
|
|
|
/* always set the value for first time, but then only if it changed
|
|
|
|
* this should limit g_object_notify invocations.
|
|
|
|
* FIXME: can we detect negative playback rates?
|
|
|
|
*/
|
|
|
|
if ((timestamp < last_sync) || (src_val != self->last_value)) {
|
|
|
|
GValue *dst_val = &self->cur_value;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (object, " mapping %s to value of type %s", _self->name,
|
|
|
|
G_VALUE_TYPE_NAME (dst_val));
|
|
|
|
/* run mapping function to convert gdouble to GValue */
|
2012-04-25 07:47:10 +00:00
|
|
|
self->convert_g_value (self, src_val, dst_val);
|
2012-01-21 19:03:52 +00:00
|
|
|
/* we can make this faster
|
|
|
|
* http://bugzilla.gnome.org/show_bug.cgi?id=536939
|
|
|
|
*/
|
|
|
|
g_object_set_property ((GObject *) object, _self->name, dst_val);
|
|
|
|
self->last_value = src_val;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (object, "no control value for param %s", _self->name);
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GValue *
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_get_value (GstControlBinding * _self,
|
2012-01-21 19:03:52 +00:00
|
|
|
GstClockTime timestamp)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
|
2012-01-21 19:03:52 +00:00
|
|
|
GValue *dst_val = NULL;
|
|
|
|
gdouble src_val;
|
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), NULL);
|
2012-01-21 19:03:52 +00:00
|
|
|
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
|
2012-01-24 20:53:14 +00:00
|
|
|
g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
/* get current value via control source */
|
2012-01-24 20:53:14 +00:00
|
|
|
if (gst_control_source_get_value (self->cs, timestamp, &src_val)) {
|
2012-01-21 19:03:52 +00:00
|
|
|
dst_val = g_new0 (GValue, 1);
|
|
|
|
g_value_init (dst_val, G_PARAM_SPEC_VALUE_TYPE (_self->pspec));
|
2012-04-25 07:47:10 +00:00
|
|
|
self->convert_g_value (self, src_val, dst_val);
|
2012-01-21 19:03:52 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG ("no control value for property %s at ts %" GST_TIME_FORMAT,
|
|
|
|
_self->name, GST_TIME_ARGS (timestamp));
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_get_value_array (GstControlBinding * _self,
|
2012-04-25 07:47:10 +00:00
|
|
|
GstClockTime timestamp, GstClockTime interval, guint n_values,
|
|
|
|
gpointer values_)
|
|
|
|
{
|
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
|
2019-10-04 17:01:46 +00:00
|
|
|
guint i;
|
2012-04-25 07:47:10 +00:00
|
|
|
gdouble *src_val;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstDirectControlBindingConvertValue convert;
|
|
|
|
gint byte_size;
|
|
|
|
guint8 *values = (guint8 *) values_;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
|
|
|
|
|
|
|
|
convert = self->convert_value;
|
|
|
|
byte_size = self->byte_size;
|
|
|
|
|
|
|
|
src_val = g_new0 (gdouble, n_values);
|
|
|
|
if ((res = gst_control_source_get_value_array (self->cs, timestamp,
|
|
|
|
interval, n_values, src_val))) {
|
|
|
|
for (i = 0; i < n_values; i++) {
|
2012-04-25 18:14:13 +00:00
|
|
|
/* we will only get NAN for sparse control sources, such as triggers */
|
2012-04-25 07:47:10 +00:00
|
|
|
if (!isnan (src_val[i])) {
|
|
|
|
convert (self, src_val[i], (gpointer) values);
|
|
|
|
} else {
|
|
|
|
GST_LOG ("no control value for property %s at index %d", _self->name,
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
values += byte_size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_LOG ("failed to get control value for property %s at ts %"
|
|
|
|
GST_TIME_FORMAT, _self->name, GST_TIME_ARGS (timestamp));
|
|
|
|
}
|
|
|
|
g_free (src_val);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_direct_control_binding_get_g_value_array (GstControlBinding * _self,
|
2012-01-21 19:03:52 +00:00
|
|
|
GstClockTime timestamp, GstClockTime interval, guint n_values,
|
|
|
|
GValue * values)
|
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
|
2019-10-04 17:01:46 +00:00
|
|
|
guint i;
|
2012-01-21 19:03:52 +00:00
|
|
|
gdouble *src_val;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GType type;
|
2012-04-25 07:47:10 +00:00
|
|
|
GstDirectControlBindingConvertGValue convert;
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-01-30 18:17:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
|
2012-01-21 19:03:52 +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-01-24 20:53:14 +00:00
|
|
|
g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
|
2012-01-21 19:03:52 +00:00
|
|
|
|
2012-04-25 07:47:10 +00:00
|
|
|
convert = self->convert_g_value;
|
2012-01-21 19:03:52 +00:00
|
|
|
type = G_PARAM_SPEC_VALUE_TYPE (_self->pspec);
|
|
|
|
|
|
|
|
src_val = g_new0 (gdouble, n_values);
|
2012-01-24 20:53:14 +00:00
|
|
|
if ((res = gst_control_source_get_value_array (self->cs, timestamp,
|
2012-01-21 19:03:52 +00:00
|
|
|
interval, n_values, src_val))) {
|
|
|
|
for (i = 0; i < n_values; i++) {
|
2012-04-25 18:14:13 +00:00
|
|
|
/* we will only get NAN for sparse control sources, such as triggers */
|
2012-01-21 19:03:52 +00:00
|
|
|
if (!isnan (src_val[i])) {
|
|
|
|
g_value_init (&values[i], type);
|
|
|
|
convert (self, src_val[i], &values[i]);
|
|
|
|
} else {
|
|
|
|
GST_LOG ("no control value for property %s at index %d", _self->name,
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GST_LOG ("failed to get control value for property %s at ts %"
|
|
|
|
GST_TIME_FORMAT, _self->name, GST_TIME_ARGS (timestamp));
|
|
|
|
}
|
|
|
|
g_free (src_val);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-01-24 20:53:14 +00:00
|
|
|
/* functions */
|
2012-01-21 19:03:52 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-30 18:17:00 +00:00
|
|
|
* gst_direct_control_binding_new:
|
2012-01-21 19:03:52 +00:00
|
|
|
* @object: the object of the property
|
|
|
|
* @property_name: the property-name to attach the control source
|
2012-06-20 02:55:02 +00:00
|
|
|
* @cs: the control source
|
2012-01-21 19:03:52 +00:00
|
|
|
*
|
|
|
|
* Create a new control-binding that attaches the #GstControlSource to the
|
2016-10-13 16:01:14 +00:00
|
|
|
* #GObject property. It will map the control source range [0.0 ... 1.0] to
|
|
|
|
* the full target property range, and clip all values outside this range.
|
2012-01-21 19:03:52 +00:00
|
|
|
*
|
2012-01-30 18:17:00 +00:00
|
|
|
* Returns: (transfer floating): the new #GstDirectControlBinding
|
2012-01-21 19:03:52 +00:00
|
|
|
*/
|
|
|
|
GstControlBinding *
|
2012-01-30 18:17:00 +00:00
|
|
|
gst_direct_control_binding_new (GstObject * object, const gchar * property_name,
|
2012-01-24 20:53:14 +00:00
|
|
|
GstControlSource * cs)
|
2012-01-21 19:03:52 +00:00
|
|
|
{
|
2012-01-30 18:17:00 +00:00
|
|
|
return (GstControlBinding *) g_object_new (GST_TYPE_DIRECT_CONTROL_BINDING,
|
2012-01-24 20:53:14 +00:00
|
|
|
"object", object, "name", property_name, "control-source", cs, NULL);
|
2012-01-21 19:03:52 +00:00
|
|
|
}
|
2015-05-27 09:29:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_direct_control_binding_new_absolute:
|
|
|
|
* @object: the object of the property
|
|
|
|
* @property_name: the property-name to attach the control source
|
|
|
|
* @cs: the control source
|
|
|
|
*
|
|
|
|
* Create a new control-binding that attaches the #GstControlSource to the
|
2016-10-13 16:01:14 +00:00
|
|
|
* #GObject property. It will directly map the control source values to the
|
|
|
|
* target property range without any transformations.
|
2015-05-27 09:29:41 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer floating): the new #GstDirectControlBinding
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
GstControlBinding *
|
|
|
|
gst_direct_control_binding_new_absolute (GstObject * object,
|
|
|
|
const gchar * property_name, GstControlSource * cs)
|
|
|
|
{
|
|
|
|
return (GstControlBinding *) g_object_new (GST_TYPE_DIRECT_CONTROL_BINDING,
|
|
|
|
"object", object, "name", property_name, "control-source", cs, "absolute",
|
|
|
|
TRUE, NULL);
|
|
|
|
}
|