spa: add spa_audio_parse_position_n

Add a function that accepts the size of the position array when reading
the audio positions. This makes it possible to decouple the position
array size from SPA_AUDIO_MAX_CHANNELS.

Also use SPA_N_ELEMENTS to pass the number of array elements to
functions instead of a fixed constant. This makes it easier to change
the array size later to a different constant without having to patch up
all the places where the size is used.
This commit is contained in:
Wim Taymans 2025-10-20 15:16:54 +02:00
parent 9e7cae13df
commit 8bbca3b8f3
27 changed files with 84 additions and 63 deletions

View file

@ -637,7 +637,7 @@ port_set_format(struct impl *this,
if (info.info.raw.rate == 0 ||
info.info.raw.channels == 0 ||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
info.info.raw.channels > SPA_N_ELEMENTS(info.info.raw.position))
return -EINVAL;
if (this->props.format != 0) {
@ -950,7 +950,8 @@ impl_init(const struct spa_handle_factory *factory,
} else if (spa_streq(k, SPA_KEY_NODE_DRIVER)) {
this->props.driver = spa_atob(s);
} else if (spa_streq(k, SPA_KEY_AUDIO_POSITION)) {
spa_audio_parse_position(s, strlen(s), this->props.pos, &this->props.channels);
spa_audio_parse_position_n(s, strlen(s), this->props.pos,
SPA_N_ELEMENTS(this->props.pos), &this->props.channels);
} else if (spa_streq(k, "clock.name")) {
spa_scnprintf(this->props.clock_name,
sizeof(this->props.clock_name),