diff --git a/src/modules/module-protocol-pulse/format.c b/src/modules/module-protocol-pulse/format.c index 08481b1a8..e2a7696d4 100644 --- a/src/modules/module-protocol-pulse/format.c +++ b/src/modules/module-protocol-pulse/format.c @@ -225,6 +225,30 @@ bool sample_spec_valid(const struct sample_spec *ss) 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) { if (channel < 0 || (size_t)channel >= SPA_N_ELEMENTS(audio_channels)) diff --git a/src/modules/module-protocol-pulse/format.h b/src/modules/module-protocol-pulse/format.h index 6a144e559..7fddfdd4e 100644 --- a/src/modules/module-protocol-pulse/format.h +++ b/src/modules/module-protocol-pulse/format.h @@ -174,6 +174,9 @@ uint32_t format_encoding2id(enum encoding enc); uint32_t sample_spec_frame_size(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); const char *channel_id2name(uint32_t channel); uint32_t channel_name2id(const char *name); diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 0d2b5c49b..0beda77a3 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -1694,28 +1694,11 @@ static int do_create_playback_stream(struct client *client, uint32_t command, ui } if (sample_spec_valid(&ss)) { struct sample_spec sfix = ss; - const char *str; rate = ss.rate; - if (fix_format) { - 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; - } + sample_spec_fix(&sfix, &props->dict, fix_format, fix_rate, fix_channels); + if (n_params < MAX_FORMATS && (params[n_params] = format_build_param(&b, 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)) { struct sample_spec sfix = ss; - const char *str; rate = ss.rate; - if (fix_format) { - 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; - } + sample_spec_fix(&sfix, &props->dict, fix_format, fix_rate, fix_channels); + if (n_params < MAX_FORMATS && (params[n_params] = format_build_param(&b, SPA_PARAM_EnumFormat, &sfix,