mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
spa: make a function to make a channel short name
Make a function that can generate and parse a short name for the positions that are not in the type list, like the AUX channels.
This commit is contained in:
parent
7177f8269d
commit
11f1298f53
16 changed files with 74 additions and 38 deletions
|
|
@ -267,12 +267,34 @@ static const struct spa_type_info spa_type_audio_channel[] = {
|
|||
|
||||
SPA_API_AUDIO_RAW_TYPES uint32_t spa_type_audio_channel_from_short_name(const char *name)
|
||||
{
|
||||
return spa_type_from_short_name(name, spa_type_audio_channel, SPA_AUDIO_CHANNEL_UNKNOWN);
|
||||
uint32_t res;
|
||||
if (spa_strstartswith(name, "AUX")) {
|
||||
if (spa_atou32(name+3, &res, 10) && res < 0x1000)
|
||||
res = SPA_AUDIO_CHANNEL_AUX0 + res;
|
||||
else
|
||||
res = SPA_AUDIO_CHANNEL_UNKNOWN;
|
||||
} else {
|
||||
res = spa_type_from_short_name(name, spa_type_audio_channel, SPA_AUDIO_CHANNEL_UNKNOWN);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
SPA_API_AUDIO_RAW_TYPES const char * spa_type_audio_channel_to_short_name(uint32_t type)
|
||||
{
|
||||
return spa_type_to_short_name(type, spa_type_audio_channel, "UNK");
|
||||
}
|
||||
SPA_API_AUDIO_RAW_TYPES const char * spa_type_audio_channel_make_short_name(uint32_t type,
|
||||
char *buf, size_t size, const char *unknown)
|
||||
{
|
||||
if (SPA_AUDIO_CHANNEL_IS_AUX(type)) {
|
||||
snprintf(buf, size, "AUX%u", type - SPA_AUDIO_CHANNEL_AUX0);
|
||||
} else {
|
||||
const char *str = spa_type_to_short_name(type, spa_type_audio_channel, NULL);
|
||||
if (str == NULL)
|
||||
return unknown;
|
||||
snprintf(buf, size, "%.7s", str);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define SPA_TYPE_INFO_AudioVolumeRampScale SPA_TYPE_INFO_ENUM_BASE "AudioVolumeRampScale"
|
||||
#define SPA_TYPE_INFO_AUDIO_VOLUME_RAMP_SCALE_BASE SPA_TYPE_INFO_AudioVolumeRampScale ":"
|
||||
|
|
|
|||
|
|
@ -241,12 +241,13 @@ static int alsa_set_param(struct state *state, const char *k, const char *s)
|
|||
static int position_to_string(struct channel_map *map, char *val, size_t len)
|
||||
{
|
||||
uint32_t i, o = 0;
|
||||
char pos[8];
|
||||
int r;
|
||||
o += snprintf(val, len, "[ ");
|
||||
for (i = 0; i < map->n_pos; i++) {
|
||||
r = snprintf(val+o, len-o, "%s%s", i == 0 ? "" : ", ",
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
map->pos[i]));
|
||||
spa_type_audio_channel_make_short_name(map->pos[i],
|
||||
pos, sizeof(pos), "UNK"));
|
||||
if (r < 0 || o + r >= len)
|
||||
return -ENOSPC;
|
||||
o += r;
|
||||
|
|
|
|||
|
|
@ -424,7 +424,6 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
|
|||
uint32_t position, bool is_dsp, bool is_monitor, bool is_control)
|
||||
{
|
||||
struct port *port = GET_PORT(this, direction, port_id);
|
||||
const char *name;
|
||||
|
||||
spa_assert(port_id < MAX_PORTS);
|
||||
|
||||
|
|
@ -439,8 +438,7 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
|
|||
port->latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
|
||||
port->latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT);
|
||||
|
||||
name = spa_debug_type_find_short_name(spa_type_audio_channel, position);
|
||||
snprintf(port->position, sizeof(port->position), "%s", name ? name : "UNK");
|
||||
spa_type_audio_channel_make_short_name(position, port->position, sizeof(port->position), "UNK");
|
||||
|
||||
port->info = SPA_PORT_INFO_INIT();
|
||||
port->info.change_mask = port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
||||
|
|
@ -2067,6 +2065,7 @@ static int setup_in_convert(struct impl *this)
|
|||
for (i = 0; i < src_info.info.raw.channels; i++) {
|
||||
for (j = 0; j < dst_info.info.raw.channels; j++) {
|
||||
uint32_t pi, pj;
|
||||
char b1[8], b2[8];
|
||||
|
||||
pi = spa_format_audio_raw_get_position(&src_info.info.raw, i);
|
||||
pj = spa_format_audio_raw_get_position(&dst_info.info.raw, j);
|
||||
|
|
@ -2077,8 +2076,8 @@ static int setup_in_convert(struct impl *this)
|
|||
remap = true;
|
||||
spa_log_debug(this->log, "%p: channel %d (%d) -> %d (%s -> %s)", this,
|
||||
i, in->remap[i], j,
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel, pi),
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel, pj));
|
||||
spa_type_audio_channel_make_short_name(pi, b1, 8, "UNK"),
|
||||
spa_type_audio_channel_make_short_name(pj, b2, 8, "UNK"));
|
||||
spa_format_audio_raw_set_position(&dst_info.info.raw, j, -1);
|
||||
break;
|
||||
}
|
||||
|
|
@ -2192,10 +2191,11 @@ static void set_volume(struct impl *this)
|
|||
static char *format_position(char *str, size_t len, uint32_t channels, uint32_t *position, uint32_t max_position)
|
||||
{
|
||||
uint32_t i, idx = 0;
|
||||
char buf[8];
|
||||
for (i = 0; i < channels; i++)
|
||||
idx += snprintf(str + idx, len - idx, "%s%s", i == 0 ? "" : " ",
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
position[i % max_position]));
|
||||
spa_type_audio_channel_make_short_name(position[i % max_position],
|
||||
buf, sizeof(buf), "UNK"));
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
@ -2359,6 +2359,7 @@ static int setup_out_convert(struct impl *this)
|
|||
for (i = 0; i < src_info.info.raw.channels; i++) {
|
||||
for (j = 0; j < dst_info.info.raw.channels; j++) {
|
||||
uint32_t pi, pj;
|
||||
char b1[8], b2[8];
|
||||
|
||||
pi = spa_format_audio_raw_get_position(&src_info.info.raw, i);
|
||||
pj = spa_format_audio_raw_get_position(&dst_info.info.raw, j);
|
||||
|
|
@ -2370,8 +2371,8 @@ static int setup_out_convert(struct impl *this)
|
|||
|
||||
spa_log_debug(this->log, "%p: channel %d (%d) -> %d (%s -> %s)", this,
|
||||
i, out->remap[i], j,
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel, pi),
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel, pj));
|
||||
spa_type_audio_channel_make_short_name(pi, b1, 8, "UNK"),
|
||||
spa_type_audio_channel_make_short_name(pj, b2, 8, "UNK"));
|
||||
|
||||
spa_format_audio_raw_set_position(&dst_info.info.raw, j, -1);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -86,11 +86,12 @@ static int position_to_string(struct channel_map *map, char *val, size_t len)
|
|||
{
|
||||
uint32_t i, o = 0;
|
||||
int r;
|
||||
char pos[8];
|
||||
o += snprintf(val, len, "[ ");
|
||||
for (i = 0; i < map->channels; i++) {
|
||||
r = snprintf(val+o, len-o, "%s%s", i == 0 ? "" : ", ",
|
||||
spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
map->pos[i]));
|
||||
spa_type_audio_channel_make_short_name(map->pos[i],
|
||||
pos, sizeof(pos), "UNK"));
|
||||
if (r < 0 || o + r >= len)
|
||||
return -ENOSPC;
|
||||
o += r;
|
||||
|
|
|
|||
|
|
@ -236,13 +236,14 @@ static inline void print_channels(char *buffer, size_t max_size, uint32_t n_posi
|
|||
{
|
||||
uint32_t i;
|
||||
struct spa_strbuf buf;
|
||||
char pos[8];
|
||||
|
||||
spa_strbuf_init(&buf, buffer, max_size);
|
||||
spa_strbuf_append(&buf, "[");
|
||||
for (i = 0; i < n_positions; i++) {
|
||||
spa_strbuf_append(&buf, "%s%s", i ? "," : "",
|
||||
spa_type_audio_channel_to_short_name(positions[i]));
|
||||
|
||||
spa_type_audio_channel_make_short_name(positions[i],
|
||||
pos, sizeof(pos), "UNK"));
|
||||
}
|
||||
spa_strbuf_append(&buf, "]");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue