2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstutils.c: Utility functions: gtk_get_property stuff, etc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
26 #include "gst_private.h"
29 #include "gstextratypes.h"
31 #define ZERO(mem) memset(&mem, 0, sizeof(mem))
34 * gst_util_get_int_arg:
35 * @object: the object to query
36 * @argname: the name of the argument
38 * Retrieves a property of an object as an integer.
40 * Returns: the property of the object
43 gst_util_get_int_arg (GObject *object, const gchar *argname)
48 g_value_init (&value, G_TYPE_INT);
49 g_object_get_property(G_OBJECT(object),argname,&value);
51 return g_value_get_int(&value);
55 * gst_util_get_bool_arg:
56 * @object: the object to query
57 * @argname: the name of the argument
59 * Retrieves a property of an object as a boolean.
61 * Returns: the property of the object
64 gst_util_get_bool_arg (GObject *object, const gchar *argname)
69 g_value_init (&value, G_TYPE_BOOLEAN);
70 g_object_get_property(G_OBJECT(object),argname,&value);
72 return g_value_get_boolean(&value);
76 * gst_util_get_long_arg:
77 * @object: the object to query
78 * @argname: the name of the argument
80 * Retrieves a property of an object as a long.
82 * Returns: the property of the object
85 gst_util_get_long_arg (GObject *object, const gchar *argname)
90 g_value_init (&value, G_TYPE_LONG);
91 g_object_get_property(G_OBJECT(object),argname,&value);
93 return g_value_get_long(&value);
97 * gst_util_get_float_arg:
98 * @object: the object to query
99 * @argname: the name of the argument
101 * Retrieves a property of an object as a float.
103 * Returns: the property of the object
106 gst_util_get_float_arg (GObject *object, const gchar *argname)
111 g_value_init (&value, G_TYPE_FLOAT);
112 g_object_get_property(G_OBJECT(object),argname,&value);
114 return g_value_get_float(&value);
118 * gst_util_get_double_arg:
119 * @object: the object to query
120 * @argname: the name of the argument
122 * Retrieves a property of an object as a double.
124 * Returns: the property of the object
127 gst_util_get_double_arg (GObject *object, const gchar *argname)
132 g_value_init (&value, G_TYPE_DOUBLE);
133 g_object_get_property(G_OBJECT(object),argname,&value);
135 return g_value_get_double(&value);
139 * gst_util_get_string_arg:
140 * @object: the object to query
141 * @argname: the name of the argument
143 * Retrieves a property of an object as a string.
145 * Returns: the property of the object
148 gst_util_get_string_arg (GObject *object, const gchar *argname)
153 g_value_init (&value, G_TYPE_STRING);
154 g_object_get_property(G_OBJECT(object),argname,&value);
156 return g_value_get_string(&value); // memleak?
160 * gst_util_get_pointer_arg:
161 * @object: the object to query
162 * @argname: the name of the argument
164 * Retrieves a property of an object as a pointer.
166 * Returns: the property of the object
169 gst_util_get_pointer_arg (GObject *object, const gchar *argname)
174 g_value_init (&value, G_TYPE_POINTER);
175 g_object_get_property(G_OBJECT(object),argname,&value);
177 return g_value_get_pointer(&value);
181 * gst_util_get_widget_property:
182 * @object: the object to query
183 * @argname: the name of the argument
185 * Retrieves a property of an object as a widget.
187 * Returns: the property of the object
189 /* COMMENTED OUT BECAUSE WE HAVE NO MORE gtk.h
191 gst_util_get_widget_property (GObject *object, const gchar *argname)
196 gtk_object_getv(G_OBJECT(object),1,&arg);
198 return GTK_WIDGET(G_VALUE_OBJECT(arg));
204 * @mem: a pointer to the memory to dump
205 * @size: the size of the memory block to dump
207 * Dumps the memory block into a hex representation. Useful for debugging.
210 gst_util_dump_mem (guchar *mem, guint size)
217 g_print("\n%08x : ", i);
223 g_print("%02x ", mem[i]);
230 * gst_util_set_object_arg:
231 * @object: the object to set the argument of
232 * @name: the name of the argument to set
233 * @value: the string value to set
235 * Convertes the string value to the type of the objects argument and
236 * sets the argument with it.
239 gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value)
242 GParamSpec *paramspec;
244 paramspec = g_object_class_find_property(G_OBJECT_GET_CLASS(object),name);
250 GST_DEBUG(0,"paramspec->flags is %d, paramspec->value_type is %d\n",
251 paramspec->flags,paramspec->value_type);
253 if (paramspec->flags & G_PARAM_WRITABLE) {
254 switch (paramspec->value_type) {
256 g_object_set (G_OBJECT (object), name, value, NULL);
261 sscanf (value, "%d", &i);
262 g_object_set (G_OBJECT (object), name, i, NULL);
267 sscanf (value, "%u", &i);
268 g_object_set (G_OBJECT (object), name, i, NULL);
273 sscanf (value, "%ld", &i);
274 g_object_set (G_OBJECT (object), name, i, NULL);
279 sscanf (value, "%lu", &i);
280 g_object_set (G_OBJECT (object), name, i, NULL);
283 case G_TYPE_BOOLEAN: {
285 if (!strncmp ("true", value, 4)) i = TRUE;
286 g_object_set (G_OBJECT (object), name, i, NULL);
291 sscanf (value, "%c", &i);
292 g_object_set (G_OBJECT (object), name, i, NULL);
297 sscanf (value, "%c", &i);
298 g_object_set (G_OBJECT (object), name, i, NULL);
303 sscanf (value, "%f", &i);
304 g_object_set (G_OBJECT (object), name, i, NULL);
307 case G_TYPE_DOUBLE: {
309 sscanf (value, "%g", &i);
310 g_object_set (G_OBJECT (object), name, (gdouble)i, NULL);
314 if (G_IS_PARAM_SPEC_ENUM(paramspec)) {
316 sscanf (value, "%d", &i);
317 g_object_set (G_OBJECT (object), name, i, NULL);
319 else if (paramspec->value_type == GST_TYPE_FILENAME) {
320 g_object_set (G_OBJECT (object), name, value, NULL);
328 // -----------------------------------------------------
330 // The following code will be moved out of the main
331 // gstreamer library someday.
336 #include "gstprops.h"
337 #include "gstpropsprivate.h"
339 static void string_append_indent (GString *str, gint count)
342 for (xx=0; xx < count; xx++)
343 g_string_append_c (str, ' ');
347 gst_print_props (GString *buf, gint indent,
348 GList *props, gboolean showname)
352 for (elem = props; elem; elem = g_list_next (elem))
354 GstPropsEntry *prop = elem->data;
356 string_append_indent (buf, indent);
358 g_string_append (buf, g_quark_to_string (prop->propid));
360 switch (prop->propstype) {
361 case GST_PROPS_INT_ID:
362 g_string_printfa (buf, "%d (int)\n", prop->data.int_data);
364 case GST_PROPS_INT_RANGE_ID:
365 g_string_printfa (buf, "%d - %d (int)\n",
366 prop->data.int_range_data.min,
367 prop->data.int_range_data.max);
369 case GST_PROPS_FLOAT_ID:
370 g_string_printfa (buf, "%f (float)\n", prop->data.float_data);
372 case GST_PROPS_FLOAT_RANGE_ID:
373 g_string_printfa (buf, "%f - %f (float)\n",
374 prop->data.float_range_data.min,
375 prop->data.float_range_data.max);
377 case GST_PROPS_BOOL_ID:
378 g_string_printfa (buf, "%s\n",
379 prop->data.bool_data ? "TRUE" : "FALSE");
381 case GST_PROPS_STRING_ID:
382 g_string_printfa (buf, "\"%s\"\n", prop->data.string_data.string);
384 case GST_PROPS_FOURCC_ID:
385 g_string_printfa (buf, "'%c%c%c%c' (fourcc)\n",
386 prop->data.fourcc_data & 0xff,
387 prop->data.fourcc_data>>8 & 0xff,
388 prop->data.fourcc_data>>16 & 0xff,
389 prop->data.fourcc_data>>24 & 0xff);
391 case GST_PROPS_LIST_ID:
392 gst_print_props (buf, indent+2, prop->data.list_data.entries, FALSE);
395 g_string_printfa (buf, "unknown proptype %d\n", prop->propstype);
401 void gst_print_pad_caps (GString *buf, gint indent, GstPad *pad)
406 realpad = GST_PAD_REALIZE(pad);
407 caps = realpad->caps;
411 string_append_indent (buf, indent);
412 g_string_printf (buf, "%s:%s has no capabilities",
413 GST_DEBUG_PAD_NAME (pad));
422 string_append_indent (buf, indent);
423 g_string_printfa (buf, "Cap[%d]: %s\n", capx++, caps->name);
425 type = gst_type_find_by_id (caps->id);
426 string_append_indent (buf, indent+2);
427 g_string_printfa (buf, "MIME type: %s\n",
428 type->mime? type->mime : "unknown/unknown");
430 if (caps->properties)
431 gst_print_props (buf, indent + 2,
432 caps->properties->properties, TRUE);