diff --git a/spa/include/spa/debug/buffer.h b/spa/include/spa/debug/buffer.h index a006c3b2c..a1cd141b8 100644 --- a/spa/include/spa/debug/buffer.h +++ b/spa/include/spa/debug/buffer.h @@ -38,12 +38,12 @@ extern "C" { * \{ */ -#include +#include #include #include #include -static inline int spa_debugc_buffer(void *ctx, int indent, const struct spa_buffer *buffer) +static inline int spa_debugc_buffer(struct spa_debug_context *ctx, int indent, const struct spa_buffer *buffer) { uint32_t i; diff --git a/spa/include/spa/debug/context.h b/spa/include/spa/debug/context.h new file mode 100644 index 000000000..945e5025c --- /dev/null +++ b/spa/include/spa/debug/context.h @@ -0,0 +1,62 @@ +/* Simple Plugin API + * + * Copyright © 2023 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_CONTEXT_H +#define SPA_DEBUG_CONTEXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include +/** + * \addtogroup spa_debug + * \{ + */ + +#ifndef spa_debugn +#define spa_debugn(_fmt,...) printf((_fmt), ## __VA_ARGS__) +#endif +#ifndef spa_debug +#define spa_debug(_fmt,...) spa_debugn(_fmt"\n", ## __VA_ARGS__) +#endif + +struct spa_debug_context { + void (*log) (struct spa_debug_context *ctx, const char *fmt, ...) SPA_PRINTF_FUNC(2, 3); +}; + +#define spa_debugc(_c,_fmt,...) (_c)?((_c)->log((_c),_fmt, ## __VA_ARGS__)):(void)spa_debug(_fmt, ## __VA_ARGS__) + +/** + * \} + */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* SPA_DEBUG_CONTEXT_H */ diff --git a/spa/include/spa/debug/dict.h b/spa/include/spa/debug/dict.h index e05414afd..ad47ad6d9 100644 --- a/spa/include/spa/debug/dict.h +++ b/spa/include/spa/debug/dict.h @@ -34,10 +34,10 @@ extern "C" { * \{ */ -#include +#include #include -static inline int spa_debugc_dict(void *ctx, int indent, const struct spa_dict *dict) +static inline int spa_debugc_dict(struct spa_debug_context *ctx, int indent, const struct spa_dict *dict) { const struct spa_dict_item *item; spa_debugc(ctx, "%*sflags:%08x n_items:%d", indent, "", dict->flags, dict->n_items); diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 52bf29335..e0bd955aa 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -35,19 +35,20 @@ extern "C" { */ #include -#include +#include +#include #include #include #include static inline int -spa_debug_buffer_format_value(struct spa_debug_buffer *buffer, const struct spa_type_info *info, +spa_debug_strbuf_format_value(struct spa_strbuf *buffer, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { switch (type) { case SPA_TYPE_Bool: - spa_debug_buffer_append(buffer, "%s", *(int32_t *) body ? "true" : "false"); + spa_strbuf_append(buffer, "%s", *(int32_t *) body ? "true" : "false"); break; case SPA_TYPE_Id: { @@ -57,41 +58,41 @@ spa_debug_buffer_format_value(struct spa_debug_buffer *buffer, const struct spa_ snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body); str = tmp; } - spa_debug_buffer_append(buffer, "%s", str); + spa_strbuf_append(buffer, "%s", str); break; } case SPA_TYPE_Int: - spa_debug_buffer_append(buffer, "%d", *(int32_t *) body); + spa_strbuf_append(buffer, "%d", *(int32_t *) body); break; case SPA_TYPE_Long: - spa_debug_buffer_append(buffer, "%" PRIi64, *(int64_t *) body); + spa_strbuf_append(buffer, "%" PRIi64, *(int64_t *) body); break; case SPA_TYPE_Float: - spa_debug_buffer_append(buffer, "%f", *(float *) body); + spa_strbuf_append(buffer, "%f", *(float *) body); break; case SPA_TYPE_Double: - spa_debug_buffer_append(buffer, "%f", *(double *) body); + spa_strbuf_append(buffer, "%f", *(double *) body); break; case SPA_TYPE_String: - spa_debug_buffer_append(buffer, "%s", (char *) body); + spa_strbuf_append(buffer, "%s", (char *) body); break; case SPA_TYPE_Rectangle: { struct spa_rectangle *r = (struct spa_rectangle *)body; - spa_debug_buffer_append(buffer, "%" PRIu32 "x%" PRIu32, r->width, r->height); + spa_strbuf_append(buffer, "%" PRIu32 "x%" PRIu32, r->width, r->height); break; } case SPA_TYPE_Fraction: { struct spa_fraction *f = (struct spa_fraction *)body; - spa_debug_buffer_append(buffer, "%" PRIu32 "/%" PRIu32, f->num, f->denom); + spa_strbuf_append(buffer, "%" PRIu32 "/%" PRIu32, f->num, f->denom); break; } case SPA_TYPE_Bitmap: - spa_debug_buffer_append(buffer, "Bitmap"); + spa_strbuf_append(buffer, "Bitmap"); break; case SPA_TYPE_Bytes: - spa_debug_buffer_append(buffer, "Bytes"); + spa_strbuf_append(buffer, "Bytes"); break; case SPA_TYPE_Array: { @@ -99,17 +100,17 @@ spa_debug_buffer_format_value(struct spa_debug_buffer *buffer, const struct spa_ struct spa_pod_array_body *b = (struct spa_pod_array_body *)body; int i = 0; info = info && info->values ? info->values : info; - spa_debug_buffer_append(buffer, "< "); + spa_strbuf_append(buffer, "< "); SPA_POD_ARRAY_BODY_FOREACH(b, size, p) { if (i++ > 0) - spa_debug_buffer_append(buffer, ", "); - spa_debug_buffer_format_value(buffer, info, b->child.type, p, b->child.size); + spa_strbuf_append(buffer, ", "); + spa_debug_strbuf_format_value(buffer, info, b->child.type, p, b->child.size); } - spa_debug_buffer_append(buffer, " >"); + spa_strbuf_append(buffer, " >"); break; } default: - spa_debug_buffer_append(buffer, "INVALID type %d", type); + spa_strbuf_append(buffer, "INVALID type %d", type); break; } return 0; @@ -120,14 +121,14 @@ spa_debug_format_value(const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { char buffer[1024]; - struct spa_debug_buffer buf; - spa_debug_buffer_init(&buf, buffer, sizeof(buffer)); - spa_debug_buffer_format_value(&buf, info, type, body, size); + struct spa_strbuf buf; + spa_strbuf_init(&buf, buffer, sizeof(buffer)); + spa_debug_strbuf_format_value(&buf, info, type, body, size); spa_debugn("%s", buffer); return 0; } -static inline int spa_debugc_format(void *ctx, int indent, +static inline int spa_debugc_format(struct spa_debug_context *ctx, int indent, const struct spa_type_info *info, const struct spa_pod *format) { const char *media_type; @@ -158,7 +159,7 @@ static inline int spa_debugc_format(void *ctx, int indent, const struct spa_pod *val; void *vals; char buffer[1024]; - struct spa_debug_buffer buf; + struct spa_strbuf buf; if (prop->key == SPA_FORMAT_mediaType || prop->key == SPA_FORMAT_mediaSubtype) @@ -176,13 +177,13 @@ static inline int spa_debugc_format(void *ctx, int indent, ti = spa_debug_type_find(info, prop->key); key = ti ? ti->name : NULL; - spa_debug_buffer_init(&buf, buffer, sizeof(buffer)); - spa_debug_buffer_append(&buf, "%*s %16s : (%s) ", indent, "", + spa_strbuf_init(&buf, buffer, sizeof(buffer)); + spa_strbuf_append(&buf, "%*s %16s : (%s) ", indent, "", key ? spa_debug_type_short_name(key) : "unknown", spa_debug_type_short_name(spa_types[type].name)); if (choice == SPA_CHOICE_None) { - spa_debug_buffer_format_value(&buf, ti ? ti->values : NULL, type, vals, size); + spa_debug_strbuf_format_value(&buf, ti ? ti->values : NULL, type, vals, size); } else { const char *ssep, *esep, *sep; @@ -202,15 +203,15 @@ static inline int spa_debugc_format(void *ctx, int indent, break; } - spa_debug_buffer_append(&buf, "%s", ssep); + spa_strbuf_append(&buf, "%s", ssep); for (i = 1; i < n_vals; i++) { vals = SPA_PTROFF(vals, size, void); if (i > 1) - spa_debug_buffer_append(&buf, "%s", sep); - spa_debug_buffer_format_value(&buf, ti ? ti->values : NULL, type, vals, size); + spa_strbuf_append(&buf, "%s", sep); + spa_debug_strbuf_format_value(&buf, ti ? ti->values : NULL, type, vals, size); } - spa_debug_buffer_append(&buf, "%s", esep); + spa_strbuf_append(&buf, "%s", esep); } spa_debugc(ctx, "%s", buffer); } diff --git a/spa/include/spa/debug/log.h b/spa/include/spa/debug/log.h index ddb695106..9e2dc73c4 100644 --- a/spa/include/spa/debug/log.h +++ b/spa/include/spa/debug/log.h @@ -33,48 +33,65 @@ extern "C" { #include #include +#include +#include + /** * \addtogroup spa_debug * \{ */ -#ifndef spa_debugn -#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 { - char *buffer; - size_t maxsize; - size_t pos; +struct spa_debug_log_ctx { + struct spa_debug_context ctx; + struct spa_log *log; + enum spa_log_level level; + const struct spa_log_topic *topic; + const char *file; + int line; + const char *func; }; -static inline void spa_debug_buffer_init(struct spa_debug_buffer *buf, char *buffer, size_t maxsize) +SPA_PRINTF_FUNC(2,3) +static inline void spa_debug_log_log(struct spa_debug_context *ctx, const char *fmt, ...) { - buf->buffer = buffer; - buf->maxsize = maxsize; - buf->pos = 0; -} - -SPA_PRINTF_FUNC(2, 3) -static inline int spa_debug_buffer_append(struct spa_debug_buffer *buf, const char *fmt, ...) -{ - size_t remain = buf->maxsize - buf->pos; - ssize_t written; + struct spa_debug_log_ctx *c = (struct spa_debug_log_ctx*)ctx; va_list args; va_start(args, fmt); - written = vsnprintf(&buf->buffer[buf->pos], remain, fmt, args); + spa_log_logtv(c->log, c->level, c->topic, c->file, c->line, c->func, fmt, args); va_end(args); - if (written > 0) - buf->pos += SPA_MIN(remain, (size_t)written); - return written; } +#define SPA_LOGF_DEBUG_INIT(_l,_lev,_t,_file,_line,_func) \ + (struct spa_debug_log_ctx){ { spa_debug_log_log }, _l, _lev, _t, \ + _file, _line, _func } + +#define SPA_LOGT_DEBUG_INIT(_l,_lev,_t) \ + SPA_LOGF_DEBUG_INIT(_l,_lev,_t,__FILE__,__LINE__,__func__) + +#define SPA_LOG_DEBUG_INIT(l,lev) \ + SPA_LOGT_DEBUG_INIT(l,lev,SPA_LOG_TOPIC_DEFAULT) + +#define spa_debug_log_pod(l,lev,indent,info,pod) \ +({ \ + struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ + if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ + spa_debugc_pod(&c.ctx, indent, info, pod); \ +}) + +#define spa_debug_log_format(l,lev,indent,info,format) \ +({ \ + struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ + if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ + spa_debugc_format(&c.ctx, indent, info, format); \ +}) + +#define spa_debug_log_mem(l,lev,indent,data,len) \ +({ \ + struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ + if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ + spa_debugc_mem(&c.ctx, indent, data, len); \ +}) + /** * \} */ @@ -83,4 +100,4 @@ static inline int spa_debug_buffer_append(struct spa_debug_buffer *buf, const ch } /* extern "C" */ #endif -#endif /* SPA_DEBUG_LOGH */ +#endif /* SPA_DEBUG_LOG_H */ diff --git a/spa/include/spa/debug/mem.h b/spa/include/spa/debug/mem.h index 1c87572b3..7924aba6c 100644 --- a/spa/include/spa/debug/mem.h +++ b/spa/include/spa/debug/mem.h @@ -36,9 +36,9 @@ extern "C" { * \{ */ -#include +#include -static inline int spa_debugc_mem(void *ctx, int indent, const void *data, size_t size) +static inline int spa_debugc_mem(struct spa_debug_context *ctx, int indent, const void *data, size_t size) { const uint8_t *t = (const uint8_t*)data; char buffer[512]; diff --git a/spa/include/spa/debug/node.h b/spa/include/spa/debug/node.h index feef4fff6..63b16d39f 100644 --- a/spa/include/spa/debug/node.h +++ b/spa/include/spa/debug/node.h @@ -35,10 +35,10 @@ extern "C" { */ #include -#include +#include #include -static inline int spa_debugc_port_info(void *ctx, int indent, const struct spa_port_info *info) +static inline int spa_debugc_port_info(struct spa_debug_context *ctx, int indent, const struct spa_port_info *info) { spa_debugc(ctx, "%*s" "struct spa_port_info %p:", indent, "", info); spa_debugc(ctx, "%*s" " flags: \t%08" PRIx64, indent, "", info->flags); diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index 881a56c06..31b707e52 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -34,14 +34,14 @@ extern "C" { * \{ */ -#include +#include #include #include #include #include static inline int -spa_debugc_pod_value(void *ctx, int indent, const struct spa_type_info *info, +spa_debugc_pod_value(struct spa_debug_context *ctx, int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { switch (type) { @@ -194,7 +194,7 @@ spa_debugc_pod_value(void *ctx, int indent, const struct spa_type_info *info, return 0; } -static inline int spa_debugc_pod(void *ctx, int indent, +static inline int spa_debugc_pod(struct spa_debug_context *ctx, int indent, const struct spa_type_info *info, const struct spa_pod *pod) { return spa_debugc_pod_value(ctx, indent, info ? info : SPA_TYPE_ROOT, diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index 008fb3417..74818a48b 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -299,21 +299,6 @@ do { \ #define spa_log_trace_fp(l,...) #endif -#define spa_log_hexdump(l,lev,indent,data,len) \ -({ \ - char str[512]; \ - uint8_t *buf = (uint8_t *)(data); \ - size_t i, j = (len); \ - int pos = 0; \ - \ - for (i = 0; i < j; i++) { \ - if (i % 16 == 0) \ - pos = 0; \ - pos += sprintf(str + pos, "%02x ", buf[i]); \ - if (i % 16 == 15 || i == j - 1) \ - spa_log_lev(l,lev, "%*s" "%s",indent,"", str); \ - } \ -}) /** \fn spa_log_error */ diff --git a/spa/include/spa/utils/string.h b/spa/include/spa/utils/string.h index edf4e954f..787a116b9 100644 --- a/spa/include/spa/utils/string.h +++ b/spa/include/spa/utils/string.h @@ -376,6 +376,33 @@ static inline char *spa_dtoa(char *str, size_t size, double val) return str; } +struct spa_strbuf { + char *buffer; + size_t maxsize; + size_t pos; +}; + +static inline void spa_strbuf_init(struct spa_strbuf *buf, char *buffer, size_t maxsize) +{ + buf->buffer = buffer; + buf->maxsize = maxsize; + buf->pos = 0; +} + +SPA_PRINTF_FUNC(2, 3) +static inline int spa_strbuf_append(struct spa_strbuf *buf, const char *fmt, ...) +{ + size_t remain = buf->maxsize - buf->pos; + ssize_t written; + va_list args; + va_start(args, fmt); + written = vsnprintf(&buf->buffer[buf->pos], remain, fmt, args); + va_end(args); + if (written > 0) + buf->pos += SPA_MIN(remain, (size_t)written); + return written; +} + /** * \} */ diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index de8fc325c..bcd749113 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -46,10 +46,8 @@ #include #include #include - -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include +#include #include "alsa.h" @@ -739,7 +737,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } @@ -764,7 +762,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 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 ac55c9578..984f1d0f7 100644 --- a/spa/plugins/alsa/alsa-pcm-device.c +++ b/spa/plugins/alsa/alsa-pcm-device.c @@ -44,10 +44,8 @@ #include #include #include - -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include +#include #include "alsa.h" @@ -466,7 +464,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index 2b09879b9..2ccc2b7ad 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -40,16 +40,14 @@ #include #include #include +#include +#include +#include #undef SPA_LOG_TOPIC_DEFAULT #define SPA_LOG_TOPIC_DEFAULT log_topic static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audioadapter"); -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) -#include -#include - #define DEFAULT_ALIGN 16 #define MAX_PORTS (SPA_AUDIO_MAX_CHANNELS+1) @@ -336,7 +334,7 @@ static int debug_params(struct impl *this, struct spa_node *node, if (filter) { spa_log_error(this->log, "with this filter:"); - spa_debugc_pod(this->log, 2, NULL, filter); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 2, NULL, filter); } else { spa_log_error(this->log, "there was no filter"); } @@ -354,7 +352,7 @@ static int debug_params(struct impl *this, struct spa_node *node, break; } spa_log_error(this->log, "unmatched %s %d:", debug, count); - spa_debugc_pod(this->log, 2, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 2, NULL, param); count++; } if (count == 0) @@ -483,8 +481,8 @@ static int configure_format(struct impl *this, uint32_t flags, const struct spa_ return 0; spa_log_debug(this->log, "%p: configure format:", this); - if (format && spa_log_level_enabled(this->log, SPA_LOG_LEVEL_DEBUG)) - spa_debugc_format(this->log, 0, NULL, format); + if (format) + spa_debug_log_format(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, format); if ((res = spa_node_port_set_param(this->follower, this->direction, 0, diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index 64d24062f..4034f99e7 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -35,6 +35,8 @@ #include +#include +#include #include #include #include @@ -563,7 +565,7 @@ static DBusHandlerResult endpoint_select_configuration(DBusConnection *conn, DBu return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } spa_log_info(monitor->log, "%p: %s select conf %d", monitor, path, size); - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, cap, (size_t)size); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, cap, (size_t)size); /* For codecs sharing the same endpoint, BlueZ-initiated connections * always pick the default one. The session manager will @@ -592,7 +594,7 @@ static DBusHandlerResult endpoint_select_configuration(DBusConnection *conn, DBu return DBUS_HANDLER_RESULT_NEED_MEMORY; goto exit_send; } - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, pconf, (size_t)size); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, pconf, (size_t)size); if ((r = dbus_message_new_method_return(m)) == NULL) return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -696,7 +698,7 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe memcpy(caps, buf, caps_size); spa_log_info(monitor->log, "%p: %s %s size:%d", monitor, path, key, caps_size); - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, ' ', caps, (size_t)caps_size); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, ' ', caps, (size_t)caps_size); } else if (spa_streq(key, "Endpoint")) { if (type != DBUS_TYPE_OBJECT_PATH) { spa_log_error(monitor->log, "Property %s of wrong type %c", key, (char)type); @@ -776,7 +778,7 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe goto error_invalid; } spa_log_info(monitor->log, "%p: selected conf %d", monitor, conf_size); - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, ' ', (uint8_t *)config, (size_t)conf_size); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, ' ', (uint8_t *)config, (size_t)conf_size); if ((r = dbus_message_new_method_return(m)) == NULL) return DBUS_HANDLER_RESULT_NEED_MEMORY; @@ -2064,7 +2066,7 @@ static int remote_endpoint_update_props(struct spa_bt_remote_endpoint *remote_en dbus_message_iter_get_fixed_array(&iter, &value, &len); spa_log_debug(monitor->log, "remote_endpoint %p: %s=%d", remote_endpoint, key, len); - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, value, (size_t)len); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, value, (size_t)len); free(remote_endpoint->capabilities); remote_endpoint->capabilities_len = 0; @@ -2616,7 +2618,7 @@ static int transport_update_props(struct spa_bt_transport *transport, dbus_message_iter_get_fixed_array(&iter, &value, &len); spa_log_debug(monitor->log, "transport %p: %s=%d", transport, key, len); - spa_log_hexdump(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, value, (size_t)len); + spa_debug_log_mem(monitor->log, SPA_LOG_LEVEL_DEBUG, 2, value, (size_t)len); free(transport->configuration); transport->configuration_len = 0; diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 2153a9cd5..dcdfeafcd 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -48,10 +48,8 @@ #include #include #include - -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include +#include #include "defs.h" #include "media-codecs.h" @@ -2117,7 +2115,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } @@ -2145,7 +2143,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } if (device > 1 || !this->nodes[device].active) @@ -2176,7 +2174,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } diff --git a/spa/plugins/bluez5/media-sink.c b/spa/plugins/bluez5/media-sink.c index cab508ffc..29eec1fe5 100644 --- a/spa/plugins/bluez5/media-sink.c +++ b/spa/plugins/bluez5/media-sink.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include @@ -949,7 +951,7 @@ static int do_start(struct impl *this) size = this->transport->configuration_len; spa_log_debug(this->log, "Transport configuration:"); - spa_log_hexdump(this->log, SPA_LOG_LEVEL_DEBUG, 2, conf, (size_t)size); + spa_debug_log_mem(this->log, SPA_LOG_LEVEL_DEBUG, 2, conf, (size_t)size); flags = this->is_duplex ? MEDIA_CODEC_FLAG_SINK : 0; diff --git a/spa/plugins/jack/jack-device.c b/spa/plugins/jack/jack-device.c index fe622e44c..0ae67d04d 100644 --- a/spa/plugins/jack/jack-device.c +++ b/spa/plugins/jack/jack-device.c @@ -43,10 +43,8 @@ #include #include #include - -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) #include +#include #include "jack-client.h" @@ -340,7 +338,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_debugc_pod(this->log, 0, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, param); return res; } activate_profile(this, idx); diff --git a/spa/plugins/videoconvert/videoadapter.c b/spa/plugins/videoconvert/videoadapter.c index c0ee81bb4..2f6f06854 100644 --- a/spa/plugins/videoconvert/videoadapter.c +++ b/spa/plugins/videoconvert/videoadapter.c @@ -40,16 +40,14 @@ #include #include #include +#include +#include +#include #undef SPA_LOG_TOPIC_DEFAULT #define SPA_LOG_TOPIC_DEFAULT log_topic static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.videoadapter"); -#undef spa_debugc -#define spa_debugc(l,...) spa_log_debug(l, __VA_ARGS__) -#include -#include - #define DEFAULT_ALIGN 16 #define MAX_PORTS 1 @@ -302,7 +300,7 @@ static int debug_params(struct impl *this, struct spa_node *node, if (filter) { spa_log_error(this->log, "with this filter:"); - spa_debugc_pod(this->log, 2, NULL, filter); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 2, NULL, filter); } else { spa_log_error(this->log, "there was no filter"); } @@ -320,7 +318,7 @@ static int debug_params(struct impl *this, struct spa_node *node, break; } spa_log_error(this->log, "unmatched %s %d:", debug, count); - spa_debugc_pod(this->log, 2, NULL, param); + spa_debug_log_pod(this->log, SPA_LOG_LEVEL_DEBUG, 2, NULL, param); count++; } if (count == 0) @@ -445,8 +443,8 @@ static int configure_format(struct impl *this, uint32_t flags, const struct spa_ int res; spa_log_debug(this->log, "%p: configure format:", this); - if (format && spa_log_level_enabled(this->log, SPA_LOG_LEVEL_DEBUG)) - spa_debugc_format(this->log, 0, NULL, format); + if (format) + spa_debug_log_format(this->log, SPA_LOG_LEVEL_DEBUG, 0, NULL, format); if ((res = spa_node_port_set_param(this->follower, this->direction, 0, diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index b9dd0e251..be42eab61 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -34,7 +34,6 @@ #include #include "log.h" -#define spa_debug pw_log_debug #include #include diff --git a/src/pipewire/log.c b/src/pipewire/log.c index 674e9227d..24841098c 100644 --- a/src/pipewire/log.c +++ b/src/pipewire/log.c @@ -232,35 +232,21 @@ pw_log_log(enum spa_log_level level, * realtime threads */ -struct log_ctx { - enum spa_log_level level; - const char *file; - int line; - const char *func; -}; - -#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__); \ -}) - #include +#include void pw_log_log_object(enum spa_log_level level, - const char *file, - int line, - const char *func, - uint32_t flags, const void *object) + const struct spa_log_topic *topic, const char *file, + int line, const char *func, uint32_t flags, const void *object) { - struct log_ctx ctx = { level, file, line, func, }; + struct spa_debug_log_ctx ctx = SPA_LOGF_DEBUG_INIT(global_log, level, + topic, 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"); + pw_log_logt(level, topic, file, line, func, "NULL"); } else { - spa_debugc_pod(&ctx, 0, SPA_TYPE_ROOT, pod); + spa_debugc_pod(&ctx.ctx, 0, SPA_TYPE_ROOT, pod); } } } diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 92d004508..8a8d31eb4 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -45,10 +45,6 @@ struct ucred { }; #endif -#ifndef spa_debug -#define spa_debug(...) pw_log_trace(__VA_ARGS__) -#endif - #define MAX_RATES 32u #define CLOCK_MIN_QUANTUM 4u #define CLOCK_MAX_QUANTUM 65536u @@ -1282,17 +1278,19 @@ void pw_control_destroy(struct pw_control *control); void pw_impl_client_unref(struct pw_impl_client *client); #define PW_LOG_OBJECT_POD (1<<0) -void pw_log_log_object(enum spa_log_level level, const char *file, int line, - const char *func, uint32_t flags, const void *object); +void pw_log_log_object(enum spa_log_level level, const struct spa_log_topic *topic, + const char *file, int line, const char *func, uint32_t flags, + const void *object); -#define pw_log_object(lev,fl,obj) \ -({ \ - if (SPA_UNLIKELY(pw_log_level_enabled (lev))) \ - pw_log_log_object(lev,__FILE__,__LINE__,__func__,(fl),(obj)); \ +#define pw_log_object(lev,t,fl,obj) \ +({ \ + if (SPA_UNLIKELY(pw_log_topic_enabled(lev,t))) \ + pw_log_log_object(lev,t,__FILE__,__LINE__, \ + __func__,(fl),(obj)); \ }) -#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod) -#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_OBJECT_POD,pod) +#define pw_log_pod(lev,pod) pw_log_object(lev,PW_LOG_TOPIC_DEFAULT,PW_LOG_OBJECT_POD,pod) +#define pw_log_format(lev,pod) pw_log_object(lev,PW_LOG_TOPIC_DEFAULT,PW_LOG_OBJECT_POD,pod) bool pw_log_is_default(void);