diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 50a883a62..3f8ee14b7 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -213,15 +213,15 @@ static void audio_channel_map_usage(void) static void audio_scale_usage(void) { - cout << "Usage:\n"; - cout << BOLD(RED("\t--audio-scale [|]\n")); - cout << "\t Floating point number that tells a static scaling factor for all\n"; - cout << "\t output channels. Scaling method can be one from these:\n"; - cout << BOLD("\t 0.0-1.0") << " - factor to scale to (usually 0-1 but can be more)\n"; - cout << BOLD("\t mixauto") << " - automatically adjust volume if using channel\n"; - cout << "\t mixing/remapping (default)\n"; - cout << BOLD("\t auto") << " - automatically adjust volume\n"; - cout << BOLD("\t none") << " - no scaling will be performed\n"; + col() << "Usage:\n"; + col() << TBOLD(TRED("\t--audio-scale [|]\n")); + col() << "\t Floating point number that tells a static scaling factor for all\n"; + col() << "\t output channels. Scaling method can be one from these:\n"; + col() << TBOLD("\t 0.0-1.0") << " - factor to scale to (usually 0-1 but can be more)\n"; + col() << TBOLD("\t mixauto") << " - automatically adjust volume if using channel\n"; + col() << "\t mixing/remapping (default)\n"; + col() << TBOLD("\t auto") << " - automatically adjust volume\n"; + col() << TBOLD("\t none") << " - no scaling will be performed\n"; } /** @@ -928,7 +928,7 @@ static void *asend_compute_and_print_stats(void *arg) { volume << (i > 0 ? " "s : ""s) << 20.0 * log(rms) / log(10.0) << "/" << 20.0 * log(peak) / log(10.0); } - LOG(LOG_LEVEL_INFO) << "[Audio sender] Volume: " << fg::green << style::bold << volume.str() << style::reset << fg::reset << " dBFS RMS/peak" << BOLD(RED((d->muted_sender ? " (muted)" : ""))) << "\n" ; + LOG(LOG_LEVEL_INFO) << "[Audio sender] Volume: " << TBOLD(TGREEN(<< volume.str() <<)) << " dBFS RMS/peak" << (d->muted_sender ? TBOLD(TRED(" (muted)")) : "") << "\n" ; delete d; diff --git a/src/blackmagic_common.cpp b/src/blackmagic_common.cpp index 6cb72600a..b2bd53288 100644 --- a/src/blackmagic_common.cpp +++ b/src/blackmagic_common.cpp @@ -41,6 +41,7 @@ #include "config_win32.h" #endif +#include #include #include #include diff --git a/src/capture_filter/flip.cpp b/src/capture_filter/flip.cpp index 56014834f..5db43df87 100644 --- a/src/capture_filter/flip.cpp +++ b/src/capture_filter/flip.cpp @@ -60,7 +60,7 @@ struct state_flip { static int init(struct module *, const char *cfg, void **state) { if (strlen(cfg) > 0) { - std::cout << RED(BOLD("flip")) << " capture filter flips the video vertically (across horizontal axis), takes no arguments\n"; + col() << TRED(TBOLD("flip")) << " capture filter flips the video vertically (across horizontal axis), takes no arguments\n"; return strcmp(cfg, "help") == 0 ? 1 : -1; } *state = static_cast(calloc(1, sizeof(state_flip))); diff --git a/src/capture_filter/grayscale.cpp b/src/capture_filter/grayscale.cpp index a2d94f47a..b73af6f9f 100644 --- a/src/capture_filter/grayscale.cpp +++ b/src/capture_filter/grayscale.cpp @@ -60,7 +60,7 @@ struct state_grayscale { static int init(struct module *, const char *cfg, void **state) { if (strlen(cfg) > 0) { - std::cout << RED(BOLD("grayscale")) << " converts image to grayscale, takes no arguments\n"; + col() << TRED(TBOLD("grayscale")) << " converts image to grayscale, takes no arguments\n"; return strcmp(cfg, "help") == 0 ? 1 : -1; } *state = static_cast(calloc(1, sizeof(state_grayscale))); diff --git a/src/capture_filter/mirror.cpp b/src/capture_filter/mirror.cpp index bceca5228..12cf5d37c 100644 --- a/src/capture_filter/mirror.cpp +++ b/src/capture_filter/mirror.cpp @@ -60,7 +60,7 @@ struct state_mirror { static int init(struct module *, const char *cfg, void **state) { if (strlen(cfg) > 0) { - std::cout << RED(BOLD("mirror")) << " capture filter flips the video horizontally (across vertical axis), takes no arguments\n"; + col() << TRED(TBOLD("mirror")) << " capture filter flips the video horizontally (across vertical axis), takes no arguments\n"; return strcmp(cfg, "help") == 0 ? 1 : -1; } *state = static_cast(calloc(1, sizeof(state_mirror))); diff --git a/src/capture_filter/preview.cpp b/src/capture_filter/preview.cpp index 5f071417e..cc48be603 100644 --- a/src/capture_filter/preview.cpp +++ b/src/capture_filter/preview.cpp @@ -127,14 +127,13 @@ static void worker(struct state_preview_filter *s, std::string path){ } static void show_help(){ - std::cout << "preview capture filter\n"; - std::cout << "usage:\n"; - std::cout << rang::style::bold << rang::fg::red << "\t--capture-filter preview" << rang::fg::reset << "[:path=][:target_size=x]" - << "\n\n" << rang::style::reset; - std::cout << "options:\n"; - std::cout << BOLD("\tpath=") << "\tpath to unix socket to connect to. Default is \"" + col() << "preview capture filter\n"; + col() << "usage:\n"; + col() << TBOLD(TRED("\t--capture-filter preview") "[:path=][:target_size=x]\n\n"); + col() << "options:\n"; + col() << TBOLD("\tpath=") << "\tpath to unix socket to connect to. Default is \"" << PLATFORM_TMP_DIR DEFAULT_PREVIEW_FILENAME "\"\n"; - std::cout << BOLD("\ttarget_size=x")<< "\tScales the video frame so that the total number of pixel is around x. If -1x-1 is passed, no scaling takes place." + col() << TBOLD("\ttarget_size=x")<< "\tScales the video frame so that the total number of pixel is around x. If -1x-1 is passed, no scaling takes place." << " Defaults are " TOSTRING(DEFAULT_SCALE_W) "x" TOSTRING(DEFAULT_SCALE_H) ".\n"; } diff --git a/src/debug.cpp b/src/debug.cpp index aeb5dc4cf..a26f58d46 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -207,7 +207,6 @@ bool parse_log_cfg(const char *conf_str, assert(show_timestamps != nullptr); using std::clog; - using std::cout; static const struct { const char *name; int level; } mapping[] = { { "quiet", LOG_LEVEL_QUIET }, @@ -224,13 +223,13 @@ bool parse_log_cfg(const char *conf_str, std::string_view cfg = conf_str; if (cfg == "help") { - cout << "log level: [0-" << LOG_LEVEL_MAX; + col() << "log level: [0-" << LOG_LEVEL_MAX; for (auto m : mapping) { - cout << "|" << m.name; + col() << "|" << m.name; } - cout << "][+repeat][+/-timestamps]\n"; - cout << BOLD("\trepeat") << " - print repeating log messages\n"; - cout << BOLD("\ttimestamps") << " - enable/disable timestamps\n"; + col() << "][+repeat][+/-timestamps]\n"; + col() << TBOLD("\trepeat") << " - print repeating log messages\n"; + col() << TBOLD("\ttimestamps") << " - enable/disable timestamps\n"; return false; } diff --git a/src/keyboard_control.cpp b/src/keyboard_control.cpp index 3406061ad..f6f44b431 100644 --- a/src/keyboard_control.cpp +++ b/src/keyboard_control.cpp @@ -471,11 +471,11 @@ void keyboard_control::run() } if (c == K_CTRL('X')) { m_locked_against_changes = !m_locked_against_changes; // ctrl-x pressed - cout << GREEN("Keyboard control: " << (m_locked_against_changes ? "" : "un") << "locked against changes\n"); + col() << TGREEN("Keyboard control: " << (m_locked_against_changes ? "" : "un") << "locked against changes\n"); continue; } if (m_locked_against_changes && guarded_keys.find(c) != guarded_keys.end()) { - cout << GREEN("Keyboard control: locked against changes, press 'Ctrl-x' to unlock or 'h' for help.\n"); + col() << TGREEN("Keyboard control: locked against changes, press 'Ctrl-x' to unlock or 'h' for help.\n"); continue; } @@ -562,7 +562,7 @@ void keyboard_control::run() case 's': if (saved_log_level == -1) { saved_log_level = log_level; - cout << GREEN("Output suspended, press 'q' to continue.\n"); + col() << TGREEN("Output suspended, press 'q' to continue.\n"); log_level = LOG_LEVEL_QUIET; } break; @@ -570,7 +570,7 @@ void keyboard_control::run() if (saved_log_level != -1) { log_level = saved_log_level; saved_log_level = -1; - cout << GREEN( "Output resumed.\n"); + col() << TGREEN( "Output resumed.\n"); } break; case 'h': @@ -592,11 +592,11 @@ void keyboard_control::run() void keyboard_control::info() { - cout << BOLD("UltraGrid version: ") << get_version_details() << "\n"; - cout << BOLD("Start time: ") << asctime(localtime(&m_start_time)); - cout << BOLD("Verbosity level: ") << log_level << (log_level == LOG_LEVEL_INFO ? " (default)" : "") << "\n"; - cout << BOLD("Locked against changes: ") << (m_locked_against_changes ? "true" : "false") << "\n"; - cout << BOLD("Audio playback delay: " << get_audio_delay()) << " ms\n"; + col() << TBOLD("UltraGrid version: ") << get_version_details() << "\n"; + col() << TBOLD("Start time: ") << asctime(localtime(&m_start_time)); + col() << TBOLD("Verbosity level: ") << log_level << (log_level == LOG_LEVEL_INFO ? " (default)" : "") << "\n"; + col() << TBOLD("Locked against changes: ") << (m_locked_against_changes ? "true" : "false") << "\n"; + col() << TBOLD("Audio playback delay: ") << get_audio_delay() << " ms\n"; { int muted_sender = -1; @@ -609,11 +609,7 @@ void keyboard_control::info() double vol = 0; sscanf(response_get_text(resp), "%lf,%d", &vol, &muted_receiver); double db = 20.0 * log10(vol); - std::streamsize p = cout.precision(); - ios_base::fmtflags f = cout.flags(); - cout << BOLD("Playback volume: ") << fixed << setprecision(2) << vol * 100.0 << "% (" << (db >= 0.0 ? "+" : "") << db << " dB)\n"; - cout.precision(p); - cout.flags(f); + color_printf(TBOLD("Playback volume: ") "%.2f%% (%s%.2f dB)\n", vol * 100.0, (db >= 0.0 ? "+" : ""), db); } free_response(resp); path = "audio.sender"; @@ -631,7 +627,7 @@ void keyboard_control::info() default: return "(unknown)"; } }; - cout << BOLD("Audio muted - sender: ") << muted_to_string(muted_sender) << ", " << BOLD("receiver: ") << muted_to_string(muted_receiver) << "\n"; + col() << TBOLD("Audio muted - sender: ") << muted_to_string(muted_sender) << ", " << TBOLD("receiver: ") << muted_to_string(muted_receiver) << "\n"; } { @@ -643,7 +639,7 @@ void keyboard_control::info() const char *text = response_get_text(r); istringstream iss(text); iss >> desc; - cout << BOLD("Captured video format: ") << desc << "\n"; + col() << TBOLD("Captured video format: ") << desc << "\n"; } free_response(r); } @@ -657,7 +653,7 @@ void keyboard_control::info() const char *text = response_get_text(r); istringstream iss(text); iss >> desc; - cout << BOLD("Received video format: ") << desc << "\n"; + col() << TBOLD("Received video format: ") << desc << "\n"; } free_response(r); } @@ -667,7 +663,7 @@ void keyboard_control::info() strcpy(m->text, "get_port"); struct response *r = send_message_sync(m_root, "control", (struct message *) m, 100, SEND_MESSAGE_FLAG_QUIET | SEND_MESSAGE_FLAG_NO_STORE); if (response_get_status(r) == RESPONSE_OK) { - cout << BOLD("Control port: ") << response_get_text(r) << "\n"; + col() << TBOLD("Control port: ") << response_get_text(r) << "\n"; } free_response(r); } @@ -677,7 +673,7 @@ void keyboard_control::info() strcpy(m->text, "status"); struct response *r = send_message_sync(m_root, "exporter", (struct message *) m, 100, SEND_MESSAGE_FLAG_QUIET | SEND_MESSAGE_FLAG_NO_STORE); if (response_get_status(r) == RESPONSE_OK) { - cout << BOLD("Exporting: ") << response_get_text(r) << "\n"; + col() << TBOLD("Exporting: ") << response_get_text(r) << "\n"; } free_response(r); } @@ -689,33 +685,33 @@ void keyboard_control::info() void keyboard_control::usage() { - cout << "\nAvailable keybindings:\n" << - BOLD("\t * 0 ") << "- increase volume" << G('*') << "\n" << - BOLD("\t / 9 ") << "- decrease volume" << G('/') << "\n" << - BOLD("\t > ") << "- increase audio delay by 10 ms" << G('>') << "\n" << - BOLD("\t < ") << "- decrease audio delay by 10 ms" << G('<') << "\n" << - BOLD("\t m ") << "- mute/unmute receiver" << G('m') << "\n" << - BOLD("\t M ") << "- mute/unmute sender" << G('M') << "\n" << - BOLD("\t v ") << "- increase verbosity level" << G('v') << "\n" << - BOLD("\t V ") << "- decrease verbosity level" << G('V') << "\n" << - BOLD("\t r ") << "- skip repeated messages (toggle) " << G('r') << "\n" << - BOLD("\t e ") << "- record captured content (toggle)" << G('e') << "\n" << - BOLD("\t h ") << "- show help" << G('h') << "\n" << - BOLD("\t i ") << "- show various information" << G('i') << "\n" << - BOLD("\t s S ") << "- suspend/resume output" << G('s') << G('S') << "\n" << - BOLD("\t c C ") << "- execute command through control socket (capital for multiple)" << G('c') << G('C') << "\n" << - BOLD("\tCtrl-x ") << "- unlock/lock against changes" << G(K_CTRL('X')) << "\n" << - BOLD("\tCtrl-c ") << "- exit " << G(K_CTRL('c')) << "\n" << + col() << "\nAvailable keybindings:\n" << + TBOLD("\t * 0 ") << "- increase volume" << G('*') << "\n" << + TBOLD("\t / 9 ") << "- decrease volume" << G('/') << "\n" << + TBOLD("\t > ") << "- increase audio delay by 10 ms" << G('>') << "\n" << + TBOLD("\t < ") << "- decrease audio delay by 10 ms" << G('<') << "\n" << + TBOLD("\t m ") << "- mute/unmute receiver" << G('m') << "\n" << + TBOLD("\t M ") << "- mute/unmute sender" << G('M') << "\n" << + TBOLD("\t v ") << "- increase verbosity level" << G('v') << "\n" << + TBOLD("\t V ") << "- decrease verbosity level" << G('V') << "\n" << + TBOLD("\t r ") << "- skip repeated messages (toggle) " << G('r') << "\n" << + TBOLD("\t e ") << "- record captured content (toggle)" << G('e') << "\n" << + TBOLD("\t h ") << "- show help" << G('h') << "\n" << + TBOLD("\t i ") << "- show various information" << G('i') << "\n" << + TBOLD("\t s S ") << "- suspend/resume output" << G('s') << G('S') << "\n" << + TBOLD("\t c C ") << "- execute command through control socket (capital for multiple)" << G('c') << G('C') << "\n" << + TBOLD("\tCtrl-x ") << "- unlock/lock against changes" << G(K_CTRL('X')) << "\n" << + TBOLD("\tCtrl-c ") << "- exit " << G(K_CTRL('c')) << "\n" << "\n"; if (key_mapping.size() > 0) { cout << "Custom keybindings:\n"; for (auto it : key_mapping) { - cout << BOLD("\t" << setw(10) << get_keycode_representation(it.first) << setw(0)) << " - " << (it.second.second.empty() ? it.second.first : it.second.second) << G(it.first) << "\n"; + col() << TBOLD("\t" << setw(10) << get_keycode_representation(it.first) << setw(0) <<) << " - " << (it.second.second.empty() ? it.second.first : it.second.second) << G(it.first) << "\n"; } cout << "\n"; } - cout << BOLD("[g]") << " indicates that that option is guarded (Ctrl-x needs to be pressed first)\n"; + col() << TBOLD("[g]") << " indicates that that option is guarded (Ctrl-x needs to be pressed first)\n"; } void keyboard_control::load_config_map() { diff --git a/src/main.cpp b/src/main.cpp index e13def998..aeafadf74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -337,7 +337,7 @@ void exit_uv(int status) { static void print_help_item(const string &name, const vector &help) { int help_lines = 0; - cout << BOLD("\t" << name); + col() << "\t" << TBOLD(<< name <<); for (auto line : help) { int spaces = help_lines == 0 ? 31 - (int) name.length() : 39; @@ -356,7 +356,7 @@ static void print_help_item(const string &name, const vector &help) { static void usage(const char *exec_path, bool full = false) { - cout << "Usage: " << BOLD(RED((exec_path ? exec_path : "")) << " [options] address\n\n"); + col() << "Usage: " << TERM_BOLD TERM_FG_RED << (exec_path ? exec_path : "") << TERM_FG_RESET << " [options] address\n\n" TERM_RESET; printf("Options:\n"); print_help_item("-h | --fullhelp", {"show usage (basic/full)"}); print_help_item("-d ", {"select display device, use '-d help'", @@ -435,7 +435,7 @@ static void print_fps(steady_clock::time_point *t0, int *frames, const string &n double seconds = duration_cast>(t1 - *t0).count(); if (seconds >= 5.0) { double fps = *frames / seconds; - LOG(LOG_LEVEL_INFO) << BOLD(rang::bg::black << rang::fg::bright_green << "[" << name << "]" << rang::fg::reset << rang::bg::reset) << " " << *frames << " frames in " << seconds << " seconds = " << BOLD(fps << " FPS\n"); + log_msg(LOG_LEVEL_INFO, TERM_BG_BLACK TERM_FG_BRIGHT_GREEN "[%s]" TERM_RESET " %d frames in %g seconds = " TBOLD("%g FPS") "\n", name.c_str(), *frames, seconds, fps); *t0 = t1; *frames = 0; } @@ -516,15 +516,15 @@ static bool parse_bitrate(char *optarg, long long int *bitrate) { return true; } if (strcmp(optarg, "help") == 0) { - const char numeric_pattern[] = "{1-9}{0-9}*[kMG][!][E]"; - cout << "Usage:\n" << - "\tuv " << BOLD("-l [auto | dynamic | unlimited | " << numeric_pattern << "]\n") << +# define NUMERIC_PATTERN "{1-9}{0-9}*[kMG][!][E]" + col() << "Usage:\n" << + "\tuv " << TERM_BOLD "-l [auto | dynamic | unlimited | " << NUMERIC_PATTERN << "]\n" TERM_RESET << "where\n" - "\t" << BOLD("auto") << " - spread packets across frame time\n" - "\t" << BOLD("dynamic") << " - similar to \"auto\" but more relaxed - occasional huge frame can spread 1.5x frame time (default)\n" - "\t" << BOLD("unlimited") << " - send packets at a wire speed (in bursts)\n" - "\t" << BOLD(numeric_pattern) << " - send packets at most at specified bitrate\n\n" << - BOLD("Notes: ") << "Use an exclamation mark to indicate intentionally very low bitrate. 'E' to use the value as a fixed bitrate, not cap /i. e. even the frames that may be sent at lower bitrate are sent at the nominal bitrate)\n" << + "\t" << TBOLD("auto") << " - spread packets across frame time\n" + "\t" << TBOLD("dynamic") << " - similar to \"auto\" but more relaxed - occasional huge frame can spread 1.5x frame time (default)\n" + "\t" << TBOLD("unlimited") << " - send packets at a wire speed (in bursts)\n" + "\t" << TBOLD(NUMERIC_PATTERN) << " - send packets at most at specified bitrate\n\n" << + TBOLD("Notes: ") << "Use an exclamation mark to indicate intentionally very low bitrate. 'E' to use the value as a fixed bitrate, not cap /i. e. even the frames that may be sent at lower bitrate are sent at the nominal bitrate)\n" << "\n"; return true; } @@ -604,12 +604,12 @@ static int parse_cuda_device(char *optarg) { } if(strncmp(token, "help", strlen("help")) == 0){ - cout << "Usage:\n" << - "\tuv " << BOLD("-Nholepunch:room=:(server= | coord_srv=:stun_srv=)[:client_name=] \n") << + col() << "Usage:\n" << + "\tuv " << TBOLD("-Nholepunch:room=:(server= | coord_srv=:stun_srv=)[:client_name=] \n") << "\twhere\n" - "\t\t" << BOLD("server") << " - used if both stun & coord server are on the same host on standard ports (3478, 12558)\n" - "\t\t" << BOLD("room") << " - name of room to join\n" - "\t\t" << BOLD("client_name") << " - name to identify as to the coord server, if not specified hostname is used\n" + "\t\t" << TBOLD("server") << " - used if both stun & coord server are on the same host on standard ports (3478, 12558)\n" + "\t\t" << TBOLD("room") << " - name of room to join\n" + "\t\t" << TBOLD("client_name") << " - name to identify as to the coord server, if not specified hostname is used\n" "\n"; return false; } @@ -881,8 +881,8 @@ static int parse_options(int argc, char *argv[], struct ug_options *opt) { case OPT_PROTOCOL: if (strcmp(optarg, "help") == 0 || strcmp(optarg, "fullhelp") == 0) { - cout << "Specify a " << BOLD("common") << " protocol for both audio and video.\n"; - cout << "Audio protocol can be one of: " << BOLD(AUDIO_PROTOCOLS "\n"); + col() << "Specify a " << TBOLD("common") << " protocol for both audio and video.\n"; + col() << "Audio protocol can be one of: " << TBOLD(AUDIO_PROTOCOLS) "\n"; video_rxtx::list(strcmp(optarg, "fullhelp") == 0); return EXIT_SUCCESS; } @@ -1385,17 +1385,17 @@ int main(int argc, char *argv[]) EXIT(ret); } - cout << BOLD("Display device : ") << opt.requested_display << "\n"; - cout << BOLD("Capture device : ") << vidcap_params_get_driver(opt.vidcap_params_head) << "\n"; - cout << BOLD("Audio capture : ") << opt.audio.send_cfg << "\n"; - cout << BOLD("Audio playback : ") << opt.audio.recv_cfg << "\n"; - cout << BOLD("MTU : ") << opt.requested_mtu << " B\n"; - cout << BOLD("Video compression: ") << opt.requested_compression << "\n"; - cout << BOLD("Audio codec : ") << get_name_to_audio_codec(get_audio_codec(opt.audio.codec_cfg)) << "\n"; - cout << BOLD("Network protocol : ") << video_rxtx::get_long_name(opt.video_protocol) << "\n"; - cout << BOLD("Audio FEC : ") << opt.audio.fec_cfg << "\n"; - cout << BOLD("Video FEC : ") << opt.requested_video_fec << "\n"; - cout << "\n"; + col() << TBOLD("Display device : ") << opt.requested_display << "\n"; + col() << TBOLD("Capture device : ") << vidcap_params_get_driver(opt.vidcap_params_head) << "\n"; + col() << TBOLD("Audio capture : ") << opt.audio.send_cfg << "\n"; + col() << TBOLD("Audio playback : ") << opt.audio.recv_cfg << "\n"; + col() << TBOLD("MTU : ") << opt.requested_mtu << " B\n"; + col() << TBOLD("Video compression: ") << opt.requested_compression << "\n"; + col() << TBOLD("Audio codec : ") << get_name_to_audio_codec(get_audio_codec(opt.audio.codec_cfg)) << "\n"; + col() << TBOLD("Network protocol : ") << video_rxtx::get_long_name(opt.video_protocol) << "\n"; + col() << TBOLD("Audio FEC : ") << opt.audio.fec_cfg << "\n"; + col() << TBOLD("Video FEC : ") << opt.requested_video_fec << "\n"; + col() << "\n"; exporter = export_init(&uv.root_module, opt.export_opts, opt.should_export); if (!exporter) { diff --git a/src/rtp/audio_decoders.cpp b/src/rtp/audio_decoders.cpp index 32dd4e183..b31de783a 100644 --- a/src/rtp/audio_decoders.cpp +++ b/src/rtp/audio_decoders.cpp @@ -451,7 +451,7 @@ static void *adec_compute_and_print_stats(void *arg) { volume << (i > 0 ? " "s : ""s) << 20.0 * log(rms) / log(10.0) << "/" << 20.0 * log(peak) / log(10.0); } - LOG(LOG_LEVEL_INFO) << "[Audio decoder] Volume: " << fg::magenta << style::bold << volume.str() << style::reset << fg::reset << " dBFS RMS/peak" << BOLD(RED((d->muted_receiver ? " (muted)" : ""))) << "\n" ; + LOG(LOG_LEVEL_INFO) << "[Audio decoder] Volume: " << TERM_BOLD TERM_FG_MAGENTA << volume.str() << TERM_RESET << " dBFS RMS/peak" << (d->muted_receiver ? TBOLD(TRED(" (muted)")) : "") << "\n" ; delete d; diff --git a/src/utils/color_out.h b/src/utils/color_out.h index 307a9c8aa..5352345a9 100644 --- a/src/utils/color_out.h +++ b/src/utils/color_out.h @@ -1,12 +1,9 @@ /** * @file utils/color_out.h * @author Martin Pulec - * - * Simple C wrapper around the rang header and utility macros for the - * rang.hpp (C++ only) */ /* - * Copyright (c) 2018-2019 CESNET, z. s. p. o. + * Copyright (c) 2018-2022 CESNET, z. s. p. o. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,55 +38,17 @@ #ifndef COLOR_OUT_H_ #define COLOR_OUT_H_ -#ifdef __cplusplus -#include "rang.hpp" -#define BOLD(x) rang::style::bold << x << rang::style::reset -#define GREEN(x) rang::fg::green << x << rang::fg::reset -#define RED(x) rang::fg::red << x << rang::fg::reset -#include -#else -#include -#include -#endif - -#define COLOR_OUT_BOLD 1u -#define COLOR_OUT_DIM 2u -#define COLOR_OUT_ITALIC 3u -#define COLOR_OUT_UNDERLINE 5u -#define COLOR_OUT_BLINK 6u -#define COLOR_OUT_RBLINK 7u -#define COLOR_OUT_REVERSED 8u -#define COLOR_OUT_CONCEAL 9u -#define COLOR_OUT_CROSSED 10u - -#define COLOR_OUT_FG_SHIFT 4u -#define COLOR_BITS 7 -#define COLOR_OUT_BLACK (1u<<4u) -#define COLOR_OUT_RED (2u<<4u) -#define COLOR_OUT_GREEN (3u<<4u) -#define COLOR_OUT_YELLOW (4u<<4u) -#define COLOR_OUT_BLUE (5u<<4u) -#define COLOR_OUT_MAGENTA (6u<<4u) -#define COLOR_OUT_CYAN (7u<<4u) -#define COLOR_OUT_GRAY (8u<<4u) -#define COLOR_OUT_BRIGHT_BLACK (61u<<4u) -#define COLOR_OUT_BRIGHT_RED (62u<<4u) -#define COLOR_OUT_BRIGHT_GREEN (63u<<4u) -#define COLOR_OUT_BRIGHT_YELLOW (64u<<4u) -#define COLOR_OUT_BRIGHT_BLUE (65u<<4u) -#define COLOR_OUT_BRIGHT_MAGENTA (66u<<4u) -#define COLOR_OUT_BRIGHT_CYAN (67u<<4u) -#define COLOR_OUT_BRIGHT_GRAY (68u<<4u) -#define COLOR_OUT_BG_SHIFT (COLOR_OUT_FG_SHIFT+COLOR_BITS) - #define TERM_RESET "\033[0m" #define TERM_BOLD "\033[1m" #define TERM_FG_RED "\033[31m" #define TERM_FG_GREEN "\033[32m" #define TERM_FG_YELLOW "\033[33m" #define TERM_FG_BLUE "\033[34m" -#define TERM_FG_MAGENTA "\033[34m" +#define TERM_FG_MAGENTA "\033[35m" +#define TERM_FG_BRIGHT_GREEN "\033[92m" #define TERM_FG_RESET "\033[39m" +#define TERM_BG_BLACK "\033[40m" +#define TERM_BG_RESET "\033[49m" #define TBOLD(x) TERM_BOLD x TERM_RESET #define TGREEN(x) TERM_FG_GREEN x TERM_FG_RESET diff --git a/src/video_capture/decklink.cpp b/src/video_capture/decklink.cpp index 2fed0df35..ebd3ccbe9 100644 --- a/src/video_capture/decklink.cpp +++ b/src/video_capture/decklink.cpp @@ -541,7 +541,7 @@ decklink_help(bool full) } cout << "\n"; if (!full) { - cout << "Possible connections: " << BOLD("SDI") << ", " << BOLD("HDMI") << ", " << BOLD("OpticalSDI") << ", " << BOLD("Component") << ", " << BOLD("Composite") << ", " << BOLD("SVideo") << "\n"; + col() << "Possible connections: " << TBOLD("SDI") << ", " << TBOLD("HDMI") << ", " << TBOLD("OpticalSDI") << ", " << TBOLD("Component") << ", " << TBOLD("Composite") << ", " << TBOLD("SVideo") << "\n"; } cout << "\n"; @@ -563,7 +563,7 @@ decklink_help(bool full) } // *** Print the model name of the DeckLink card - cout << "\t" << BOLD(numDevices) << ") " << BOLD(GREEN(deviceName)) << "\n"; + col() << "\t" << TBOLD(<< numDevices <<) << ") " << TBOLD(TGREEN(<< deviceName <<)) << "\n"; // Increment the total number of DeckLink cards found numDevices++; diff --git a/src/video_capture/ndi.cpp b/src/video_capture/ndi.cpp index 7103e2703..a2a2d4166 100644 --- a/src/video_capture/ndi.cpp +++ b/src/video_capture/ndi.cpp @@ -129,23 +129,23 @@ static void show_help(struct vidcap_state_ndi *s) { "[:help][:name=][:url=][:audio_level=][:bandwidth=][:color=][:extra_ips=][:progressive]\n" << rang::style::reset << "where\n"; - cout << BOLD("\tname\n") << + col() << TBOLD("\tname\n") << "\t\tname of the NDI source in form " "\"MACHINE_NAME (NDI_SOURCE_NAME)\"\n"; - cout << BOLD("\turl\n") << + col() << TBOLD("\turl\n") << "\t\tURL, typically or :\n"; - cout << BOLD("\taudio_level\n") << + col() << TBOLD("\taudio_level\n") << "\t\taudio headroom above reference level (in dB, or mic/line, default " << 20 * log(DEFAULT_AUDIO_DIVISOR) / log(10) << ")\n"; - cout << BOLD("\tbandwidth\n") << - "\t\trequired bandwidth, " << BOLD(NDIlib_recv_bandwidth_audio_only) << " - audio only, " << BOLD(NDIlib_recv_bandwidth_lowest) << " - lowest, " << BOLD(NDIlib_recv_bandwidth_highest) << " - highest (default)\n"; - cout << BOLD("\tcolor\n") << - "\t\tcolor format, " << BOLD(NDIlib_recv_color_format_BGRX_BGRA) << " - BGRX/BGRA, " << BOLD(NDIlib_recv_color_format_UYVY_BGRA) << " - UYVY/BGRA, " << - BOLD(NDIlib_recv_color_format_RGBX_RGBA) << " - RGBX/RGBA, " << BOLD(NDIlib_recv_color_format_UYVY_RGBA) << " - UYVY/RGBA, " << BOLD(NDIlib_recv_color_format_fastest) << - " - fastest (UYVY), " << BOLD(NDIlib_recv_color_format_best) << " - best (default, P216/UYVY)\n" + col() << TBOLD("\tbandwidth\n") << + "\t\trequired bandwidth, " << TBOLD(<< NDIlib_recv_bandwidth_audio_only << ) << " - audio only, " TBOLD(<< NDIlib_recv_bandwidth_lowest <<) " - lowest, " TBOLD(<< NDIlib_recv_bandwidth_highest <<) " - highest (default)\n"; + col() << TBOLD("\tcolor\n") << + "\t\tcolor format, " << TBOLD(<< NDIlib_recv_color_format_BGRX_BGRA <<) << " - BGRX/BGRA, " << TBOLD(<< NDIlib_recv_color_format_UYVY_BGRA <<) << " - UYVY/BGRA, " << + TBOLD(<< NDIlib_recv_color_format_RGBX_RGBA <<) << " - RGBX/RGBA, " << TBOLD(<< NDIlib_recv_color_format_UYVY_RGBA <<) << " - UYVY/RGBA, " << TBOLD(<< NDIlib_recv_color_format_fastest <<) << + " - fastest (UYVY), " << TBOLD(<< NDIlib_recv_color_format_best <<) << " - best (default, P216/UYVY)\n" "\t\tSelection is on NDI runtime and usually depends on presence of alpha channel. UG ignores alpha channel for YCbCr codecs.\n"; - cout << BOLD("\textra_ips\n") << + col() << TBOLD("\textra_ips\n") << "\t\tadditional IP addresses for query in format \"12.0.0.8,13.0.12.8\"\n"; - cout << BOLD("\tprogressive\n") << + col() << TBOLD("\tprogressive\n") << "\t\tprefer progressive capture for interlaced input\n" "\n"; diff --git a/src/video_capture/spout.cpp b/src/video_capture/spout.cpp index 35d2a6c27..c3d9e9ea1 100644 --- a/src/video_capture/spout.cpp +++ b/src/video_capture/spout.cpp @@ -87,13 +87,13 @@ struct state_vidcap_spout { static void usage() { - cout << "Usage:\n"; - cout << "\t" << BOLD(RED("-t spout") << "[:name=|device=][:fps=][:codec=]") << "\n"; - cout << "where\n"; - cout << "\t" << BOLD("name") << "\n\t\tSPOUT server name\n"; - cout << "\t" << BOLD("fps") << "\n\t\tFPS count (default: " << DEFAULT_FPS << ")\n"; - cout << "\t" << BOLD("codec") << "\n\t\tvideo codec (default: " << get_codec_name(DEFAULT_CODEC) << ")\n"; - cout << "\nServers:\n"; + col() << "Usage:\n"; + col() << "\t" << TBOLD(TRED("-t spout") << "[:name=|device=][:fps=][:codec=]") << "\n"; + col() << "where\n"; + col() << "\t" << TBOLD("name") << "\n\t\tSPOUT server name\n"; + col() << "\t" << TBOLD("fps") << "\n\t\tFPS count (default: " << DEFAULT_FPS << ")\n"; + col() << "\t" << TBOLD("codec") << "\n\t\tvideo codec (default: " << get_codec_name(DEFAULT_CODEC) << ")\n"; + col() << "\nServers:\n"; auto receiver = shared_ptr(new SpoutReceiver); int count = receiver->GetSenderCount(); @@ -110,7 +110,7 @@ static void usage() if (!receiver->GetSenderInfo(name.data(), width, height, dxShareHandle, dwFormat)) { LOG(LOG_LEVEL_ERROR) << "Cannot get server " << name.data() << "details\n"; } - cout << "\t" << i << ") " << BOLD(name.data()) << " - width: " << width << ", height: " << height << "\n"; + col() << "\t" << i << ") " << TBOLD(<< name.data() <<) << " - width: " << width << ", height: " << height << "\n"; } } diff --git a/src/video_capture/testcard.cpp b/src/video_capture/testcard.cpp index 5fabc6b41..af69fd288 100644 --- a/src/video_capture/testcard.cpp +++ b/src/video_capture/testcard.cpp @@ -84,8 +84,6 @@ constexpr int AUDIO_BUFFER_SIZE(int ch_count) { return AUDIO_SAMPLE_RATE * AUDIO #define MOD_NAME "[testcard] " constexpr video_desc default_format = { 1920, 1080, UYVY, 25.0, INTERLACED_MERGED, 1 }; -using rang::fg; -using rang::style; using namespace std; struct testcard_state { diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index 932070618..b4ac208be 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -291,13 +291,13 @@ static void usage() { cout << "where:\n"; for(const auto& opt : usage_opts){ if (opt.is_boolean) { - cout << BOLD("\t" << opt.opt_str + 1); + col() << TBOLD("\t" << opt.opt_str + 1 <<); } else { - cout << BOLD("\t<" << opt.opt_str[1] << ">"); + col() << TBOLD("\t<" << opt.opt_str[1] << ">"); } cout << " - " << opt.description << "\n"; } - cout << BOLD("\t") << " - CUDA device(s) to use (comma separated)\n"; + col() << TBOLD("\t") << " - CUDA device(s) to use (comma separated)\n"; } #define ASSIGN_CHECK_VAL(var, str, minval) do { long long val = unit_evaluate(str); \ diff --git a/src/video_compress/gpujpeg.cpp b/src/video_compress/gpujpeg.cpp index 3a86c2d3f..51ba0fe45 100644 --- a/src/video_compress/gpujpeg.cpp +++ b/src/video_compress/gpujpeg.cpp @@ -464,17 +464,17 @@ struct module * gpujpeg_compress_init(struct module *parent, const char *opts) if(opts && strcmp(opts, "help") == 0) { cout << "GPUJPEG comperssion usage:\n"; - cout << "\t" << BOLD(RED("-c GPUJPEG") << "[:[:]][:interleaved][:RGB|Y601|Y601full|Y709]][:subsampling=][:alpha]\n"); + col() << "\t" << TBOLD(TRED("-c GPUJPEG") << "[:[:]][:interleaved][:RGB|Y601|Y601full|Y709]][:subsampling=][:alpha]\n"); cout << "where\n"; for(const auto& i : usage_opts){ - cout << "\t" < 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3) int xpos, ypos, width, height; glfwGetMonitorWorkarea(mon[i], &xpos, &ypos, &width, &height); @@ -464,31 +464,31 @@ static void gl_show_help(bool full) { << (full ? " [--param " GL_DISABLE_10B_OPT_PARAM_NAME "|" GL_WINDOW_HINT_OPT_PARAM_NAME "==]" : "") << "\n\n" << rang::style::reset; cout << "options:\n"; - cout << BOLD("\td") << "\t\tdeinterlace\n"; - cout << BOLD("\tfs[=]") << "\tfullscreen with optional display specification\n"; - cout << BOLD("\tmodeset[=]")<< "\tset received video mode as display mode (in fullscreen); modeset=|size - set specified FPS or only size\n"; - cout << BOLD("\tnodecorate") << "\tdisable window decorations\n"; - cout << BOLD("\tnovsync") << "\t\tdo not turn sync on VBlank\n"; - cout << BOLD("\tvsync=") << "\tsets vsync to: 0 - disable; 1 - enable; -1 - adaptive vsync; D - leaves system default\n"; - cout << BOLD("\tsingle") << "\t\tuse single buffer (instead of double-buffering)\n"; - cout << BOLD("\taspect=/") << "\trequested video aspect (eg. 16/9). Leave unset if PAR = 1.\n"; - cout << BOLD("\tcursor") << "\t\tshow visible cursor\n"; - cout << BOLD("\tsize") << "\t\tspecifies desired size of window compared " + col() << TBOLD("\td") << "\t\tdeinterlace\n"; + col() << TBOLD("\tfs[=]") << "\tfullscreen with optional display specification\n"; + col() << TBOLD("\tmodeset[=]")<< "\tset received video mode as display mode (in fullscreen); modeset=|size - set specified FPS or only size\n"; + col() << TBOLD("\tnodecorate") << "\tdisable window decorations\n"; + col() << TBOLD("\tnovsync") << "\t\tdo not turn sync on VBlank\n"; + col() << TBOLD("\tvsync=") << "\tsets vsync to: 0 - disable; 1 - enable; -1 - adaptive vsync; D - leaves system default\n"; + col() << TBOLD("\tsingle") << "\t\tuse single buffer (instead of double-buffering)\n"; + col() << TBOLD("\taspect=/") << "\trequested video aspect (eg. 16/9). Leave unset if PAR = 1.\n"; + col() << TBOLD("\tcursor") << "\t\tshow visible cursor\n"; + col() << TBOLD("\tsize") << "\t\tspecifies desired size of window compared " "to native resolution (in percents)\n"; - cout << BOLD("\tsyphon") << "\t\tuse Syphon (optionally with name)\n"; - cout << BOLD("\tspout") << "\t\tuse Spout (optionally with name)\n"; - cout << BOLD("\thide-window") << "\tdo not show OpenGL window (useful with Syphon/SPOUT)\n"; - cout << BOLD("\t[no]pbo") << "\t\tWhether or not use PBO (ignore if not sure)\n"; + col() << TBOLD("\tsyphon") << "\t\tuse Syphon (optionally with name)\n"; + col() << TBOLD("\tspout") << "\t\tuse Spout (optionally with name)\n"; + col() << TBOLD("\thide-window") << "\tdo not show OpenGL window (useful with Syphon/SPOUT)\n"; + col() << TBOLD("\t[no]pbo") << "\t\tWhether or not use PBO (ignore if not sure)\n"; if (full) { - cout << BOLD("\t--param " GL_DISABLE_10B_OPT_PARAM_NAME) << "\tdo not set 10-bit framebuffer (performance issues)\n"; - cout << BOLD("\t--param " GL_WINDOW_HINT_OPT_PARAM_NAME) << "=[:=] set GLFW window hint key to value , eg. 0x20006=1 to autoiconify (experts only)\n"; + col() << TBOLD("\t--param " GL_DISABLE_10B_OPT_PARAM_NAME) << "\tdo not set 10-bit framebuffer (performance issues)\n"; + col() << TBOLD("\t--param " GL_WINDOW_HINT_OPT_PARAM_NAME) << "=[:=] set GLFW window hint key to value , eg. 0x20006=1 to autoiconify (experts only)\n"; } printf("\nkeyboard shortcuts:\n"); for (auto i : keybindings) { char keyname[50]; get_keycode_name(i.first, keyname, sizeof keyname); - cout << "\t" << BOLD(keyname) << "\t\t" << i.second << "\n"; + col() << "\t" << TBOLD(<< keyname <<) << "\t\t" << i.second << "\n"; } gl_print_monitors(full); diff --git a/src/video_display/rpi4_out.cpp b/src/video_display/rpi4_out.cpp index cf60ba9c4..37d034f19 100644 --- a/src/video_display/rpi4_out.cpp +++ b/src/video_display/rpi4_out.cpp @@ -366,12 +366,12 @@ struct rpi4_display_state{ }; static void print_rpi4_out_help(){ - std::cout << "usage:\n"; - std::cout << rang::style::bold << rang::fg::red << "\t-d rpi4" << rang::fg::reset << "[:force-size=x|:position=x|:fs]* | help\n\n" << rang::style::reset; - std::cout << "options:\n"; - std::cout << BOLD("\tfs") << "\t\tfullscreen\n"; - std::cout << BOLD("\tforce-size") << "\t\tspecifies desired size of output\n"; - std::cout << BOLD("\tposition") << "\t\tspecifies the desired position of output (coordinates of top left corner)\n"; + col() << "usage:\n"; + col() << TBOLD(TRED("\t-d rpi4") << "[:force-size=x|:position=x|:fs]* | help\n\n"); + col() << "options:\n"; + col() << TBOLD("\tfs") << "\t\tfullscreen\n"; + col() << TBOLD("\tforce-size") << "\t\tspecifies desired size of output\n"; + col() << TBOLD("\tposition") << "\t\tspecifies the desired position of output (coordinates of top left corner)\n"; } static void *display_rpi4_init(struct module *parent, const char *cfg, unsigned int flags) diff --git a/src/video_display/unix_sock.cpp b/src/video_display/unix_sock.cpp index 86de08947..dba0d7342 100644 --- a/src/video_display/unix_sock.cpp +++ b/src/video_display/unix_sock.cpp @@ -101,15 +101,15 @@ struct state_unix_sock { }; static void show_help(){ - std::cout << "unix_socket/preview display. The two display are identical apart from their defaults and the fact that preview never blocks on putf().\n"; - std::cout << "usage:\n"; - std::cout << rang::style::bold << rang::fg::red << "\t-d (unix_socket|preview)" << rang::fg::reset << "[:path=][:target_size=x]" - << "\n\n" << rang::style::reset; - std::cout << "options:\n"; - std::cout << BOLD("\tpath=") << "\tpath to unix socket to connect to. Defaults are \"" + col() << "unix_socket/preview display. The two display are identical apart from their defaults and the fact that preview never blocks on putf().\n"; + col() << "usage:\n"; + col() << TBOLD(TRED("\t-d (unix_socket|preview)") << "[:path=][:target_size=x]") + << "\n\n"; + col() << "options:\n"; + col() << TBOLD("\tpath=") << "\tpath to unix socket to connect to. Defaults are \"" << PLATFORM_TMP_DIR DEFAULT_PREVIEW_FILENAME "\" for preview and \"" << PLATFORM_TMP_DIR DEFAULT_DISP_FILENAME "\" for unix_sock\n"; - std::cout << BOLD("\ttarget_size=x")<< "\tScales the video frame so that the total number of pixel is around x. If -1x-1 is passed, no scaling takes place." + col() << TBOLD("\ttarget_size=x")<< "\tScales the video frame so that the total number of pixel is around x. If -1x-1 is passed, no scaling takes place." << "Defaults are -1x-1 for unix_sock and " TOSTRING(DEFAULT_SCALE_W) "x" TOSTRING(DEFAULT_SCALE_H) " for preview.\n"; }