2 * Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
4 * gstdparam.c: Dynamic Parameter functionality
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include <gst/gstinfo.h>
27 #include "dparammanager.h"
29 static void gst_dparam_class_init (GstDParamClass *klass);
30 static void gst_dparam_init (GstDParam *dparam);
31 static void gst_dparam_dispose (GObject *object);
32 static void gst_dparam_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
33 static void gst_dparam_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
47 static guint gst_dparam_signals[LAST_SIGNAL] = { 0 };
50 gst_dparam_get_type(void) {
51 static GType dparam_type = 0;
54 static const GTypeInfo dparam_info = {
55 sizeof(GstDParamClass),
58 (GClassInitFunc)gst_dparam_class_init,
63 (GInstanceInitFunc)gst_dparam_init,
65 dparam_type = g_type_register_static(GST_TYPE_OBJECT, "GstDParam", &dparam_info, 0);
71 gst_dparam_class_init (GstDParamClass *klass)
73 GObjectClass *gobject_class;
74 GstDParamClass *dparam_class;
75 GstObjectClass *gstobject_class;
77 gobject_class = (GObjectClass*)klass;
78 dparam_class = (GstDParamClass*)klass;
79 gstobject_class = (GstObjectClass*) klass;
81 gobject_class->get_property = gst_dparam_get_property;
82 gobject_class->set_property = gst_dparam_set_property;
84 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALUE_FLOAT,
85 g_param_spec_float("value_float","Float Value",
86 "The value that should be changed if gfloat is the type",
87 (gfloat)G_MININT64, (gfloat)G_MAXINT64, 0.0F, G_PARAM_READWRITE));
88 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALUE_INT,
89 g_param_spec_int("value_int","Integer Value",
90 "The value that should be changed if gint is the type",
91 G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
92 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALUE_INT64,
93 g_param_spec_int64("value_int64","64 bit Integer Value",
94 "The value that should be changed if gint64 is the type",
95 G_MININT64, G_MAXINT64, 0, G_PARAM_READWRITE));
97 gobject_class->dispose = gst_dparam_dispose;
99 gst_dparam_signals[VALUE_CHANGED] =
100 g_signal_new ("value_changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
101 G_STRUCT_OFFSET (GstDParamClass, value_changed), NULL, NULL,
102 gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
103 /*gstobject_class->save_thyself = gst_dparam_save_thyself; */
108 gst_dparam_init (GstDParam *dparam)
110 g_return_if_fail (dparam != NULL);
111 GST_DPARAM_TYPE(dparam) = 0;
112 GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam)=0LL;
113 GST_DPARAM_LAST_UPDATE_TIMESTAMP(dparam)=0LL;
114 GST_DPARAM_READY_FOR_UPDATE(dparam)=FALSE;
115 dparam->lock = g_mutex_new ();
120 * @type: the type that this dparam will store
122 * Returns: a new instance of GstDParam
125 gst_dparam_new (GType type)
129 dparam = g_object_new (gst_dparam_get_type (), NULL);
130 dparam->do_update_func = gst_dparam_do_update_default;
132 GST_DPARAM_TYPE(dparam) = type;
139 gst_dparam_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
142 g_return_if_fail(GST_IS_DPARAM(object));
143 dparam = GST_DPARAM(object);
146 case ARG_VALUE_FLOAT:
147 g_value_set_float (value, dparam->value_float);
151 g_value_set_float (value, dparam->value_int);
154 case ARG_VALUE_INT64:
155 g_value_set_float (value, dparam->value_int64);
158 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
164 gst_dparam_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
167 g_return_if_fail(GST_IS_DPARAM(object));
168 dparam = GST_DPARAM(object);
169 GST_DPARAM_LOCK(dparam);
172 case ARG_VALUE_FLOAT:
173 GST_DEBUG(GST_CAT_PARAMS, "setting value from %f to %f", dparam->value_float, g_value_get_float (value));
174 dparam->value_float = g_value_get_float (value);
175 GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam) = GST_DPARAM_LAST_UPDATE_TIMESTAMP(dparam);
176 GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
180 GST_DEBUG(GST_CAT_PARAMS, "setting value from %d to %d", dparam->value_int, g_value_get_int (value));
181 dparam->value_int = g_value_get_int (value);
182 GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam) = GST_DPARAM_LAST_UPDATE_TIMESTAMP(dparam);
183 GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
186 case ARG_VALUE_INT64:
187 GST_DEBUG(GST_CAT_PARAMS, "setting value from %"
188 G_GINT64_FORMAT " to %"
190 dparam->value_int64, g_value_get_int64 (value));
191 dparam->value_int64 = g_value_get_int (value);
192 GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam) = GST_DPARAM_LAST_UPDATE_TIMESTAMP(dparam);
193 GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
200 /* note that this signal is sent while we still have the lock. */
201 g_signal_emit (G_OBJECT (dparam), gst_dparam_signals[VALUE_CHANGED], 0);
202 GST_DPARAM_UNLOCK(dparam);
206 gst_dparam_do_update_default (GstDParam *dparam, gint64 timestamp, GValue *value, GstDParamUpdateInfo update_info)
208 GST_DPARAM_LOCK(dparam);
210 g_return_if_fail (G_VALUE_TYPE(value) == GST_DPARAM_TYPE(dparam));
211 GST_DEBUG(GST_CAT_PARAMS, "updating value for %s(%p)",GST_DPARAM_NAME (dparam),dparam);
213 switch (G_VALUE_TYPE(value)) {
215 g_value_set_float(value, dparam->value_float);
219 g_value_set_int(value, dparam->value_int);
223 g_value_set_int64(value, dparam->value_int64);
230 GST_DPARAM_LAST_UPDATE_TIMESTAMP(dparam) = timestamp;
231 GST_DPARAM_NEXT_UPDATE_TIMESTAMP(dparam) = timestamp;
232 GST_DPARAM_READY_FOR_UPDATE(dparam) = FALSE;
234 GST_DPARAM_UNLOCK(dparam);
238 gst_dparam_dispose (GObject *object)
240 GstDParam *dparam = GST_DPARAM(object);
241 gchar *dparam_name = g_strdup(GST_DPARAM_NAME(dparam));
243 GST_DEBUG (GST_CAT_PLUGIN_INFO, "disposing of %s", dparam_name);
244 if (GST_DPARAM_MANAGER(dparam)){
245 gst_dpman_detach_dparam(GST_DPARAM_MANAGER(dparam), dparam_name);
252 * @dparam: GstDParam instance
253 * @manager: the GstDParamManager that this dparam belongs to
257 gst_dparam_attach (GstDParam *dparam, GstDParamManager *manager, GParamSpec *param_spec, gchar *unit_name)
260 g_return_if_fail (dparam != NULL);
261 g_return_if_fail (GST_IS_DPARAM (dparam));
262 g_return_if_fail (manager != NULL);
263 g_return_if_fail (GST_IS_DPMAN (manager));
264 g_return_if_fail (param_spec != NULL);
265 g_return_if_fail (unit_name != NULL);
266 g_return_if_fail (G_IS_PARAM_SPEC (param_spec));
268 GST_DPARAM_NAME(dparam) = g_param_spec_get_name(param_spec);
269 GST_DPARAM_PARAM_SPEC(dparam) = param_spec;
270 GST_DPARAM_MANAGER(dparam) = manager;
271 GST_DPARAM_UNIT_NAME(dparam) = unit_name;
272 GST_DPARAM_IS_LOG(dparam) = gst_unitconv_unit_is_logarithmic(unit_name);
273 GST_DEBUG(GST_CAT_PARAMS, "attaching %s to dparam %p",GST_DPARAM_NAME (dparam),dparam);
279 * @dparam: GstDParam instance
280 * @manager: the GstDParamManager that this dparam belongs to
284 gst_dparam_detach (GstDParam *dparam)
287 g_return_if_fail (dparam != NULL);
288 g_return_if_fail (GST_IS_DPARAM (dparam));
290 GST_DEBUG(GST_CAT_PARAMS, "detaching %s from dparam %p",GST_DPARAM_NAME (dparam),dparam);
292 GST_DPARAM_NAME(dparam) = NULL;
293 GST_DPARAM_PARAM_SPEC(dparam) = NULL;
294 GST_DPARAM_MANAGER(dparam) = NULL;