mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 08:40:19 +00:00
moved parse_audio_capture_format() to host.cpp
This commit is contained in:
59
src/host.cpp
59
src/host.cpp
@@ -202,6 +202,61 @@ static void load_libgcc()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool parse_audio_capture_format(const char *optarg)
|
||||
{
|
||||
if (strcmp(optarg, "help") == 0) {
|
||||
printf("Usage:\n");
|
||||
printf("\t--audio-capture-format {channels=<num>|bps=<bits_per_sample>|sample_rate=<rate>}*\n");
|
||||
printf("\t\tmultiple options can be separated by a colon\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<char[]> arg_copy(new char[strlen(optarg) + 1]);
|
||||
char *arg = arg_copy.get();
|
||||
strcpy(arg, optarg);
|
||||
|
||||
char *item = nullptr;
|
||||
char *save_ptr = nullptr;
|
||||
char *endptr = nullptr;
|
||||
char *tmp = arg;
|
||||
|
||||
while ((item = strtok_r(tmp, ":", &save_ptr))) {
|
||||
if (strncmp(item, "channels=", strlen("channels=")) == 0) {
|
||||
item += strlen("channels=");
|
||||
audio_capture_channels = strtol(item, &endptr, 10);
|
||||
if (audio_capture_channels < 1 || endptr != item + strlen(item)) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Invalid number of channels %s!\n", item);
|
||||
return false;
|
||||
}
|
||||
} else if (strncmp(item, "bps=", strlen("bps=")) == 0) {
|
||||
item += strlen("bps=");
|
||||
int bps = strtol(item, &endptr, 10);
|
||||
if (bps % 8 != 0 || (bps != 8 && bps != 16 && bps != 24 && bps != 32) || endptr != item + strlen(item)) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Invalid bps %s!\n", item);
|
||||
log_msg(LOG_LEVEL_ERROR, "Supported values are 8, 16, 24, or 32 bits.\n");
|
||||
return false;
|
||||
|
||||
}
|
||||
audio_capture_bps = bps / 8;
|
||||
} else if (strncmp(item, "sample_rate=", strlen("sample_rate=")) == 0) {
|
||||
const char *sample_rate_str = item + strlen("sample_rate=");
|
||||
long long val = unit_evaluate(sample_rate_str);
|
||||
if (val <= 0 || val > numeric_limits<decltype(audio_capture_sample_rate)>::max()) {
|
||||
LOG(LOG_LEVEL_ERROR) << "Invalid sample_rate " << sample_rate_str << "!\n";
|
||||
return false;
|
||||
}
|
||||
audio_capture_sample_rate = val;
|
||||
} else {
|
||||
log_msg(LOG_LEVEL_ERROR, "Unkonwn format for --audio-capture-format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_set_logging(int argc, char *argv[])
|
||||
{
|
||||
char *log_opt = nullptr;
|
||||
@@ -583,6 +638,10 @@ bool validate_param(const char *param)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses command-line parameters given as "--param <key>=<val>[...".
|
||||
*/
|
||||
bool parse_params(char *optarg)
|
||||
{
|
||||
if (optarg != nullptr && strcmp(optarg, "help") == 0) {
|
||||
|
||||
@@ -134,6 +134,7 @@ void print_configuration(void);
|
||||
const char *get_commandline_param(const char *key);
|
||||
|
||||
bool set_output_buffering();
|
||||
bool parse_audio_capture_format(const char *optarg);
|
||||
bool parse_params(char *optarg);
|
||||
void register_param(const char *param, const char *doc);
|
||||
bool validate_param(const char *param);
|
||||
|
||||
54
src/main.cpp
54
src/main.cpp
@@ -502,60 +502,6 @@ static void *capture_thread(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool parse_audio_capture_format(const char *optarg)
|
||||
{
|
||||
if (strcmp(optarg, "help") == 0) {
|
||||
printf("Usage:\n");
|
||||
printf("\t--audio-capture-format {channels=<num>|bps=<bits_per_sample>|sample_rate=<rate>}*\n");
|
||||
printf("\t\tmultiple options can be separated by a colon\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<char[]> arg_copy(new char[strlen(optarg) + 1]);
|
||||
char *arg = arg_copy.get();
|
||||
strcpy(arg, optarg);
|
||||
|
||||
char *item, *save_ptr, *tmp;
|
||||
tmp = arg;
|
||||
char *endptr;
|
||||
|
||||
while ((item = strtok_r(tmp, ":", &save_ptr))) {
|
||||
if (strncmp(item, "channels=", strlen("channels=")) == 0) {
|
||||
item += strlen("channels=");
|
||||
audio_capture_channels = strtol(item, &endptr, 10);
|
||||
if (audio_capture_channels < 1 || endptr != item + strlen(item)) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Invalid number of channels %s!\n", item);
|
||||
return false;
|
||||
}
|
||||
} else if (strncmp(item, "bps=", strlen("bps=")) == 0) {
|
||||
item += strlen("bps=");
|
||||
int bps = strtol(item, &endptr, 10);
|
||||
if (bps % 8 != 0 || (bps != 8 && bps != 16 && bps != 24 && bps != 32) || endptr != item + strlen(item)) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Invalid bps %s!\n", item);
|
||||
log_msg(LOG_LEVEL_ERROR, "Supported values are 8, 16, 24, or 32 bits.\n");
|
||||
return false;
|
||||
|
||||
}
|
||||
audio_capture_bps = bps / 8;
|
||||
} else if (strncmp(item, "sample_rate=", strlen("sample_rate=")) == 0) {
|
||||
const char *sample_rate_str = item + strlen("sample_rate=");
|
||||
long long val = unit_evaluate(sample_rate_str);
|
||||
if (val <= 0 || val > numeric_limits<decltype(audio_capture_sample_rate)>::max()) {
|
||||
LOG(LOG_LEVEL_ERROR) << "Invalid sample_rate " << sample_rate_str << "!\n";
|
||||
return false;
|
||||
}
|
||||
audio_capture_sample_rate = val;
|
||||
} else {
|
||||
log_msg(LOG_LEVEL_ERROR, "Unkonwn format for --audio-capture-format!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp = NULL;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_bitrate(char *optarg, long long int *bitrate) {
|
||||
if (strcmp(optarg, "auto") == 0) {
|
||||
*bitrate = RATE_AUTO;
|
||||
|
||||
Reference in New Issue
Block a user