json: add helper function to parse channel positions

Use the helper instead of duplicating the same code.

Also add some helpers to parse a json array of uint32_t

Move some functions to convert between type name and id.
This commit is contained in:
Wim Taymans 2024-09-18 09:54:34 +02:00
parent 911a601b95
commit e2991f6398
34 changed files with 256 additions and 791 deletions

View file

@ -25,6 +25,7 @@
#include <spa/pod/builder.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <spa/param/latency-utils.h>
#include <spa/param/tag-utils.h>
@ -324,31 +325,6 @@ struct stream {
unsigned int have_latency:1;
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -358,9 +334,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, 0);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void ringbuffer_init(struct ringbuffer *r, void *buf, uint32_t size)
@ -854,13 +831,13 @@ static int create_stream(struct stream_info *info)
s->info = impl->info;
if ((str = pw_properties_get(info->stream_props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(&s->info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), s->info.position, &s->info.channels);
if (s->info.channels == 0)
s->info = impl->info;
spa_zero(remap_info);
if ((str = pw_properties_get(info->stream_props, "combine.audio.position")) != NULL)
parse_position(&remap_info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), remap_info.position, &remap_info.channels);
if (remap_info.channels == 0)
remap_info = s->info;

View file

@ -21,6 +21,7 @@
#include <spa/debug/types.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <spa/param/latency-utils.h>
#include <spa/pod/builder.h>
#include <spa/pod/dynamic.h>
@ -1191,31 +1192,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1229,9 +1205,10 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
@ -1389,17 +1366,21 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
}
if ((str = pw_properties_get(impl->capture_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
parse_position(&impl->capture_info, str, strlen(str));
spa_audio_parse_position(str, strlen(str),
impl->capture_info.position, &impl->capture_info.channels);
}
if ((str = pw_properties_get(impl->source_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
parse_position(&impl->source_info, str, strlen(str));
spa_audio_parse_position(str, strlen(str),
impl->source_info.position, &impl->source_info.channels);
}
if ((str = pw_properties_get(impl->sink_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
parse_position(&impl->sink_info, str, strlen(str));
spa_audio_parse_position(str, strlen(str),
impl->sink_info.position, &impl->sink_info.channels);
impl->playback_info = impl->sink_info;
}
if ((str = pw_properties_get(impl->playback_props, SPA_KEY_AUDIO_POSITION)) != NULL) {
parse_position(&impl->playback_info, str, strlen(str));
spa_audio_parse_position(str, strlen(str),
impl->playback_info.position, &impl->playback_info.channels);
if (impl->playback_info.channels != impl->sink_info.channels)
impl->playback_info = impl->sink_info;
}

View file

@ -17,6 +17,7 @@
#include <spa/utils/json.h>
#include <spa/utils/ringbuffer.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/debug/types.h>
#include <pipewire/impl.h>
@ -447,31 +448,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -482,7 +458,7 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, 0);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -24,6 +24,7 @@
#include <spa/pod/builder.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
@ -272,41 +273,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -314,7 +280,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -323,9 +289,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static int calc_frame_size(const struct spa_audio_info_raw *info)

View file

@ -24,6 +24,7 @@
#include <spa/pod/builder.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
@ -278,41 +279,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -320,7 +286,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -329,9 +295,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static int calc_frame_size(const struct spa_audio_info_raw *info)

View file

@ -24,6 +24,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <spa/control/ump-utils.h>
#include <pipewire/impl.h>
@ -1406,16 +1407,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_devices(struct impl *impl, const char *val, size_t len)
{
struct spa_json it[1];
@ -1431,21 +1422,6 @@ static void parse_devices(struct impl *impl, const char *val, size_t len)
}
}
static void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[2];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1456,9 +1432,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -21,6 +21,7 @@
#include <spa/support/cpu.h>
#include <spa/param/latency-utils.h>
#include <spa/param/tag-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/pod/dynamic.h>
#include <spa/debug/types.h>
#include <spa/debug/log.h>
@ -2904,31 +2905,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -2939,7 +2915,7 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->channels = pw_properties_get_int32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -24,6 +24,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <spa/control/ump-utils.h>
#include <pipewire/impl.h>
@ -991,31 +992,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1026,9 +1002,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -17,6 +17,7 @@
#include <spa/utils/json.h>
#include <spa/utils/ringbuffer.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/debug/types.h>
#include <pipewire/impl.h>
@ -769,31 +770,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -804,7 +780,7 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, 0);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -26,6 +26,7 @@
#include <spa/debug/types.h>
#include <spa/pod/builder.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
@ -1146,31 +1147,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1181,9 +1157,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -29,6 +29,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
@ -1172,31 +1173,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1207,9 +1183,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)

View file

@ -28,6 +28,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
@ -754,41 +755,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -796,7 +762,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -805,9 +771,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static int calc_frame_size(const struct spa_audio_info_raw *info)

View file

@ -7,6 +7,7 @@
#include <spa/param/audio/format.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <spa/utils/json.h>
#include "format.h"
@ -130,22 +131,12 @@ uint32_t format_pa2id(enum sample_format format)
const char *format_id2name(uint32_t format)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (spa_type_audio_format[i].type == format)
return spa_debug_type_short_name(spa_type_audio_format[i].name);
}
return "UNKNOWN";
return spa_type_audio_format_to_short_name(format);
}
uint32_t format_name2id(const char *name)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (spa_streq(name, spa_debug_type_short_name(spa_type_audio_format[i].name)))
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
return spa_type_audio_format_from_short_name(name);
}
uint32_t format_paname2id(const char *name, size_t size)
@ -289,22 +280,12 @@ uint32_t channel_pa2id(enum channel_position channel)
const char *channel_id2name(uint32_t channel)
{
int i;
for (i = 0; spa_type_audio_channel[i].name; i++) {
if (spa_type_audio_channel[i].type == channel)
return spa_debug_type_short_name(spa_type_audio_channel[i].name);
}
return "UNK";
return spa_type_audio_channel_to_short_name(channel);
}
uint32_t channel_name2id(const char *name)
{
int i;
for (i = 0; spa_type_audio_channel[i].name; i++) {
if (strcmp(name, spa_debug_type_short_name(spa_type_audio_channel[i].name)) == 0)
return spa_type_audio_channel[i].type;
}
return SPA_AUDIO_CHANNEL_UNKNOWN;
return spa_type_audio_channel_from_short_name(name);
}
enum channel_position channel_id2pa(uint32_t id, uint32_t *aux)
@ -354,6 +335,13 @@ void channel_map_to_positions(const struct channel_map *map, uint32_t *pos)
pos[i] = map->map[i];
}
void positions_to_channel_map(const uint32_t *pos, uint32_t channels, struct channel_map *map)
{
uint32_t i;
for (i = 0; i < channels; i++)
map->map[i] = pos[i];
}
void channel_map_parse(const char *str, struct channel_map *map)
{
const char *p = str;
@ -440,17 +428,9 @@ void channel_map_parse(const char *str, struct channel_map *map)
void channel_map_parse_position(const char *str, struct channel_map *map)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], str, strlen(str)) <= 0)
return;
map->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
map->channels < SPA_AUDIO_MAX_CHANNELS) {
map->map[map->channels++] = channel_name2id(v);
}
uint32_t channels = 0, position[SPA_AUDIO_MAX_CHANNELS];
spa_audio_parse_position(str, strlen(str), position, &channels);
positions_to_channel_map(position, channels, map);
}
bool channel_map_valid(const struct channel_map *map)

View file

@ -27,6 +27,7 @@
#include <spa/debug/types.h>
#include <spa/param/audio/type-info.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
@ -785,41 +786,6 @@ static void impl_free(struct impl *impl)
free(impl);
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
static inline 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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static int calc_frame_size(struct spa_audio_info_raw *info)
{
int res = info->channels;
@ -861,7 +827,7 @@ static int parse_audio_info(const struct pw_properties *props, struct spa_audio_
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -870,9 +836,10 @@ static int parse_audio_info(const struct pw_properties *props, struct spa_audio_
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
return calc_frame_size(info);
}

View file

@ -27,6 +27,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/latency-utils.h>
#include <spa/param/audio/raw.h>
#include <spa/param/audio/raw-json.h>
#include <pipewire/impl.h>
#include <pipewire/i18n.h>
@ -1064,41 +1065,6 @@ static const struct pw_impl_module_events module_events = {
.destroy = module_destroy,
};
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -1106,7 +1072,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -1115,9 +1081,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static int calc_frame_size(struct spa_audio_info_raw *info)

View file

@ -10,6 +10,7 @@
#include <spa/utils/ringbuffer.h>
#include <spa/utils/dll.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/control/control.h>
#include <spa/control/ump-utils.h>
#include <spa/debug/types.h>
@ -269,41 +270,6 @@ static const struct format_info *find_audio_format_info(const struct spa_audio_i
return NULL;
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -311,7 +277,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -320,9 +286,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static uint32_t msec_to_samples(struct impl *impl, float msec)

View file

@ -23,6 +23,7 @@
#include <spa/utils/string.h>
#include <spa/utils/json.h>
#include <spa/param/audio/format.h>
#include <spa/param/audio/raw-json.h>
#include <spa/debug/types.h>
#include <pipewire/impl.h>
@ -502,41 +503,6 @@ static int add_snapcast_stream(struct impl *impl, struct tunnel *t,
return -ENOENT;
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
static inline 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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -544,10 +510,10 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
if (info->format == 0) {
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
}
pw_properties_set(props, PW_KEY_AUDIO_FORMAT, str);
@ -559,9 +525,10 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
pw_properties_setf(props, PW_KEY_AUDIO_CHANNELS, "%d", info->channels);
}

View file

@ -10,6 +10,7 @@
#include <spa/utils/ringbuffer.h>
#include <spa/utils/dll.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/control/control.h>
#include <spa/control/ump-utils.h>
#include <spa/debug/types.h>
@ -187,41 +188,6 @@ static const struct format_info *find_audio_format_info(const struct spa_audio_i
return NULL;
}
static inline uint32_t format_from_name(const char *name, size_t len)
{
int i;
for (i = 0; spa_type_audio_format[i].name; i++) {
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
return spa_type_audio_format[i].type;
}
return SPA_AUDIO_FORMAT_UNKNOWN;
}
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 void parse_position(struct spa_audio_info_raw *info, const char *val, size_t len)
{
struct spa_json it[1];
char v[256];
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
return;
info->channels = 0;
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 &&
info->channels < SPA_AUDIO_MAX_CHANNELS) {
info->position[info->channels++] = channel_from_name(v);
}
}
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
{
const char *str;
@ -229,7 +195,7 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
spa_zero(*info);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
str = DEFAULT_FORMAT;
info->format = format_from_name(str, strlen(str));
info->format = spa_type_audio_format_from_short_name(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
if (info->rate == 0)
@ -238,9 +204,10 @@ static void parse_audio_info(const struct pw_properties *props, struct spa_audio
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
info->channels = SPA_MIN(info->channels, SPA_AUDIO_MAX_CHANNELS);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
if (info->channels == 0)
parse_position(info, DEFAULT_POSITION, strlen(DEFAULT_POSITION));
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
info->position, &info->channels);
}
static uint32_t msec_to_samples(struct impl *impl, uint32_t msec)

View file

@ -19,6 +19,7 @@
#include <spa/param/audio/layout.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw-json.h>
#include <spa/utils/type-info.h>
#include <spa/param/tag-utils.h>
#include <spa/param/props.h>
@ -79,8 +80,8 @@ struct data;
typedef int (*fill_fn)(struct data *d, void *dest, unsigned int n_frames, bool *null_frame);
struct channelmap {
int n_channels;
int channels[SPA_AUDIO_MAX_CHANNELS];
uint32_t n_channels;
uint32_t channels[SPA_AUDIO_MAX_CHANNELS];
};
struct data {
@ -119,7 +120,7 @@ struct data {
unsigned int bitrate;
unsigned int rate;
int channels;
uint32_t channels;
struct channelmap channelmap;
unsigned int stride;
enum unit latency_unit;
@ -566,10 +567,10 @@ static int channelmap_from_sf(struct channelmap *map)
[SF_CHANNEL_MAP_TOP_REAR_RIGHT] = SPA_AUDIO_CHANNEL_TRR,
[SF_CHANNEL_MAP_TOP_REAR_CENTER] = SPA_AUDIO_CHANNEL_TRC
};
int i;
uint32_t i;
for (i = 0; i < map->n_channels; i++) {
if (map->channels[i] >= 0 && map->channels[i] < (int) SPA_N_ELEMENTS(table))
if (map->channels[i] < SPA_N_ELEMENTS(table))
map->channels[i] = table[map->channels[i]];
else
map->channels[i] = SPA_AUDIO_CHANNEL_UNKNOWN;
@ -578,8 +579,8 @@ static int channelmap_from_sf(struct channelmap *map)
}
struct mapping {
const char *name;
unsigned int channels;
unsigned int values[32];
uint32_t channels;
uint32_t values[32];
};
static const struct mapping maps[] =
@ -599,21 +600,8 @@ static const struct mapping maps[] =
{ "surround-71", SPA_AUDIO_LAYOUT_7_1 },
};
static unsigned int find_channel(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 int parse_channelmap(const char *channel_map, struct channelmap *map)
{
int i, nch;
SPA_FOR_EACH_ELEMENT_VAR(maps, m) {
if (spa_streq(m->name, channel_map)) {
map->n_channels = m->channels;
@ -623,16 +611,7 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
}
}
spa_auto(pw_strv) ch = pw_split_strv(channel_map, ",", SPA_AUDIO_MAX_CHANNELS, &nch);
if (ch == NULL)
return -1;
map->n_channels = nch;
for (i = 0; i < map->n_channels; i++) {
int c = find_channel(ch[i]);
map->channels[i] = c;
}
spa_audio_parse_position(channel_map, strlen(channel_map), map->channels, &map->n_channels);
return 0;
}
@ -673,13 +652,11 @@ static int channelmap_default(struct channelmap *map, int n_channels)
static void channelmap_print(struct channelmap *map)
{
int i;
uint32_t i;
for (i = 0; i < map->n_channels; i++) {
const char *name = spa_debug_type_find_name(spa_type_audio_channel, map->channels[i]);
if (name == NULL)
name = ":UNK";
fprintf(stderr, "%s%s", spa_debug_type_short_name(name), i + 1 < map->n_channels ? "," : "");
const char *name = spa_type_audio_channel_to_short_name(map->channels[i]);
fprintf(stderr, "%s%s", name, i + 1 < map->n_channels ? "," : "");
}
}
@ -1499,7 +1476,7 @@ static int setup_sndfile(struct data *data)
if (data->verbose)
fprintf(stderr, "sndfile: opened file \"%s\" format %08x channels:%d rate:%d\n",
data->filename, info.format, info.channels, info.samplerate);
if (data->channels > 0 && info.channels != data->channels) {
if (data->channels > 0 && info.channels != (int)data->channels) {
fprintf(stderr, "sndfile: given channels (%u) don't match file channels (%d)\n",
data->channels, info.channels);
return -EINVAL;

View file

@ -233,8 +233,7 @@ static void node_param(void *data, int seq,
struct spa_audio_info_raw info = { 0 };
if (spa_format_audio_raw_parse(param, &info) >= 0) {
snprintf(n->format, sizeof(n->format), "%6.6s %d %d",
spa_debug_type_find_short_name(
spa_type_audio_format, info.format),
spa_type_audio_format_to_short_name(info.format),
info.channels, info.rate);
}
break;
@ -272,7 +271,7 @@ static void node_param(void *data, int seq,
struct spa_video_info_raw info = { 0 };
if (spa_format_video_raw_parse(param, &info) >= 0) {
snprintf(n->format, sizeof(n->format), "%6.6s %dx%d",
spa_debug_type_find_short_name(spa_type_video_format, info.format),
spa_type_video_format_to_short_name(info.format),
info.size.width, info.size.height);
}
break;