Blame libs/gst/controller/gstdirectcontrolbinding.c

Packit a6ee4b
/* GStreamer
Packit a6ee4b
 *
Packit a6ee4b
 * Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
Packit a6ee4b
 *
Packit a6ee4b
 * gstdirectcontrolbinding.c: Direct attachment for control sources
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
/**
Packit a6ee4b
 * SECTION:gstdirectcontrolbinding
Packit a6ee4b
 * @title: GstDirectControlBinding
Packit a6ee4b
 * @short_description: direct attachment for control sources
Packit a6ee4b
 *
Packit a6ee4b
 * A value mapping object that attaches control sources to gobject properties. It
Packit a6ee4b
 * will map the control values directly to the target property range. If a
Packit a6ee4b
 * non-absolute direct control binding is used, the value range [0.0 ... 1.0]
Packit a6ee4b
 * is mapped to full target property range, and all values outside the range
Packit a6ee4b
 * will be clipped. An absolute control binding will not do any value
Packit a6ee4b
 * transformations.
Packit a6ee4b
 */
Packit a6ee4b
#ifdef HAVE_CONFIG_H
Packit a6ee4b
#include "config.h"
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#include <glib-object.h>
Packit a6ee4b
#include <gst/gst.h>
Packit a6ee4b
Packit a6ee4b
#include "gstdirectcontrolbinding.h"
Packit a6ee4b
Packit a6ee4b
#include <gst/math-compat.h>
Packit a6ee4b
Packit a6ee4b
#define GST_CAT_DEFAULT control_binding_debug
Packit a6ee4b
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
Packit a6ee4b
Packit a6ee4b
Packit a6ee4b
static GObject *gst_direct_control_binding_constructor (GType type,
Packit a6ee4b
    guint n_construct_params, GObjectConstructParam * construct_params);
Packit a6ee4b
static void gst_direct_control_binding_set_property (GObject * object,
Packit a6ee4b
    guint prop_id, const GValue * value, GParamSpec * pspec);
Packit a6ee4b
static void gst_direct_control_binding_get_property (GObject * object,
Packit a6ee4b
    guint prop_id, GValue * value, GParamSpec * pspec);
Packit a6ee4b
static void gst_direct_control_binding_dispose (GObject * object);
Packit a6ee4b
static void gst_direct_control_binding_finalize (GObject * object);
Packit a6ee4b
Packit a6ee4b
static gboolean gst_direct_control_binding_sync_values (GstControlBinding *
Packit a6ee4b
    _self, GstObject * object, GstClockTime timestamp, GstClockTime last_sync);
Packit a6ee4b
static GValue *gst_direct_control_binding_get_value (GstControlBinding * _self,
Packit a6ee4b
    GstClockTime timestamp);
Packit a6ee4b
static gboolean gst_direct_control_binding_get_value_array (GstControlBinding *
Packit a6ee4b
    _self, GstClockTime timestamp, GstClockTime interval, guint n_values,
Packit a6ee4b
    gpointer values);
Packit a6ee4b
static gboolean gst_direct_control_binding_get_g_value_array (GstControlBinding
Packit a6ee4b
    * _self, GstClockTime timestamp, GstClockTime interval, guint n_values,
Packit a6ee4b
    GValue * values);
Packit a6ee4b
Packit a6ee4b
#define _do_init \
Packit a6ee4b
  GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gstdirectcontrolbinding", 0, \
Packit a6ee4b
      "dynamic parameter control source attachment");
Packit a6ee4b
Packit a6ee4b
#define gst_direct_control_binding_parent_class parent_class
Packit a6ee4b
G_DEFINE_TYPE_WITH_CODE (GstDirectControlBinding, gst_direct_control_binding,
Packit a6ee4b
    GST_TYPE_CONTROL_BINDING, _do_init);
Packit a6ee4b
Packit a6ee4b
enum
Packit a6ee4b
{
Packit a6ee4b
  PROP_0,
Packit a6ee4b
  PROP_CS,
Packit a6ee4b
  PROP_ABSOLUTE,
Packit a6ee4b
  PROP_LAST
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
static GParamSpec *properties[PROP_LAST];
Packit a6ee4b
Packit a6ee4b
/* mapping functions */
Packit a6ee4b
Packit a6ee4b
#define DEFINE_CONVERT(type,Type,TYPE,ROUNDING_OP) \
Packit a6ee4b
static void \
Packit a6ee4b
convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) \
Packit a6ee4b
{ \
Packit a6ee4b
  GParamSpec##Type *pspec = G_PARAM_SPEC_##TYPE (((GstControlBinding *)self)->pspec); \
Packit a6ee4b
  g##type v; \
Packit a6ee4b
  \
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0); \
Packit a6ee4b
  v = (g##type) ROUNDING_OP (pspec->minimum * (1-s)) + (g##type) ROUNDING_OP (pspec->maximum * s); \
Packit a6ee4b
  g_value_set_##type (d, v); \
Packit a6ee4b
} \
Packit a6ee4b
\
Packit a6ee4b
static void \
Packit a6ee4b
convert_value_to_##type (GstDirectControlBinding *self, gdouble s, gpointer d_) \
Packit a6ee4b
{ \
Packit a6ee4b
  GParamSpec##Type *pspec = G_PARAM_SPEC_##TYPE (((GstControlBinding *)self)->pspec); \
Packit a6ee4b
  g##type *d = (g##type *)d_; \
Packit a6ee4b
  \
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0); \
Packit a6ee4b
  *d = (g##type) ROUNDING_OP (pspec->minimum * (1-s)) + (g##type) ROUNDING_OP (pspec->maximum * s); \
Packit a6ee4b
} \
Packit a6ee4b
\
Packit a6ee4b
static void \
Packit a6ee4b
abs_convert_g_value_to_##type (GstDirectControlBinding *self, gdouble s, GValue *d) \
Packit a6ee4b
{ \
Packit a6ee4b
  g##type v; \
Packit a6ee4b
  v = (g##type) ROUNDING_OP (s); \
Packit a6ee4b
  g_value_set_##type (d, v); \
Packit a6ee4b
} \
Packit a6ee4b
\
Packit a6ee4b
static void \
Packit a6ee4b
abs_convert_value_to_##type (GstDirectControlBinding *self, gdouble s, gpointer d_) \
Packit a6ee4b
{ \
Packit a6ee4b
  g##type *d = (g##type *)d_; \
Packit a6ee4b
  *d = (g##type) ROUNDING_OP (s); \
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
DEFINE_CONVERT (int, Int, INT, rint);
Packit a6ee4b
DEFINE_CONVERT (uint, UInt, UINT, rint);
Packit a6ee4b
DEFINE_CONVERT (long, Long, LONG, rint);
Packit a6ee4b
DEFINE_CONVERT (ulong, ULong, ULONG, rint);
Packit a6ee4b
DEFINE_CONVERT (int64, Int64, INT64, rint);
Packit a6ee4b
DEFINE_CONVERT (uint64, UInt64, UINT64, rint);
Packit a6ee4b
DEFINE_CONVERT (float, Float, FLOAT, /*NOOP*/);
Packit a6ee4b
DEFINE_CONVERT (double, Double, DOUBLE, /*NOOP*/);
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
convert_g_value_to_boolean (GstDirectControlBinding * self, gdouble s,
Packit a6ee4b
    GValue * d)
Packit a6ee4b
{
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0);
Packit a6ee4b
  g_value_set_boolean (d, (gboolean) (s + 0.5));
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
convert_value_to_boolean (GstDirectControlBinding * self, gdouble s,
Packit a6ee4b
    gpointer d_)
Packit a6ee4b
{
Packit a6ee4b
  gboolean *d = (gboolean *) d_;
Packit a6ee4b
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0);
Packit a6ee4b
  *d = (gboolean) (s + 0.5);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
convert_g_value_to_enum (GstDirectControlBinding * self, gdouble s, GValue * d)
Packit a6ee4b
{
Packit a6ee4b
  GParamSpecEnum *pspec =
Packit a6ee4b
      G_PARAM_SPEC_ENUM (((GstControlBinding *) self)->pspec);
Packit a6ee4b
  GEnumClass *e = pspec->enum_class;
Packit a6ee4b
  gint v;
Packit a6ee4b
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0);
Packit a6ee4b
  v = s * (e->n_values - 1);
Packit a6ee4b
  g_value_set_enum (d, e->values[v].value);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
convert_value_to_enum (GstDirectControlBinding * self, gdouble s, gpointer d_)
Packit a6ee4b
{
Packit a6ee4b
  GParamSpecEnum *pspec =
Packit a6ee4b
      G_PARAM_SPEC_ENUM (((GstControlBinding *) self)->pspec);
Packit a6ee4b
  GEnumClass *e = pspec->enum_class;
Packit a6ee4b
  gint *d = (gint *) d_;
Packit a6ee4b
Packit a6ee4b
  s = CLAMP (s, 0.0, 1.0);
Packit a6ee4b
  *d = e->values[(gint) (s * (e->n_values - 1))].value;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* vmethods */
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_class_init (GstDirectControlBindingClass * klass)
Packit a6ee4b
{
Packit a6ee4b
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit a6ee4b
  GstControlBindingClass *control_binding_class =
Packit a6ee4b
      GST_CONTROL_BINDING_CLASS (klass);
Packit a6ee4b
Packit a6ee4b
  gobject_class->constructor = gst_direct_control_binding_constructor;
Packit a6ee4b
  gobject_class->set_property = gst_direct_control_binding_set_property;
Packit a6ee4b
  gobject_class->get_property = gst_direct_control_binding_get_property;
Packit a6ee4b
  gobject_class->dispose = gst_direct_control_binding_dispose;
Packit a6ee4b
  gobject_class->finalize = gst_direct_control_binding_finalize;
Packit a6ee4b
Packit a6ee4b
  control_binding_class->sync_values = gst_direct_control_binding_sync_values;
Packit a6ee4b
  control_binding_class->get_value = gst_direct_control_binding_get_value;
Packit a6ee4b
  control_binding_class->get_value_array =
Packit a6ee4b
      gst_direct_control_binding_get_value_array;
Packit a6ee4b
  control_binding_class->get_g_value_array =
Packit a6ee4b
      gst_direct_control_binding_get_g_value_array;
Packit a6ee4b
Packit a6ee4b
  properties[PROP_CS] =
Packit a6ee4b
      g_param_spec_object ("control-source", "ControlSource",
Packit a6ee4b
      "The control source",
Packit a6ee4b
      GST_TYPE_CONTROL_SOURCE,
Packit a6ee4b
      G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
Packit a6ee4b
Packit a6ee4b
  properties[PROP_ABSOLUTE] =
Packit a6ee4b
      g_param_spec_boolean ("absolute", "Absolute",
Packit a6ee4b
      "Whether the control values are absolute",
Packit a6ee4b
      FALSE,
Packit a6ee4b
      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
Packit a6ee4b
Packit a6ee4b
  g_object_class_install_properties (gobject_class, PROP_LAST, properties);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_init (GstDirectControlBinding * self)
Packit a6ee4b
{
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static GObject *
Packit a6ee4b
gst_direct_control_binding_constructor (GType type, guint n_construct_params,
Packit a6ee4b
    GObjectConstructParam * construct_params)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self;
Packit a6ee4b
Packit a6ee4b
  self =
Packit a6ee4b
      GST_DIRECT_CONTROL_BINDING (G_OBJECT_CLASS (parent_class)->constructor
Packit a6ee4b
      (type, n_construct_params, construct_params));
Packit a6ee4b
Packit a6ee4b
  if (GST_CONTROL_BINDING_PSPEC (self)) {
Packit a6ee4b
    GType type, base;
Packit a6ee4b
Packit a6ee4b
    base = type = G_PARAM_SPEC_VALUE_TYPE (GST_CONTROL_BINDING_PSPEC (self));
Packit a6ee4b
    g_value_init (&self->cur_value, type);
Packit a6ee4b
    while ((type = g_type_parent (type)))
Packit a6ee4b
      base = type;
Packit a6ee4b
Packit a6ee4b
    GST_DEBUG ("  using type %s", g_type_name (base));
Packit a6ee4b
Packit a6ee4b
    /* select mapping function */
Packit a6ee4b
Packit a6ee4b
#define SET_CONVERT_FUNCTION(type) \
Packit a6ee4b
    if (self->ABI.abi.want_absolute) { \
Packit a6ee4b
        self->convert_g_value = abs_convert_g_value_to_##type; \
Packit a6ee4b
        self->convert_value = abs_convert_value_to_##type; \
Packit a6ee4b
    } \
Packit a6ee4b
    else { \
Packit a6ee4b
        self->convert_g_value = convert_g_value_to_##type; \
Packit a6ee4b
        self->convert_value = convert_value_to_##type; \
Packit a6ee4b
    } \
Packit a6ee4b
    self->byte_size = sizeof (g##type);
Packit a6ee4b
Packit a6ee4b
Packit a6ee4b
    switch (base) {
Packit a6ee4b
      case G_TYPE_INT:
Packit a6ee4b
        SET_CONVERT_FUNCTION (int);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_UINT:
Packit a6ee4b
        SET_CONVERT_FUNCTION (uint);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_LONG:
Packit a6ee4b
        SET_CONVERT_FUNCTION (long);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_ULONG:
Packit a6ee4b
        SET_CONVERT_FUNCTION (ulong);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_INT64:
Packit a6ee4b
        SET_CONVERT_FUNCTION (int64);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_UINT64:
Packit a6ee4b
        SET_CONVERT_FUNCTION (uint64);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_FLOAT:
Packit a6ee4b
        SET_CONVERT_FUNCTION (float);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_DOUBLE:
Packit a6ee4b
        SET_CONVERT_FUNCTION (double);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_BOOLEAN:
Packit a6ee4b
        self->convert_g_value = convert_g_value_to_boolean;
Packit a6ee4b
        self->convert_value = convert_value_to_boolean;
Packit a6ee4b
        self->byte_size = sizeof (gboolean);
Packit a6ee4b
        break;
Packit a6ee4b
      case G_TYPE_ENUM:
Packit a6ee4b
        self->convert_g_value = convert_g_value_to_enum;
Packit a6ee4b
        self->convert_value = convert_value_to_enum;
Packit a6ee4b
        self->byte_size = sizeof (gint);
Packit a6ee4b
        break;
Packit a6ee4b
      default:
Packit a6ee4b
        GST_WARNING ("incomplete implementation for paramspec type '%s'",
Packit a6ee4b
            G_PARAM_SPEC_TYPE_NAME (GST_CONTROL_BINDING_PSPEC (self)));
Packit a6ee4b
        GST_CONTROL_BINDING_PSPEC (self) = NULL;
Packit a6ee4b
        break;
Packit a6ee4b
    }
Packit a6ee4b
  }
Packit a6ee4b
  return (GObject *) self;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_set_property (GObject * object, guint prop_id,
Packit a6ee4b
    const GValue * value, GParamSpec * pspec)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
Packit a6ee4b
Packit a6ee4b
  switch (prop_id) {
Packit a6ee4b
    case PROP_CS:
Packit a6ee4b
      self->cs = g_value_dup_object (value);
Packit a6ee4b
      break;
Packit a6ee4b
    case PROP_ABSOLUTE:
Packit a6ee4b
      self->ABI.abi.want_absolute = g_value_get_boolean (value);
Packit a6ee4b
      break;
Packit a6ee4b
    default:
Packit a6ee4b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit a6ee4b
      break;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_get_property (GObject * object, guint prop_id,
Packit a6ee4b
    GValue * value, GParamSpec * pspec)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
Packit a6ee4b
Packit a6ee4b
  switch (prop_id) {
Packit a6ee4b
    case PROP_CS:
Packit a6ee4b
      g_value_set_object (value, self->cs);
Packit a6ee4b
      break;
Packit a6ee4b
    case PROP_ABSOLUTE:
Packit a6ee4b
      g_value_set_boolean (value, self->ABI.abi.want_absolute);
Packit a6ee4b
      break;
Packit a6ee4b
    default:
Packit a6ee4b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit a6ee4b
      break;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_dispose (GObject * object)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
Packit a6ee4b
Packit a6ee4b
  if (self->cs)
Packit a6ee4b
    gst_object_replace ((GstObject **) & self->cs, NULL);
Packit a6ee4b
Packit a6ee4b
  G_OBJECT_CLASS (parent_class)->dispose (object);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static void
Packit a6ee4b
gst_direct_control_binding_finalize (GObject * object)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (object);
Packit a6ee4b
Packit a6ee4b
  if (G_IS_VALUE (&self->cur_value))
Packit a6ee4b
    g_value_unset (&self->cur_value);
Packit a6ee4b
Packit a6ee4b
  G_OBJECT_CLASS (parent_class)->finalize (object);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_direct_control_binding_sync_values (GstControlBinding * _self,
Packit a6ee4b
    GstObject * object, GstClockTime timestamp, GstClockTime last_sync)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
Packit a6ee4b
  gdouble src_val;
Packit a6ee4b
  gboolean ret;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
Packit a6ee4b
Packit a6ee4b
  GST_LOG_OBJECT (object, "property '%s' at ts=%" GST_TIME_FORMAT,
Packit a6ee4b
      _self->name, GST_TIME_ARGS (timestamp));
Packit a6ee4b
Packit a6ee4b
  ret = gst_control_source_get_value (self->cs, timestamp, &src_val);
Packit a6ee4b
  if (G_LIKELY (ret)) {
Packit a6ee4b
    GST_LOG_OBJECT (object, "  new value %lf", src_val);
Packit a6ee4b
    /* always set the value for first time, but then only if it changed
Packit a6ee4b
     * this should limit g_object_notify invocations.
Packit a6ee4b
     * FIXME: can we detect negative playback rates?
Packit a6ee4b
     */
Packit a6ee4b
    if ((timestamp < last_sync) || (src_val != self->last_value)) {
Packit a6ee4b
      GValue *dst_val = &self->cur_value;
Packit a6ee4b
Packit a6ee4b
      GST_LOG_OBJECT (object, "  mapping %s to value of type %s", _self->name,
Packit a6ee4b
          G_VALUE_TYPE_NAME (dst_val));
Packit a6ee4b
      /* run mapping function to convert gdouble to GValue */
Packit a6ee4b
      self->convert_g_value (self, src_val, dst_val);
Packit a6ee4b
      /* we can make this faster
Packit a6ee4b
       * http://bugzilla.gnome.org/show_bug.cgi?id=536939
Packit a6ee4b
       */
Packit a6ee4b
      g_object_set_property ((GObject *) object, _self->name, dst_val);
Packit a6ee4b
      self->last_value = src_val;
Packit a6ee4b
    }
Packit a6ee4b
  } else {
Packit a6ee4b
    GST_DEBUG_OBJECT (object, "no control value for param %s", _self->name);
Packit a6ee4b
  }
Packit a6ee4b
  return (ret);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static GValue *
Packit a6ee4b
gst_direct_control_binding_get_value (GstControlBinding * _self,
Packit a6ee4b
    GstClockTime timestamp)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
Packit a6ee4b
  GValue *dst_val = NULL;
Packit a6ee4b
  gdouble src_val;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), NULL);
Packit a6ee4b
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
Packit a6ee4b
  g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
Packit a6ee4b
Packit a6ee4b
  /* get current value via control source */
Packit a6ee4b
  if (gst_control_source_get_value (self->cs, timestamp, &src_val)) {
Packit a6ee4b
    dst_val = g_new0 (GValue, 1);
Packit a6ee4b
    g_value_init (dst_val, G_PARAM_SPEC_VALUE_TYPE (_self->pspec));
Packit a6ee4b
    self->convert_g_value (self, src_val, dst_val);
Packit a6ee4b
  } else {
Packit a6ee4b
    GST_LOG ("no control value for property %s at ts %" GST_TIME_FORMAT,
Packit a6ee4b
        _self->name, GST_TIME_ARGS (timestamp));
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  return dst_val;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_direct_control_binding_get_value_array (GstControlBinding * _self,
Packit a6ee4b
    GstClockTime timestamp, GstClockTime interval, guint n_values,
Packit a6ee4b
    gpointer values_)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
Packit a6ee4b
  gint i;
Packit a6ee4b
  gdouble *src_val;
Packit a6ee4b
  gboolean res = FALSE;
Packit a6ee4b
  GstDirectControlBindingConvertValue convert;
Packit a6ee4b
  gint byte_size;
Packit a6ee4b
  guint8 *values = (guint8 *) values_;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
Packit a6ee4b
  g_return_val_if_fail (values, FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
Packit a6ee4b
Packit a6ee4b
  convert = self->convert_value;
Packit a6ee4b
  byte_size = self->byte_size;
Packit a6ee4b
Packit a6ee4b
  src_val = g_new0 (gdouble, n_values);
Packit a6ee4b
  if ((res = gst_control_source_get_value_array (self->cs, timestamp,
Packit a6ee4b
              interval, n_values, src_val))) {
Packit a6ee4b
    for (i = 0; i < n_values; i++) {
Packit a6ee4b
      /* we will only get NAN for sparse control sources, such as triggers */
Packit a6ee4b
      if (!isnan (src_val[i])) {
Packit a6ee4b
        convert (self, src_val[i], (gpointer) values);
Packit a6ee4b
      } else {
Packit a6ee4b
        GST_LOG ("no control value for property %s at index %d", _self->name,
Packit a6ee4b
            i);
Packit a6ee4b
      }
Packit a6ee4b
      values += byte_size;
Packit a6ee4b
    }
Packit a6ee4b
  } else {
Packit a6ee4b
    GST_LOG ("failed to get control value for property %s at ts %"
Packit a6ee4b
        GST_TIME_FORMAT, _self->name, GST_TIME_ARGS (timestamp));
Packit a6ee4b
  }
Packit a6ee4b
  g_free (src_val);
Packit a6ee4b
  return res;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
static gboolean
Packit a6ee4b
gst_direct_control_binding_get_g_value_array (GstControlBinding * _self,
Packit a6ee4b
    GstClockTime timestamp, GstClockTime interval, guint n_values,
Packit a6ee4b
    GValue * values)
Packit a6ee4b
{
Packit a6ee4b
  GstDirectControlBinding *self = GST_DIRECT_CONTROL_BINDING (_self);
Packit a6ee4b
  gint i;
Packit a6ee4b
  gdouble *src_val;
Packit a6ee4b
  gboolean res = FALSE;
Packit a6ee4b
  GType type;
Packit a6ee4b
  GstDirectControlBindingConvertGValue convert;
Packit a6ee4b
Packit a6ee4b
  g_return_val_if_fail (GST_IS_DIRECT_CONTROL_BINDING (self), FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
Packit a6ee4b
  g_return_val_if_fail (values, FALSE);
Packit a6ee4b
  g_return_val_if_fail (GST_CONTROL_BINDING_PSPEC (self), FALSE);
Packit a6ee4b
Packit a6ee4b
  convert = self->convert_g_value;
Packit a6ee4b
  type = G_PARAM_SPEC_VALUE_TYPE (_self->pspec);
Packit a6ee4b
Packit a6ee4b
  src_val = g_new0 (gdouble, n_values);
Packit a6ee4b
  if ((res = gst_control_source_get_value_array (self->cs, timestamp,
Packit a6ee4b
              interval, n_values, src_val))) {
Packit a6ee4b
    for (i = 0; i < n_values; i++) {
Packit a6ee4b
      /* we will only get NAN for sparse control sources, such as triggers */
Packit a6ee4b
      if (!isnan (src_val[i])) {
Packit a6ee4b
        g_value_init (&values[i], type);
Packit a6ee4b
        convert (self, src_val[i], &values[i]);
Packit a6ee4b
      } else {
Packit a6ee4b
        GST_LOG ("no control value for property %s at index %d", _self->name,
Packit a6ee4b
            i);
Packit a6ee4b
      }
Packit a6ee4b
    }
Packit a6ee4b
  } else {
Packit a6ee4b
    GST_LOG ("failed to get control value for property %s at ts %"
Packit a6ee4b
        GST_TIME_FORMAT, _self->name, GST_TIME_ARGS (timestamp));
Packit a6ee4b
  }
Packit a6ee4b
  g_free (src_val);
Packit a6ee4b
  return res;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/* functions */
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_direct_control_binding_new:
Packit a6ee4b
 * @object: the object of the property
Packit a6ee4b
 * @property_name: the property-name to attach the control source
Packit a6ee4b
 * @cs: the control source
Packit a6ee4b
 *
Packit a6ee4b
 * Create a new control-binding that attaches the #GstControlSource to the
Packit a6ee4b
 * #GObject property. It will map the control source range [0.0 ... 1.0] to
Packit a6ee4b
 * the full target property range, and clip all values outside this range.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer floating): the new #GstDirectControlBinding
Packit a6ee4b
 */
Packit a6ee4b
GstControlBinding *
Packit a6ee4b
gst_direct_control_binding_new (GstObject * object, const gchar * property_name,
Packit a6ee4b
    GstControlSource * cs)
Packit a6ee4b
{
Packit a6ee4b
  return (GstControlBinding *) g_object_new (GST_TYPE_DIRECT_CONTROL_BINDING,
Packit a6ee4b
      "object", object, "name", property_name, "control-source", cs, NULL);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_direct_control_binding_new_absolute:
Packit a6ee4b
 * @object: the object of the property
Packit a6ee4b
 * @property_name: the property-name to attach the control source
Packit a6ee4b
 * @cs: the control source
Packit a6ee4b
 *
Packit a6ee4b
 * Create a new control-binding that attaches the #GstControlSource to the
Packit a6ee4b
 * #GObject property. It will directly map the control source values to the
Packit a6ee4b
 * target property range without any transformations.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: (transfer floating): the new #GstDirectControlBinding
Packit a6ee4b
 *
Packit a6ee4b
 * Since: 1.6
Packit a6ee4b
 */
Packit a6ee4b
GstControlBinding *
Packit a6ee4b
gst_direct_control_binding_new_absolute (GstObject * object,
Packit a6ee4b
    const gchar * property_name, GstControlSource * cs)
Packit a6ee4b
{
Packit a6ee4b
  return (GstControlBinding *) g_object_new (GST_TYPE_DIRECT_CONTROL_BINDING,
Packit a6ee4b
      "object", object, "name", property_name, "control-source", cs, "absolute",
Packit a6ee4b
      TRUE, NULL);
Packit a6ee4b
}