From 09b615db0a0c47477498ea8e7f059adaba0f4da8 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Sat, 25 Jan 2020 01:05:18 +0100 Subject: [PATCH] Support v0 ffmpeg/Ogg Theora configuration migration --- src/cfg_stream.c | 8 ++++++++ src/ezstream-cfgmigrate.c | 4 ++-- tests/check_cfg.h | 19 +++++++++++++++++++ tests/check_cfg_stream.c | 10 +++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/cfg_stream.c b/src/cfg_stream.c index e48bd99..ba812d6 100644 --- a/src/cfg_stream.c +++ b/src/cfg_stream.c @@ -291,6 +291,14 @@ cfg_stream_set_encoder(struct cfg_stream *s, struct cfg_stream_list *not_used, const char *encoder, const char **errstrp) { (void)not_used; + + if (NULL == encoder) { + if (s->encoder) + xfree(s->encoder); + s->encoder = NULL; + return (0); + } + SET_XSTRDUP(s->encoder, encoder, errstrp); return (0); } diff --git a/src/ezstream-cfgmigrate.c b/src/ezstream-cfgmigrate.c index 4561248..d6774d1 100644 --- a/src/ezstream-cfgmigrate.c +++ b/src/ezstream-cfgmigrate.c @@ -387,9 +387,9 @@ _parse_ezconfig0(EZCONFIG *ez) if (cfg_stream_get_encoder(str) && NULL == cfg_encoder_list_find(enc_list, cfg_stream_get_encoder(str))) { - log_error("%s: %s encoder not found due to errors", + log_warning("%s: %s encoder not found; disabling reencoding", v0_cfgfile, cfg_stream_get_encoder(str)); - return (-1); + cfg_stream_set_encoder(str, NULL, NULL, NULL); } if (0 > cfg_server_validate(srv, &err_str) || diff --git a/tests/check_cfg.h b/tests/check_cfg.h index d067f7c..28d0024 100644 --- a/tests/check_cfg.h +++ b/tests/check_cfg.h @@ -28,6 +28,16 @@ ck_assert_str_eq(errstr, "empty"); \ } while (0) +#define TEST_EMPTYSTR_T_NULL(type, objget, list, setter) do { \ + type obj3 = objget(list, #setter); \ + const char *errstr; \ + \ + errstr = NULL; \ + ck_assert_int_eq(setter(obj3, list, NULL, NULL), 0); \ + ck_assert_int_eq(setter(obj3, list, "", &errstr), -1); \ + ck_assert_str_eq(errstr, "empty"); \ +} while (0) + #define TEST_XSTRDUP(setter, getter) do { \ TEST_EMPTYSTR(setter); \ \ @@ -44,6 +54,15 @@ ck_assert_str_eq(getter(obj2), "check_cfg"); \ } while (0) +#define TEST_XSTRDUP_T_NULL(type, objget, list, setter, getter) do { \ + type obj2 = objget(list, #setter); \ + \ + TEST_EMPTYSTR_T_NULL(type, objget, list, setter); \ + \ + ck_assert_int_eq(setter(obj2, list, "check_cfg", NULL), 0); \ + ck_assert_str_eq(getter(obj2), "check_cfg"); \ +} while (0) + #define TEST_STRLCPY(setter, getter, length) do { \ char buf[length + 1]; \ const char *errstr2; \ diff --git a/tests/check_cfg_stream.c b/tests/check_cfg_stream.c index ea2ddeb..e2e27a4 100644 --- a/tests/check_cfg_stream.c +++ b/tests/check_cfg_stream.c @@ -130,7 +130,15 @@ END_TEST START_TEST(test_stream_encoder) { - TEST_XSTRDUP_T(cfg_stream_t, cfg_stream_list_get, streams, + cfg_stream_t str = cfg_stream_list_get(streams, "test_stream_encoder"); + + ck_assert_ptr_eq(cfg_stream_get_encoder(str), NULL); + ck_assert_int_eq(cfg_stream_set_encoder(str, NULL, "test", NULL), 0); + ck_assert_str_eq(cfg_stream_get_encoder(str), "test"); + ck_assert_int_eq(cfg_stream_set_encoder(str, NULL, NULL, NULL), 0); + ck_assert_ptr_eq(cfg_stream_get_encoder(str), NULL); + + TEST_XSTRDUP_T_NULL(cfg_stream_t, cfg_stream_list_get, streams, cfg_stream_set_encoder, cfg_stream_get_encoder); } END_TEST