+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* Simple Plugin API */ |
| 2 | /* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans */ |
| 3 | /* SPDX-License-Identifier: MIT */ |
| 4 | |
| 5 | #ifndef SPA_DEBUG_LOG_H |
| 6 | #define SPA_DEBUG_LOG_H |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdarg.h> |
| 10 | |
| 11 | #include <spa/utils/defs.h> |
| 12 | #include <spa/support/log.h> |
| 13 | #include <spa/debug/context.h> |
| 14 | #include <spa/debug/dict.h> |
| 15 | #include <spa/debug/format.h> |
| 16 | #include <spa/debug/mem.h> |
| 17 | #include <spa/debug/pod.h> |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | #ifndef SPA_API_DEBUG_LOG |
| 24 | #ifdef SPA_API_IMPL |
| 25 | #define SPA_API_DEBUG_LOG SPA_API_IMPL |
| 26 | #else |
| 27 | #define SPA_API_DEBUG_LOG static inline |
| 28 | #endif |
| 29 | #endif |
| 30 | |
| 31 | /** |
| 32 | * \addtogroup spa_debug |
| 33 | * \{ |
| 34 | */ |
| 35 | |
| 36 | struct spa_debug_log_ctx { |
| 37 | struct spa_debug_context ctx; |
| 38 | struct spa_log *log; |
| 39 | enum spa_log_level level; |
| 40 | const struct spa_log_topic *topic; |
| 41 | const char *file; |
| 42 | int line; |
| 43 | const char *func; |
| 44 | }; |
| 45 | |
| 46 | SPA_PRINTF_FUNC(2,3) |
| 47 | SPA_API_DEBUG_LOG void spa_debug_log_log(struct spa_debug_context *ctx, const char *fmt, ...) |
| 48 | { |
| 49 | struct spa_debug_log_ctx *c = SPA_CONTAINER_OF(ctx, struct spa_debug_log_ctx, ctx); |
| 50 | va_list args; |
| 51 | va_start(args, fmt); |
| 52 | spa_log_logtv(c->log, c->level, c->topic, c->file, c->line, c->func, fmt, args); |
| 53 | va_end(args); |
| 54 | } |
| 55 | |
| 56 | #define SPA_LOGF_DEBUG_INIT(_l,_lev,_t,_file,_line,_func) \ |
| 57 | (struct spa_debug_log_ctx){ { spa_debug_log_log }, _l, _lev, _t, \ |
| 58 | _file, _line, _func } |
| 59 | |
| 60 | #define SPA_LOGT_DEBUG_INIT(_l,_lev,_t) \ |
| 61 | SPA_LOGF_DEBUG_INIT(_l,_lev,_t,__FILE__,__LINE__,__func__) |
| 62 | |
| 63 | #define SPA_LOG_DEBUG_INIT(l,lev) \ |
| 64 | SPA_LOGT_DEBUG_INIT(l,lev,SPA_LOG_TOPIC_DEFAULT) |
| 65 | |
| 66 | #define spa_debug_log_pod(l,lev,indent,info,pod) \ |
| 67 | ({ \ |
| 68 | struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ |
| 69 | if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ |
| 70 | spa_debugc_pod(&c.ctx, indent, info, pod); \ |
| 71 | }) |
| 72 | |
| 73 | #define spa_debug_log_format(l,lev,indent,info,format) \ |
| 74 | ({ \ |
| 75 | struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ |
| 76 | if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ |
| 77 | spa_debugc_format(&c.ctx, indent, info, format); \ |
| 78 | }) |
| 79 | |
| 80 | #define spa_debug_log_mem(l,lev,indent,data,len) \ |
| 81 | ({ \ |
| 82 | struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ |
| 83 | if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ |
| 84 | spa_debugc_mem(&c.ctx, indent, data, len); \ |
| 85 | }) |
| 86 | |
| 87 | #define spa_debug_log_dict(l,lev,indent,dict) \ |
| 88 | ({ \ |
| 89 | struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ |
| 90 | if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) \ |
| 91 | spa_debugc_dict(&c.ctx, indent, dict); \ |
| 92 | }) |
| 93 | |
| 94 | #define spa_debug_log_error_location(l,lev,loc,fmt,...) \ |
| 95 | ({ \ |
| 96 | struct spa_debug_log_ctx c = SPA_LOG_DEBUG_INIT(l,lev); \ |
| 97 | if (SPA_UNLIKELY(spa_log_level_topic_enabled(c.log, c.topic, c.level))) { \ |
| 98 | if (fmt) spa_debugc(&c.ctx, fmt, __VA_ARGS__); \ |
| 99 | spa_debugc_error_location(&c.ctx, loc); \ |
| 100 | } \ |
| 101 | }) |
| 102 | |
| 103 | /** |
| 104 | * \} |
| 105 | */ |
| 106 | |
| 107 | #ifdef __cplusplus |
| 108 | } /* extern "C" */ |
| 109 | #endif |
| 110 | |
| 111 | #endif /* SPA_DEBUG_LOG_H */ |