obs-x264: Log ignored options
When an x264 option doesn't include a "=", it is silently ignored. This is frustrating for users. Log when part of the options string is ignored. Aside from logging, this commit should not change behavior.
This commit is contained in:
@@ -29,12 +29,17 @@ struct obs_x264_options obs_x264_parse_options(const char *options_string)
|
||||
return (struct obs_x264_options){
|
||||
.count = 0,
|
||||
.options = NULL,
|
||||
.ignored_word_count = 0,
|
||||
.ignored_words = NULL,
|
||||
.input_words = NULL,
|
||||
};
|
||||
}
|
||||
size_t input_option_count = 0;
|
||||
for (char **input_word = input_words; *input_word; ++input_word)
|
||||
input_option_count += 1;
|
||||
char **ignored_words =
|
||||
bmalloc(input_option_count * sizeof(*ignored_words));
|
||||
char **ignored_word = ignored_words;
|
||||
struct obs_x264_option *out_options =
|
||||
bmalloc(input_option_count * sizeof(*out_options));
|
||||
struct obs_x264_option *out_option = out_options;
|
||||
@@ -42,11 +47,16 @@ struct obs_x264_options obs_x264_parse_options(const char *options_string)
|
||||
if (getparam(*input_word, &out_option->name,
|
||||
&out_option->value)) {
|
||||
++out_option;
|
||||
} else {
|
||||
*ignored_word = *input_word;
|
||||
++ignored_word;
|
||||
}
|
||||
}
|
||||
return (struct obs_x264_options){
|
||||
.count = out_option - out_options,
|
||||
.options = out_options,
|
||||
.ignored_word_count = ignored_word - ignored_words,
|
||||
.ignored_words = ignored_words,
|
||||
.input_words = input_words,
|
||||
};
|
||||
}
|
||||
@@ -56,5 +66,6 @@ void obs_x264_free_options(struct obs_x264_options options)
|
||||
for (size_t i = 0; i < options.count; ++i) {
|
||||
bfree(options.options[i].name);
|
||||
}
|
||||
bfree(options.ignored_words);
|
||||
strlist_free(options.input_words);
|
||||
}
|
||||
|
@@ -10,6 +10,8 @@ struct obs_x264_option {
|
||||
struct obs_x264_options {
|
||||
size_t count;
|
||||
struct obs_x264_option *options;
|
||||
size_t ignored_word_count;
|
||||
char **ignored_words;
|
||||
char **input_words;
|
||||
};
|
||||
|
||||
|
@@ -18,16 +18,19 @@ static void test_obs_x264_parse_options()
|
||||
|
||||
options = obs_x264_parse_options(NULL);
|
||||
CHECK(options.count == 0);
|
||||
CHECK(options.ignored_word_count == 0);
|
||||
obs_x264_free_options(options);
|
||||
|
||||
options = obs_x264_parse_options("");
|
||||
CHECK(options.count == 0);
|
||||
CHECK(options.ignored_word_count == 0);
|
||||
obs_x264_free_options(options);
|
||||
|
||||
options = obs_x264_parse_options("ref=3");
|
||||
CHECK(options.count == 1);
|
||||
CHECK(strcmp(options.options[0].name, "ref") == 0);
|
||||
CHECK(strcmp(options.options[0].value, "3") == 0);
|
||||
CHECK(options.ignored_word_count == 0);
|
||||
obs_x264_free_options(options);
|
||||
|
||||
options = obs_x264_parse_options("ref=3 bframes=8");
|
||||
@@ -36,16 +39,21 @@ static void test_obs_x264_parse_options()
|
||||
CHECK(strcmp(options.options[0].value, "3") == 0);
|
||||
CHECK(strcmp(options.options[1].name, "bframes") == 0);
|
||||
CHECK(strcmp(options.options[1].value, "8") == 0);
|
||||
CHECK(options.ignored_word_count == 0);
|
||||
obs_x264_free_options(options);
|
||||
|
||||
// Invalid options are dropped.
|
||||
// Invalid options are ignored.
|
||||
options = obs_x264_parse_options(
|
||||
"ref=3 option_with_no_equal_sign bframes=8");
|
||||
"ref=3 option_with_no_equal_sign bframes=8 1234");
|
||||
CHECK(options.count == 2);
|
||||
CHECK(strcmp(options.options[0].name, "ref") == 0);
|
||||
CHECK(strcmp(options.options[0].value, "3") == 0);
|
||||
CHECK(strcmp(options.options[1].name, "bframes") == 0);
|
||||
CHECK(strcmp(options.options[1].value, "8") == 0);
|
||||
CHECK(options.ignored_word_count == 2);
|
||||
CHECK(strcmp(options.ignored_words[0], "option_with_no_equal_sign") ==
|
||||
0);
|
||||
CHECK(strcmp(options.ignored_words[1], "1234") == 0);
|
||||
obs_x264_free_options(options);
|
||||
|
||||
// Extra whitespace is ignored between and around options.
|
||||
@@ -55,6 +63,7 @@ static void test_obs_x264_parse_options()
|
||||
CHECK(strcmp(options.options[0].value, "3") == 0);
|
||||
CHECK(strcmp(options.options[1].name, "bframes") == 0);
|
||||
CHECK(strcmp(options.options[1].value, "8") == 0);
|
||||
CHECK(options.ignored_word_count == 0);
|
||||
obs_x264_free_options(options);
|
||||
}
|
||||
|
||||
|
@@ -510,6 +510,9 @@ static void update_params(struct obs_x264 *obsx264, obs_data_t *settings,
|
||||
else
|
||||
obsx264->params.i_csp = X264_CSP_NV12;
|
||||
|
||||
for (size_t i = 0; i < options->ignored_word_count; ++i)
|
||||
warn("ignoring invalid x264 option: %s",
|
||||
options->ignored_words[i]);
|
||||
for (size_t i = 0; i < options->count; ++i)
|
||||
set_param(obsx264, options->options[i]);
|
||||
|
||||
|
Reference in New Issue
Block a user