audioconvert: use given channelmap for volume

Use the given channelmap for the volume, like it used to be in old
audioconvert.

This makes new streams expose a volume even when not negotiated yet.
This commit is contained in:
Wim Taymans 2022-09-05 15:29:16 +02:00
parent 71ec8650ba
commit 201e6ae9fd

View file

@ -32,6 +32,7 @@
#include <spa/support/log.h> #include <spa/support/log.h>
#include <spa/utils/result.h> #include <spa/utils/result.h>
#include <spa/utils/list.h> #include <spa/utils/list.h>
#include <spa/utils/json.h>
#include <spa/utils/names.h> #include <spa/utils/names.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include <spa/node/node.h> #include <spa/node/node.h>
@ -2769,6 +2770,34 @@ impl_get_size(const struct spa_handle_factory *factory,
return sizeof(struct impl); return sizeof(struct impl);
} }
static uint32_t channel_from_name(const char *name)
{
int i;
for (i = 0; spa_type_audio_channel[i].name; i++) {
if (spa_streq(name, spa_debug_type_short_name(spa_type_audio_channel[i].name)))
return spa_type_audio_channel[i].type;
}
return SPA_AUDIO_CHANNEL_UNKNOWN;
}
static inline uint32_t parse_position(uint32_t *pos, const char *val, size_t len)
{
struct spa_json it[2];
char v[256];
uint32_t i = 0;
spa_json_init(&it[0], val, len);
if (spa_json_enter_array(&it[0], &it[1]) <= 0)
spa_json_init(&it[1], val, len);
while (spa_json_get_string(&it[1], v, sizeof(v)) > 0 &&
i < SPA_AUDIO_MAX_CHANNELS) {
pos[i++] = channel_from_name(v);
}
return i;
}
static int static int
impl_init(const struct spa_handle_factory *factory, impl_init(const struct spa_handle_factory *factory,
struct spa_handle *handle, struct spa_handle *handle,
@ -2819,10 +2848,16 @@ impl_init(const struct spa_handle_factory *factory,
else else
this->direction = SPA_DIRECTION_INPUT; this->direction = SPA_DIRECTION_INPUT;
} }
else if (spa_streq(k, SPA_KEY_AUDIO_POSITION))
this->props.n_channels = parse_position(this->props.channel_map, s, strlen(s));
else else
audioconvert_set_param(this, k, s); audioconvert_set_param(this, k, s);
} }
this->props.channel.n_volumes = this->props.n_channels;
this->props.soft.n_volumes = this->props.n_channels;
this->props.monitor.n_volumes = this->props.n_channels;
this->dir[SPA_DIRECTION_INPUT].latency = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT); this->dir[SPA_DIRECTION_INPUT].latency = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
this->dir[SPA_DIRECTION_OUTPUT].latency = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT); this->dir[SPA_DIRECTION_OUTPUT].latency = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);