diff --git a/gst/gstinfo.c b/gst/gstinfo.c
index 6858b8376501055d4dbc1ec1c8b99eabf8678d3b..226876822adb5d8601a14464eb80d105801fcb00 100644 (file)
--- a/gst/gstinfo.c
+++ b/gst/gstinfo.c
#include "gst_private.h"
#include "gstinfo.h"
+#undef gst_debug_remove_log_function
+#undef gst_debug_add_log_function
+
#ifndef GST_DISABLE_GST_DEBUG
#ifdef HAVE_DLFCN_H
# include <printf.h>
#endif
#include <stdio.h> /* fprintf */
+#include <glib/gstdio.h>
+#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* getpid on UNIX */
#endif
#include "gstutils.h"
#include "gstquark.h"
#include "gstsegment.h"
-#ifdef HAVE_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#endif
#include <glib/gprintf.h> /* g_sprintf */
#define PRETTY_TAGS_DEFAULT TRUE
static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
-static gint __default_level;
-static gint __use_color;
+static volatile gint G_GNUC_MAY_ALIAS __default_level = GST_LEVEL_DEFAULT;
+static volatile gint G_GNUC_MAY_ALIAS __use_color = 1;
+
+static FILE *log_file;
/* FIXME: export this? */
gboolean
in_valgrind = GST_VG_UNCHECKED;
if (in_valgrind == GST_VG_UNCHECKED) {
-#ifdef HAVE_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
if (RUNNING_ON_VALGRIND) {
GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
printf ("GStreamer has detected that it is running inside valgrind.\n");
g_assert (in_valgrind == GST_VG_NO_VALGRIND ||
in_valgrind == GST_VG_INSIDE);
}
- return (in_valgrind == GST_VG_INSIDE) ? TRUE : FALSE;
+ return (in_valgrind == GST_VG_INSIDE);
}
/**
{
const gchar *env;
- g_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
- g_atomic_int_set (&__use_color, 1);
+ env = g_getenv ("GST_DEBUG_FILE");
+ if (env != NULL && *env != '\0') {
+ if (strcmp (env, "-") == 0) {
+ log_file = stdout;
+ } else {
+ log_file = g_fopen (env, "w");
+ if (log_file == NULL) {
+ g_printerr ("Could not open log file '%s' for writing: %s\n", env,
+ g_strerror (errno));
+ log_file = stderr;
+ }
+ }
+ } else {
+ log_file = stderr;
+ }
/* get time we started for debugging messages */
_priv_gst_info_start_time = gst_util_get_timestamp ();
/* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
#define GST_CAT_DEFAULT _GST_CAT_DEBUG
+
+/**
+ * gst_debug_log2:
+ * @category: category to log
+ * @level: level of the message is in
+ * @location: the file, function name, and line number of the location that
+ * emitted the message
+ * @object: the object this message relates to or NULL if none
+ * @format: a printf style format string
+ * @...: optional arguments for the format
+ *
+ * Logs the given message using the currently registered debugging handlers.
+ */
+void
+gst_debug_log2 (GstDebugCategory * category, GstDebugLevel level,
+ const GstDebugTraceLocation * location,
+ GObject * object, const gchar * format, ...)
+{
+ va_list var_args;
+
+ va_start (var_args, format);
+ gst_debug_log_valist2 (category, level, location, object, format, var_args);
+ va_end (var_args);
+}
+
+
/**
* gst_debug_log:
* @category: category to log
* @file: the file that emitted the message, usually the __FILE__ identifier
* @function: the function that emitted the message
* @line: the line from that the message was emitted, usually __LINE__
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ * or NULL if none
* @format: a printf style format string
* @...: optional arguments for the format
*
va_end (var_args);
}
+#ifdef _MSC_VER
+/* based on g_basename(), which we can't use because it was deprecated */
+static inline const gchar *
+gst_path_basename (const gchar * file_name)
+{
+ register const gchar *base;
+
+ base = strrchr (file_name, G_DIR_SEPARATOR);
+
+ {
+ const gchar *q = strrchr (file_name, '/');
+ if (base == NULL || (q != NULL && q > base))
+ base = q;
+ }
+
+ if (base)
+ return base + 1;
+
+ if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
+ return file_name + 2;
+
+ return file_name;
+}
+#endif
+
/**
* gst_debug_log_valist:
* @category: category to log
* @file: the file that emitted the message, usually the __FILE__ identifier
* @function: the function that emitted the message
* @line: the line from that the message was emitted, usually __LINE__
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ * or NULL if none
* @format: a printf style format string
* @args: optional arguments for the format
*
gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
const gchar * file, const gchar * function, gint line,
GObject * object, const gchar * format, va_list args)
+{
+ GstDebugTraceLocation location = {
+ .file = file,
+ .function = function,
+ .line = line
+ };
+ gst_debug_log_valist2 (category, level, &location, object, format, args);
+}
+
+
+/**
+ * gst_debug_log_valist2:
+ * @category: category to log
+ * @level: level of the message is in
+ * @location: the file, function name, and line number of the location that
+ * emitted the message
+ * @object: the object this message relates to or NULL if none
+ * @format: a printf style format string
+ * @args: optional arguments for the format
+ *
+ * Logs the given message using the currently registered debugging handlers.
+ */
+void
+gst_debug_log_valist2 (GstDebugCategory * category, GstDebugLevel level,
+ const GstDebugTraceLocation * location,
+ GObject * object, const gchar * format, va_list args)
{
GstDebugMessage message;
LogFuncEntry *entry;
GSList *handler;
-#ifdef _MSC_VER
- gchar *file_basename;
-#endif
-
g_return_if_fail (category != NULL);
- g_return_if_fail (file != NULL);
- g_return_if_fail (function != NULL);
+ g_return_if_fail (location != NULL);
+ g_return_if_fail (location->file != NULL);
+ g_return_if_fail (location->function != NULL);
g_return_if_fail (format != NULL);
-#ifdef _MSC_VER
- /*
- * The predefined macro __FILE__ is always the exact path given to the
+ /* The predefined macro __FILE__ is always the exact path given to the
* compiler with MSVC, which may or may not be the basename. We work
- * around it at runtime to improve the readability.
- */
- file = file_basename = g_path_get_basename (file);
+ * around it at runtime to improve the readability. */
+#ifdef _MSC_VER
+ file = gst_path_basename (file);
#endif
message.message = NULL;
while (handler) {
entry = handler->data;
handler = g_slist_next (handler);
- entry->func (category, level, file, function, line, object, &message,
- entry->user_data);
+ // TODO: change GstLogFunction and pass GstDebugTraceLocation ptr instead..
+ entry->func (category, level, location->file, location->function,
+ location->line, object, &message, entry->user_data);
}
g_free (message.message);
va_end (message.arguments);
-
-#ifdef _MSC_VER
- g_free (file_basename);
-#endif
}
/**
return gst_structure_to_string (s);
}
-static gchar *
+gchar *
gst_debug_print_object (gpointer ptr)
{
GObject *object = (GObject *) ptr;
if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
return gst_info_structure_to_string ((GstStructure *) ptr);
}
+ if (GST_IS_BUFFER (ptr)) {
+ GstBuffer *buf = (GstBuffer *) ptr;
+ gchar *caps, *ret;
+
+ caps = gst_caps_to_string (GST_BUFFER_CAPS (buf));
+ ret =
+ g_strdup_printf ("%p, data %p, malloc %p, ts %" GST_TIME_FORMAT
+ ", dur %" GST_TIME_FORMAT ", size %u, offset %" G_GUINT64_FORMAT
+ ", offset_end %" G_GUINT64_FORMAT ", caps: %s", buf,
+ GST_BUFFER_DATA (buf), GST_BUFFER_MALLOCDATA (buf),
+ GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
+ GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_BUFFER_SIZE (buf),
+ GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), caps);
+
+ g_free (caps);
+ return ret;
+ }
#ifdef USE_POISONING
if (*(guint32 *) ptr == 0xffffffff) {
return g_strdup_printf ("<poisoned@%p>", ptr);
#ifdef HAVE_PRINTF_EXTENSION
-static gchar *
+gchar *
gst_debug_print_segment (gpointer ptr)
{
GstSegment *segment = (GstSegment *) ptr;
* terminals.
* You need to free the string after use.
*
- * Returns: a string containing the color definition
+ * Returns: (transfer full) (type gchar*): a string containing the color
+ * definition
*/
gchar *
gst_debug_construct_term_color (guint colorinfo)
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
/* GST_LEVEL_FIXME */
FOREGROUND_RED | FOREGROUND_GREEN,
- /* placeholder for log level 7 */
- 0,
+ /* GST_LEVEL_TRACE */
+ FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
/* placeholder for log level 8 */
0,
/* GST_LEVEL_MEMDUMP */
"\033[36m", /* GST_LEVEL_DEBUG */
"\033[37m", /* GST_LEVEL_LOG */
"\033[33;01m", /* GST_LEVEL_FIXME */
- "\033[37m", /* placeholder for log level 7 */
+ "\033[37m", /* GST_LEVEL_TRACE */
"\033[37m", /* placeholder for log level 8 */
"\033[37m" /* GST_LEVEL_MEMDUMP */
};
* @function: the function that emitted the message
* @line: the line from that the message was emitted, usually __LINE__
* @message: the actual message
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ * or NULL if none
* @unused: an unused variable, reserved for some user_data.
*
* The default logging handler used by GStreamer. Logging functions get called
* whenever a macro like GST_DEBUG or similar is used. This function outputs the
- * message and additional info using the glib error handler.
+ * message and additional info to stderr (or the log file specified via the
+ * GST_DEBUG_FILE environment variable).
+ *
* You can add other handlers by using gst_debug_add_log_function().
* And you can remove this handler by calling
* gst_debug_remove_log_function(gst_debug_log_default);
pid = getpid ();
is_colored = gst_debug_is_colored ();
- elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
- gst_util_get_timestamp ());
-
if (object) {
obj = gst_debug_print_object (object);
} else {
obj = g_strdup ("");
}
+ elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
+ gst_util_get_timestamp ());
+
if (is_colored) {
#ifndef G_OS_WIN32
/* colors, non-windows */
levelcolor = levelcolormap[level];
#define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
- g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
+ fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
pidcolor, pid, clear, g_thread_self (), levelcolor,
gst_debug_level_get_name (level), clear, color,
gst_debug_category_get_name (category), file, line, function, obj,
clear, gst_debug_message_get (message));
+ fflush (log_file);
#undef PRINT_FMT
g_free (color);
#else
* thing. */
static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
-#define SET_COLOR(c) \
- SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
+#define SET_COLOR(c) G_STMT_START { \
+ if (log_file == stderr) \
+ SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c)); \
+ } G_STMT_END
g_static_mutex_lock (&win_print_mutex);
/* timestamp */
- g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
+ fprintf (log_file, "%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
+ fflush (log_file);
/* pid */
SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
- g_printerr (PID_FMT, pid);
+ fprintf (log_file, PID_FMT, pid);
+ fflush (log_file);
/* thread */
SET_COLOR (clear);
- g_printerr (" " PTR_FMT " ", g_thread_self ());
+ fprintf (log_file, " " PTR_FMT " ", g_thread_self ());
+ fflush (log_file);
/* level */
SET_COLOR (levelcolormap[level]);
- g_printerr ("%s ", gst_debug_level_get_name (level));
+ fprintf (log_file, "%s ", gst_debug_level_get_name (level));
+ fflush (log_file);
/* category */
SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
(category)));
- g_printerr (CAT_FMT, gst_debug_category_get_name (category),
+ fprintf (log_file, CAT_FMT, gst_debug_category_get_name (category),
file, line, function, obj);
+ fflush (log_file);
/* message */
SET_COLOR (clear);
- g_printerr (" %s\n", gst_debug_message_get (message));
+ fprintf (log_file, " %s\n", gst_debug_message_get (message));
+ fflush (log_file);
g_static_mutex_unlock (&win_print_mutex);
#endif
} else {
/* no color, all platforms */
#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
- g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
- g_thread_self (), gst_debug_level_get_name (level),
+ fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
+ pid, g_thread_self (), gst_debug_level_get_name (level),
gst_debug_category_get_name (category), file, line, function, obj,
gst_debug_message_get (message));
+ fflush (log_file);
#undef PRINT_FMT
}
return "LOG ";
case GST_LEVEL_FIXME:
return "FIXME ";
+ case GST_LEVEL_TRACE:
+ return "TRACE ";
case GST_LEVEL_MEMDUMP:
return "MEMDUMP";
default:
/**
* gst_debug_add_log_function:
* @func: the function to use
- * @data: user data
+ * @data: (closure): user data
*
* Adds the logging function to the list of logging functions.
- * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
+ * Be sure to use #G_GNUC_NO_INSTRUMENT on that function, it is needed.
*/
void
gst_debug_add_log_function (GstLogFunction func, gpointer data)
LogFuncEntry *entry;
GSList *list;
- g_return_if_fail (func != NULL);
+ if (func == NULL)
+ func = gst_debug_log_default;
entry = g_slice_new (LogFuncEntry);
entry->func = func;
{
guint removals;
- g_return_val_if_fail (func != NULL, 0);
+ if (func == NULL)
+ func = gst_debug_log_default;
removals =
gst_debug_remove_with_compare_func
* @colored: Whether to use colored output or not
*
* Sets or unsets the use of coloured debugging output.
+ *
+ * This function may be called before gst_init().
*/
void
gst_debug_set_colored (gboolean colored)
{
- g_atomic_int_set (&__use_color, colored ? 1 : 0);
+ g_atomic_int_set (&__use_color, (gint) colored);
}
/**
gboolean
gst_debug_is_colored (void)
{
- return g_atomic_int_get (&__use_color) == 0 ? FALSE : TRUE;
+ return (gboolean) g_atomic_int_get (&__use_color);
}
/**
*
* Sets the default threshold to the given level and updates all categories to
* use this threshold.
+ *
+ * This function may be called before gst_init().
*/
void
gst_debug_set_default_threshold (GstDebugLevel level)
GstDebugLevel
gst_debug_category_get_threshold (GstDebugCategory * category)
{
- return g_atomic_int_get (&category->threshold);
+ return (GstDebugLevel) g_atomic_int_get (&category->threshold);
}
/**
* may change anytime.
* The caller has to free the list after use.
*
- * Returns: the list of categories
+ * Returns: (transfer container) (element-type Gst.DebugCategory): the list of
+ * debug categories
*/
GSList *
gst_debug_get_all_categories (void)
{
}
-G_CONST_RETURN gchar *
+const gchar *
gst_debug_level_get_name (GstDebugLevel level)
{
return "NONE";
return GST_LEVEL_NONE;
}
-G_CONST_RETURN gchar *
+const gchar *
gst_debug_category_get_name (GstDebugCategory * category)
{
return "";
return 0;
}
-G_CONST_RETURN gchar *
+const gchar *
gst_debug_category_get_description (GstDebugCategory * category)
{
return "";