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:
Wim Taymans 2024-09-18 15:46:49 +02:00
parent d932e52d5b
commit e3a7035e8f
19 changed files with 204 additions and 255 deletions

View file

@ -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)