mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-28 05:40:26 -04:00
spa: avoid using SPA_AUDIO_MAX_CHANNELS
Use SPA_N_ELEMENTS instead of the array we try to handle.
This commit is contained in:
parent
818d1435ce
commit
dbc5c81e4a
7 changed files with 22 additions and 16 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -1228,8 +1228,9 @@ static int probe_ffado_device(struct impl *impl)
|
|||
impl->source.ports[i] = port;
|
||||
}
|
||||
if (impl->source.info.channels != n_channels) {
|
||||
uint32_t n_pos = SPA_MIN(n_channels, SPA_N_ELEMENTS(impl->source.info.position));
|
||||
impl->source.info.channels = n_channels;
|
||||
for (i = 0; i < SPA_MIN(impl->source.info.channels, SPA_AUDIO_MAX_CHANNELS); i++)
|
||||
for (i = 0; i < n_pos; i++)
|
||||
impl->source.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
|
||||
|
|
@ -1254,8 +1255,9 @@ static int probe_ffado_device(struct impl *impl)
|
|||
impl->sink.ports[i] = port;
|
||||
}
|
||||
if (impl->sink.info.channels != n_channels) {
|
||||
uint32_t n_pos = SPA_MIN(n_channels, SPA_N_ELEMENTS(impl->sink.info.position));
|
||||
impl->sink.info.channels = n_channels;
|
||||
for (i = 0; i < SPA_MIN(impl->sink.info.channels, SPA_AUDIO_MAX_CHANNELS); i++)
|
||||
for (i = 0; i < n_pos; i++)
|
||||
impl->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1691,7 +1691,8 @@ static void copy_position(struct spa_audio_info_raw *dst, const struct spa_audio
|
|||
{
|
||||
if (SPA_FLAG_IS_SET(dst->flags, SPA_AUDIO_FLAG_UNPOSITIONED) &&
|
||||
!SPA_FLAG_IS_SET(src->flags, SPA_AUDIO_FLAG_UNPOSITIONED)) {
|
||||
for (uint32_t i = 0; i < SPA_MIN(src->channels, SPA_AUDIO_MAX_CHANNELS); i++)
|
||||
uint32_t i, n_pos = SPA_MIN(src->channels, SPA_N_ELEMENTS(dst->position));
|
||||
for (i = 0; i < n_pos; i++)
|
||||
dst->position[i] = src->position[i];
|
||||
SPA_FLAG_CLEAR(dst->flags, SPA_AUDIO_FLAG_UNPOSITIONED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ static void param_format_changed(struct impl *impl, const struct spa_pod *param,
|
|||
(impl->info.channels != 0 &&
|
||||
(impl->info.channels != info.channels ||
|
||||
memcmp(impl->info.position, info.position,
|
||||
SPA_MIN(info.channels, SPA_AUDIO_MAX_CHANNELS) * sizeof(uint32_t)) != 0))) {
|
||||
SPA_MIN(info.channels, SPA_N_ELEMENTS(info.position)) * sizeof(uint32_t)) != 0))) {
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod_builder b;
|
||||
const struct spa_pod *params[1];
|
||||
|
|
|
|||
|
|
@ -450,7 +450,7 @@ 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];
|
||||
uint32_t channels = 0, position[CHANNELS_MAX];
|
||||
spa_audio_parse_position_n(str, strlen(str), position,
|
||||
SPA_N_ELEMENTS(position), &channels);
|
||||
positions_to_channel_map(position, channels, map);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue