From 601aa3ffb1e5ed6afc286863d03c85c2013aae9a Mon Sep 17 00:00:00 2001 From: Matthew Glazar Date: Sat, 16 May 2020 23:10:05 -0700 Subject: [PATCH] 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. --- plugins/obs-x264/obs-x264-options.c | 11 +++++++++++ plugins/obs-x264/obs-x264-options.h | 2 ++ plugins/obs-x264/obs-x264-test.c | 13 +++++++++++-- plugins/obs-x264/obs-x264.c | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/obs-x264/obs-x264-options.c b/plugins/obs-x264/obs-x264-options.c index 8ad712e4e..a1e7a66b7 100644 --- a/plugins/obs-x264/obs-x264-options.c +++ b/plugins/obs-x264/obs-x264-options.c @@ -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); } diff --git a/plugins/obs-x264/obs-x264-options.h b/plugins/obs-x264/obs-x264-options.h index 6c65dc686..12c0674e9 100644 --- a/plugins/obs-x264/obs-x264-options.h +++ b/plugins/obs-x264/obs-x264-options.h @@ -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; }; diff --git a/plugins/obs-x264/obs-x264-test.c b/plugins/obs-x264/obs-x264-test.c index 2ede53448..e64e824be 100644 --- a/plugins/obs-x264/obs-x264-test.c +++ b/plugins/obs-x264/obs-x264-test.c @@ -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); } diff --git a/plugins/obs-x264/obs-x264.c b/plugins/obs-x264/obs-x264.c index 1c952dd76..4c54670a3 100644 --- a/plugins/obs-x264/obs-x264.c +++ b/plugins/obs-x264/obs-x264.c @@ -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]);