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"
24 #include "gstelement.h"
27 extern gchar *_gst_progname;
30 /***** DEBUG system *****/
31 GHashTable *__gst_function_pointers = NULL;
35 /***** INFO system *****/
36 GstInfoHandler _gst_info_handler = gst_default_info_handler;
37 #ifdef GST_INFO_ENABLED_VERBOSE
38 guint32 _gst_info_categories = 0xffffffff;
40 guint32 _gst_info_categories = 0x00000001;
43 static gchar *_gst_info_category_strings[] = {
70 * gst_default_info_handler:
71 * @category: category of the INFO message
72 * @file: the file the INFO occurs in
73 * @function: the function the INFO occurs in
74 * @line: the line number in the file
75 * @debug_string: the current debug_string in the function, if any
76 * @element: pointer to the #GstElement in question
77 * @string: the actual INFO string
79 * Prints out the INFO mesage in a variant of the following form:
81 * INFO:gst_function:542(args): [elementname] something neat happened
84 gst_default_info_handler (gint category, gchar *file, gchar *function,
85 gint line, gchar *debug_string,
86 void *element, gchar *string)
89 gchar *elementname = empty,*location = empty;
91 if (debug_string == NULL) debug_string = "";
92 if (category != GST_CAT_GST_INIT)
93 location = g_strdup_printf("%s:%d%s:",function,line,debug_string);
94 if (element && GST_IS_ELEMENT (element))
95 elementname = g_strdup_printf (" [%s]", GST_OBJECT_NAME (element));
97 fprintf(stderr,"INFO:%s%s %s\n",location,elementname,string);
99 if (location != empty) g_free(location);
100 if (elementname != empty) g_free(elementname);
106 * gst_info_set_categories:
107 * @categories: bitmask of INFO categories to enable
109 * Enable the output of INFO categories based on the given bitmask.
110 * The bit for any given category is (1 << GST_CAT_...).
113 gst_info_set_categories (guint32 categories) {
114 _gst_info_categories = categories;
116 GST_INFO (0, "setting INFO categories to 0x%08X",categories);
120 * gst_info_get_categories:
122 * Returns: the current bitmask of enabled INFO categories
123 * The bit for any given category is (1 << GST_CAT_...).
126 gst_info_get_categories () {
127 return _gst_info_categories;
131 * gst_info_enable_category:
132 * @category: the category to enable
134 * Enables the given GST_CAT_... INFO category.
137 gst_info_enable_category (gint category) {
138 _gst_info_categories |= (1 << category);
139 if (_gst_info_categories)
140 GST_INFO (0, "setting INFO categories to 0x%08X",_gst_info_categories);
144 * gst_info_disable_category:
145 * @category: the category to disable
147 * Disables the given GST_CAT_... INFO category.
150 gst_info_disable_category (gint category) {
151 _gst_info_categories &= ~ (1 << category);
152 if (_gst_info_categories)
153 GST_INFO (0, "setting INFO categories to 0x%08X",_gst_info_categories);
158 /***** DEBUG system *****/
159 guint32 _gst_debug_categories = 0x00000000;
163 * gst_debug_set_categories:
164 * @categories: bitmask of DEBUG categories to enable
166 * Enable the output of DEBUG categories based on the given bitmask.
167 * The bit for any given category is (1 << GST_CAT_...).
170 gst_debug_set_categories (guint32 categories) {
171 _gst_debug_categories = categories;
173 GST_INFO (0, "setting DEBUG categories to 0x%08X",categories);
177 * gst_debug_get_categories:
179 * Returns: the current bitmask of enabled DEBUG categories
180 * The bit for any given category is (1 << GST_CAT_...).
183 gst_debug_get_categories () {
184 return _gst_debug_categories;
188 * gst_debug_enable_category:
189 * @category: the category to enable
191 * Enables the given GST_CAT_... DEBUG category.
194 gst_debug_enable_category (gint category) {
195 _gst_debug_categories |= (1 << category);
196 if (_gst_debug_categories)
197 GST_INFO (0, "setting DEBUG categories to 0x%08X",_gst_debug_categories);
201 * gst_debug_disable_category:
202 * @category: the category to disable
204 * Disables the given GST_CAT_... DEBUG category.
207 gst_debug_disable_category (gint category) {
208 _gst_debug_categories &= ~ (1 << category);
209 if (_gst_debug_categories)
210 GST_INFO (0, "setting DEBUG categories to 0x%08X",_gst_debug_categories);
214 * gst_get_category_name:
215 * @category: the category to return the name of
217 * Returns: string containing the name of the category
220 gst_get_category_name (gint category) {
221 if ((category >= 0) && (category < GST_CAT_MAX_CATEGORY))
222 return _gst_info_category_strings[category];
229 /***** ERROR system *****/
230 GstErrorHandler _gst_error_handler = gst_default_error_handler;
233 * gst_default_error_handler:
234 * @file: the file the ERROR occurs in
235 * @function: the function the INFO occurs in
236 * @line: the line number in the file
237 * @debug_string: the current debug_string in the function, if any
238 * @element: pointer to the #GstElement in question
239 * @object: pointer to a related object
240 * @string: the actual ERROR string
242 * Prints out the given ERROR string in a variant of the following format:
244 * ***** GStreamer ERROR ***** in file gstsomething.c at gst_function:399(arg)
245 * Element: /pipeline/thread/element.src
246 * Error: peer is null!
247 * ***** attempting to stack trace.... *****
249 * At the end, it attempts to print the stack trace via GDB.
252 gst_default_error_handler (gchar *file, gchar *function,
253 gint line, gchar *debug_string,
254 void *element, void *object, gchar *string)
260 // if there are NULL pointers, point them to null strings to clean up output
261 if (!debug_string) debug_string = "";
262 if (!string) string = "";
264 // print out a preamble
265 fprintf(stderr,"***** GStreamer ERROR ***** in file %s at %s:%d%s\n",
266 file,function,line,debug_string);
268 // if there's an element, print out the pertinent information
270 if (GST_IS_OBJECT(element)) {
271 path = gst_object_get_path_string(element);
272 fprintf(stderr,"Element: %s",path);
273 chars = 9 + strlen(path);
276 fprintf(stderr,"Element ptr: %p",element);
277 chars = 15 + sizeof(void*)*2;
281 // if there's an object, print it out as well
283 // attempt to pad the line, or create a new one
285 for (i=0;i<(40-chars)/8+1;i++) fprintf(stderr,"\t");
287 fprintf(stderr,"\n");
289 if (GST_IS_OBJECT(object)) {
290 path = gst_object_get_path_string(object);
291 fprintf(stderr,"Object: %s",path);
294 fprintf(stderr,"Object ptr: %p",object);
298 fprintf(stderr,"\n");
299 fprintf(stderr,"Error: %s\n",string);
303 fprintf(stderr,"***** attempting to stack trace.... *****\n");
305 g_on_error_stack_trace (_gst_progname);