From e3574d3d6638ead862e4f4a15488215a5224ef86 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 10 Jan 2023 16:17:33 +0100 Subject: [PATCH] one-shot logger updates On one-shot second and further calls of one-shot message, no output was producet, yet empty buffer was submitted to Log_output resulting in false repeate messages: Last message repeated times To simplify the stuff, C++ API was removed and in the C API the Logger is taken only if actual message will be output. If someone is willing to use the C++ API, it can be later readded (not really needed now, only simple message are presented). --- src/debug.cpp | 5 +++-- src/debug.h | 10 +--------- src/rtp/audio_decoders.cpp | 2 +- src/rtp/video_decoders.cpp | 4 ++-- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index c0f5bbecf..079a554a0 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -141,10 +141,11 @@ void log_msg(int level, const char *format, ...) { } void log_msg_once(int level, uint32_t id, const char *msg) { - if (log_level < level) { + if (Logger::oneshot_messages.count(id) > 0 || log_level < level) { return; } - Logger(level).once(id, msg); + Logger::oneshot_messages.insert(id); + Logger(level).Get() << msg; } /** diff --git a/src/debug.h b/src/debug.h index cdb81a219..60bf3774d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -298,26 +298,18 @@ public: inline std::ostream& Get() { return oss; } - inline void once(uint32_t id, const std::string &msg) { - if (oneshot_messages.count(id) > 0) { - return; - } - oneshot_messages.insert(id); - oss << msg; - } private: int level; std::ostringstream oss; + friend void log_msg_once(int level, uint32_t id, const char *msg); static thread_local std::set oneshot_messages; }; #define LOG(level) \ if ((level) <= log_level) Logger(level).Get() -#define LOG_ONCE(level, id, msg) \ -if ((level) <= log_level) Logger(level).once(id, msg) #endif diff --git a/src/rtp/audio_decoders.cpp b/src/rtp/audio_decoders.cpp index db5462780..6c8f2901e 100644 --- a/src/rtp/audio_decoders.cpp +++ b/src/rtp/audio_decoders.cpp @@ -674,7 +674,7 @@ int decode_audio_frame(struct coded_data *cdata, void *pbuf_data, struct pbuf_st } } else { if (pt == PT_Unassign_Type95) { - LOG_ONCE(LOG_LEVEL_WARNING, to_fourcc('U', 'V', 'P', 'T'), MOD_NAME "Unassigned PT 95 received, ignoring.\n"); + log_msg_once(LOG_LEVEL_WARNING, to_fourcc('U', 'V', 'P', 'T'), MOD_NAME "Unassigned PT 95 received, ignoring.\n"); } else { log_msg(LOG_LEVEL_WARNING, "Unknown audio packet type: %d\n", pt); } diff --git a/src/rtp/video_decoders.cpp b/src/rtp/video_decoders.cpp index cb5631b6c..f59742eb2 100644 --- a/src/rtp/video_decoders.cpp +++ b/src/rtp/video_decoders.cpp @@ -1404,7 +1404,7 @@ bool parse_video_hdr(uint32_t *hdr, struct video_desc *desc) desc->fps = compute_fps(fps_pt, fpsd, fd, fi); if (desc->fps == -1) { - LOG_ONCE(LOG_LEVEL_WARNING, to_fourcc('U', 'F', 'P', 'S'), MOD_NAME "Unsupported FPS received (newer UG?), setting to 30.\n"); + log_msg_once(LOG_LEVEL_WARNING, to_fourcc('U', 'F', 'P', 'S'), MOD_NAME "Unsupported FPS received (newer UG?), setting to 30.\n"); desc->fps = 30.0; } @@ -1612,7 +1612,7 @@ int decode_video_frame(struct coded_data *cdata, void *decoder_data, struct pbuf break; default: if (pt == PT_Unassign_Type95) { - LOG_ONCE(LOG_LEVEL_WARNING, to_fourcc('U', 'V', 'P', 'T'), MOD_NAME "Unassigned PT 95 received, ignoring.\n"); + log_msg_once(LOG_LEVEL_WARNING, to_fourcc('U', 'V', 'P', 'T'), MOD_NAME "Unassigned PT 95 received, ignoring.\n"); } else { LOG(LOG_LEVEL_WARNING) << MOD_NAME "Unknown packet type: " << pckt->pt << ".\n"; }