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
|
|
@ -514,6 +514,7 @@ static void make_stream_ports(struct stream *s)
|
|||
for (i = 0; i < s->n_ports; i++) {
|
||||
struct port *port = s->ports[i];
|
||||
char *link_port = NULL;
|
||||
char pos[8];
|
||||
|
||||
if (port != NULL) {
|
||||
s->ports[i] = NULL;
|
||||
|
|
@ -523,8 +524,9 @@ static void make_stream_ports(struct stream *s)
|
|||
}
|
||||
|
||||
if (i < s->info.channels) {
|
||||
str = spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
spa_format_audio_raw_get_position(&s->info, i));
|
||||
str = spa_type_audio_channel_make_short_name(
|
||||
spa_format_audio_raw_get_position(&s->info, i),
|
||||
pos, sizeof(pos), NULL);
|
||||
if (str)
|
||||
snprintf(name, sizeof(name), "%s_%s", prefix, str);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -441,11 +441,12 @@ static void make_stream_ports(struct stream *s)
|
|||
}
|
||||
|
||||
if (i < s->info.channels) {
|
||||
str = spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
spa_format_audio_raw_get_position(&s->info, i));
|
||||
str = spa_type_audio_channel_make_short_name(
|
||||
spa_format_audio_raw_get_position(&s->info, i),
|
||||
name, sizeof(name), "UNK");
|
||||
props = pw_properties_new(
|
||||
PW_KEY_FORMAT_DSP, "32 bit float mono audio",
|
||||
PW_KEY_AUDIO_CHANNEL, str ? str : "UNK",
|
||||
PW_KEY_AUDIO_CHANNEL, str,
|
||||
PW_KEY_PORT_PHYSICAL, "true",
|
||||
NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -601,12 +601,12 @@ static void make_stream_ports(struct stream *s)
|
|||
}
|
||||
|
||||
if (i < s->info.channels) {
|
||||
str = spa_debug_type_find_short_name(spa_type_audio_channel,
|
||||
spa_format_audio_raw_get_position(&s->info, i));
|
||||
|
||||
str = spa_type_audio_channel_make_short_name(
|
||||
spa_format_audio_raw_get_position(&s->info, i),
|
||||
name, sizeof(name), "UNK");
|
||||
props = pw_properties_new(
|
||||
PW_KEY_FORMAT_DSP, "32 bit float mono audio",
|
||||
PW_KEY_AUDIO_CHANNEL, str ? str : "UNK",
|
||||
PW_KEY_AUDIO_CHANNEL, str,
|
||||
PW_KEY_PORT_PHYSICAL, "true",
|
||||
NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -298,9 +298,9 @@ uint32_t channel_pa2id(enum channel_position channel)
|
|||
return audio_channels[channel].channel;
|
||||
}
|
||||
|
||||
const char *channel_id2name(uint32_t channel)
|
||||
const char *channel_id2name(uint32_t channel, char *buf, size_t size)
|
||||
{
|
||||
return spa_type_audio_channel_to_short_name(channel);
|
||||
return spa_type_audio_channel_make_short_name(channel, buf, size, "UNK");
|
||||
}
|
||||
|
||||
uint32_t channel_name2id(const char *name)
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ void sample_spec_fix(struct sample_spec *ss, struct channel_map *map,
|
|||
struct spa_dict *props);
|
||||
|
||||
uint32_t channel_pa2id(enum channel_position channel);
|
||||
const char *channel_id2name(uint32_t channel);
|
||||
const char *channel_id2name(uint32_t channel, char *buf, size_t size);
|
||||
uint32_t channel_name2id(const char *name);
|
||||
enum channel_position channel_id2pa(uint32_t id, uint32_t *aux);
|
||||
const char *channel_id2paname(uint32_t id, uint32_t *aux);
|
||||
|
|
|
|||
|
|
@ -761,11 +761,13 @@ int message_dump(enum spa_log_level level, const char *prefix, struct message *m
|
|||
case TAG_CHANNEL_MAP:
|
||||
{
|
||||
struct channel_map map;
|
||||
char pos[8];
|
||||
if ((res = read_channel_map(m, &map)) < 0)
|
||||
return res;
|
||||
pw_log(level, "%s %u: channelmap: channels:%u", prefix, o, map.channels);
|
||||
for (i = 0; i < map.channels; i++)
|
||||
pw_log(level, "%s %d: %s", prefix, i, channel_id2name(map.map[i]));
|
||||
pw_log(level, "%s %d: %s", prefix, i,
|
||||
channel_id2name(map.map[i], pos, sizeof(pos)));
|
||||
break;
|
||||
}
|
||||
case TAG_CVOLUME:
|
||||
|
|
|
|||
|
|
@ -283,14 +283,15 @@ void audioinfo_to_properties(struct spa_audio_info_raw *info, struct pw_properti
|
|||
if (info->rate)
|
||||
pw_properties_setf(props, SPA_KEY_AUDIO_RATE, "%u", info->rate);
|
||||
if (info->channels) {
|
||||
char *s, *p;
|
||||
char *s, *p, pos[8];
|
||||
|
||||
pw_properties_setf(props, SPA_KEY_AUDIO_CHANNELS, "%u", info->channels);
|
||||
|
||||
p = s = alloca(info->channels * 8);
|
||||
for (i = 0; i < info->channels; i++)
|
||||
p += spa_scnprintf(p, 8, "%s%s", i == 0 ? "" : ", ",
|
||||
channel_id2name(spa_format_audio_raw_get_position(info, i)));
|
||||
channel_id2name(spa_format_audio_raw_get_position(info, i),
|
||||
pos, sizeof(pos)));
|
||||
pw_properties_setf(props, SPA_KEY_AUDIO_POSITION, "[ %s ]", s);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,9 +295,11 @@ static int do_extension_stream_restore_write(struct module *module, struct clien
|
|||
fprintf(f, " ]");
|
||||
}
|
||||
if (map.channels > 0) {
|
||||
char pos[8];
|
||||
fprintf(f, ", \"channels\": [");
|
||||
for (i = 0; i < map.channels; i++)
|
||||
fprintf(f, "%s\"%s\"", (i == 0 ? " ":", "), channel_id2name(map.map[i]));
|
||||
fprintf(f, "%s\"%s\"", (i == 0 ? " ":", "),
|
||||
channel_id2name(map.map[i], pos, sizeof(pos)));
|
||||
fprintf(f, " ]");
|
||||
}
|
||||
if (device_name != NULL && device_name[0] &&
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ static void pw_properties_from_avahi_string(const char *key, const char *value,
|
|||
else if (spa_streq(key, "channel_map")) {
|
||||
struct channel_map channel_map;
|
||||
uint32_t i, pos[CHANNELS_MAX];
|
||||
char *p, *s;
|
||||
char *p, *s, buf[8];
|
||||
|
||||
spa_zero(channel_map);
|
||||
channel_map_parse(value, &channel_map);
|
||||
|
|
@ -198,7 +198,7 @@ static void pw_properties_from_avahi_string(const char *key, const char *value,
|
|||
p += spa_scnprintf(p, 2, "[");
|
||||
for (i = 0; i < channel_map.channels; i++)
|
||||
p += spa_scnprintf(p, 8, "%s%s", i == 0 ? "" : ",",
|
||||
channel_id2name(pos[i]));
|
||||
channel_id2name(pos[i], buf, sizeof(buf)));
|
||||
p += spa_scnprintf(p, 2, "]");
|
||||
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -747,10 +747,11 @@ static int channelmap_default(struct channelmap *map, int n_channels)
|
|||
static void channelmap_print(struct channelmap *map)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
char pos[8];
|
||||
for (i = 0; i < map->n_channels; i++) {
|
||||
const char *name = spa_type_audio_channel_to_short_name(map->channels[i]);
|
||||
fprintf(stderr, "%s%s", name, i + 1 < map->n_channels ? "," : "");
|
||||
fprintf(stderr, "%s%s", i ? "," : "",
|
||||
spa_type_audio_channel_make_short_name(map->channels[i],
|
||||
pos, sizeof(pos), "UNK"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue