mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-21 01:40:34 -05: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
|
|
@ -697,13 +697,13 @@ static int apply_device_props(struct impl *this, struct acp_device *dev, struct
|
|||
break;
|
||||
case SPA_PROP_channelVolumes:
|
||||
if ((n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
volumes, SPA_N_ELEMENTS(volumes))) > 0) {
|
||||
changed++;
|
||||
}
|
||||
break;
|
||||
case SPA_PROP_channelMap:
|
||||
if (spa_pod_copy_array(&prop->value, SPA_TYPE_Id,
|
||||
channels, SPA_AUDIO_MAX_CHANNELS) > 0) {
|
||||
channels, SPA_N_ELEMENTS(channels)) > 0) {
|
||||
changed++;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ void spa_alsa_emit_port_info(struct state *state, bool full);
|
|||
|
||||
static inline void spa_alsa_parse_position(struct channel_map *map, const char *val, size_t len)
|
||||
{
|
||||
spa_audio_parse_position(val, len, map->pos, &map->channels);
|
||||
spa_audio_parse_position_n(val, len, map->pos, SPA_N_ELEMENTS(map->pos), &map->channels);
|
||||
}
|
||||
|
||||
static inline uint32_t spa_alsa_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len)
|
||||
|
|
|
|||
|
|
@ -1104,11 +1104,11 @@ static void graph_info(void *object, const struct spa_filter_graph_info *info)
|
|||
else if (spa_streq(k, "n_outputs"))
|
||||
spa_atou32(s, &g->n_outputs, 0);
|
||||
else if (spa_streq(k, "inputs.audio.position"))
|
||||
spa_audio_parse_position(s, strlen(s),
|
||||
g->inputs_position, &g->n_inputs);
|
||||
spa_audio_parse_position_n(s, strlen(s), g->inputs_position,
|
||||
SPA_N_ELEMENTS(g->inputs_position), &g->n_inputs);
|
||||
else if (spa_streq(k, "outputs.audio.position"))
|
||||
spa_audio_parse_position(s, strlen(s),
|
||||
g->outputs_position, &g->n_outputs);
|
||||
spa_audio_parse_position_n(s, strlen(s), g->outputs_position,
|
||||
SPA_N_ELEMENTS(g->outputs_position), &g->n_outputs);
|
||||
else if (spa_streq(k, "latency")) {
|
||||
double latency;
|
||||
if (spa_atod(s, &latency))
|
||||
|
|
@ -1749,7 +1749,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
|
|||
case SPA_PROP_channelVolumes:
|
||||
if (!p->lock_volumes &&
|
||||
(n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
p->channel.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
p->channel.volumes, SPA_N_ELEMENTS(p->channel.volumes))) > 0) {
|
||||
have_channel_volume = true;
|
||||
p->channel.n_volumes = n;
|
||||
changed++;
|
||||
|
|
@ -1757,7 +1757,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
|
|||
break;
|
||||
case SPA_PROP_channelMap:
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Id,
|
||||
p->channel_map, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
p->channel_map, SPA_N_ELEMENTS(p->channel_map))) > 0) {
|
||||
p->n_channels = n;
|
||||
changed++;
|
||||
}
|
||||
|
|
@ -1772,7 +1772,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
|
|||
case SPA_PROP_softVolumes:
|
||||
if (!p->lock_volumes &&
|
||||
(n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
p->soft.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
p->soft.volumes, SPA_N_ELEMENTS(p->soft.volumes))) > 0) {
|
||||
have_soft_volume = true;
|
||||
p->soft.n_volumes = n;
|
||||
changed++;
|
||||
|
|
@ -1784,7 +1784,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
|
|||
break;
|
||||
case SPA_PROP_monitorVolumes:
|
||||
if ((n = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
p->monitor.volumes, SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
p->monitor.volumes, SPA_N_ELEMENTS(p->monitor.volumes))) > 0) {
|
||||
p->monitor.n_volumes = n;
|
||||
changed++;
|
||||
}
|
||||
|
|
@ -4297,8 +4297,9 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
}
|
||||
else if (spa_streq(k, SPA_KEY_AUDIO_POSITION)) {
|
||||
if (s != NULL)
|
||||
spa_audio_parse_position(s, strlen(s), this->props.channel_map,
|
||||
&this->props.n_channels);
|
||||
spa_audio_parse_position_n(s, strlen(s),
|
||||
this->props.channel_map, SPA_N_ELEMENTS(this->props.channel_map),
|
||||
&this->props.n_channels);
|
||||
}
|
||||
else if (spa_streq(k, SPA_KEY_PORT_IGNORE_LATENCY))
|
||||
this->port_ignore_latency = spa_atob(s);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ static int avb_set_param(struct state *state, const char *k, const char *s)
|
|||
state->default_format = spa_type_audio_format_from_short_name(s);
|
||||
fmt_change++;
|
||||
} else if (spa_streq(k, SPA_KEY_AUDIO_POSITION)) {
|
||||
spa_audio_parse_position(s, strlen(s), state->default_pos.pos,
|
||||
spa_audio_parse_position_n(s, strlen(s), state->default_pos.pos,
|
||||
SPA_N_ELEMENTS(state->default_pos.pos),
|
||||
&state->default_pos.channels);
|
||||
fmt_change++;
|
||||
} else if (spa_streq(k, SPA_KEY_AUDIO_ALLOWED_RATES)) {
|
||||
|
|
|
|||
|
|
@ -6861,7 +6861,8 @@ static void parse_bap_locations(struct spa_bt_monitor *this, const struct spa_di
|
|||
if (spa_atou32(str, value, 0))
|
||||
return;
|
||||
|
||||
if (!spa_audio_parse_position(str, strlen(str), position, &n_channels)) {
|
||||
if (!spa_audio_parse_position_n(str, strlen(str), position,
|
||||
SPA_N_ELEMENTS(position), &n_channels)) {
|
||||
spa_log_error(this->log, "property %s '%s' is not valid position array", key, str);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2972,11 +2972,11 @@ static int apply_device_props(struct impl *this, struct node *node, struct spa_p
|
|||
break;
|
||||
case SPA_PROP_channelVolumes:
|
||||
n_volumes = spa_pod_copy_array(&prop->value, SPA_TYPE_Float,
|
||||
volumes, SPA_AUDIO_MAX_CHANNELS);
|
||||
volumes, SPA_N_ELEMENTS(volumes));
|
||||
break;
|
||||
case SPA_PROP_channelMap:
|
||||
n_channels = spa_pod_copy_array(&prop->value, SPA_TYPE_Id,
|
||||
channels, SPA_AUDIO_MAX_CHANNELS);
|
||||
channels, SPA_N_ELEMENTS(channels));
|
||||
break;
|
||||
case SPA_PROP_latencyOffsetNsec:
|
||||
if (spa_pod_get_long(&prop->value, &latency_offset) == 0) {
|
||||
|
|
|
|||
|
|
@ -749,7 +749,7 @@ static int impl_set_props(void *object, enum spa_direction direction, const stru
|
|||
float vols[MAX_CHANNELS];
|
||||
|
||||
if ((n_vols = spa_pod_copy_array(&prop->value, SPA_TYPE_Float, vols,
|
||||
SPA_AUDIO_MAX_CHANNELS)) > 0) {
|
||||
SPA_N_ELEMENTS(vols))) > 0) {
|
||||
if (vol->n_volumes != n_vols)
|
||||
do_volume = true;
|
||||
vol->n_volumes = n_vols;
|
||||
|
|
@ -2119,8 +2119,9 @@ static int load_graph(struct graph *graph, const struct spa_dict *props)
|
|||
spa_log_error(impl->log, "%s expects an array", key);
|
||||
return -EINVAL;
|
||||
}
|
||||
spa_audio_parse_position(val, len, graph->inputs_position,
|
||||
&graph->n_inputs_position);
|
||||
spa_audio_parse_position_n(val, len, graph->inputs_position,
|
||||
SPA_N_ELEMENTS(graph->inputs_position),
|
||||
&graph->n_inputs_position);
|
||||
impl->info.n_inputs = graph->n_inputs_position;
|
||||
}
|
||||
else if (spa_streq("outputs.audio.position", key)) {
|
||||
|
|
@ -2129,8 +2130,9 @@ static int load_graph(struct graph *graph, const struct spa_dict *props)
|
|||
spa_log_error(impl->log, "%s expects an array", key);
|
||||
return -EINVAL;
|
||||
}
|
||||
spa_audio_parse_position(val, len, graph->outputs_position,
|
||||
&graph->n_outputs_position);
|
||||
spa_audio_parse_position_n(val, len, graph->outputs_position,
|
||||
SPA_N_ELEMENTS(graph->outputs_position),
|
||||
&graph->n_outputs_position);
|
||||
impl->info.n_outputs = graph->n_outputs_position;
|
||||
}
|
||||
else if (spa_streq("nodes", key)) {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ static int port_set_format(void *object,
|
|||
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_S16 ||
|
||||
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;
|
||||
|
||||
this->bpf = 2 * info.info.raw.channels;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue