mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-02-08 10:06:23 -05:00
spa: make helper to init spa_audio_info_raw from dict
Make a function that can initialize raw audio info from a dict and fill in the defaults. We can use this in many of the modules when the audio format is parsed.
This commit is contained in:
parent
d932e52d5b
commit
e3a7035e8f
19 changed files with 204 additions and 255 deletions
|
|
@ -14,7 +14,9 @@ extern "C" {
|
|||
* \{
|
||||
*/
|
||||
|
||||
#include <spa/utils/dict.h>
|
||||
#include <spa/utils/json.h>
|
||||
#include <spa/param/audio/raw.h>
|
||||
#include <spa/param/audio/raw-types.h>
|
||||
|
||||
static inline int
|
||||
|
|
@ -36,6 +38,51 @@ spa_audio_parse_position(const char *str, size_t len,
|
|||
return channels;
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_audio_info_raw_update(struct spa_audio_info_raw *info, const char *key, const char *val, bool force)
|
||||
{
|
||||
uint32_t v;
|
||||
if (spa_streq(key, SPA_KEY_AUDIO_FORMAT)) {
|
||||
if (force || info->format == 0)
|
||||
info->format = (enum spa_audio_format)spa_type_audio_format_from_short_name(val);
|
||||
} else if (spa_streq(key, SPA_KEY_AUDIO_RATE)) {
|
||||
if (spa_atou32(val, &v, 0) && (force || info->rate == 0))
|
||||
info->rate = v;
|
||||
} else if (spa_streq(key, SPA_KEY_AUDIO_CHANNELS)) {
|
||||
if (spa_atou32(val, &v, 0) && (force || info->channels == 0))
|
||||
info->channels = SPA_MIN(v, SPA_AUDIO_MAX_CHANNELS);
|
||||
} else if (spa_streq(key, SPA_KEY_AUDIO_POSITION)) {
|
||||
if (force || info->channels == 0)
|
||||
spa_audio_parse_position(val, strlen(val), info->position, &info->channels);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int SPA_SENTINEL
|
||||
spa_audio_info_raw_init_dict_keys(struct spa_audio_info_raw *info,
|
||||
const struct spa_dict *defaults,
|
||||
const struct spa_dict *dict, ...)
|
||||
{
|
||||
spa_zero(*info);
|
||||
if (dict) {
|
||||
const char *val, *key;
|
||||
va_list args;
|
||||
va_start(args, dict);
|
||||
while ((key = va_arg(args, const char *))) {
|
||||
if ((val = spa_dict_lookup(dict, key)) == NULL)
|
||||
continue;
|
||||
spa_audio_info_raw_update(info, key, val, true);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
if (defaults) {
|
||||
const struct spa_dict_item *it;
|
||||
spa_dict_for_each(it, defaults)
|
||||
spa_audio_info_raw_update(info, it->key, it->value, false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ struct spa_dict_item {
|
|||
const char *value;
|
||||
};
|
||||
|
||||
#define SPA_DICT_ITEM_INIT(key,value) ((struct spa_dict_item) { (key), (value) })
|
||||
#define SPA_DICT_ITEM(key,value) ((struct spa_dict_item) { (key), (value) })
|
||||
#define SPA_DICT_ITEM_INIT(key,value) SPA_DICT_ITEM(key,value)
|
||||
|
||||
struct spa_dict {
|
||||
#define SPA_DICT_FLAG_SORTED (1<<0) /**< items are sorted */
|
||||
|
|
@ -37,8 +38,12 @@ struct spa_dict {
|
|||
const struct spa_dict_item *items;
|
||||
};
|
||||
|
||||
#define SPA_DICT_INIT(items,n_items) ((struct spa_dict) { 0, (n_items), (items) })
|
||||
#define SPA_DICT_INIT_ARRAY(items) ((struct spa_dict) { 0, SPA_N_ELEMENTS(items), (items) })
|
||||
#define SPA_DICT(items,n_items) ((struct spa_dict) { 0, (n_items), (items) })
|
||||
#define SPA_DICT_ARRAY(items) SPA_DICT((items),SPA_N_ELEMENTS(items))
|
||||
#define SPA_DICT_ITEMS(...) SPA_DICT_ARRAY(((struct spa_dict_item[]) { __VA_ARGS__}))
|
||||
|
||||
#define SPA_DICT_INIT(items,n_items) SPA_DICT(items,n_items)
|
||||
#define SPA_DICT_INIT_ARRAY(items) SPA_DICT_ARRAY(items)
|
||||
|
||||
#define spa_dict_for_each(item, dict) \
|
||||
for ((item) = (dict)->items; \
|
||||
|
|
|
|||
|
|
@ -327,17 +327,13 @@ struct stream {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
info->format = SPA_AUDIO_FORMAT_F32P;
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void ringbuffer_init(struct ringbuffer *r, void *buf, uint32_t size)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,6 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
|
|||
#define PW_LOG_TOPIC_DEFAULT mod_topic
|
||||
|
||||
#define DEFAULT_RATE 48000
|
||||
#define DEFAULT_CHANNELS 2
|
||||
#define DEFAULT_POSITION "[ FL FR ]"
|
||||
|
||||
/* Hopefully this is enough for any combination of AEC engine and resampler
|
||||
|
|
@ -1194,21 +1193,15 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
*info = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P);
|
||||
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
|
||||
if (info->rate == 0)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@
|
|||
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
|
||||
#define PW_LOG_TOPIC_DEFAULT mod_topic
|
||||
|
||||
#define DEFAULT_POSITION "[ FL FR ]"
|
||||
|
||||
static const struct spa_dict_item module_props[] = {
|
||||
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
|
||||
{ PW_KEY_MODULE_DESCRIPTION, "Create example filter streams" },
|
||||
|
|
@ -450,15 +452,14 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
*info = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P);
|
||||
info->rate = pw_properties_get_int32(props, PW_KEY_AUDIO_RATE, 0);
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -275,24 +275,16 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static int calc_frame_size(const struct spa_audio_info_raw *info)
|
||||
|
|
|
|||
|
|
@ -281,24 +281,16 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static int calc_frame_size(const struct spa_audio_info_raw *info)
|
||||
|
|
|
|||
|
|
@ -1424,18 +1424,13 @@ static void parse_devices(struct impl *impl, const char *val, size_t len)
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
info->format = SPA_AUDIO_FORMAT_F32P;
|
||||
info->rate = 0;
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -2907,15 +2907,12 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
*info = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P);
|
||||
info->rate = pw_properties_get_int32(props, PW_KEY_AUDIO_RATE, info->rate);
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P")),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
|
|||
#define MAX_PORTS 128
|
||||
|
||||
#define DEFAULT_CLIENT_NAME "PipeWire"
|
||||
#define DEFAULT_CHANNELS 2
|
||||
#define DEFAULT_POSITION "[ FL FR ]"
|
||||
#define DEFAULT_MIDI_PORTS 1
|
||||
|
||||
|
|
@ -994,18 +993,13 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
info->format = SPA_AUDIO_FORMAT_F32P;
|
||||
info->rate = 0;
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -772,15 +772,13 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
*info = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P);
|
||||
info->rate = pw_properties_get_int32(props, PW_KEY_AUDIO_RATE, 0);
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P")),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -1149,18 +1149,13 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
info->format = SPA_AUDIO_FORMAT_F32P;
|
||||
info->rate = 0;
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -1175,18 +1175,13 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
info->format = SPA_AUDIO_FORMAT_F32P;
|
||||
info->rate = 0;
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, "F32P"),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static void copy_props(struct impl *impl, struct pw_properties *props, const char *key)
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@
|
|||
|
||||
#define DEFAULT_FORMAT "S16"
|
||||
#define DEFAULT_RATE 48000
|
||||
#define DEFAULT_CHANNELS 2
|
||||
#define DEFAULT_POSITION "[ FL FR ]"
|
||||
|
||||
#define RINGBUFFER_SIZE (1u << 22)
|
||||
|
|
@ -757,24 +756,16 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static int calc_frame_size(const struct spa_audio_info_raw *info)
|
||||
|
|
|
|||
|
|
@ -822,24 +822,16 @@ static int calc_frame_size(struct spa_audio_info_raw *info)
|
|||
|
||||
static int parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
|
||||
return calc_frame_size(info);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1067,24 +1067,16 @@ static const struct pw_impl_module_events module_events = {
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static int calc_frame_size(struct spa_audio_info_raw *info)
|
||||
|
|
|
|||
|
|
@ -272,24 +272,16 @@ static const struct format_info *find_audio_format_info(const struct spa_audio_i
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static uint32_t msec_to_samples(struct impl *impl, float msec)
|
||||
|
|
|
|||
|
|
@ -505,30 +505,20 @@ static int add_snapcast_stream(struct impl *impl, struct tunnel *t,
|
|||
|
||||
static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
info->format = spa_type_audio_format_from_short_name(str);
|
||||
if (info->format == 0) {
|
||||
str = DEFAULT_FORMAT;
|
||||
info->format = spa_type_audio_format_from_short_name(str);
|
||||
}
|
||||
pw_properties_set(props, PW_KEY_AUDIO_FORMAT, str);
|
||||
|
||||
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
|
||||
if (info->rate == 0)
|
||||
info->rate = DEFAULT_RATE;
|
||||
pw_properties_set(props, PW_KEY_AUDIO_FORMAT,
|
||||
spa_type_audio_format_to_short_name(info->format));
|
||||
pw_properties_setf(props, PW_KEY_AUDIO_RATE, "%d", info->rate);
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
pw_properties_setf(props, PW_KEY_AUDIO_CHANNELS, "%d", info->channels);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,24 +190,16 @@ static const struct format_info *find_audio_format_info(const struct spa_audio_i
|
|||
|
||||
static void parse_audio_info(const struct pw_properties *props, struct spa_audio_info_raw *info)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
spa_zero(*info);
|
||||
if ((str = pw_properties_get(props, PW_KEY_AUDIO_FORMAT)) == NULL)
|
||||
str = DEFAULT_FORMAT;
|
||||
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)
|
||||
info->rate = DEFAULT_RATE;
|
||||
|
||||
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)
|
||||
spa_audio_parse_position(str, strlen(str), info->position, &info->channels);
|
||||
if (info->channels == 0)
|
||||
spa_audio_parse_position(DEFAULT_POSITION, strlen(DEFAULT_POSITION),
|
||||
info->position, &info->channels);
|
||||
spa_audio_info_raw_init_dict_keys(info,
|
||||
&SPA_DICT_ITEMS(
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_FORMAT, DEFAULT_FORMAT),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_RATE, SPA_STRINGIFY(DEFAULT_RATE)),
|
||||
SPA_DICT_ITEM(SPA_KEY_AUDIO_POSITION, DEFAULT_POSITION)),
|
||||
&props->dict,
|
||||
SPA_KEY_AUDIO_FORMAT,
|
||||
SPA_KEY_AUDIO_RATE,
|
||||
SPA_KEY_AUDIO_CHANNELS,
|
||||
SPA_KEY_AUDIO_POSITION, NULL);
|
||||
}
|
||||
|
||||
static uint32_t msec_to_samples(struct impl *impl, uint32_t msec)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue