filter-chain: improve error reporting

This commit is contained in:
Wim Taymans 2022-05-05 15:24:51 +02:00
parent 6458df3678
commit 73694f72ee
2 changed files with 27 additions and 11 deletions

View file

@ -1298,8 +1298,10 @@ static int parse_config(struct node *node, struct spa_json *config)
if (spa_json_is_container(val, len)) if (spa_json_is_container(val, len))
len = spa_json_container_len(config, val, len); len = spa_json_container_len(config, val, len);
if ((node->config = malloc(len+1)) != NULL) if ((node->config = malloc(len+1)) == NULL)
spa_json_parse_stringn(val, len, node->config, len+1); return -errno;
spa_json_parse_stringn(val, len, node->config, len+1);
return 0; return 0;
} }
@ -1316,9 +1318,16 @@ static int parse_control(struct node *node, struct spa_json *control)
while (spa_json_get_string(control, key, sizeof(key)) > 0) { while (spa_json_get_string(control, key, sizeof(key)) > 0) {
float fl; float fl;
if (spa_json_get_float(control, &fl) <= 0) const char *val;
int len;
if ((len = spa_json_next(control, &val)) < 0)
break; break;
set_control_value(node, key, &fl);
if (spa_json_parse_float(val, len, &fl) <= 0)
pw_log_warn("control '%s' expects a number, ignoring", key);
else
set_control_value(node, key, &fl);
} }
return 0; return 0;
} }
@ -1430,6 +1439,7 @@ static int load_node(struct graph *graph, struct spa_json *json)
bool have_control = false; bool have_control = false;
bool have_config = false; bool have_config = false;
uint32_t i; uint32_t i;
int res;
while (spa_json_get_string(json, key, sizeof(key)) > 0) { while (spa_json_get_string(json, key, sizeof(key)) > 0) {
if (spa_streq("type", key)) { if (spa_streq("type", key)) {
@ -1524,7 +1534,8 @@ static int load_node(struct graph *graph, struct spa_json *json)
spa_list_init(&port->link_list); spa_list_init(&port->link_list);
} }
if (have_config) if (have_config)
parse_config(node, &config); if ((res = parse_config(node, &config)) < 0)
pw_log_warn("error parsing config: %s", spa_strerror(res));
if (have_control) if (have_control)
parse_control(node, &control); parse_control(node, &control);
@ -1911,7 +1922,7 @@ static int load_graph(struct graph *graph, struct pw_properties *props)
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("nodes", key)) { if (spa_streq("nodes", key)) {
if (spa_json_enter_array(&it[1], &it[2]) <= 0) { if (spa_json_enter_array(&it[1], &it[2]) <= 0) {
pw_log_error("nodes expect an array"); pw_log_error("nodes expects an array");
return -EINVAL; return -EINVAL;
} }
while (spa_json_enter_object(&it[2], &it[3]) > 0) { while (spa_json_enter_object(&it[2], &it[3]) > 0) {
@ -1920,22 +1931,27 @@ static int load_graph(struct graph *graph, struct pw_properties *props)
} }
} }
else if (spa_streq("links", key)) { else if (spa_streq("links", key)) {
if (spa_json_enter_array(&it[1], &it[2]) <= 0) if (spa_json_enter_array(&it[1], &it[2]) <= 0) {
pw_log_error("links expects an array");
return -EINVAL; return -EINVAL;
}
while (spa_json_enter_object(&it[2], &it[3]) > 0) { while (spa_json_enter_object(&it[2], &it[3]) > 0) {
if ((res = parse_link(graph, &it[3])) < 0) if ((res = parse_link(graph, &it[3])) < 0)
return res; return res;
} }
} }
else if (spa_streq("inputs", key)) { else if (spa_streq("inputs", key)) {
if (spa_json_enter_array(&it[1], &inputs) <= 0) if (spa_json_enter_array(&it[1], &inputs) <= 0) {
pw_log_error("inputs expects an array");
return -EINVAL; return -EINVAL;
}
pinputs = &inputs; pinputs = &inputs;
} }
else if (spa_streq("outputs", key)) { else if (spa_streq("outputs", key)) {
if (spa_json_enter_array(&it[1], &outputs) <= 0) if (spa_json_enter_array(&it[1], &outputs) <= 0) {
pw_log_error("outputs expects an array");
return -EINVAL; return -EINVAL;
}
poutputs = &outputs; poutputs = &outputs;
} else if (spa_json_next(&it[1], &val) < 0) } else if (spa_json_next(&it[1], &val) < 0)
break; break;

View file

@ -485,7 +485,7 @@ static float *read_samples(const char *filename, float gain, int delay, int offs
spa_zero(info); spa_zero(info);
f = sf_open(filename, SFM_READ, &info) ; f = sf_open(filename, SFM_READ, &info) ;
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "can't open %s", filename); pw_log_error("can't open %s", filename);
return NULL; return NULL;
} }