pulse-server: move fix function to format functions

This commit is contained in:
Wim Taymans 2023-02-23 09:22:56 +01:00
parent 4163991a97
commit d11f8d5dea
3 changed files with 31 additions and 38 deletions

View file

@ -225,6 +225,30 @@ bool sample_spec_valid(const struct sample_spec *ss)
ss->channels > 0 && ss->channels <= CHANNELS_MAX); ss->channels > 0 && ss->channels <= CHANNELS_MAX);
} }
void sample_spec_fix(struct sample_spec *ss, struct spa_dict *props,
bool fix_format, bool fix_rate, bool fix_channels)
{
const char *str;
if (fix_format) {
if ((str = spa_dict_lookup(props, "pulse.fix.format")) != NULL)
ss->format = format_name2id(str);
else
ss->format = SPA_AUDIO_FORMAT_UNKNOWN;
}
if (fix_rate) {
if ((str = spa_dict_lookup(props, "pulse.fix.rate")) != NULL)
ss->rate = atoi(str);
else
ss->rate = 0;
}
if (fix_channels) {
if ((str = spa_dict_lookup(props, "pulse.fix.channels")) != NULL)
ss->channels = atoi(str);
else
ss->channels = 0;
}
}
uint32_t channel_pa2id(enum channel_position channel) uint32_t channel_pa2id(enum channel_position channel)
{ {
if (channel < 0 || (size_t)channel >= SPA_N_ELEMENTS(audio_channels)) if (channel < 0 || (size_t)channel >= SPA_N_ELEMENTS(audio_channels))

View file

@ -174,6 +174,9 @@ uint32_t format_encoding2id(enum encoding enc);
uint32_t sample_spec_frame_size(const struct sample_spec *ss); uint32_t sample_spec_frame_size(const struct sample_spec *ss);
bool sample_spec_valid(const struct sample_spec *ss); bool sample_spec_valid(const struct sample_spec *ss);
void sample_spec_fix(struct sample_spec *ss, struct spa_dict *props,
bool fix_format, bool fix_rate, bool fix_channels);
uint32_t channel_pa2id(enum channel_position channel); uint32_t channel_pa2id(enum channel_position channel);
const char *channel_id2name(uint32_t channel); const char *channel_id2name(uint32_t channel);
uint32_t channel_name2id(const char *name); uint32_t channel_name2id(const char *name);

View file

@ -1694,28 +1694,11 @@ static int do_create_playback_stream(struct client *client, uint32_t command, ui
} }
if (sample_spec_valid(&ss)) { if (sample_spec_valid(&ss)) {
struct sample_spec sfix = ss; struct sample_spec sfix = ss;
const char *str;
rate = ss.rate; rate = ss.rate;
if (fix_format) { sample_spec_fix(&sfix, &props->dict, fix_format, fix_rate, fix_channels);
if ((str = pw_properties_get(props, "pulse.fix.format")) != NULL)
sfix.format = format_name2id(str);
else
sfix.format = SPA_AUDIO_FORMAT_UNKNOWN;
}
if (fix_rate) {
if ((str = pw_properties_get(props, "pulse.fix.rate")) != NULL)
sfix.rate = atoi(str);
else
sfix.rate = 0;
}
if (fix_channels) {
if ((str = pw_properties_get(props, "pulse.fix.channels")) != NULL)
sfix.channels = atoi(str);
else
sfix.channels = 0;
}
if (n_params < MAX_FORMATS && if (n_params < MAX_FORMATS &&
(params[n_params] = format_build_param(&b, (params[n_params] = format_build_param(&b,
SPA_PARAM_EnumFormat, &sfix, SPA_PARAM_EnumFormat, &sfix,
@ -1957,28 +1940,11 @@ static int do_create_record_stream(struct client *client, uint32_t command, uint
} }
if (sample_spec_valid(&ss)) { if (sample_spec_valid(&ss)) {
struct sample_spec sfix = ss; struct sample_spec sfix = ss;
const char *str;
rate = ss.rate; rate = ss.rate;
if (fix_format) { sample_spec_fix(&sfix, &props->dict, fix_format, fix_rate, fix_channels);
if ((str = pw_properties_get(props, "pulse.fix.format")) != NULL)
sfix.format = format_name2id(str);
else
sfix.format = SPA_AUDIO_FORMAT_UNKNOWN;
}
if (fix_rate) {
if ((str = pw_properties_get(props, "pulse.fix.rate")) != NULL)
sfix.rate = atoi(str);
else
sfix.rate = 0;
}
if (fix_channels) {
if ((str = pw_properties_get(props, "pulse.fix.channels")) != NULL)
sfix.channels = atoi(str);
else
sfix.channels = 0;
}
if (n_params < MAX_FORMATS && if (n_params < MAX_FORMATS &&
(params[n_params] = format_build_param(&b, (params[n_params] = format_build_param(&b,
SPA_PARAM_EnumFormat, &sfix, SPA_PARAM_EnumFormat, &sfix,