mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 11:40:22 +00:00
parse_bitrate: use also for hd-rum-transcode
This commit is contained in:
83
src/host.cpp
83
src/host.cpp
@@ -6,7 +6,7 @@
|
||||
* This file contains common external definitions.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2013-2023 CESNET, z. s. p. o.
|
||||
* Copyright (c) 2013-2024 CESNET
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -968,6 +968,87 @@ bool parse_params(const char *optarg, bool preinit)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
parse_bitrate(char *optarg, long long int *bitrate)
|
||||
{
|
||||
unordered_map<string, long long int> bitrate_spec_map = {
|
||||
{"auto", RATE_AUTO },
|
||||
{ "dynamic", RATE_DYNAMIC },
|
||||
{ "unlimited", RATE_UNLIMITED},
|
||||
};
|
||||
|
||||
if (auto it = bitrate_spec_map.find(optarg);
|
||||
it != bitrate_spec_map.end()) {
|
||||
*bitrate = it->second;
|
||||
return true;
|
||||
}
|
||||
if (strcmp(optarg, "help") == 0) {
|
||||
constexpr char const *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"
|
||||
<< 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"
|
||||
<< SBOLD(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;
|
||||
}
|
||||
bool force = false;
|
||||
bool fixed = false;
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (optarg[strlen(optarg) - 1] == '!' ||
|
||||
optarg[strlen(optarg) - 1] == 'E') {
|
||||
if (optarg[strlen(optarg) - 1] == '!') {
|
||||
force = true;
|
||||
optarg[strlen(optarg) - 1] = '\0';
|
||||
}
|
||||
if (optarg[strlen(optarg) - 1] == 'E') {
|
||||
fixed = true;
|
||||
optarg[strlen(optarg) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
*bitrate = unit_evaluate(optarg, nullptr);
|
||||
if (*bitrate <= 0) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Invalid bitrate %s!\n", optarg);
|
||||
return false;
|
||||
}
|
||||
constexpr long long mb5 =
|
||||
5ll * 1000 *
|
||||
1000; // it'll take 6.4 sec to send 4 MB frame at 5 Mbps
|
||||
constexpr long long gb100 =
|
||||
100ll * 1000 * 1000 *
|
||||
1000; // traffic shaping to eg. 40 Gbps may make sense
|
||||
if ((*bitrate < mb5 || *bitrate > gb100) && !force) {
|
||||
log_msg(LOG_LEVEL_WARNING,
|
||||
"Bitrate %lld bps seems to be too %s, use \"-l %s!\" "
|
||||
"to force if this is not a mistake.\n",
|
||||
*bitrate, *bitrate < mb5 ? "low" : "high", optarg);
|
||||
return false;
|
||||
}
|
||||
if (fixed) {
|
||||
*bitrate |= RATE_FLAG_FIXED_RATE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void print_param_doc()
|
||||
{
|
||||
for (unsigned int i = 0; i < sizeof params / sizeof params[0]; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user