mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
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:
parent
9e7cae13df
commit
8bbca3b8f3
27 changed files with 84 additions and 63 deletions
|
|
@ -269,7 +269,7 @@ static int port_set_format(void *object,
|
|||
return -EINVAL;
|
||||
if (d->format.rate == 0 ||
|
||||
d->format.channels == 0 ||
|
||||
d->format.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
d->format.channels > SPA_N_ELEMENTS(d->format.position))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -866,13 +866,15 @@ static int create_stream(struct stream_info *info)
|
|||
|
||||
s->info = impl->info;
|
||||
if ((str = pw_properties_get(info->stream_props, SPA_KEY_AUDIO_POSITION)) != NULL)
|
||||
spa_audio_parse_position(str, strlen(str), s->info.position, &s->info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), s->info.position,
|
||||
SPA_N_ELEMENTS(s->info.position), &s->info.channels);
|
||||
if (s->info.channels == 0)
|
||||
s->info = impl->info;
|
||||
|
||||
spa_zero(remap_info);
|
||||
if ((str = pw_properties_get(info->stream_props, "combine.audio.position")) != NULL)
|
||||
spa_audio_parse_position(str, strlen(str), remap_info.position, &remap_info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), remap_info.position,
|
||||
SPA_N_ELEMENTS(remap_info.position), &remap_info.channels);
|
||||
if (remap_info.channels == 0)
|
||||
remap_info = s->info;
|
||||
|
||||
|
|
|
|||
|
|
@ -1371,21 +1371,21 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
}
|
||||
|
||||
if ((str = pw_properties_get(impl->capture_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
|
||||
spa_audio_parse_position(str, strlen(str),
|
||||
impl->capture_info.position, &impl->capture_info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), impl->capture_info.position,
|
||||
SPA_N_ELEMENTS(impl->capture_info.position), &impl->capture_info.channels);
|
||||
}
|
||||
if ((str = pw_properties_get(impl->source_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
|
||||
spa_audio_parse_position(str, strlen(str),
|
||||
impl->source_info.position, &impl->source_info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), impl->source_info.position,
|
||||
SPA_N_ELEMENTS(impl->source_info.position), &impl->source_info.channels);
|
||||
}
|
||||
if ((str = pw_properties_get(impl->sink_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
|
||||
spa_audio_parse_position(str, strlen(str),
|
||||
impl->sink_info.position, &impl->sink_info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), impl->sink_info.position,
|
||||
SPA_N_ELEMENTS(impl->sink_info.position), &impl->sink_info.channels);
|
||||
impl->playback_info = impl->sink_info;
|
||||
}
|
||||
if ((str = pw_properties_get(impl->playback_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
|
||||
spa_audio_parse_position(str, strlen(str),
|
||||
impl->playback_info.position, &impl->playback_info.channels);
|
||||
spa_audio_parse_position_n(str, strlen(str), impl->playback_info.position,
|
||||
SPA_N_ELEMENTS(impl->playback_info.position), &impl->playback_info.channels);
|
||||
if (impl->playback_info.channels != impl->sink_info.channels)
|
||||
impl->playback_info = impl->sink_info;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ static void capture_param_changed(void *data, uint32_t id, const struct spa_pod
|
|||
return;
|
||||
if (info.rate == 0 ||
|
||||
info.channels == 0 ||
|
||||
info.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
info.channels > SPA_N_ELEMENTS(info.position))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -876,7 +876,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
|
|||
uint32_t n;
|
||||
float vols[MAX_CHANNELS];
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
s->volume.n_volumes = n;
|
||||
for (n = 0; n < s->volume.n_volumes; n++)
|
||||
s->volume.volumes[n] = vols[n];
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
|
|||
uint32_t n;
|
||||
float vols[MAX_CHANNELS];
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
s->volume.n_volumes = n;
|
||||
for (n = 0; n < s->volume.n_volumes; n++)
|
||||
s->volume.volumes[n] = vols[n];
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ static void param_format_changed(struct impl *impl, const struct spa_pod *param,
|
|||
if (param != NULL) {
|
||||
if (spa_format_audio_raw_parse(param, &info) < 0 ||
|
||||
info.channels == 0 ||
|
||||
info.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
info.channels > SPA_N_ELEMENTS(info.position))
|
||||
return;
|
||||
|
||||
if ((impl->info.format != 0 && impl->info.format != info.format) ||
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ static void make_stream_ports(struct stream *s)
|
|||
|
||||
if (i < s->info.channels) {
|
||||
str = spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
s->info.position[i % SPA_AUDIO_MAX_CHANNELS]);
|
||||
s->info.position[i % SPA_N_ELEMENTS(s->info.position)]);
|
||||
props = pw_properties_new(
|
||||
PW_KEY_FORMAT_DSP, "32 bit float mono audio",
|
||||
PW_KEY_AUDIO_CHANNEL, str ? str : "UNK",
|
||||
|
|
@ -514,7 +514,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
|
|||
uint32_t n;
|
||||
float vols[MAX_CHANNELS];
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
s->volume.n_volumes = n;
|
||||
for (n = 0; n < s->volume.n_volumes; n++)
|
||||
s->volume.volumes[n] = vols[n];
|
||||
|
|
@ -863,7 +863,8 @@ static int handle_follower_setup(struct impl *impl, struct nj2_session_params *p
|
|||
}
|
||||
impl->sink.info.rate = peer->params.sample_rate;
|
||||
if ((uint32_t)peer->params.send_audio_channels != impl->sink.info.channels) {
|
||||
impl->sink.info.channels = SPA_MIN(peer->params.send_audio_channels, (int)SPA_AUDIO_MAX_CHANNELS);
|
||||
impl->sink.info.channels = SPA_MIN(peer->params.send_audio_channels,
|
||||
(int)SPA_N_ELEMENTS(impl->sink.info.position));
|
||||
for (i = 0; i < impl->sink.info.channels; i++)
|
||||
impl->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
|
|
@ -874,7 +875,8 @@ static int handle_follower_setup(struct impl *impl, struct nj2_session_params *p
|
|||
}
|
||||
impl->source.info.rate = peer->params.sample_rate;
|
||||
if ((uint32_t)peer->params.recv_audio_channels != impl->source.info.channels) {
|
||||
impl->source.info.channels = SPA_MIN(peer->params.recv_audio_channels, (int)SPA_AUDIO_MAX_CHANNELS);
|
||||
impl->source.info.channels = SPA_MIN(peer->params.recv_audio_channels,
|
||||
(int)SPA_N_ELEMENTS(impl->source.info.position));
|
||||
for (i = 0; i < impl->source.info.channels; i++)
|
||||
impl->source.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ static void parse_props(struct stream *s, const struct spa_pod *param)
|
|||
uint32_t n;
|
||||
float vols[MAX_CHANNELS];
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
s->volume.n_volumes = n;
|
||||
for (n = 0; n < s->volume.n_volumes; n++)
|
||||
s->volume.volumes[n] = vols[n];
|
||||
|
|
@ -1026,14 +1026,16 @@ static int handle_follower_available(struct impl *impl, struct nj2_session_param
|
|||
follower->source.n_ports = peer->params.recv_audio_channels + peer->params.recv_midi_channels;
|
||||
follower->source.info.rate = peer->params.sample_rate;
|
||||
if ((uint32_t)peer->params.recv_audio_channels != follower->source.info.channels) {
|
||||
follower->source.info.channels = SPA_MIN(peer->params.recv_audio_channels, (int)SPA_AUDIO_MAX_CHANNELS);
|
||||
follower->source.info.channels = SPA_MIN(peer->params.recv_audio_channels,
|
||||
(int)SPA_N_ELEMENTS(follower->source.info.position));
|
||||
for (i = 0; i < follower->source.info.channels; i++)
|
||||
follower->source.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
follower->sink.n_ports = peer->params.send_audio_channels + peer->params.send_midi_channels;
|
||||
follower->sink.info.rate = peer->params.sample_rate;
|
||||
if ((uint32_t)peer->params.send_audio_channels != follower->sink.info.channels) {
|
||||
follower->sink.info.channels = SPA_MIN(peer->params.send_audio_channels, (int)SPA_AUDIO_MAX_CHANNELS);
|
||||
follower->sink.info.channels = SPA_MIN(peer->params.send_audio_channels,
|
||||
(int)SPA_N_ELEMENTS(follower->sink.info.position));
|
||||
for (i = 0; i < follower->sink.info.channels; i++)
|
||||
follower->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ static void stream_param_changed(void *d, uint32_t id, const struct spa_pod *par
|
|||
float vols[MAX_CHANNELS];
|
||||
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
volume.channels = SPA_MIN(PA_CHANNELS_MAX, n);
|
||||
for (n = 0; n < volume.channels; n++)
|
||||
volume.values[n] = pa_sw_volume_from_linear(vols[n]);
|
||||
|
|
|
|||
|
|
@ -1617,7 +1617,7 @@ static void stream_props_changed(struct impl *impl, uint32_t id, const struct sp
|
|||
float soft_vols[MAX_CHANNELS];
|
||||
|
||||
if ((n_vols = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
vols, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
vols, SPA_N_ELEMENTS(vols))) > 0) {
|
||||
volume = 0.0f;
|
||||
for (i = 0; i < n_vols; i++) {
|
||||
volume += vols[i];
|
||||
|
|
|
|||
|
|
@ -704,7 +704,8 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
|
|||
}
|
||||
}
|
||||
|
||||
spa_audio_parse_position(channel_map, strlen(channel_map), map->channels, &map->n_channels);
|
||||
spa_audio_parse_position_n(channel_map, strlen(channel_map),
|
||||
map->channels, SPA_N_ELEMENTS(map->channels), &map->n_channels);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue