2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstinfo.c: INFO, ERROR, and DEBUG systems
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.
23 #include "gst_private.h"
26 extern gchar *_gst_progname;
29 /***** DEBUG system *****/
30 GHashTable *__gst_function_pointers = NULL;
34 /***** INFO system *****/
35 GstInfoHandler _gst_info_handler = gst_default_info_handler;
36 #ifdef GST_INFO_ENABLED_VERBOSE
37 guint32 _gst_info_categories = 0xffffffff;
39 guint32 _gst_info_categories = 0x00000001;
42 static gchar *_gst_info_category_strings[] = {
69 * gst_default_info_handler:
70 * @category: category of the INFO message
71 * @file: the file the INFO occurs in
72 * @function: the function the INFO occurs in
73 * @line: the line number in the file
74 * @debug_string: the current debug_string in the function, if any
75 * @element: pointer to the #GstElement in question
76 * @string: the actual INFO string
78 * Prints out the INFO mesage in a variant of the following form:
80 * INFO:gst_function:542(args): [elementname] something neat happened
83 gst_default_info_handler (gint category, gchar *file, gchar *function,
84 gint line, gchar *debug_string,
85 void *element, gchar *string)
88 gchar *elementname = empty,*location = empty;
90 if (debug_string == NULL) debug_string = "";
91 if (category != GST_CAT_GST_INIT)
92 location = g_strdup_printf("%s:%d%s:",function,line,debug_string);
93 if (element && GST_IS_ELEMENT (element))
94 elementname = g_strdup_printf (" [%s]",gst_element_get_name (element));
96 fprintf(stderr,"INFO:%s%s %s\n",location,elementname,string);
98 if (location != empty) g_free(location);
99 if (elementname != empty) g_free(elementname);
105 * gst_info_set_categories:
106 * @categories: bitmask of INFO categories to enable
108 * Enable the output of INFO categories based on the given bitmask.
109 * The bit for any given category is (1 << GST_CAT_...).
112 gst_info_set_categories (guint32 categories) {
113 _gst_info_categories = categories;
115 GST_INFO (0, "setting INFO categories to 0x%08X",categories);
119 * gst_info_get_categories:
121 * Returns: the current bitmask of enabled INFO categories
122 * The bit for any given category is (1 << GST_CAT_...).
125 gst_info_get_categories () {
126 return _gst_info_categories;
130 * gst_info_enable_category:
131 * @category: the category to enable
133 * Enables the given GST_CAT_... INFO category.
136 gst_info_enable_category (gint category) {
137 _gst_info_categories |= (1 << category);
138 if (_gst_info_categories)
139 GST_INFO (0, "setting INFO categories to 0x%08X",_gst_info_categories);
143 * gst_info_disable_category:
144 * @category: the category to disable
146 * Disables the given GST_CAT_... INFO category.
149 gst_info_disable_category (gint category) {
150 _gst_info_categories &= ~ (1 << category);
151 if (_gst_info_categories)
152 GST_INFO (0, "setting INFO categories to 0x%08X",_gst_info_categories);
157 /***** DEBUG system *****/
158 guint32 _gst_debug_categories = 0x00000000;
162 * gst_debug_set_categories:
163 * @categories: bitmask of DEBUG categories to enable
165 * Enable the output of DEBUG categories based on the given bitmask.
166 * The bit for any given category is (1 << GST_CAT_...).
169 gst_debug_set_categories (guint32 categories) {
170 _gst_debug_categories = categories;
172 GST_INFO (0, "setting DEBUG categories to 0x%08X",categories);
176 * gst_debug_get_categories:
178 * Returns: the current bitmask of enabled DEBUG categories
179 * The bit for any given category is (1 << GST_CAT_...).
182 gst_debug_get_categories () {
183 return _gst_debug_categories;
187 * gst_debug_enable_category:
188 * @category: the category to enable
190 * Enables the given GST_CAT_... DEBUG category.
193 gst_debug_enable_category (gint category) {
194 _gst_debug_categories |= (1 << category);
195 if (_gst_debug_categories)
196 GST_INFO (0, "setting DEBUG categories to 0x%08X",_gst_debug_categories);
200 * gst_debug_disable_category:
201 * @category: the category to disable
203 * Disables the given GST_CAT_... DEBUG category.
206 gst_debug_disable_category (gint category) {
207 _gst_debug_categories &= ~ (1 << category);
208 if (_gst_debug_categories)
209 GST_INFO (0, "setting DEBUG categories to 0x%08X",_gst_debug_categories);
213 * gst_get_category_name:
214 * @category: the category to return the name of
216 * Returns: string containing the name of the category
219 gst_get_category_name (gint category) {
220 if ((category >= 0) && (category < GST_CAT_MAX_CATEGORY))
221 return _gst_info_category_strings[category];
228 /***** ERROR system *****/
229 GstErrorHandler _gst_error_handler = gst_default_error_handler;
232 * gst_default_error_handler:
233 * @file: the file the ERROR occurs in
234 * @function: the function the INFO occurs in
235 * @line: the line number in the file
236 * @debug_string: the current debug_string in the function, if any
237 * @element: pointer to the #GstElement in question
238 * @object: pointer to a related object
239 * @string: the actual ERROR string
241 * Prints out the given ERROR string in a variant of the following format:
243 * ***** GStreamer ERROR ***** in file gstsomething.c at gst_function:399(arg)
244 * Element: /pipeline/thread/element.src
245 * Error: peer is null!
246 * ***** attempting to stack trace.... *****
248 * At the end, it attempts to print the stack trace via GDB.
251 gst_default_error_handler (gchar *file, gchar *function,
252 gint line, gchar *debug_string,
253 void *element, void *object, gchar *string)
259 // if there are NULL pointers, point them to null strings to clean up output
260 if (!debug_string) debug_string = "";
261 if (!string) string = "";
263 // print out a preamble
264 fprintf(stderr,"***** GStreamer ERROR ***** in file %s at %s:%d%s\n",
265 file,function,line,debug_string);
267 // if there's an element, print out the pertinent information
269 if (GST_IS_OBJECT(element)) {
270 path = gst_object_get_path_string(element);
271 fprintf(stderr,"Element: %s",path);
272 chars = 9 + strlen(path);
275 fprintf(stderr,"Element ptr: %p",element);
276 chars = 15 + sizeof(void*)*2;
280 // if there's an object, print it out as well
282 // attempt to pad the line, or create a new one
284 for (i=0;i<(40-chars)/8+1;i++) fprintf(stderr,"\t");
286 fprintf(stderr,"\n");
288 if (GST_IS_OBJECT(object)) {
289 path = gst_object_get_path_string(object);
290 fprintf(stderr,"Object: %s",path);
293 fprintf(stderr,"Object ptr: %p",object);
297 fprintf(stderr,"\n");
298 fprintf(stderr,"Error: %s\n",string);
302 fprintf(stderr,"***** attempting to stack trace.... *****\n");
304 g_on_error_stack_trace (_gst_progname);