Skip to content

Commit b44af19

Browse files
committed
audio sender: use colors for sample cnt summary
1 parent bc47cd3 commit b44af19

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/audio/audio.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include "ug_runtime_error.hpp"
8787
#include "utils/color_out.h"
8888
#include "utils/net.h"
89+
#include "utils/misc.h" // for get_stat_color
8990
#include "utils/sdp.h"
9091
#include "utils/string_view_utils.hpp"
9192
#include "utils/thread.h"
@@ -987,9 +988,14 @@ struct asend_stats_processing_data {
987988
static void *asend_compute_and_print_stats(void *arg) {
988989
auto *d = (struct asend_stats_processing_data*) arg;
989990

990-
log_msg(LOG_LEVEL_INFO, "[Audio sender] Sent %d samples in last %f seconds.\n",
991-
d->frame.get_sample_count(),
992-
d->seconds);
991+
const double exp_samples = d->frame.get_sample_rate() * d->seconds;
992+
const char *dec_cnt_warn_col =
993+
get_stat_color(d->frame.get_sample_count() / exp_samples);
994+
995+
log_msg(LOG_LEVEL_INFO,
996+
"[Audio sender] Sent %s%d samples" TERM_FG_RESET
997+
" in last %f seconds.\n",
998+
dec_cnt_warn_col, d->frame.get_sample_count(), d->seconds);
993999

9941000
char volume[STR_LEN];
9951001
char *vol_start = volume;

src/utils/misc.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,22 @@ bool invalid_arg_is_numeric(const char *what) {
344344
return strncmp(what, "stoi", 4) == 0 || strncmp(what, "stod", 4) == 0;
345345
}
346346

347+
/**
348+
* get warning color for status printout
349+
*
350+
* If ratio is <= 0.98 or >= 1.02, return "warning" color (different for 2% and
351+
* 5% outside the range). Note that the caller must also output TERM_RESET or
352+
* TERM_FG_RESET to reset the terminal FG color.
353+
*
354+
* @returns the color (or "")
355+
*/
356+
const char *
357+
get_stat_color(double ratio)
358+
{
359+
const double diff = fabs(1 - ratio);
360+
if (diff < 0.02) {
361+
return "";
362+
}
363+
return diff < 0.05 ? T256_FG_SYM(T_ARCTIC_LIME)
364+
: T256_FG_SYM(T_SADDLE_BROWN);
365+
}

src/utils/misc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void print_module_usage(const char *module_name, const struct key_val *options,
7373

7474
bool invalid_arg_is_numeric(const char *what);
7575

76+
const char *get_stat_color(double ratio);
77+
7678
#ifdef __cplusplus
7779
}
7880
#endif

0 commit comments

Comments
 (0)