spa: avoid using SPA_AUDIO_MAX_CHANNELS

Use SPA_N_ELEMENTS instead of the array we try to handle.
This commit is contained in:
Wim Taymans 2025-10-21 16:05:33 +02:00
parent 818d1435ce
commit dbc5c81e4a
7 changed files with 22 additions and 16 deletions

View file

@ -31,20 +31,20 @@ extern "C" {
SPA_API_AUDIO_RAW_UTILS uint32_t
spa_format_audio_raw_get_position(const struct spa_audio_info_raw *info, uint32_t idx)
{
uint32_t pos;
if (idx < SPA_AUDIO_MAX_CHANNELS) {
uint32_t pos, max_position = SPA_N_ELEMENTS(info->position);
if (idx < max_position) {
pos = info->position[idx];
} else {
pos = info->position[idx % SPA_AUDIO_MAX_CHANNELS];
pos = info->position[idx % max_position];
if (SPA_AUDIO_CHANNEL_IS_AUX(pos))
pos += (idx / SPA_AUDIO_MAX_CHANNELS) * SPA_AUDIO_MAX_CHANNELS;
pos += (idx / max_position) * max_position;
}
return pos;
}
SPA_API_AUDIO_RAW_UTILS void
spa_format_audio_raw_set_position(struct spa_audio_info_raw *info, uint32_t idx, uint32_t position)
{
if (idx < SPA_AUDIO_MAX_CHANNELS)
if (idx < SPA_N_ELEMENTS(info->position))
info->position[idx] = position;
}

View file

@ -2046,7 +2046,7 @@ static int do_auto_port_config(struct impl *this, const char *str)
return -ENOENT;
if (format.media_subtype == SPA_MEDIA_SUBTYPE_raw) {
uint32_t n_pos = SPA_MIN(SPA_AUDIO_MAX_CHANNELS, format.info.raw.channels);
uint32_t n_pos = SPA_MIN(SPA_N_ELEMENTS(format.info.raw.position), format.info.raw.channels);
if (position == POSITION_AUX) {
for (i = 0; i < n_pos; i++)
format.info.raw.position[i] = SPA_AUDIO_CHANNEL_START_Aux + i;

View file

@ -2060,8 +2060,9 @@ static int setup_in_convert(struct impl *this)
dst_info.info.raw.channels,
dst_info.info.raw.rate);
qsort(dst_info.info.raw.position, SPA_MIN(dst_info.info.raw.channels, SPA_AUDIO_MAX_CHANNELS),
sizeof(uint32_t), int32_cmp);
qsort(dst_info.info.raw.position, SPA_MIN(dst_info.info.raw.channels,
SPA_N_ELEMENTS(dst_info.info.raw.position)),
sizeof(uint32_t), int32_cmp);
for (i = 0; i < src_info.info.raw.channels; i++) {
for (j = 0; j < dst_info.info.raw.channels; j++) {
@ -2222,7 +2223,8 @@ static int setup_channelmix(struct impl *this, uint32_t channels, uint32_t *posi
spa_log_info(this->log, "in %s (%016"PRIx64")", format_position(str, sizeof(str),
src_chan, position, max_position), src_mask);
spa_log_info(this->log, "out %s (%016"PRIx64")", format_position(str, sizeof(str),
dst_chan, out->format.info.raw.position, SPA_AUDIO_MAX_CHANNELS), dst_mask);
dst_chan, out->format.info.raw.position,
SPA_N_ELEMENTS(out->format.info.raw.position)), dst_mask);
spa_log_info(this->log, "%p: %s/%d@%d->%s/%d@%d %08"PRIx64":%08"PRIx64, this,
spa_debug_type_find_name(spa_type_audio_format, SPA_AUDIO_FORMAT_DSP_F32),
@ -2350,8 +2352,9 @@ static int setup_out_convert(struct impl *this)
dst_info.info.raw.channels,
dst_info.info.raw.rate);
qsort(src_info.info.raw.position, SPA_MIN(src_info.info.raw.channels, SPA_AUDIO_MAX_CHANNELS),
sizeof(uint32_t), int32_cmp);
qsort(src_info.info.raw.position, SPA_MIN(src_info.info.raw.channels,
SPA_N_ELEMENTS(src_info.info.raw.position)),
sizeof(uint32_t), int32_cmp);
for (i = 0; i < src_info.info.raw.channels; i++) {
for (j = 0; j < dst_info.info.raw.channels; j++) {