From 3c67821c4a8ecfe198334f04d53687e8d67d24c5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 18 Jan 2023 13:09:00 +0100 Subject: [PATCH] spa: add context to debug functions Add new spa_debugc_ funnctions that take a context. The user should also redefine the spa_debugc macro to handle the context. Use this to let some plugins log the pod and format to the log without using the global logger. Also use this to remove our custom pod logger function by reusing the spa one with a custom context. --- spa/include/spa/debug/buffer.h | 70 +++++----- spa/include/spa/debug/dict.h | 10 +- spa/include/spa/debug/format.h | 11 +- spa/include/spa/debug/log.h | 11 +- spa/include/spa/debug/mem.h | 8 +- spa/include/spa/debug/node.h | 18 ++- spa/include/spa/debug/pod.h | 76 ++++++----- spa/plugins/alsa/alsa-acp-device.c | 7 +- spa/plugins/alsa/alsa-pcm-device.c | 5 +- spa/plugins/audioconvert/audioadapter.c | 13 +- spa/plugins/bluez5/bluez5-device.c | 9 +- spa/plugins/jack/jack-device.c | 5 +- spa/plugins/videoconvert/videoadapter.c | 13 +- src/pipewire/log.c | 170 ++---------------------- 14 files changed, 158 insertions(+), 268 deletions(-) diff --git a/spa/include/spa/debug/buffer.h b/spa/include/spa/debug/buffer.h index df6beaad4..a006c3b2c 100644 --- a/spa/include/spa/debug/buffer.h +++ b/spa/include/spa/debug/buffer.h @@ -43,51 +43,51 @@ extern "C" { #include #include -static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) +static inline int spa_debugc_buffer(void *ctx, int indent, const struct spa_buffer *buffer) { uint32_t i; - spa_debug("%*s" "struct spa_buffer %p:", indent, "", buffer); - spa_debug("%*s" " n_metas: %u (at %p)", indent, "", buffer->n_metas, buffer->metas); + spa_debugc(ctx, "%*s" "struct spa_buffer %p:", indent, "", buffer); + spa_debugc(ctx, "%*s" " n_metas: %u (at %p)", indent, "", buffer->n_metas, buffer->metas); for (i = 0; i < buffer->n_metas; i++) { struct spa_meta *m = &buffer->metas[i]; const char *type_name; type_name = spa_debug_type_find_name(spa_type_meta_type, m->type); - spa_debug("%*s" " meta %d: type %d (%s), data %p, size %d:", indent, "", i, m->type, + spa_debugc(ctx, "%*s" " meta %d: type %d (%s), data %p, size %d:", indent, "", i, m->type, type_name, m->data, m->size); switch (m->type) { case SPA_META_Header: { struct spa_meta_header *h = (struct spa_meta_header*)m->data; - spa_debug("%*s" " struct spa_meta_header:", indent, ""); - spa_debug("%*s" " flags: %08x", indent, "", h->flags); - spa_debug("%*s" " offset: %u", indent, "", h->offset); - spa_debug("%*s" " seq: %" PRIu64, indent, "", h->seq); - spa_debug("%*s" " pts: %" PRIi64, indent, "", h->pts); - spa_debug("%*s" " dts_offset: %" PRIi64, indent, "", h->dts_offset); + spa_debugc(ctx, "%*s" " struct spa_meta_header:", indent, ""); + spa_debugc(ctx, "%*s" " flags: %08x", indent, "", h->flags); + spa_debugc(ctx, "%*s" " offset: %u", indent, "", h->offset); + spa_debugc(ctx, "%*s" " seq: %" PRIu64, indent, "", h->seq); + spa_debugc(ctx, "%*s" " pts: %" PRIi64, indent, "", h->pts); + spa_debugc(ctx, "%*s" " dts_offset: %" PRIi64, indent, "", h->dts_offset); break; } case SPA_META_VideoCrop: { struct spa_meta_region *h = (struct spa_meta_region*)m->data; - spa_debug("%*s" " struct spa_meta_region:", indent, ""); - spa_debug("%*s" " x: %d", indent, "", h->region.position.x); - spa_debug("%*s" " y: %d", indent, "", h->region.position.y); - spa_debug("%*s" " width: %d", indent, "", h->region.size.width); - spa_debug("%*s" " height: %d", indent, "", h->region.size.height); + spa_debugc(ctx, "%*s" " struct spa_meta_region:", indent, ""); + spa_debugc(ctx, "%*s" " x: %d", indent, "", h->region.position.x); + spa_debugc(ctx, "%*s" " y: %d", indent, "", h->region.position.y); + spa_debugc(ctx, "%*s" " width: %d", indent, "", h->region.size.width); + spa_debugc(ctx, "%*s" " height: %d", indent, "", h->region.size.height); break; } case SPA_META_VideoDamage: { struct spa_meta_region *h; spa_meta_for_each(h, m) { - spa_debug("%*s" " struct spa_meta_region:", indent, ""); - spa_debug("%*s" " x: %d", indent, "", h->region.position.x); - spa_debug("%*s" " y: %d", indent, "", h->region.position.y); - spa_debug("%*s" " width: %d", indent, "", h->region.size.width); - spa_debug("%*s" " height: %d", indent, "", h->region.size.height); + spa_debugc(ctx, "%*s" " struct spa_meta_region:", indent, ""); + spa_debugc(ctx, "%*s" " x: %d", indent, "", h->region.position.x); + spa_debugc(ctx, "%*s" " y: %d", indent, "", h->region.position.y); + spa_debugc(ctx, "%*s" " width: %d", indent, "", h->region.size.width); + spa_debugc(ctx, "%*s" " height: %d", indent, "", h->region.size.height); } break; } @@ -96,28 +96,32 @@ static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) case SPA_META_Cursor: break; default: - spa_debug("%*s" " Unknown:", indent, ""); - spa_debug_mem(5, m->data, m->size); + spa_debugc(ctx, "%*s" " Unknown:", indent, ""); + spa_debugc_mem(ctx, 5, m->data, m->size); } } - spa_debug("%*s" " n_datas: \t%u (at %p)", indent, "", buffer->n_datas, buffer->datas); + spa_debugc(ctx, "%*s" " n_datas: \t%u (at %p)", indent, "", buffer->n_datas, buffer->datas); for (i = 0; i < buffer->n_datas; i++) { struct spa_data *d = &buffer->datas[i]; - spa_debug("%*s" " type: %d (%s)", indent, "", d->type, + spa_debugc(ctx, "%*s" " type: %d (%s)", indent, "", d->type, spa_debug_type_find_name(spa_type_data_type, d->type)); - spa_debug("%*s" " flags: %d", indent, "", d->flags); - spa_debug("%*s" " data: %p", indent, "", d->data); - spa_debug("%*s" " fd: %" PRIi64, indent, "", d->fd); - spa_debug("%*s" " offset: %d", indent, "", d->mapoffset); - spa_debug("%*s" " maxsize: %u", indent, "", d->maxsize); - spa_debug("%*s" " chunk: %p", indent, "", d->chunk); - spa_debug("%*s" " offset: %d", indent, "", d->chunk->offset); - spa_debug("%*s" " size: %u", indent, "", d->chunk->size); - spa_debug("%*s" " stride: %d", indent, "", d->chunk->stride); + spa_debugc(ctx, "%*s" " flags: %d", indent, "", d->flags); + spa_debugc(ctx, "%*s" " data: %p", indent, "", d->data); + spa_debugc(ctx, "%*s" " fd: %" PRIi64, indent, "", d->fd); + spa_debugc(ctx, "%*s" " offset: %d", indent, "", d->mapoffset); + spa_debugc(ctx, "%*s" " maxsize: %u", indent, "", d->maxsize); + spa_debugc(ctx, "%*s" " chunk: %p", indent, "", d->chunk); + spa_debugc(ctx, "%*s" " offset: %d", indent, "", d->chunk->offset); + spa_debugc(ctx, "%*s" " size: %u", indent, "", d->chunk->size); + spa_debugc(ctx, "%*s" " stride: %d", indent, "", d->chunk->stride); } return 0; } +static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) +{ + return spa_debugc_buffer(NULL, indent, buffer); +} /** * \} */ diff --git a/spa/include/spa/debug/dict.h b/spa/include/spa/debug/dict.h index 10498f27c..e05414afd 100644 --- a/spa/include/spa/debug/dict.h +++ b/spa/include/spa/debug/dict.h @@ -37,16 +37,20 @@ extern "C" { #include #include -static inline int spa_debug_dict(int indent, const struct spa_dict *dict) +static inline int spa_debugc_dict(void *ctx, int indent, const struct spa_dict *dict) { const struct spa_dict_item *item; - spa_debug("%*sflags:%08x n_items:%d", indent, "", dict->flags, dict->n_items); + spa_debugc(ctx, "%*sflags:%08x n_items:%d", indent, "", dict->flags, dict->n_items); spa_dict_for_each(item, dict) { - spa_debug("%*s %s = \"%s\"", indent, "", item->key, item->value); + spa_debugc(ctx, "%*s %s = \"%s\"", indent, "", item->key, item->value); } return 0; } +static inline int spa_debug_dict(int indent, const struct spa_dict *dict) +{ + return spa_debugc_dict(NULL, indent, dict); +} /** * \} */ diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 54748dcaf..52bf29335 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -127,7 +127,7 @@ spa_debug_format_value(const struct spa_type_info *info, return 0; } -static inline int spa_debug_format(int indent, +static inline int spa_debugc_format(void *ctx, int indent, const struct spa_type_info *info, const struct spa_pod *format) { const char *media_type; @@ -147,7 +147,7 @@ static inline int spa_debug_format(int indent, media_type = spa_debug_type_find_name(spa_type_media_type, mtype); media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype); - spa_debug("%*s %s/%s", indent, "", + spa_debugc(ctx, "%*s %s/%s", indent, "", media_type ? spa_debug_type_short_name(media_type) : "unknown", media_subtype ? spa_debug_type_short_name(media_subtype) : "unknown"); @@ -212,11 +212,16 @@ static inline int spa_debug_format(int indent, } spa_debug_buffer_append(&buf, "%s", esep); } - spa_debug("%s", buffer); + spa_debugc(ctx, "%s", buffer); } return 0; } +static inline int spa_debug_format(int indent, + const struct spa_type_info *info, const struct spa_pod *format) +{ + return spa_debugc_format(NULL, indent, info, format); +} /** * \} */ diff --git a/spa/include/spa/debug/log.h b/spa/include/spa/debug/log.h index ca6c6e899..ddb695106 100644 --- a/spa/include/spa/debug/log.h +++ b/spa/include/spa/debug/log.h @@ -38,11 +38,14 @@ extern "C" { * \{ */ -#ifndef spa_debug -#define spa_debug(fmt,...) ({ printf((fmt"\n"), ## __VA_ARGS__); }) -#endif #ifndef spa_debugn -#define spa_debugn(fmt,...) ({ printf((fmt), ## __VA_ARGS__); }) +#define spa_debugn(_fmt,...) printf((_fmt), ## __VA_ARGS__) +#endif +#ifndef spa_debug +#define spa_debug(_fmt,...) spa_debugn(_fmt"\n", ## __VA_ARGS__) +#endif +#ifndef spa_debugc +#define spa_debugc(_c,_fmt,...) spa_debug(_fmt, ## __VA_ARGS__) #endif struct spa_debug_buffer { diff --git a/spa/include/spa/debug/mem.h b/spa/include/spa/debug/mem.h index 4999c00bd..1c87572b3 100644 --- a/spa/include/spa/debug/mem.h +++ b/spa/include/spa/debug/mem.h @@ -38,7 +38,7 @@ extern "C" { #include -static inline int spa_debug_mem(int indent, const void *data, size_t size) +static inline int spa_debugc_mem(void *ctx, int indent, const void *data, size_t size) { const uint8_t *t = (const uint8_t*)data; char buffer[512]; @@ -50,12 +50,16 @@ static inline int spa_debug_mem(int indent, const void *data, size_t size) pos = sprintf(buffer, "%p: ", &t[i]); pos += sprintf(buffer + pos, "%02x ", t[i]); if (i % 16 == 15 || i == size - 1) { - spa_debug("%*s" "%s", indent, "", buffer); + spa_debugc(ctx, "%*s" "%s", indent, "", buffer); } } return 0; } +static inline int spa_debug_mem(int indent, const void *data, size_t size) +{ + return spa_debugc_mem(NULL, indent, data, size); +} /** * \} */ diff --git a/spa/include/spa/debug/node.h b/spa/include/spa/debug/node.h index 6ec14b4fa..feef4fff6 100644 --- a/spa/include/spa/debug/node.h +++ b/spa/include/spa/debug/node.h @@ -38,19 +38,23 @@ extern "C" { #include #include -static inline int spa_debug_port_info(int indent, const struct spa_port_info *info) +static inline int spa_debugc_port_info(void *ctx, int indent, const struct spa_port_info *info) { - spa_debug("%*s" "struct spa_port_info %p:", indent, "", info); - spa_debug("%*s" " flags: \t%08" PRIx64, indent, "", info->flags); - spa_debug("%*s" " rate: \t%d/%d", indent, "", info->rate.num, info->rate.denom); - spa_debug("%*s" " props:", indent, ""); + spa_debugc(ctx, "%*s" "struct spa_port_info %p:", indent, "", info); + spa_debugc(ctx, "%*s" " flags: \t%08" PRIx64, indent, "", info->flags); + spa_debugc(ctx, "%*s" " rate: \t%d/%d", indent, "", info->rate.num, info->rate.denom); + spa_debugc(ctx, "%*s" " props:", indent, ""); if (info->props) - spa_debug_dict(indent + 2, info->props); + spa_debugc_dict(ctx, indent + 2, info->props); else - spa_debug("%*s" " none", indent, ""); + spa_debugc(ctx, "%*s" " none", indent, ""); return 0; } +static inline int spa_debug_port_info(int indent, const struct spa_port_info *info) +{ + return spa_debugc_port_info(NULL, indent, info); +} /** * \} */ diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index 1468aab04..881a56c06 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -41,56 +41,56 @@ extern "C" { #include static inline int -spa_debug_pod_value(int indent, const struct spa_type_info *info, +spa_debugc_pod_value(void *ctx, int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { switch (type) { case SPA_TYPE_Bool: - spa_debug("%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false"); + spa_debugc(ctx, "%*s" "Bool %s", indent, "", (*(int32_t *) body) ? "true" : "false"); break; case SPA_TYPE_Id: - spa_debug("%*s" "Id %-8d (%s)", indent, "", *(int32_t *) body, + spa_debugc(ctx, "%*s" "Id %-8d (%s)", indent, "", *(int32_t *) body, spa_debug_type_find_name(info, *(int32_t *) body)); break; case SPA_TYPE_Int: - spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body); + spa_debugc(ctx, "%*s" "Int %d", indent, "", *(int32_t *) body); break; case SPA_TYPE_Long: - spa_debug("%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body); + spa_debugc(ctx, "%*s" "Long %" PRIi64 "", indent, "", *(int64_t *) body); break; case SPA_TYPE_Float: - spa_debug("%*s" "Float %f", indent, "", *(float *) body); + spa_debugc(ctx, "%*s" "Float %f", indent, "", *(float *) body); break; case SPA_TYPE_Double: - spa_debug("%*s" "Double %f", indent, "", *(double *) body); + spa_debugc(ctx, "%*s" "Double %f", indent, "", *(double *) body); break; case SPA_TYPE_String: - spa_debug("%*s" "String \"%s\"", indent, "", (char *) body); + spa_debugc(ctx, "%*s" "String \"%s\"", indent, "", (char *) body); break; case SPA_TYPE_Fd: - spa_debug("%*s" "Fd %d", indent, "", *(int *) body); + spa_debugc(ctx, "%*s" "Fd %d", indent, "", *(int *) body); break; case SPA_TYPE_Pointer: { struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body; - spa_debug("%*s" "Pointer %s %p", indent, "", + spa_debugc(ctx, "%*s" "Pointer %s %p", indent, "", spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value); break; } case SPA_TYPE_Rectangle: { struct spa_rectangle *r = (struct spa_rectangle *)body; - spa_debug("%*s" "Rectangle %dx%d", indent, "", r->width, r->height); + spa_debugc(ctx, "%*s" "Rectangle %dx%d", indent, "", r->width, r->height); break; } case SPA_TYPE_Fraction: { struct spa_fraction *f = (struct spa_fraction *)body; - spa_debug("%*s" "Fraction %d/%d", indent, "", f->num, f->denom); + spa_debugc(ctx, "%*s" "Fraction %d/%d", indent, "", f->num, f->denom); break; } case SPA_TYPE_Bitmap: - spa_debug("%*s" "Bitmap", indent, ""); + spa_debugc(ctx, "%*s" "Bitmap", indent, ""); break; case SPA_TYPE_Array: { @@ -98,12 +98,12 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, void *p; const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type); - spa_debug("%*s" "Array: child.size %d, child.type %s", indent, "", + spa_debugc(ctx, "%*s" "Array: child.size %d, child.type %s", indent, "", b->child.size, ti ? ti->name : "unknown"); info = info && info->values ? info->values : info; SPA_POD_ARRAY_BODY_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size); + spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); break; } case SPA_TYPE_Choice: @@ -112,19 +112,19 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, void *p; const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type); - spa_debug("%*s" "Choice: type %s, flags %08x %d %d", indent, "", + spa_debugc(ctx, "%*s" "Choice: type %s, flags %08x %d %d", indent, "", ti ? ti->name : "unknown", b->flags, size, b->child.size); SPA_POD_CHOICE_BODY_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size); + spa_debugc_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); break; } case SPA_TYPE_Struct: { struct spa_pod *b = (struct spa_pod *)body, *p; - spa_debug("%*s" "Struct: size %d", indent, "", size); + spa_debugc(ctx, "%*s" "Struct: size %d", indent, "", size); SPA_POD_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size); + spa_debugc_pod_value(ctx, indent + 2, info, p->type, SPA_POD_BODY(p), p->size); break; } case SPA_TYPE_Object: @@ -137,7 +137,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, ii = ti ? spa_debug_type_find(ti->values, 0) : NULL; ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL; - spa_debug("%*s" "Object: size %d, type %s (%d), id %s (%d)", indent, "", size, + spa_debugc(ctx, "%*s" "Object: size %d, type %s (%d), id %s (%d)", indent, "", size, ti ? ti->name : "unknown", b->type, ii ? ii->name : "unknown", b->id); info = ti ? ti->values : info; @@ -145,10 +145,10 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, SPA_POD_OBJECT_BODY_FOREACH(b, size, p) { ii = spa_debug_type_find(info, p->key); - spa_debug("%*s" "Prop: key %s (%d), flags %08x", indent+2, "", + spa_debugc(ctx, "%*s" "Prop: key %s (%d), flags %08x", indent+2, "", ii ? ii->name : "unknown", p->key, p->flags); - spa_debug_pod_value(indent + 4, ii ? ii->values : NULL, + spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL, p->value.type, SPA_POD_CONTENTS(struct spa_pod_prop, p), p->value.size); @@ -163,16 +163,16 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, ti = spa_debug_type_find(info, b->unit); - spa_debug("%*s" "Sequence: size %d, unit %s", indent, "", size, + spa_debugc(ctx, "%*s" "Sequence: size %d, unit %s", indent, "", size, ti ? ti->name : "unknown"); SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) { ii = spa_debug_type_find(spa_type_control, c->type); - spa_debug("%*s" "Control: offset %d, type %s", indent+2, "", + spa_debugc(ctx, "%*s" "Control: offset %d, type %s", indent+2, "", c->offset, ii ? ii->name : "unknown"); - spa_debug_pod_value(indent + 4, ii ? ii->values : NULL, + spa_debugc_pod_value(ctx, indent + 4, ii ? ii->values : NULL, c->value.type, SPA_POD_CONTENTS(struct spa_pod_control, c), c->value.size); @@ -180,29 +180,41 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, break; } case SPA_TYPE_Bytes: - spa_debug("%*s" "Bytes", indent, ""); - spa_debug_mem(indent + 2, body, size); + spa_debugc(ctx, "%*s" "Bytes", indent, ""); + spa_debugc_mem(ctx, indent + 2, body, size); break; case SPA_TYPE_None: - spa_debug("%*s" "None", indent, ""); - spa_debug_mem(indent + 2, body, size); + spa_debugc(ctx, "%*s" "None", indent, ""); + spa_debugc_mem(ctx, indent + 2, body, size); break; default: - spa_debug("%*s" "unhandled POD type %d", indent, "", type); + spa_debugc(ctx, "%*s" "unhandled POD type %d", indent, "", type); break; } return 0; } -static inline int spa_debug_pod(int indent, +static inline int spa_debugc_pod(void *ctx, int indent, const struct spa_type_info *info, const struct spa_pod *pod) { - return spa_debug_pod_value(indent, info ? info : SPA_TYPE_ROOT, + return spa_debugc_pod_value(ctx, indent, info ? info : SPA_TYPE_ROOT, SPA_POD_TYPE(pod), SPA_POD_BODY(pod), SPA_POD_BODY_SIZE(pod)); } +static inline int +spa_debug_pod_value(int indent, const struct spa_type_info *info, + uint32_t type, void *body, uint32_t size) +{ + return spa_debugc_pod_value(NULL, indent, info, type, body, size); +} + +static inline int spa_debug_pod(int indent, + const struct spa_type_info *info, const struct spa_pod *pod) +{ + return spa_debugc_pod(NULL, indent, info, pod); +} /** * \} */ diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index a94b28d0f..de8fc325c 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -46,6 +46,9 @@ #include #include #include + +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include "alsa.h" @@ -736,7 +739,7 @@ static int impl_set_param(void *object, SPA_PARAM_PROFILE_index, SPA_POD_Int(&idx), SPA_PARAM_PROFILE_save, SPA_POD_OPT_Bool(&save))) < 0) { spa_log_warn(this->log, "can't parse profile"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } @@ -761,7 +764,7 @@ static int impl_set_param(void *object, SPA_PARAM_ROUTE_props, SPA_POD_OPT_Pod(&props), SPA_PARAM_ROUTE_save, SPA_POD_OPT_Bool(&save))) < 0) { spa_log_warn(this->log, "can't parse route"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } if (device >= this->card->n_devices) diff --git a/spa/plugins/alsa/alsa-pcm-device.c b/spa/plugins/alsa/alsa-pcm-device.c index 1664e38f5..ac55c9578 100644 --- a/spa/plugins/alsa/alsa-pcm-device.c +++ b/spa/plugins/alsa/alsa-pcm-device.c @@ -44,6 +44,9 @@ #include #include #include + +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include "alsa.h" @@ -463,7 +466,7 @@ static int impl_set_param(void *object, SPA_TYPE_OBJECT_ParamProfile, NULL, SPA_PARAM_PROFILE_index, SPA_POD_Int(&idx))) < 0) { spa_log_warn(this->log, "can't parse profile"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index 12a5b1451..2b09879b9 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -45,10 +45,8 @@ #define SPA_LOG_TOPIC_DEFAULT log_topic static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audioadapter"); -static struct spa_log *global_log; - -#undef spa_debug -#define spa_debug(...) spa_log_debug(global_log, __VA_ARGS__) +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include @@ -338,7 +336,7 @@ static int debug_params(struct impl *this, struct spa_node *node, if (filter) { spa_log_error(this->log, "with this filter:"); - spa_debug_pod(2, NULL, filter); + spa_debugc_pod(this->log, 2, NULL, filter); } else { spa_log_error(this->log, "there was no filter"); } @@ -356,7 +354,7 @@ static int debug_params(struct impl *this, struct spa_node *node, break; } spa_log_error(this->log, "unmatched %s %d:", debug, count); - spa_debug_pod(2, NULL, param); + spa_debugc_pod(this->log, 2, NULL, param); count++; } if (count == 0) @@ -486,7 +484,7 @@ static int configure_format(struct impl *this, uint32_t flags, const struct spa_ spa_log_debug(this->log, "%p: configure format:", this); if (format && spa_log_level_enabled(this->log, SPA_LOG_LEVEL_DEBUG)) - spa_debug_format(0, NULL, format); + spa_debugc_format(this->log, 0, NULL, format); if ((res = spa_node_port_set_param(this->follower, this->direction, 0, @@ -1644,7 +1642,6 @@ impl_init(const struct spa_handle_factory *factory, this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); spa_log_topic_init(this->log, log_topic); - global_log = this->log; this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 9571c0674..2153a9cd5 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -48,6 +48,9 @@ #include #include #include + +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include "defs.h" @@ -2114,7 +2117,7 @@ static int impl_set_param(void *object, SPA_PARAM_PROFILE_index, SPA_POD_Int(&idx), SPA_PARAM_PROFILE_save, SPA_POD_OPT_Bool(&save))) < 0) { spa_log_warn(this->log, "can't parse profile"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } @@ -2142,7 +2145,7 @@ static int impl_set_param(void *object, SPA_PARAM_ROUTE_props, SPA_POD_OPT_Pod(&props), SPA_PARAM_ROUTE_save, SPA_POD_OPT_Bool(&save))) < 0) { spa_log_warn(this->log, "can't parse route"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } if (device > 1 || !this->nodes[device].active) @@ -2173,7 +2176,7 @@ static int impl_set_param(void *object, SPA_PROP_bluetoothAudioCodec, SPA_POD_OPT_Id(&codec_id), SPA_PROP_bluetoothOffloadActive, SPA_POD_OPT_Bool(&offload_active))) < 0) { spa_log_warn(this->log, "can't parse props"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } diff --git a/spa/plugins/jack/jack-device.c b/spa/plugins/jack/jack-device.c index fa4ccc2db..fe622e44c 100644 --- a/spa/plugins/jack/jack-device.c +++ b/spa/plugins/jack/jack-device.c @@ -43,6 +43,9 @@ #include #include #include + +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include "jack-client.h" @@ -337,7 +340,7 @@ static int impl_set_param(void *object, SPA_TYPE_OBJECT_ParamProfile, NULL, SPA_PARAM_PROFILE_index, SPA_POD_Int(&idx))) < 0) { spa_log_warn(this->log, "can't parse profile"); - spa_debug_pod(0, NULL, param); + spa_debugc_pod(this->log, 0, NULL, param); return res; } activate_profile(this, idx); diff --git a/spa/plugins/videoconvert/videoadapter.c b/spa/plugins/videoconvert/videoadapter.c index 3dac14c32..c0ee81bb4 100644 --- a/spa/plugins/videoconvert/videoadapter.c +++ b/spa/plugins/videoconvert/videoadapter.c @@ -45,10 +45,8 @@ #define SPA_LOG_TOPIC_DEFAULT log_topic static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.videoadapter"); -static struct spa_log *global_log; - -#undef spa_debug -#define spa_debug(...) spa_log_debug(global_log, __VA_ARGS__) +#undef spa_debugc +#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include #include @@ -304,7 +302,7 @@ static int debug_params(struct impl *this, struct spa_node *node, if (filter) { spa_log_error(this->log, "with this filter:"); - spa_debug_pod(2, NULL, filter); + spa_debugc_pod(this->log, 2, NULL, filter); } else { spa_log_error(this->log, "there was no filter"); } @@ -322,7 +320,7 @@ static int debug_params(struct impl *this, struct spa_node *node, break; } spa_log_error(this->log, "unmatched %s %d:", debug, count); - spa_debug_pod(2, NULL, param); + spa_debugc_pod(this->log, 2, NULL, param); count++; } if (count == 0) @@ -448,7 +446,7 @@ static int configure_format(struct impl *this, uint32_t flags, const struct spa_ spa_log_debug(this->log, "%p: configure format:", this); if (format && spa_log_level_enabled(this->log, SPA_LOG_LEVEL_DEBUG)) - spa_debug_format(0, NULL, format); + spa_debugc_format(this->log, 0, NULL, format); if ((res = spa_node_port_set_param(this->follower, this->direction, 0, @@ -1579,7 +1577,6 @@ impl_init(const struct spa_handle_factory *factory, this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); spa_log_topic_init(this->log, log_topic); - global_log = this->log; this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); diff --git a/src/pipewire/log.c b/src/pipewire/log.c index 22d14555b..674e9227d 100644 --- a/src/pipewire/log.c +++ b/src/pipewire/log.c @@ -239,163 +239,14 @@ struct log_ctx { const char *func; }; -#define _log(_c,fmt,...) pw_log_log(_c->level, _c->file, _c->line, _c->func, \ - "%*s" fmt, indent, "", ## __VA_ARGS__) +#undef spa_debugc +#define spa_debugc(_ctx,_fmt,...) \ +({ struct log_ctx *_c = _ctx; \ + pw_log_log(_c->level, _c->file, _c->line, _c->func, \ + _fmt, ## __VA_ARGS__); \ +}) -static inline int -log_pod_value(struct log_ctx *ctx, int indent, const struct spa_type_info *info, - uint32_t type, void *body, uint32_t size) -{ - switch (type) { - case SPA_TYPE_Bool: - _log(ctx, "Bool %s", (*(int32_t *) body) ? "true" : "false"); - break; - case SPA_TYPE_Id: - _log(ctx, "Id %-8d (%s)", *(int32_t *) body, - spa_debug_type_find_name(info, *(int32_t *) body)); - break; - case SPA_TYPE_Int: - _log(ctx, "Int %d", *(int32_t *) body); - break; - case SPA_TYPE_Long: - _log(ctx, "Long %" PRIi64 "", *(int64_t *) body); - break; - case SPA_TYPE_Float: - _log(ctx, "Float %f", *(float *) body); - break; - case SPA_TYPE_Double: - _log(ctx, "Double %f", *(double *) body); - break; - case SPA_TYPE_String: - _log(ctx, "String \"%s\"", (char *) body); - break; - case SPA_TYPE_Fd: - _log(ctx, "Fd %d", *(int *) body); - break; - case SPA_TYPE_Pointer: - { - struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body; - _log(ctx, "Pointer %s %p", - spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value); - break; - } - case SPA_TYPE_Rectangle: - { - struct spa_rectangle *r = (struct spa_rectangle *)body; - _log(ctx, "Rectangle %dx%d", r->width, r->height); - break; - } - case SPA_TYPE_Fraction: - { - struct spa_fraction *f = (struct spa_fraction *)body; - _log(ctx, "Fraction %d/%d", f->num, f->denom); - break; - } - case SPA_TYPE_Bitmap: - _log(ctx, "Bitmap"); - break; - case SPA_TYPE_Array: - { - struct spa_pod_array_body *b = (struct spa_pod_array_body *)body; - void *p; - const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type); - - _log(ctx, "Array: child.size %d, child.type %s", b->child.size, - ti ? ti->name : "unknown"); - - SPA_POD_ARRAY_BODY_FOREACH(b, size, p) - log_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); - break; - } - case SPA_TYPE_Choice: - { - struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body; - void *p; - const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type); - - _log(ctx, "Choice: type %s, flags %08x %d %d", - ti ? ti->name : "unknown", b->flags, size, b->child.size); - - SPA_POD_CHOICE_BODY_FOREACH(b, size, p) - log_pod_value(ctx, indent + 2, info, b->child.type, p, b->child.size); - break; - } - case SPA_TYPE_Struct: - { - struct spa_pod *b = (struct spa_pod *)body, *p; - _log(ctx, "Struct: size %d", size); - SPA_POD_FOREACH(b, size, p) - log_pod_value(ctx, indent + 2, info, p->type, SPA_POD_BODY(p), p->size); - break; - } - case SPA_TYPE_Object: - { - struct spa_pod_object_body *b = (struct spa_pod_object_body *)body; - struct spa_pod_prop *p; - const struct spa_type_info *ti, *ii; - - ti = spa_debug_type_find(info, b->type); - ii = ti ? spa_debug_type_find(ti->values, 0) : NULL; - ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL; - - _log(ctx, "Object: size %d, type %s (%d), id %s (%d)", size, - ti ? ti->name : "unknown", b->type, ii ? ii->name : "unknown", b->id); - - info = ti ? ti->values : info; - - indent += 2; - SPA_POD_OBJECT_BODY_FOREACH(b, size, p) { - ii = spa_debug_type_find(info, p->key); - - _log(ctx, "Prop: key %s (%d), flags %08x", - ii ? ii->name : "unknown", p->key, p->flags); - - log_pod_value(ctx, indent + 2, ii ? ii->values : NULL, - p->value.type, - SPA_POD_CONTENTS(struct spa_pod_prop, p), - p->value.size); - } - indent -= 2; - break; - } - case SPA_TYPE_Sequence: - { - struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body; - const struct spa_type_info *ti, *ii; - struct spa_pod_control *c; - - ti = spa_debug_type_find(info, b->unit); - - _log(ctx, "%*s" "Sequence: size %d, unit %s", indent, "", size, - ti ? ti->name : "unknown"); - - indent +=2; - SPA_POD_SEQUENCE_BODY_FOREACH(b, size, c) { - ii = spa_debug_type_find(spa_type_control, c->type); - - _log(ctx, "Control: offset %d, type %s", - c->offset, ii ? ii->name : "unknown"); - - log_pod_value(ctx, indent + 2, ii ? ii->values : NULL, - c->value.type, - SPA_POD_CONTENTS(struct spa_pod_control, c), - c->value.size); - } - indent -=2; - break; - } - case SPA_TYPE_Bytes: - _log(ctx, "Bytes"); - break; - case SPA_TYPE_None: - _log(ctx, "None"); - break; - default: - _log(ctx, "unhandled POD type %d", type); - break; - } - return 0; -} +#include void pw_log_log_object(enum spa_log_level level, const char *file, @@ -403,16 +254,13 @@ void pw_log_log_object(enum spa_log_level level, const char *func, uint32_t flags, const void *object) { - struct log_ctx ctx = { level, file, 0, func, }; + struct log_ctx ctx = { level, file, line, func, }; if (flags & PW_LOG_OBJECT_POD) { const struct spa_pod *pod = object; if (pod == NULL) { pw_log_log(level, file, line, func, "NULL"); } else { - log_pod_value(&ctx, 0, SPA_TYPE_ROOT, - SPA_POD_TYPE(pod), - SPA_POD_BODY(pod), - SPA_POD_BODY_SIZE(pod)); + spa_debugc_pod(&ctx, 0, SPA_TYPE_ROOT, pod); } } }