pulse-server: improve module args compatibility

Boolean switches can also be true with 'y', 'yes', 't' and 'on'
This commit is contained in:
Wim Taymans 2021-09-21 17:37:39 +02:00
parent 310e6009ca
commit c8f629a0a3
6 changed files with 14 additions and 5 deletions

View file

@ -227,6 +227,14 @@ int module_args_to_audioinfo(struct impl *impl, struct pw_properties *props, str
return 0; return 0;
} }
bool module_args_parse_bool(const char *v)
{
if (spa_streq(v, "1") || !strcasecmp(v, "y") || !strcasecmp(v, "t") ||
!strcasecmp(v, "yes") || !strcasecmp(v, "true") || !strcasecmp(v, "on"))
return true;
return false;
}
#include "modules/registry.h" #include "modules/registry.h"
static const struct module_info module_list[] = { static const struct module_info module_list[] = {

View file

@ -82,5 +82,6 @@ void module_add_listener(struct module *module,
void module_args_add_props(struct pw_properties *props, const char *str); void module_args_add_props(struct pw_properties *props, const char *str);
int module_args_to_audioinfo(struct impl *impl, struct pw_properties *props, struct spa_audio_info_raw *info); int module_args_to_audioinfo(struct impl *impl, struct pw_properties *props, struct spa_audio_info_raw *info);
bool module_args_parse_bool(const char *str);
#endif #endif

View file

@ -189,7 +189,7 @@ struct module *create_module_loopback(struct impl *impl, const char *argument)
if ((str = pw_properties_get(props, "remix")) != NULL) { if ((str = pw_properties_get(props, "remix")) != NULL) {
/* Note that the boolean is inverted */ /* Note that the boolean is inverted */
pw_properties_set(playback_props, PW_KEY_STREAM_DONT_REMIX, pw_properties_set(playback_props, PW_KEY_STREAM_DONT_REMIX,
pw_properties_parse_bool(str) ? "false" : "true"); module_args_parse_bool(str) ? "false" : "true");
pw_properties_set(props, "remix", NULL); pw_properties_set(props, "remix", NULL);
} }

View file

@ -200,7 +200,7 @@ struct module *create_module_remap_sink(struct impl *impl, const char *argument)
if ((str = pw_properties_get(props, "remix")) != NULL) { if ((str = pw_properties_get(props, "remix")) != NULL) {
/* Note that the boolean is inverted */ /* Note that the boolean is inverted */
pw_properties_set(playback_props, PW_KEY_STREAM_DONT_REMIX, pw_properties_set(playback_props, PW_KEY_STREAM_DONT_REMIX,
pw_properties_parse_bool(str) ? "false" : "true"); module_args_parse_bool(str) ? "false" : "true");
pw_properties_set(props, "remix", NULL); pw_properties_set(props, "remix", NULL);
} }

View file

@ -200,7 +200,7 @@ struct module *create_module_remap_source(struct impl *impl, const char *argumen
if ((str = pw_properties_get(props, "remix")) != NULL) { if ((str = pw_properties_get(props, "remix")) != NULL) {
/* Note that the boolean is inverted */ /* Note that the boolean is inverted */
pw_properties_set(capture_props, PW_KEY_STREAM_DONT_REMIX, pw_properties_set(capture_props, PW_KEY_STREAM_DONT_REMIX,
pw_properties_parse_bool(str) ? "false" : "true"); module_args_parse_bool(str) ? "false" : "true");
pw_properties_set(props, "remix", NULL); pw_properties_set(props, "remix", NULL);
} }

View file

@ -268,12 +268,12 @@ struct module *create_module_switch_on_connect(struct impl *impl, const char *ar
module_args_add_props(props, argument); module_args_add_props(props, argument);
if ((str = pw_properties_get(props, "only_from_unavailable")) != NULL) { if ((str = pw_properties_get(props, "only_from_unavailable")) != NULL) {
only_from_unavailable = pw_properties_parse_bool(str); only_from_unavailable = module_args_parse_bool(str);
pw_properties_set(props, "only_from_unavailable", NULL); pw_properties_set(props, "only_from_unavailable", NULL);
} }
if ((str = pw_properties_get(props, "ignore_virtual")) != NULL) { if ((str = pw_properties_get(props, "ignore_virtual")) != NULL) {
ignore_virtual = pw_properties_parse_bool(str); ignore_virtual = module_args_parse_bool(str);
pw_properties_set(props, "ignore_virtual", NULL); pw_properties_set(props, "ignore_virtual", NULL);
} }