2001-12-23 17:27:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
|
|
|
|
*
|
|
|
|
* gstdparam.c: Dynamic Parameter functionality
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-12-23 17:27:58 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gstinfo.h>
|
|
|
|
|
2002-04-12 09:24:37 +00:00
|
|
|
#include "dparam.h"
|
|
|
|
#include "dparammanager.h"
|
2004-02-03 03:31:26 +00:00
|
|
|
#include <gst/gstmarshal.h>
|
2001-12-23 17:27:58 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (_gst_control_debug);
|
|
|
|
|
|
|
|
static void gst_dparam_class_init (GstDParamClass * klass);
|
|
|
|
static void gst_dparam_init (GstDParam * dparam);
|
|
|
|
static void gst_dparam_dispose (GObject * object);
|
|
|
|
static void gst_dparam_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dparam_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_VALUE_FLOAT,
|
|
|
|
ARG_VALUE_DOUBLE,
|
|
|
|
ARG_VALUE_INT,
|
|
|
|
ARG_VALUE_INT64,
|
2002-03-04 18:54:20 +00:00
|
|
|
};
|
2001-12-23 17:27:58 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-05-29 18:45:25 +00:00
|
|
|
VALUE_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_dparam_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GType
|
|
|
|
gst_dparam_get_type (void)
|
|
|
|
{
|
|
|
|
static GType dparam_type = 0;
|
|
|
|
|
|
|
|
if (!dparam_type) {
|
|
|
|
static const GTypeInfo dparam_info = {
|
|
|
|
sizeof (GstDParamClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_dparam_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstDParam),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_dparam_init,
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam_type =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_type_register_static (GST_TYPE_OBJECT, "GstDParam", &dparam_info, 0);
|
2004-03-13 15:27:01 +00:00
|
|
|
}
|
|
|
|
return dparam_type;
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_class_init (GstDParamClass * klass)
|
2001-12-23 17:27:58 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstDParamClass *dparam_class;
|
|
|
|
GstObjectClass *gstobject_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
dparam_class = (GstDParamClass *) klass;
|
|
|
|
gstobject_class = (GstObjectClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_dparam_get_property;
|
|
|
|
gobject_class->set_property = gst_dparam_set_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VALUE_FLOAT,
|
|
|
|
g_param_spec_float ("value_float", "Float Value",
|
2004-03-15 19:27:17 +00:00
|
|
|
"The value that should be changed if gfloat is the type",
|
|
|
|
-G_MAXFLOAT, G_MAXFLOAT, 0.0F, G_PARAM_READWRITE));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VALUE_DOUBLE,
|
|
|
|
g_param_spec_double ("value_double", "Double Value",
|
2004-03-15 19:27:17 +00:00
|
|
|
"The value that should be changed if gdouble is the type",
|
|
|
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VALUE_INT,
|
|
|
|
g_param_spec_int ("value_int", "Integer Value",
|
2004-03-15 19:27:17 +00:00
|
|
|
"The value that should be changed if gint is the type",
|
|
|
|
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
|
2004-03-13 15:27:01 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VALUE_INT64,
|
|
|
|
g_param_spec_int64 ("value_int64", "64 bit Integer Value",
|
2004-03-15 19:27:17 +00:00
|
|
|
"The value that should be changed if gint64 is the type",
|
|
|
|
G_MININT64, G_MAXINT64, 0, G_PARAM_READWRITE));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = gst_dparam_dispose;
|
|
|
|
|
|
|
|
gst_dparam_signals[VALUE_CHANGED] =
|
|
|
|
g_signal_new ("value-changed", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDParamClass, value_changed), NULL,
|
|
|
|
NULL, gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
|
|
/*gstobject_class->save_thyself = gst_dparam_save_thyself; */
|
2001-12-23 17:27:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_init (GstDParam * dparam)
|
2001-12-23 17:27:58 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
g_return_if_fail (dparam != NULL);
|
|
|
|
GST_DPARAM_TYPE (dparam) = 0;
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) = 0LL;
|
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam) = 0LL;
|
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = FALSE;
|
|
|
|
dparam->lock = g_mutex_new ();
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_dparam_new:
|
|
|
|
* @type: the type that this dparam will store
|
|
|
|
*
|
|
|
|
* Returns: a new instance of GstDParam
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstDParam *
|
2001-12-23 17:27:58 +00:00
|
|
|
gst_dparam_new (GType type)
|
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstDParam *dparam;
|
2001-12-23 17:27:58 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam = g_object_new (gst_dparam_get_type (), NULL);
|
|
|
|
dparam->do_update_func = gst_dparam_do_update_default;
|
2002-03-04 18:54:20 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_TYPE (dparam) = type;
|
|
|
|
|
|
|
|
return dparam;
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|
|
|
|
|
2002-03-04 18:54:20 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_dparam_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-03-04 18:54:20 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstDParam *dparam;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_DPARAM (object));
|
|
|
|
dparam = GST_DPARAM (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_VALUE_FLOAT:
|
|
|
|
g_value_set_float (value, dparam->value_float);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_DOUBLE:
|
|
|
|
g_value_set_double (value, dparam->value_double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_INT:
|
|
|
|
g_value_set_int (value, dparam->value_int);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_INT64:
|
|
|
|
g_value_set_int64 (value, dparam->value_int64);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2002-03-04 18:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_dparam_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-03-04 18:54:20 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstDParam *dparam;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_DPARAM (object));
|
|
|
|
dparam = GST_DPARAM (object);
|
|
|
|
GST_DPARAM_LOCK (dparam);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_VALUE_FLOAT:
|
|
|
|
GST_DEBUG ("setting value from %g to %g", dparam->value_float,
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_get_float (value));
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam->value_float = g_value_get_float (value);
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) =
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_DOUBLE:
|
|
|
|
GST_DEBUG ("setting value from %g to %g",
|
2004-03-15 19:27:17 +00:00
|
|
|
dparam->value_double, g_value_get_double (value));
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam->value_double = g_value_get_double (value);
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) =
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_INT:
|
|
|
|
GST_DEBUG ("setting value from %d to %d", dparam->value_int,
|
2004-03-15 19:27:17 +00:00
|
|
|
g_value_get_int (value));
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam->value_int = g_value_get_int (value);
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) =
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_VALUE_INT64:
|
|
|
|
GST_DEBUG ("setting value from %"
|
2004-03-15 19:27:17 +00:00
|
|
|
G_GINT64_FORMAT " to %"
|
|
|
|
G_GINT64_FORMAT, dparam->value_int64, g_value_get_int64 (value));
|
2004-03-13 15:27:01 +00:00
|
|
|
dparam->value_int64 = g_value_get_int64 (value);
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) =
|
2004-03-15 19:27:17 +00:00
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note that this signal is sent while we still have the lock. */
|
|
|
|
g_signal_emit (G_OBJECT (dparam), gst_dparam_signals[VALUE_CHANGED], 0);
|
|
|
|
GST_DPARAM_UNLOCK (dparam);
|
2002-03-04 18:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_do_update_default (GstDParam * dparam, gint64 timestamp,
|
|
|
|
GValue * value, GstDParamUpdateInfo update_info)
|
2002-03-04 18:54:20 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_LOCK (dparam);
|
|
|
|
|
|
|
|
g_return_if_fail (G_VALUE_TYPE (value) == GST_DPARAM_TYPE (dparam));
|
|
|
|
GST_DEBUG ("updating value for %s(%p)", GST_DPARAM_NAME (dparam), dparam);
|
|
|
|
|
|
|
|
switch (G_VALUE_TYPE (value)) {
|
|
|
|
case G_TYPE_FLOAT:
|
|
|
|
g_value_set_float (value, dparam->value_float);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TYPE_DOUBLE:
|
|
|
|
g_value_set_double (value, dparam->value_double);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TYPE_INT:
|
|
|
|
g_value_set_int (value, dparam->value_int);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TYPE_INT64:
|
|
|
|
g_value_set_int64 (value, dparam->value_int64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DPARAM_LAST_UPDATE_TIMESTAMP (dparam) = timestamp;
|
|
|
|
GST_DPARAM_NEXT_UPDATE_TIMESTAMP (dparam) = timestamp;
|
|
|
|
GST_DPARAM_READY_FOR_UPDATE (dparam) = FALSE;
|
|
|
|
|
|
|
|
GST_DPARAM_UNLOCK (dparam);
|
2002-03-04 18:54:20 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 17:27:58 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_dispose (GObject * object)
|
2001-12-23 17:27:58 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstDParam *dparam = GST_DPARAM (object);
|
|
|
|
gchar *dparam_name = g_strdup (GST_DPARAM_NAME (dparam));
|
|
|
|
|
|
|
|
GST_DEBUG ("disposing of %s", dparam_name);
|
|
|
|
if (GST_DPARAM_MANAGER (dparam)) {
|
|
|
|
gst_dpman_detach_dparam (GST_DPARAM_MANAGER (dparam), dparam_name);
|
|
|
|
}
|
|
|
|
g_free (dparam_name);
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_dparam_attach
|
|
|
|
* @dparam: GstDParam instance
|
|
|
|
* @manager: the GstDParamManager that this dparam belongs to
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_attach (GstDParam * dparam, GstDParamManager * manager,
|
|
|
|
GParamSpec * param_spec, gchar * unit_name)
|
2001-12-23 17:27:58 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
g_return_if_fail (dparam != NULL);
|
|
|
|
g_return_if_fail (GST_IS_DPARAM (dparam));
|
|
|
|
g_return_if_fail (manager != NULL);
|
|
|
|
g_return_if_fail (GST_IS_DPMAN (manager));
|
|
|
|
g_return_if_fail (param_spec != NULL);
|
|
|
|
g_return_if_fail (unit_name != NULL);
|
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC (param_spec));
|
|
|
|
g_return_if_fail (G_PARAM_SPEC_VALUE_TYPE (param_spec) ==
|
|
|
|
GST_DPARAM_TYPE (dparam));
|
|
|
|
|
2004-03-24 15:51:27 +00:00
|
|
|
gst_object_set_name (GST_OBJECT (dparam), g_param_spec_get_name (param_spec));
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_PARAM_SPEC (dparam) = param_spec;
|
|
|
|
GST_DPARAM_MANAGER (dparam) = manager;
|
|
|
|
GST_DPARAM_UNIT_NAME (dparam) = unit_name;
|
|
|
|
GST_DPARAM_IS_LOG (dparam) = gst_unitconv_unit_is_logarithmic (unit_name);
|
|
|
|
GST_DEBUG ("attaching %s to dparam %p", GST_DPARAM_NAME (dparam), dparam);
|
2002-03-04 18:54:20 +00:00
|
|
|
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_dparam_detach
|
|
|
|
* @dparam: GstDParam instance
|
|
|
|
* @manager: the GstDParamManager that this dparam belongs to
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dparam_detach (GstDParam * dparam)
|
2001-12-23 17:27:58 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
g_return_if_fail (dparam != NULL);
|
|
|
|
g_return_if_fail (GST_IS_DPARAM (dparam));
|
|
|
|
|
|
|
|
GST_DEBUG ("detaching %s from dparam %p", GST_DPARAM_NAME (dparam), dparam);
|
|
|
|
|
2004-03-24 15:51:27 +00:00
|
|
|
gst_object_set_name (GST_OBJECT (dparam), NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DPARAM_PARAM_SPEC (dparam) = NULL;
|
|
|
|
GST_DPARAM_MANAGER (dparam) = NULL;
|
2001-12-23 17:27:58 +00:00
|
|
|
}
|