mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-27 14:31:01 +00:00
API: add GST_SEGMENT_FORMAT, which is a printf extension we register that lets us easily dump GstSegments into debug ...
Original commit message from CVS: * configure.ac: * docs/gst/gstreamer-sections.txt: * gst/gstconfig.h.in: * gst/gstinfo.c: (_gst_debug_init), (gst_debug_print_segment), (_gst_info_printf_extension_ptr), (_gst_info_printf_extension_segment): API: add GST_SEGMENT_FORMAT, which is a printf extension we register that lets us easily dump GstSegments into debug logs (#350419). * tests/check/gst/gstinfo.c: (segment_printf_extension_log_func), (info_segment_format_printf_extension), (gst_info_suite): Add simple unit test that logs a bunch of different segments (not valgrinded at the moment because of leaks in gst_debug_add_log_function).
This commit is contained in:
parent
cb49718e86
commit
57212633aa
6 changed files with 231 additions and 8 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
||||||
|
2006-08-08 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
* docs/gst/gstreamer-sections.txt:
|
||||||
|
* gst/gstconfig.h.in:
|
||||||
|
* gst/gstinfo.c: (_gst_debug_init), (gst_debug_print_segment),
|
||||||
|
(_gst_info_printf_extension_ptr),
|
||||||
|
(_gst_info_printf_extension_segment):
|
||||||
|
API: add GST_SEGMENT_FORMAT, which is a printf extension we
|
||||||
|
register that lets us easily dump GstSegments into debug
|
||||||
|
logs (#350419).
|
||||||
|
|
||||||
|
* tests/check/gst/gstinfo.c: (segment_printf_extension_log_func),
|
||||||
|
(info_segment_format_printf_extension), (gst_info_suite):
|
||||||
|
Add simple unit test that logs a bunch of different segments (not
|
||||||
|
valgrinded at the moment because of leaks in gst_debug_add_log_function).
|
||||||
|
|
||||||
2006-08-09 Edward Hervey <edward@fluendo.com>
|
2006-08-09 Edward Hervey <edward@fluendo.com>
|
||||||
|
|
||||||
* libs/gst/base/gstbasetransform.c:
|
* libs/gst/base/gstbasetransform.c:
|
||||||
|
|
|
@ -321,13 +321,16 @@ GST_CHECK_FUNCTION
|
||||||
dnl test for register_printf_function
|
dnl test for register_printf_function
|
||||||
AC_CHECK_FUNC(register_printf_function,
|
AC_CHECK_FUNC(register_printf_function,
|
||||||
[
|
[
|
||||||
GST_PRINTF_EXTENSION_FORMAT_DEFINE="#define GST_PTR_FORMAT \"P\""
|
GST_PRINTF_EXTENSION_POINTER_FORMAT_DEFINE="#define GST_PTR_FORMAT \"P\""
|
||||||
|
GST_PRINTF_EXTENSION_SEGMENT_FORMAT_DEFINE="#define GST_SEGMENT_FORMAT \"Q\""
|
||||||
AC_DEFINE(HAVE_PRINTF_EXTENSION, 1,
|
AC_DEFINE(HAVE_PRINTF_EXTENSION, 1,
|
||||||
[Defined if we have register_printf_function ()])
|
[Defined if we have register_printf_function ()])
|
||||||
],
|
],
|
||||||
GST_PRINTF_EXTENSION_FORMAT_DEFINE="#define GST_PTR_FORMAT \"p\""
|
GST_PRINTF_EXTENSION_POINTER_FORMAT_DEFINE="#define GST_PTR_FORMAT \"p\""
|
||||||
|
GST_PRINTF_EXTENSION_SEGMENT_FORMAT_DEFINE="#define GST_SEGMENT_FORMAT \"p\""
|
||||||
)
|
)
|
||||||
AC_SUBST(GST_PRINTF_EXTENSION_FORMAT_DEFINE)
|
AC_SUBST(GST_PRINTF_EXTENSION_POINTER_FORMAT_DEFINE)
|
||||||
|
AC_SUBST(GST_PRINTF_EXTENSION_SEGMENT_FORMAT_DEFINE)
|
||||||
|
|
||||||
dnl test if we have dladdr(); we use it for debugging; see gst/gstinfo.c
|
dnl test if we have dladdr(); we use it for debugging; see gst/gstinfo.c
|
||||||
save_cflags="$CFLAGS"
|
save_cflags="$CFLAGS"
|
||||||
|
|
|
@ -381,6 +381,7 @@ GST_DISABLE_URI
|
||||||
GST_DISABLE_LOADSAVE_REGISTRY
|
GST_DISABLE_LOADSAVE_REGISTRY
|
||||||
GST_HAVE_GLIB_2_8
|
GST_HAVE_GLIB_2_8
|
||||||
GST_PTR_FORMAT
|
GST_PTR_FORMAT
|
||||||
|
GST_SEGMENT_FORMAT
|
||||||
GST_EXPORT
|
GST_EXPORT
|
||||||
GST_PLUGIN_EXPORT
|
GST_PLUGIN_EXPORT
|
||||||
GST_PADDING
|
GST_PADDING
|
||||||
|
|
|
@ -144,7 +144,16 @@
|
||||||
* printf format type used to debug GStreamer types.
|
* printf format type used to debug GStreamer types.
|
||||||
* This can only be used on types whose size is >= sizeof(gpointer).
|
* This can only be used on types whose size is >= sizeof(gpointer).
|
||||||
*/
|
*/
|
||||||
@GST_PRINTF_EXTENSION_FORMAT_DEFINE@
|
@GST_PRINTF_EXTENSION_POINTER_FORMAT_DEFINE@
|
||||||
|
/**
|
||||||
|
* GST_SEGMENT_FORMAT:
|
||||||
|
*
|
||||||
|
* printf format type used to debug GStreamer segments.
|
||||||
|
* This can only be used on pointers to GstSegment structures.
|
||||||
|
*
|
||||||
|
* Since: 0.10.10
|
||||||
|
*/
|
||||||
|
@GST_PRINTF_EXTENSION_SEGMENT_FORMAT_DEFINE@
|
||||||
|
|
||||||
/* whether or not the CPU supports unaligned access */
|
/* whether or not the CPU supports unaligned access */
|
||||||
@GST_HAVE_UNALIGNED_ACCESS_DEFINE@
|
@GST_HAVE_UNALIGNED_ACCESS_DEFINE@
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
#include <string.h> /* G_VA_COPY */
|
#include <string.h> /* G_VA_COPY */
|
||||||
#include "gst_private.h"
|
#include "gst_private.h"
|
||||||
#include "gstutils.h"
|
#include "gstutils.h"
|
||||||
|
#include "gstsegment.h"
|
||||||
#ifdef HAVE_VALGRIND
|
#ifdef HAVE_VALGRIND
|
||||||
# include <valgrind/valgrind.h>
|
# include <valgrind/valgrind.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,7 +150,9 @@ static void gst_debug_reset_threshold (gpointer category, gpointer unused);
|
||||||
static void gst_debug_reset_all_thresholds (void);
|
static void gst_debug_reset_all_thresholds (void);
|
||||||
|
|
||||||
#ifdef HAVE_PRINTF_EXTENSION
|
#ifdef HAVE_PRINTF_EXTENSION
|
||||||
static int _gst_info_printf_extension (FILE * stream,
|
static int _gst_info_printf_extension_ptr (FILE * stream,
|
||||||
|
const struct printf_info *info, const void *const *args);
|
||||||
|
static int _gst_info_printf_extension_segment (FILE * stream,
|
||||||
const struct printf_info *info, const void *const *args);
|
const struct printf_info *info, const void *const *args);
|
||||||
static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
|
static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
|
||||||
size_t n, int *argtypes);
|
size_t n, int *argtypes);
|
||||||
|
@ -279,8 +282,10 @@ _gst_debug_init (void)
|
||||||
start_time = GST_TIMEVAL_TO_TIME (current);
|
start_time = GST_TIMEVAL_TO_TIME (current);
|
||||||
|
|
||||||
#ifdef HAVE_PRINTF_EXTENSION
|
#ifdef HAVE_PRINTF_EXTENSION
|
||||||
register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension,
|
register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
|
||||||
_gst_info_printf_extension_arginfo);
|
_gst_info_printf_extension_arginfo);
|
||||||
|
register_printf_function (GST_SEGMENT_FORMAT[0],
|
||||||
|
_gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* do NOT use a single debug function before this line has been run */
|
/* do NOT use a single debug function before this line has been run */
|
||||||
|
@ -490,6 +495,48 @@ gst_debug_print_object (gpointer ptr)
|
||||||
return g_strdup_printf ("%p", ptr);
|
return g_strdup_printf ("%p", ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
gst_debug_print_segment (gpointer ptr)
|
||||||
|
{
|
||||||
|
GstSegment *segment = (GstSegment *) ptr;
|
||||||
|
|
||||||
|
/* nicely printed segment */
|
||||||
|
if (segment == NULL) {
|
||||||
|
return g_strdup ("(NULL)");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (segment->format) {
|
||||||
|
case GST_FORMAT_UNDEFINED:{
|
||||||
|
return g_strdup_printf ("UNDEFINED segment");
|
||||||
|
}
|
||||||
|
case GST_FORMAT_TIME:{
|
||||||
|
return g_strdup_printf ("time segment start=%" GST_TIME_FORMAT
|
||||||
|
", stop=%" GST_TIME_FORMAT ", last_stop=%" GST_TIME_FORMAT
|
||||||
|
", duration=%" GST_TIME_FORMAT ", rate=%f, applied_rate=%f"
|
||||||
|
", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
|
||||||
|
GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop),
|
||||||
|
GST_TIME_ARGS (segment->last_stop), GST_TIME_ARGS (segment->duration),
|
||||||
|
segment->rate, segment->applied_rate, (guint) segment->flags,
|
||||||
|
GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->accum));
|
||||||
|
}
|
||||||
|
default:{
|
||||||
|
const gchar *format_name;
|
||||||
|
|
||||||
|
format_name = gst_format_get_name (segment->format);
|
||||||
|
if (G_UNLIKELY (format_name == NULL))
|
||||||
|
format_name = "(UNKNOWN FORMAT)";
|
||||||
|
return g_strdup_printf ("%s segment start=%" G_GINT64_FORMAT
|
||||||
|
", stop=%" G_GINT64_FORMAT ", last_stop=%" G_GINT64_FORMAT
|
||||||
|
", duration=%" G_GINT64_FORMAT ", rate=%f, applied_rate=%f"
|
||||||
|
", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
|
||||||
|
format_name, segment->start, segment->stop, segment->last_stop,
|
||||||
|
segment->duration, segment->rate, segment->applied_rate,
|
||||||
|
(guint) segment->flags, GST_TIME_ARGS (segment->time),
|
||||||
|
GST_TIME_ARGS (segment->accum));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_debug_construct_term_color:
|
* gst_debug_construct_term_color:
|
||||||
* @colorinfo: the color info
|
* @colorinfo: the color info
|
||||||
|
@ -1174,7 +1221,7 @@ _gst_debug_register_funcptr (GstDebugFuncPtr func, gchar * ptrname)
|
||||||
|
|
||||||
#ifdef HAVE_PRINTF_EXTENSION
|
#ifdef HAVE_PRINTF_EXTENSION
|
||||||
static int
|
static int
|
||||||
_gst_info_printf_extension (FILE * stream, const struct printf_info *info,
|
_gst_info_printf_extension_ptr (FILE * stream, const struct printf_info *info,
|
||||||
const void *const *args)
|
const void *const *args)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
@ -1188,7 +1235,26 @@ _gst_info_printf_extension (FILE * stream, const struct printf_info *info,
|
||||||
len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
|
len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
|
||||||
buffer);
|
buffer);
|
||||||
|
|
||||||
free (buffer);
|
g_free (buffer);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_gst_info_printf_extension_segment (FILE * stream,
|
||||||
|
const struct printf_info *info, const void *const *args)
|
||||||
|
{
|
||||||
|
char *buffer;
|
||||||
|
int len;
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
|
buffer = NULL;
|
||||||
|
ptr = *(void **) args[0];
|
||||||
|
|
||||||
|
buffer = gst_debug_print_segment (ptr);
|
||||||
|
len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
|
||||||
|
buffer);
|
||||||
|
|
||||||
|
g_free (buffer);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
127
tests/check/gst/gstinfo.c
Normal file
127
tests/check/gst/gstinfo.c
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
/* GStreamer
|
||||||
|
*
|
||||||
|
* Unit tests for GstInfo
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gst/check/gstcheck.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
segment_printf_extension_log_func (GstDebugCategory * category,
|
||||||
|
GstDebugLevel level, const gchar * file, const gchar * function,
|
||||||
|
gint line, GObject * object, GstDebugMessage * message, gpointer unused)
|
||||||
|
{
|
||||||
|
const gchar *dbg_msg;
|
||||||
|
|
||||||
|
dbg_msg = gst_debug_message_get (message);
|
||||||
|
fail_unless (dbg_msg != NULL);
|
||||||
|
|
||||||
|
/* g_print ("%s\n", dbg_msg); */
|
||||||
|
|
||||||
|
/* quick hack to still get stuff to show if GST_DEBUG is set */
|
||||||
|
if (g_getenv ("GST_DEBUG")) {
|
||||||
|
gst_debug_log_default (category, level, file, function, line, object,
|
||||||
|
message, unused);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check our GST_SEGMENT_FORMAT printf extension stuff */
|
||||||
|
GST_START_TEST (info_segment_format_printf_extension)
|
||||||
|
{
|
||||||
|
/* set up our own log function to make sure the code in gstinfo is actually
|
||||||
|
* executed without GST_DEBUG being set or it being output to stdout */
|
||||||
|
gst_debug_remove_log_function (gst_debug_log_default);
|
||||||
|
gst_debug_add_log_function (segment_printf_extension_log_func, NULL);
|
||||||
|
|
||||||
|
gst_debug_set_default_threshold (GST_LEVEL_LOG);
|
||||||
|
|
||||||
|
/* TIME segment */
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
|
||||||
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
||||||
|
|
||||||
|
gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
|
||||||
|
GST_FORMAT_TIME, 0, 5 * 60 * GST_SECOND, 0);
|
||||||
|
|
||||||
|
segment.last_stop = 2 * GST_SECOND;
|
||||||
|
segment.duration = 90 * 60 * GST_SECOND;
|
||||||
|
|
||||||
|
GST_LOG ("TIME: %" GST_SEGMENT_FORMAT, &segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BYTE segment */
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
|
||||||
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
||||||
|
|
||||||
|
gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
|
||||||
|
GST_FORMAT_BYTES, 0, 9999999, 0);
|
||||||
|
|
||||||
|
GST_LOG ("BYTE: %" GST_SEGMENT_FORMAT, &segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UNKNOWN format segment (format numbers are consecutive from 0) */
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
|
||||||
|
gst_segment_init (&segment, 98765432);
|
||||||
|
|
||||||
|
gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
|
||||||
|
GST_FORMAT_BYTES, 0, 987654321, 0);
|
||||||
|
|
||||||
|
GST_LOG ("UNKNOWN: %" GST_SEGMENT_FORMAT, &segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UNDEFINED format segment */
|
||||||
|
{
|
||||||
|
GstSegment segment;
|
||||||
|
|
||||||
|
gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
|
||||||
|
|
||||||
|
GST_LOG ("UNDEFINED: %" GST_SEGMENT_FORMAT, &segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NULL segment */
|
||||||
|
GST_LOG ("NULL: %" GST_SEGMENT_FORMAT, NULL);
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
gst_debug_set_default_threshold (GST_LEVEL_NONE);
|
||||||
|
gst_debug_add_log_function (gst_debug_log_default, NULL);
|
||||||
|
gst_debug_remove_log_function (segment_printf_extension_log_func);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
static Suite *
|
||||||
|
gst_info_suite (void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create ("GstInfo");
|
||||||
|
TCase *tc_chain = tcase_create ("info");
|
||||||
|
|
||||||
|
tcase_set_timeout (tc_chain, 30);
|
||||||
|
|
||||||
|
suite_add_tcase (s, tc_chain);
|
||||||
|
tcase_add_test (tc_chain, info_segment_format_printf_extension);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_CHECK_MAIN (gst_info);
|
Loading…
Reference in a new issue