mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
spa: move debug log defines to one place
Use spa_debug to debug formats. Make debug go to stdout by default.
This commit is contained in:
parent
136989eaa6
commit
a16cd95593
7 changed files with 82 additions and 42 deletions
|
|
@ -38,14 +38,11 @@ extern "C" {
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <spa/debug/log.h>
|
||||||
#include <spa/debug/mem.h>
|
#include <spa/debug/mem.h>
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
#include <spa/buffer/type-info.h>
|
#include <spa/buffer/type-info.h>
|
||||||
|
|
||||||
#ifndef spa_debug
|
|
||||||
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer)
|
static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,9 @@ extern "C" {
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <spa/debug/log.h>
|
||||||
#include <spa/utils/dict.h>
|
#include <spa/utils/dict.h>
|
||||||
|
|
||||||
#ifndef spa_debug
|
|
||||||
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int spa_debug_dict(int indent, const struct spa_dict *dict)
|
static inline int spa_debug_dict(int indent, const struct spa_dict *dict)
|
||||||
{
|
{
|
||||||
const struct spa_dict_item *item;
|
const struct spa_dict_item *item;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <spa/pod/parser.h>
|
#include <spa/pod/parser.h>
|
||||||
|
#include <spa/debug/log.h>
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
#include <spa/param/type-info.h>
|
#include <spa/param/type-info.h>
|
||||||
#include <spa/param/format-utils.h>
|
#include <spa/param/format-utils.h>
|
||||||
|
|
@ -45,7 +46,7 @@ spa_debug_format_value(const struct spa_type_info *info,
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPA_TYPE_Bool:
|
case SPA_TYPE_Bool:
|
||||||
fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false");
|
spa_debugn("%s", *(int32_t *) body ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Id:
|
case SPA_TYPE_Id:
|
||||||
{
|
{
|
||||||
|
|
@ -55,41 +56,41 @@ spa_debug_format_value(const struct spa_type_info *info,
|
||||||
snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body);
|
snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body);
|
||||||
str = tmp;
|
str = tmp;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s", str);
|
spa_debugn("%s", str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPA_TYPE_Int:
|
case SPA_TYPE_Int:
|
||||||
fprintf(stderr, "%d", *(int32_t *) body);
|
spa_debugn("%d", *(int32_t *) body);
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Long:
|
case SPA_TYPE_Long:
|
||||||
fprintf(stderr, "%" PRIi64, *(int64_t *) body);
|
spa_debugn("%" PRIi64, *(int64_t *) body);
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Float:
|
case SPA_TYPE_Float:
|
||||||
fprintf(stderr, "%f", *(float *) body);
|
spa_debugn("%f", *(float *) body);
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Double:
|
case SPA_TYPE_Double:
|
||||||
fprintf(stderr, "%g", *(double *) body);
|
spa_debugn("%g", *(double *) body);
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_String:
|
case SPA_TYPE_String:
|
||||||
fprintf(stderr, "%s", (char *) body);
|
spa_debugn("%s", (char *) body);
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Rectangle:
|
case SPA_TYPE_Rectangle:
|
||||||
{
|
{
|
||||||
struct spa_rectangle *r = (struct spa_rectangle *)body;
|
struct spa_rectangle *r = (struct spa_rectangle *)body;
|
||||||
fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height);
|
spa_debugn("%" PRIu32 "x%" PRIu32, r->width, r->height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPA_TYPE_Fraction:
|
case SPA_TYPE_Fraction:
|
||||||
{
|
{
|
||||||
struct spa_fraction *f = (struct spa_fraction *)body;
|
struct spa_fraction *f = (struct spa_fraction *)body;
|
||||||
fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom);
|
spa_debugn("%" PRIu32 "/%" PRIu32, f->num, f->denom);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPA_TYPE_Bitmap:
|
case SPA_TYPE_Bitmap:
|
||||||
fprintf(stderr, "Bitmap");
|
spa_debugn("Bitmap");
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Bytes:
|
case SPA_TYPE_Bytes:
|
||||||
fprintf(stderr, "Bytes");
|
spa_debugn("Bytes");
|
||||||
break;
|
break;
|
||||||
case SPA_TYPE_Array:
|
case SPA_TYPE_Array:
|
||||||
{
|
{
|
||||||
|
|
@ -97,17 +98,17 @@ spa_debug_format_value(const struct spa_type_info *info,
|
||||||
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
|
struct spa_pod_array_body *b = (struct spa_pod_array_body *)body;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
info = info && info->values ? info->values : info;
|
info = info && info->values ? info->values : info;
|
||||||
fprintf(stderr, "< ");
|
spa_debugn("< ");
|
||||||
SPA_POD_ARRAY_BODY_FOREACH(b, size, p) {
|
SPA_POD_ARRAY_BODY_FOREACH(b, size, p) {
|
||||||
if (i++ > 0)
|
if (i++ > 0)
|
||||||
fprintf(stderr, ", ");
|
spa_debugn(", ");
|
||||||
spa_debug_format_value(info, b->child.type, p, b->child.size);
|
spa_debug_format_value(info, b->child.type, p, b->child.size);
|
||||||
}
|
}
|
||||||
fprintf(stderr, " >");
|
spa_debugn(" >");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "INVALID type %d", type);
|
spa_debugn("INVALID type %d", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -133,7 +134,7 @@ static inline int spa_debug_format(int indent,
|
||||||
media_type = spa_debug_type_find_name(spa_type_media_type, mtype);
|
media_type = spa_debug_type_find_name(spa_type_media_type, mtype);
|
||||||
media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype);
|
media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype);
|
||||||
|
|
||||||
fprintf(stderr, "%*s %s/%s\n", indent, "",
|
spa_debug("%*s %s/%s", indent, "",
|
||||||
media_type ? spa_debug_type_short_name(media_type) : "unknown",
|
media_type ? spa_debug_type_short_name(media_type) : "unknown",
|
||||||
media_subtype ? spa_debug_type_short_name(media_subtype) : "unknown");
|
media_subtype ? spa_debug_type_short_name(media_subtype) : "unknown");
|
||||||
|
|
||||||
|
|
@ -160,7 +161,7 @@ static inline int spa_debug_format(int indent,
|
||||||
ti = spa_debug_type_find(info, prop->key);
|
ti = spa_debug_type_find(info, prop->key);
|
||||||
key = ti ? ti->name : NULL;
|
key = ti ? ti->name : NULL;
|
||||||
|
|
||||||
fprintf(stderr, "%*s %16s : (%s) ", indent, "",
|
spa_debugn("%*s %16s : (%s) ", indent, "",
|
||||||
key ? spa_debug_type_short_name(key) : "unknown",
|
key ? spa_debug_type_short_name(key) : "unknown",
|
||||||
spa_debug_type_short_name(spa_types[type].name));
|
spa_debug_type_short_name(spa_types[type].name));
|
||||||
|
|
||||||
|
|
@ -185,17 +186,17 @@ static inline int spa_debug_format(int indent,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "%s", ssep);
|
spa_debugn("%s", ssep);
|
||||||
|
|
||||||
for (i = 1; i < n_vals; i++) {
|
for (i = 1; i < n_vals; i++) {
|
||||||
vals = SPA_PTROFF(vals, size, void);
|
vals = SPA_PTROFF(vals, size, void);
|
||||||
if (i > 1)
|
if (i > 1)
|
||||||
fprintf(stderr, "%s", sep);
|
spa_debugn("%s", sep);
|
||||||
spa_debug_format_value(ti ? ti->values : NULL, type, vals, size);
|
spa_debug_format_value(ti ? ti->values : NULL, type, vals, size);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s", esep);
|
spa_debugn("%s", esep);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
spa_debugn("\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
53
spa/include/spa/debug/log.h
Normal file
53
spa/include/spa/debug/log.h
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* Simple Plugin API
|
||||||
|
*
|
||||||
|
* Copyright © 2022 Wim Taymans
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SPA_DEBUG_LOG_H
|
||||||
|
#define SPA_DEBUG_LOG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
/**
|
||||||
|
* \addtogroup spa_debug
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef spa_debug
|
||||||
|
#define spa_debug(fmt,...) ({ printf(fmt"\n", ## __VA_ARGS__); })
|
||||||
|
#endif
|
||||||
|
#ifndef spa_debugn
|
||||||
|
#define spa_debugn(fmt,...) ({ printf(fmt, ## __VA_ARGS__); })
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SPA_DEBUG_LOGH */
|
||||||
|
|
@ -29,16 +29,14 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \addtogroup spa_debug
|
* \addtogroup spa_debug
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <spa/utils/dict.h>
|
#include <spa/debug/log.h>
|
||||||
|
|
||||||
#ifndef spa_debug
|
|
||||||
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int spa_debug_mem(int indent, const void *data, size_t size)
|
static inline int spa_debug_mem(int indent, const void *data, size_t size)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,9 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <spa/node/node.h>
|
#include <spa/node/node.h>
|
||||||
|
#include <spa/debug/log.h>
|
||||||
#include <spa/debug/dict.h>
|
#include <spa/debug/dict.h>
|
||||||
|
|
||||||
#ifndef spa_debug
|
|
||||||
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int spa_debug_port_info(int indent, const struct spa_port_info *info)
|
static inline int spa_debug_port_info(int indent, const struct spa_port_info *info)
|
||||||
{
|
{
|
||||||
spa_debug("%*s" "struct spa_port_info %p:", indent, "", info);
|
spa_debug("%*s" "struct spa_port_info %p:", indent, "", info);
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,12 @@ extern "C" {
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <spa/debug/log.h>
|
||||||
#include <spa/debug/mem.h>
|
#include <spa/debug/mem.h>
|
||||||
#include <spa/debug/types.h>
|
#include <spa/debug/types.h>
|
||||||
#include <spa/pod/pod.h>
|
#include <spa/pod/pod.h>
|
||||||
#include <spa/pod/iter.h>
|
#include <spa/pod/iter.h>
|
||||||
|
|
||||||
#ifndef spa_debug
|
|
||||||
#define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); })
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
spa_debug_pod_value(int indent, const struct spa_type_info *info,
|
spa_debug_pod_value(int indent, const struct spa_type_info *info,
|
||||||
uint32_t type, void *body, uint32_t size)
|
uint32_t type, void *body, uint32_t size)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue