filter-chain: improve error reporting

Log en error message when config section is missing or doesn't have
an object.
Log warning when ignoring an unknown key.
This commit is contained in:
Wim Taymans 2023-04-16 20:35:12 +02:00
parent 381be87e37
commit 647c55dba9

View file

@ -290,12 +290,16 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
if (impl->type != BQ_NONE) if (impl->type != BQ_NONE)
return impl; return impl;
if (config == NULL) if (config == NULL) {
pw_log_error("biquads:bq_raw requires a config section");
goto error; goto error;
}
spa_json_init(&it[0], config, strlen(config)); spa_json_init(&it[0], config, strlen(config));
if (spa_json_enter_object(&it[0], &it[1]) <= 0) if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
pw_log_error("biquads:config section must be an object");
goto error; goto error;
}
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
if (spa_streq(key, "coefficients")) { if (spa_streq(key, "coefficients")) {
@ -351,9 +355,12 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
goto error; goto error;
} }
} }
else if (spa_json_next(&it[1], &val) < 0) else {
pw_log_warn("biquads: ignoring coefficients key: '%s'", key);
if (spa_json_next(&it[3], &val) < 0)
break; break;
} }
}
if (labs((long)rate - (long)SampleRate) < if (labs((long)rate - (long)SampleRate) <
labs((long)best_rate - (long)SampleRate)) { labs((long)best_rate - (long)SampleRate)) {
best_rate = rate; best_rate = rate;
@ -361,9 +368,12 @@ static void *bq_instantiate(const struct fc_descriptor * Descriptor,
} }
} }
} }
else if (spa_json_next(&it[1], &val) < 0) else {
pw_log_warn("biquads: ignoring config key: '%s'", key);
if (spa_json_next(&it[1], &val) < 0)
break; break;
} }
}
return impl; return impl;
error: error:
@ -844,12 +854,16 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
unsigned long rate; unsigned long rate;
errno = EINVAL; errno = EINVAL;
if (config == NULL) if (config == NULL) {
pw_log_error("convolver: requires a config section");
return NULL; return NULL;
}
spa_json_init(&it[0], config, strlen(config)); spa_json_init(&it[0], config, strlen(config));
if (spa_json_enter_object(&it[0], &it[1]) <= 0) if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
pw_log_error("convolver:config must be an object");
return NULL; return NULL;
}
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
if (spa_streq(key, "blocksize")) { if (spa_streq(key, "blocksize")) {
@ -920,9 +934,12 @@ static void * convolver_instantiate(const struct fc_descriptor * Descriptor,
return NULL; return NULL;
} }
} }
else if (spa_json_next(&it[1], &val) < 0) else {
pw_log_warn("convolver: ignoring config key: '%s'", key);
if (spa_json_next(&it[1], &val) < 0)
break; break;
} }
}
if (filenames[0] == NULL) { if (filenames[0] == NULL) {
pw_log_error("convolver:filename was not given"); pw_log_error("convolver:filename was not given");
return NULL; return NULL;
@ -1063,13 +1080,16 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor,
float max_delay = 1.0f; float max_delay = 1.0f;
if (config == NULL) { if (config == NULL) {
pw_log_error("delay: requires a config section");
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
spa_json_init(&it[0], config, strlen(config)); spa_json_init(&it[0], config, strlen(config));
if (spa_json_enter_object(&it[0], &it[1]) <= 0) if (spa_json_enter_object(&it[0], &it[1]) <= 0) {
pw_log_error("delay:config must be an object");
return NULL; return NULL;
}
while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) {
if (spa_streq(key, "max-delay")) { if (spa_streq(key, "max-delay")) {
@ -1077,10 +1097,12 @@ static void *delay_instantiate(const struct fc_descriptor * Descriptor,
pw_log_error("delay:max-delay requires a number"); pw_log_error("delay:max-delay requires a number");
return NULL; return NULL;
} }
} } else {
else if (spa_json_next(&it[1], &val) < 0) pw_log_warn("delay: ignoring config key: '%s'", key);
if (spa_json_next(&it[1], &val) < 0)
break; break;
} }
}
if (max_delay <= 0.0f) if (max_delay <= 0.0f)
max_delay = 1.0f; max_delay = 1.0f;