From 6ef9969abc130868eadcaec272fae35b67acafb8 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 11 Jun 2019 16:20:46 +0200 Subject: [PATCH] Use logger again Use logger again where there is output printed in a color or highlighted. --- src/audio/audio.cpp | 4 +--- src/rtp/audio_decoders.cpp | 6 +----- src/rtp/pbuf.cpp | 23 ++++++++++------------- src/rtp/video_decoders.cpp | 23 ++++++++++------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index faa475772..50690547b 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -880,9 +880,7 @@ static void *asend_compute_and_print_stats(void *arg) { for (int i = 0; i < d->frame.get_channel_count(); ++i) { double rms, peak; rms = calculate_rms(&d->frame, i, &peak); - if (log_level >= LOG_LEVEL_INFO) { - cerr << "[Audio sender] Channel " << i << " - volume: " << setprecision(2) << fixed << fg::green << style::bold << 20 * log(rms) / log(10) << style::reset << fg::reset << " dBFS RMS, " << fg::green << style::bold << 20 * log(peak) / log(10) << style::reset << fg::reset << " dBFS peak.\n"; - } + LOG(LOG_LEVEL_INFO) << "[Audio sender] Channel " << i << " - volume: " << setprecision(2) << fixed << fg::green << style::bold << 20 * log(rms) / log(10) << style::reset << fg::reset << " dBFS RMS, " << fg::green << style::bold << 20 * log(peak) / log(10) << style::reset << fg::reset << " dBFS peak.\n"; } delete d; diff --git a/src/rtp/audio_decoders.cpp b/src/rtp/audio_decoders.cpp index e62dc8e85..729c2b19e 100644 --- a/src/rtp/audio_decoders.cpp +++ b/src/rtp/audio_decoders.cpp @@ -70,12 +70,10 @@ #include #include #include -#include #include using rang::fg; using rang::style; -using std::cerr; using std::fixed; using std::ostringstream; using std::setprecision; @@ -375,9 +373,7 @@ static void *adec_compute_and_print_stats(void *arg) { for (int i = 0; i < d->frame.get_channel_count(); ++i) { double rms, peak; rms = calculate_rms(&d->frame, i, &peak); - if (log_level >= LOG_LEVEL_INFO) { - std::cerr << "[Audio decoder] Channel " << i << " - volume: " << fg::magenta << style::bold << setprecision(2) << fixed << 20 * log(rms) / log(10) << style::reset << fg::reset << " dBFS RMS, " << fg::magenta << style::bold << 20 * log(peak) / log(10) << style::reset << fg::reset << " dBFS peak.\n"; - } + LOG(LOG_LEVEL_INFO) << "[Audio decoder] Channel " << i << " - volume: " << fg::magenta << style::bold << setprecision(2) << fixed << 20 * log(rms) / log(10) << style::reset << fg::reset << " dBFS RMS, " << fg::magenta << style::bold << 20 * log(peak) / log(10) << style::reset << fg::reset << " dBFS peak.\n"; } delete d; diff --git a/src/rtp/pbuf.cpp b/src/rtp/pbuf.cpp index 20013b964..e50393478 100644 --- a/src/rtp/pbuf.cpp +++ b/src/rtp/pbuf.cpp @@ -76,7 +76,6 @@ static_assert(STATS_INTERVAL % (sizeof(unsigned long long) * CHAR_BIT) == 0, "STATS_INTERVAL must be divisible by (sizeof(ull) * CHAR_BIT)"); using rang::fg; -using std::cerr; using std::dec; using std::hex; using std::max; @@ -381,18 +380,16 @@ void pbuf_insert(struct pbuf *playout_buf, rtp_packet * pkt) if ((pkt->ts - playout_buf->last_display_ts) > 90000 * 5 && playout_buf->expected_pkts > 0) { // print stats - if (log_level >= LOG_LEVEL_INFO) { - double loss_pct = (double) playout_buf->received_pkts / - playout_buf->expected_pkts * 100.0; - cerr << "SSRC " << hex << setfill('0') << setw(8) << - pkt->ssrc << ": " << setw(0) << dec - << playout_buf->received_pkts << "/" - << playout_buf->expected_pkts << " packets received (" - << (loss_pct < 100.0 ? fg::red : fg::reset) - << setprecision(4) << loss_pct << "%" << fg::reset - << "), max loss " << playout_buf->longest_gap - << (playout_buf->out_of_order_pkts ? ", out-of-order pkts" : "") << ".\n"; - } + double loss_pct = (double) playout_buf->received_pkts / + playout_buf->expected_pkts * 100.0; + LOG(LOG_LEVEL_INFO) << "SSRC " << hex << setfill('0') << setw(8) << + pkt->ssrc << ": " << setw(0) << dec + << playout_buf->received_pkts << "/" + << playout_buf->expected_pkts << " packets received (" + << (loss_pct < 100.0 ? fg::red : fg::reset) + << setprecision(4) << loss_pct << "%" << fg::reset + << "), max loss " << playout_buf->longest_gap + << (playout_buf->out_of_order_pkts ? ", out-of-order pkts" : "") << ".\n"; playout_buf->expected_pkts = playout_buf->received_pkts = 0; playout_buf->last_display_ts = pkt->ts; playout_buf->longest_gap = 0; diff --git a/src/rtp/video_decoders.cpp b/src/rtp/video_decoders.cpp index 772646118..c268d8ab0 100644 --- a/src/rtp/video_decoders.cpp +++ b/src/rtp/video_decoders.cpp @@ -211,10 +211,16 @@ struct reported_statistics_cumul { unsigned long long int nano_per_frame_expected = 0; unsigned long int reported_frames = 0; void print() { - if (log_level < LOG_LEVEL_INFO) { - return; + ostringstream fec; + if (fec_ok + fec_nok + fec_corrected > 0) { + fec << " FEC noerr/OK/NOK: " + << style::bold << fec_ok << style::reset + << "/" + << style::bold << fec_corrected << style::reset + << "/" + << style::bold << fec_nok << style::reset; } - cerr << style::underline << "Video dec stats" << style::reset << " (cumulative): " + LOG(LOG_LEVEL_INFO) << style::underline << "Video dec stats" << style::reset << " (cumulative): " << style::bold << displayed + dropped + missing << style::reset << " total / " << style::bold << displayed << style::reset @@ -224,16 +230,7 @@ struct reported_statistics_cumul { << style::bold << corrupted << style::reset << " corr / " << style::bold << missing << style::reset - << " missing."; - if (fec_ok + fec_nok + fec_corrected > 0) { - cerr << " FEC noerr/OK/NOK: " - << style::bold << fec_ok << style::reset - << "/" - << style::bold << fec_corrected << style::reset - << "/" - << style::bold << fec_nok << style::reset; - } - cerr << "\n"; + << " missing." << fec.str() << "\n"; } };