modules: handle format parsing errors

This commit is contained in:
Wim Taymans 2025-10-23 18:01:35 +02:00
parent b8eeb2db45
commit 5e1e3fca1e
17 changed files with 125 additions and 66 deletions

View file

@ -815,13 +815,14 @@ static int calc_frame_size(struct spa_audio_info_raw *info)
case SPA_AUDIO_FORMAT_F64_OE:
return res * 8;
default:
return 0;
return -ENOTSUP;
}
}
static int parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
spa_audio_info_raw_init_dict_keys(info,
int res;
if ((res = spa_audio_info_raw_init_dict_keys(info,
&SPA_DICT_ITEMS(
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
@ -830,7 +831,8 @@ static int parse_audio_info(const struct pw_properties *props, struct spa_audio_
SPA_KEY_AUDIO_FORMAT,
SPA_KEY_AUDIO_RATE,
SPA_KEY_AUDIO_CHANNELS,
SPA_KEY_AUDIO_POSITION, NULL);
SPA_KEY_AUDIO_POSITION, NULL)) < 0)
return res;
return calc_frame_size(info);
}
@ -851,6 +853,7 @@ static int parse_params(struct impl *impl)
const char *str;
struct spa_json it[1];
char value[512];
int res;
pw_properties_fetch_bool(impl->props, "capture", &impl->capture);
pw_properties_fetch_bool(impl->props, "playback", &impl->playback);
@ -894,19 +897,20 @@ static int parse_params(struct impl *impl)
copy_props(impl, PW_KEY_NODE_VIRTUAL);
copy_props(impl, PW_KEY_NODE_NETWORK);
impl->capture_frame_size = parse_audio_info(impl->capture_props, &impl->capture_info);
if (impl->capture_frame_size == 0) {
if ((res = parse_audio_info(impl->capture_props, &impl->capture_info)) <= 0) {
pw_log_error("unsupported capture audio format:%d channels:%d",
impl->capture_info.format, impl->capture_info.channels);
return -EINVAL;
}
impl->capture_frame_size = res;
impl->playback_frame_size = parse_audio_info(impl->playback_props, &impl->playback_info);
if (impl->playback_frame_size == 0) {
if ((res = parse_audio_info(impl->playback_props, &impl->playback_info)) <= 0) {
pw_log_error("unsupported playback audio format:%d channels:%d",
impl->playback_info.format, impl->playback_info.channels);
return -EINVAL;
}
impl->playback_frame_size = res;
if (impl->capture_info.rate != 0 &&
pw_properties_get(impl->capture_props, PW_KEY_NODE_RATE) == NULL)
pw_properties_setf(impl->capture_props, PW_KEY_NODE_RATE,