mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-08 10:06:23 -05:00
treewide: access the position information using helpers
Make sure we don't access out of bounds and that we use the helpers wherever we can to access the position information.
This commit is contained in:
parent
8bbca3b8f3
commit
818d1435ce
25 changed files with 155 additions and 114 deletions
|
|
@ -348,9 +348,9 @@ uint32_t channel_paname2id(const char *name, size_t size)
|
|||
}
|
||||
|
||||
|
||||
void channel_map_to_positions(const struct channel_map *map, uint32_t *pos)
|
||||
void channel_map_to_positions(const struct channel_map *map, uint32_t *pos, uint32_t max_pos)
|
||||
{
|
||||
uint32_t i, channels = SPA_MIN(map->channels, SPA_AUDIO_MAX_CHANNELS);
|
||||
uint32_t i, channels = SPA_MIN(map->channels, max_pos);
|
||||
for (i = 0; i < channels; i++)
|
||||
pos[i] = map->map[i];
|
||||
}
|
||||
|
|
@ -535,8 +535,7 @@ int format_parse_param(const struct spa_pod *param, bool collect,
|
|||
info.info.raw.rate = 48000;
|
||||
if (info.info.raw.format == 0 ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_N_ELEMENTS(info.info.raw.position))
|
||||
info.info.raw.channels == 0)
|
||||
return -ENOTSUP;
|
||||
}
|
||||
break;
|
||||
|
|
@ -586,7 +585,7 @@ int format_parse_param(const struct spa_pod *param, bool collect,
|
|||
if (info.info.raw.channels) {
|
||||
map->channels = SPA_MIN(info.info.raw.channels, CHANNELS_MAX);
|
||||
for (i = 0; i < map->channels; i++)
|
||||
map->map[i] = info.info.raw.position[i];
|
||||
map->map[i] = spa_format_audio_raw_get_position(&info.info.raw, i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -634,8 +633,8 @@ const struct spa_pod *format_build_param(struct spa_pod_builder *b, uint32_t id,
|
|||
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(spec->channels), 0);
|
||||
|
||||
if (map && map->channels == spec->channels) {
|
||||
uint32_t positions[SPA_AUDIO_MAX_CHANNELS];
|
||||
channel_map_to_positions(map, positions);
|
||||
uint32_t positions[spec->channels];
|
||||
channel_map_to_positions(map, positions, spec->channels);
|
||||
spa_pod_builder_add(b, SPA_FORMAT_AUDIO_position,
|
||||
SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id,
|
||||
spec->channels, positions), 0);
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ enum channel_position channel_id2pa(uint32_t id, uint32_t *aux);
|
|||
const char *channel_id2paname(uint32_t id, uint32_t *aux);
|
||||
uint32_t channel_paname2id(const char *name, size_t size);
|
||||
|
||||
void channel_map_to_positions(const struct channel_map *map, uint32_t *pos);
|
||||
void channel_map_to_positions(const struct channel_map *map, uint32_t *pos, uint32_t max_pos);
|
||||
void channel_map_parse(const char *str, struct channel_map *map);
|
||||
bool channel_map_valid(const struct channel_map *map);
|
||||
void channel_map_parse_position(const char *str, struct channel_map *map);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <spa/utils/list.h>
|
||||
#include <spa/utils/hook.h>
|
||||
#include <spa/utils/string.h>
|
||||
#include <spa/param/audio/raw-utils.h>
|
||||
#include <pipewire/log.h>
|
||||
#include <pipewire/map.h>
|
||||
#include <pipewire/properties.h>
|
||||
|
|
@ -226,14 +227,15 @@ int module_args_to_audioinfo_keys(struct impl *impl, struct pw_properties *props
|
|||
info->channels, map.channels);
|
||||
return -EINVAL;
|
||||
}
|
||||
channel_map_to_positions(&map, info->position);
|
||||
channel_map_to_positions(&map, info->position, SPA_N_ELEMENTS(info->position));
|
||||
pw_properties_set(props, key_channel_map, NULL);
|
||||
} else {
|
||||
if (info->channels == 0)
|
||||
info->channels = impl->defs.sample_spec.channels;
|
||||
|
||||
if (info->channels == impl->defs.channel_map.channels) {
|
||||
channel_map_to_positions(&impl->defs.channel_map, info->position);
|
||||
channel_map_to_positions(&impl->defs.channel_map,
|
||||
info->position, SPA_N_ELEMENTS(info->position));
|
||||
} else if (info->channels == 1) {
|
||||
info->position[0] = SPA_AUDIO_CHANNEL_MONO;
|
||||
} else if (info->channels == 2) {
|
||||
|
|
@ -242,7 +244,7 @@ int module_args_to_audioinfo_keys(struct impl *impl, struct pw_properties *props
|
|||
} else {
|
||||
/* FIXME add more mappings */
|
||||
for (i = 0; i < info->channels; i++)
|
||||
info->position[i] = SPA_AUDIO_CHANNEL_UNKNOWN;
|
||||
spa_format_audio_raw_set_position(info, i, SPA_AUDIO_CHANNEL_UNKNOWN);
|
||||
}
|
||||
if (info->position[0] == SPA_AUDIO_CHANNEL_UNKNOWN)
|
||||
info->flags |= SPA_AUDIO_FLAG_UNPOSITIONED;
|
||||
|
|
@ -288,7 +290,7 @@ void audioinfo_to_properties(struct spa_audio_info_raw *info, struct pw_properti
|
|||
p = s = alloca(info->channels * 8);
|
||||
for (i = 0; i < info->channels; i++)
|
||||
p += spa_scnprintf(p, 8, "%s%s", i == 0 ? "" : ", ",
|
||||
channel_id2name(info->position[i]));
|
||||
channel_id2name(spa_format_audio_raw_get_position(info, i)));
|
||||
pw_properties_setf(props, SPA_KEY_AUDIO_POSITION, "[ %s ]", s);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue