gstreamer/libs/gst/control/dparam.c
Andy Wingo 0067d17205 removal of //-style comments don't link plugins to core libs -- the versioning is done internally to the plugins with...
Original commit message from CVS:
* removal of //-style comments
* don't link plugins to core libs -- the versioning is done internally to the plugins with the plugin_info struct,
and symbol resolution is lazy, so we can always know if a plugin can be loaded by the plugin_info data. in theory.
2002-03-19 04:10:13 +00:00

280 lines
8 KiB
C

/* 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.
*/
#include <math.h>
#include <string.h>
#include <gst/gstinfo.h>
#include <gst/control/dparam.h>
#include <gst/control/dparammanager.h>
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_INT,
ARG_VALUE_INT64,
ARG_IS_LOG,
ARG_IS_RATE,
};
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,
};
dparam_type = g_type_register_static(GST_TYPE_OBJECT, "GstDParam", &dparam_info, 0);
}
return dparam_type;
}
static void
gst_dparam_class_init (GstDParamClass *klass)
{
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",
"The value that should be changed if gfloat is the type",
(gfloat)G_MININT64, (gfloat)G_MAXINT64, 0.0F, G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALUE_INT,
g_param_spec_int("value_int","Integer Value",
"The value that should be changed if gint is the type",
G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALUE_INT64,
g_param_spec_int64("value_int64","64 bit Integer Value",
"The value that should be changed if gint64 is the type",
G_MININT64, G_MAXINT64, 0, G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_IS_LOG,
g_param_spec_boolean("is_log","Is a Log Value",
"This dparam should be interpreted on a log scale",
FALSE, G_PARAM_READABLE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_IS_RATE,
g_param_spec_boolean("is_rate","Is a sample rate proportion",
"This dparam value represents a proportion of the sample rate (eg half of the sample rate will be 0.5)",
FALSE, G_PARAM_READABLE));
gobject_class->dispose = gst_dparam_dispose;
/*gstobject_class->save_thyself = gst_dparam_save_thyself; */
}
static void
gst_dparam_init (GstDParam *dparam)
{
g_return_if_fail (dparam != NULL);
GST_DPARAM_TYPE(dparam) = 0;
GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam)=0LL;
GST_DPARAM_READY_FOR_UPDATE(dparam)=FALSE;
dparam->lock = g_mutex_new ();
}
/**
* gst_dparam_new:
* @type: the type that this dparam will store
*
* Returns: a new instance of GstDParam
*/
GstDParam*
gst_dparam_new (GType type)
{
GstDParam *dparam;
dparam = g_object_new (gst_dparam_get_type (), NULL);
dparam->do_update_func = gst_dparam_do_update_default;
GST_DPARAM_TYPE(dparam) = type;
return dparam;
}
static void
gst_dparam_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
GstDParam *dparam;
g_return_if_fail(GST_IS_DPARAM(object));
dparam = GST_DPARAM(object);
switch (prop_id) {
case ARG_IS_LOG:
g_value_set_boolean (value, dparam->is_log);
break;
case ARG_IS_RATE:
g_value_set_boolean (value, dparam->is_rate);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_dparam_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
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(GST_CAT_PARAMS, "setting value from %f to %f\n", dparam->value_float, g_value_get_float (value));
dparam->value_float = g_value_get_float (value);
GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
break;
case ARG_VALUE_INT:
GST_DEBUG(GST_CAT_PARAMS, "setting value from %d to %d\n", dparam->value_int, g_value_get_int (value));
dparam->value_int = g_value_get_int (value);
GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
break;
case ARG_VALUE_INT64:
GST_DEBUG(GST_CAT_PARAMS, "setting value from %lld to %lld\n", dparam->value_int64, g_value_get_int64 (value));
dparam->value_int64 = g_value_get_int (value);
GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
break;
default:
break;
}
GST_DPARAM_UNLOCK(dparam);
}
void
gst_dparam_do_update_default (GstDParam *dparam, gint64 timestamp, GValue *value)
{
GST_DPARAM_LOCK(dparam);
g_return_if_fail (G_VALUE_TYPE(value) == GST_DPARAM_TYPE(dparam));
GST_DEBUG(GST_CAT_PARAMS, "updating value for %s(%p)\n",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_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_READY_FOR_UPDATE(dparam) = FALSE;
GST_DPARAM_UNLOCK(dparam);
}
static void
gst_dparam_dispose (GObject *object)
{
GstDParam *dparam = GST_DPARAM(object);
gchar *dparam_name = g_strdup(GST_DPARAM_NAME(dparam));
g_print("disposing of %s\n", dparam_name);
if (GST_DPARAM_MANAGER(dparam)){
gst_dpman_detach_dparam(GST_DPARAM_MANAGER(dparam), dparam_name);
}
g_free(dparam_name);
}
/**
* gst_dparam_attach
* @dparam: GstDParam instance
* @manager: the GstDParamManager that this dparam belongs to
*
*/
void
gst_dparam_attach (GstDParam *dparam, GstDParamManager *manager, GParamSpec *param_spec, gboolean is_log, gboolean is_rate)
{
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 (G_IS_PARAM_SPEC (param_spec));
GST_DPARAM_NAME(dparam) = g_param_spec_get_name(param_spec);
GST_DPARAM_PARAM_SPEC(dparam) = param_spec;
GST_DPARAM_MANAGER(dparam) = manager;
dparam->is_log = is_log;
dparam->is_rate = is_rate;
GST_DEBUG(GST_CAT_PARAMS, "attaching %s to dparam %p\n",GST_DPARAM_NAME (dparam),dparam);
}
/**
* gst_dparam_detach
* @dparam: GstDParam instance
* @manager: the GstDParamManager that this dparam belongs to
*
*/
void
gst_dparam_detach (GstDParam *dparam)
{
g_return_if_fail (dparam != NULL);
g_return_if_fail (GST_IS_DPARAM (dparam));
GST_DEBUG(GST_CAT_PARAMS, "detaching %s from dparam %p\n",GST_DPARAM_NAME (dparam),dparam);
GST_DPARAM_NAME(dparam) = NULL;
GST_DPARAM_PARAM_SPEC(dparam) = NULL;
GST_DPARAM_MANAGER(dparam) = NULL;
}