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

@ -451,7 +451,8 @@ void channel_map_parse(const char *str, struct channel_map *map)
void channel_map_parse_position(const char *str, struct channel_map *map)
{
uint32_t channels = 0, position[SPA_AUDIO_MAX_CHANNELS];
spa_audio_parse_position(str, strlen(str), position, &channels);
spa_audio_parse_position_n(str, strlen(str), position,
SPA_N_ELEMENTS(position), &channels);
positions_to_channel_map(position, channels, map);
}
@ -535,7 +536,7 @@ int format_parse_param(const struct spa_pod *param, bool collect,
if (info.info.raw.format == 0 ||
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 -ENOTSUP;
}
break;

View file

@ -53,7 +53,7 @@ int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bo
if (monitor)
continue;
info->volume.channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
info->volume.values, CHANNELS_MAX);
info->volume.values, SPA_N_ELEMENTS(info->volume.values));
SPA_FLAG_UPDATE(info->flags, VOLUME_HW_VOLUME,
prop->flags & SPA_POD_PROP_FLAG_HARDWARE);
break;
@ -68,7 +68,7 @@ int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bo
if (!monitor)
continue;
info->volume.channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
info->volume.values, CHANNELS_MAX);
info->volume.values, SPA_N_ELEMENTS(info->volume.values));
SPA_FLAG_CLEAR(info->flags, VOLUME_HW_VOLUME);
break;
case SPA_PROP_volumeBase:
@ -84,7 +84,7 @@ int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bo
}
case SPA_PROP_channelMap:
info->map.channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Id,
info->map.map, CHANNELS_MAX);
info->map.map, SPA_N_ELEMENTS(info->map.map));
break;
default:
break;