mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 04:40:16 +00:00
set output buffering early
setvbuf() should be called on a stream prior to any operation with the stream. Previously it was to late -- it was even after configuration summary was printed to stdout.
This commit is contained in:
@@ -613,9 +613,7 @@ static int parse_fmt(int argc, char **argv, struct cmdline_parameters *parsed)
|
||||
} else if(strcmp(argv[start_index], "--verbose") == 0) {
|
||||
parsed->verbose = true;
|
||||
} else if(strcmp(argv[start_index], "--param") == 0 && start_index < argc - 1) {
|
||||
if (!parse_params(argv[++start_index])) {
|
||||
return -1;
|
||||
}
|
||||
// already handled in common_preinit()
|
||||
} else {
|
||||
LOG(LOG_LEVEL_FATAL) << MOD_NAME << "Unknown global parameter: " << argv[start_index] << "\n\n";
|
||||
usage(argv[0]);
|
||||
|
||||
35
src/host.cpp
35
src/host.cpp
@@ -124,6 +124,8 @@ struct init_data {
|
||||
list <void *> opened_libs;
|
||||
};
|
||||
|
||||
static bool parse_params(char *optarg);
|
||||
|
||||
void common_cleanup(struct init_data *init)
|
||||
{
|
||||
if (init) {
|
||||
@@ -150,7 +152,7 @@ ADD_TO_PARAM("stdout-buf",
|
||||
ADD_TO_PARAM("stderr-buf",
|
||||
"* stderr-buf={no|line|full}\n"
|
||||
" Buffering for stderr\n");
|
||||
bool set_output_buffering() {
|
||||
static bool set_output_buffering() {
|
||||
const unordered_map<const char *, pair<FILE *, int>> outs = { // pair<output, default mode>
|
||||
{ "stdout-buf", pair{stdout, _IOLBF} },
|
||||
{ "stderr-buf", pair{stderr, _IONBF} }
|
||||
@@ -264,11 +266,18 @@ bool parse_audio_capture_format(const char *optarg)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_set_logging(int argc, char *argv[])
|
||||
/**
|
||||
* Sets things that must be set before anything else (logging and params)
|
||||
*
|
||||
* (params because used by set
|
||||
*/
|
||||
static bool parse_opts_set_logging(int argc, char *argv[])
|
||||
{
|
||||
char *log_opt = nullptr;
|
||||
static struct option getopt_options[] = {
|
||||
{"verbose", optional_argument, nullptr, 'V'}, { nullptr, 0, nullptr, 0 }
|
||||
{"param", no_argument, nullptr, OPT_PARAM}, // no_argument -- sic (!), see below
|
||||
{"verbose", optional_argument, nullptr, 'V'},
|
||||
{ nullptr, 0, nullptr, 0 }
|
||||
};
|
||||
int saved_opterr = opterr;
|
||||
opterr = 0; // options are further handled in main.cpp
|
||||
@@ -289,7 +298,16 @@ static bool parse_set_logging(int argc, char *argv[])
|
||||
log_level += 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case OPT_PARAM:
|
||||
if (i == argc - 1) {
|
||||
fprintf(stderr, "Missing argument to \"--param\"!\n");
|
||||
return false;
|
||||
}
|
||||
if (!parse_params(argv[i + 1])) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default: // will be handled in main
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -313,10 +331,15 @@ struct init_data *common_preinit(int argc, char *argv[])
|
||||
uv_argc = argc;
|
||||
uv_argv = argv;
|
||||
|
||||
if (!parse_set_logging(argc, argv)) {
|
||||
if (!parse_opts_set_logging(argc, argv)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!set_output_buffering()) {
|
||||
LOG(LOG_LEVEL_WARNING) << "Cannot set console output buffering!\n";
|
||||
}
|
||||
std::clog.rdbuf(std::cout.rdbuf()); // use stdout for logs by default
|
||||
|
||||
#ifdef HAVE_X
|
||||
void *handle = dlopen(X11_LIB_NAME, RTLD_NOW);
|
||||
|
||||
@@ -664,7 +687,7 @@ bool validate_param(const char *param)
|
||||
/**
|
||||
* Parses command-line parameters given as "--param <key>=<val>[...".
|
||||
*/
|
||||
bool parse_params(char *optarg)
|
||||
static bool parse_params(char *optarg)
|
||||
{
|
||||
if (optarg != nullptr && strcmp(optarg, "help") == 0) {
|
||||
puts("Params can be one or more (separated by comma) of following:");
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#define EXIT_FAIL_CONTROL_SOCK 9
|
||||
#define EXIT_FAIL_NETWORK 10
|
||||
#define EXIT_FAIL_AUDIO 11
|
||||
#define OPT_PARAM (('O' << 8) | 'P')
|
||||
|
||||
#define BUG_MSG "Please report a bug to " PACKAGE_BUGREPORT " if you reach here."
|
||||
|
||||
@@ -137,9 +138,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);
|
||||
void print_param_doc(void);
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@@ -137,7 +137,6 @@ static constexpr const char *DEFAULT_AUDIO_CODEC = "PCM";
|
||||
#define OPT_IMPORT (('I' << 8) | 'M')
|
||||
#define OPT_LIST_MODULES (('L' << 8) | 'M')
|
||||
#define OPT_MCAST_IF (('M' << 8) | 'I')
|
||||
#define OPT_PARAM (('O' << 8) | 'P')
|
||||
#define OPT_PIX_FMTS (('P' << 8) | 'F')
|
||||
#define OPT_PROTOCOL (('P' << 8) | 'R')
|
||||
#define OPT_START_PAUSED (('S' << 8) | 'P')
|
||||
@@ -1066,10 +1065,7 @@ static int parse_options(int argc, char *argv[], struct ug_options *opt) {
|
||||
opt->start_paused = true;
|
||||
break;
|
||||
case OPT_PARAM:
|
||||
if (!parse_params(optarg)) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
break; // already handled in common_preinit()
|
||||
case OPT_PIX_FMTS:
|
||||
print_pixel_formats();
|
||||
return EXIT_SUCCESS;
|
||||
@@ -1159,11 +1155,6 @@ static int adjust_params(struct ug_options *opt) {
|
||||
opt->force_ip_version = 4;
|
||||
}
|
||||
|
||||
if (!set_output_buffering()) {
|
||||
LOG(LOG_LEVEL_WARNING) << "Cannot set console output buffering!\n";
|
||||
}
|
||||
std::clog.rdbuf(std::cout.rdbuf()); // use stdout for logs by default
|
||||
|
||||
// default values for different RXTX protocols
|
||||
if (strcasecmp(opt->video_protocol, "rtsp") == 0 || strcasecmp(opt->video_protocol, "sdp") == 0) {
|
||||
if (opt->requested_compression == nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user