modules: switch a few modules to the new property helpers

This commit is contained in:
Peter Hutterer 2021-10-12 14:29:57 +10:00 committed by Wim Taymans
parent d8de1cb255
commit 1d8d7e90ce
6 changed files with 16 additions and 41 deletions

View file

@ -35,12 +35,10 @@
void select_best(struct selector *s, struct pw_manager_object *o)
{
const char *str;
int32_t prio = 0;
if (o->props &&
(str = pw_properties_get(o->props, PW_KEY_PRIORITY_SESSION)) != NULL) {
prio = pw_properties_parse_int(str);
pw_properties_fetch_int32(o->props, PW_KEY_PRIORITY_SESSION, &prio) == 0) {
if (s->best == NULL || prio > s->score) {
s->best = o;
s->score = prio;
@ -75,19 +73,15 @@ struct pw_manager_object *select_object(struct pw_manager *m, struct selector *s
bool collect_is_linked(struct pw_manager *m, uint32_t obj_id, enum pw_direction direction)
{
struct pw_manager_object *o;
const char *str;
uint32_t in_node, out_node;
spa_list_for_each(o, &m->object_list, link) {
if (o->props == NULL || !pw_manager_object_is_link(o))
continue;
if ((str = pw_properties_get(o->props, PW_KEY_LINK_OUTPUT_NODE)) == NULL)
if (pw_properties_fetch_uint32(o->props, PW_KEY_LINK_OUTPUT_NODE, &out_node) != 0 ||
pw_properties_fetch_uint32(o->props, PW_KEY_LINK_INPUT_NODE, &in_node) != 0)
continue;
out_node = pw_properties_parse_int(str);
if ((str = pw_properties_get(o->props, PW_KEY_LINK_INPUT_NODE)) == NULL)
continue;
in_node = pw_properties_parse_int(str);
if ((direction == PW_DIRECTION_OUTPUT && obj_id == out_node) ||
(direction == PW_DIRECTION_INPUT && obj_id == in_node))
@ -99,19 +93,15 @@ bool collect_is_linked(struct pw_manager *m, uint32_t obj_id, enum pw_direction
struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t obj_id, enum pw_direction direction)
{
struct pw_manager_object *o, *p;
const char *str;
uint32_t in_node, out_node;
spa_list_for_each(o, &m->object_list, link) {
if (o->props == NULL || !pw_manager_object_is_link(o))
continue;
if ((str = pw_properties_get(o->props, PW_KEY_LINK_OUTPUT_NODE)) == NULL)
if (pw_properties_fetch_uint32(o->props, PW_KEY_LINK_OUTPUT_NODE, &out_node) != 0 ||
pw_properties_fetch_uint32(o->props, PW_KEY_LINK_INPUT_NODE, &in_node) != 0)
continue;
out_node = pw_properties_parse_int(str);
if ((str = pw_properties_get(o->props, PW_KEY_LINK_INPUT_NODE)) == NULL)
continue;
in_node = pw_properties_parse_int(str);
if (direction == PW_DIRECTION_OUTPUT && obj_id == out_node) {
struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, };

View file

@ -225,8 +225,7 @@ struct module *create_module_tunnel_sink(struct impl *impl, const char *argument
d->module = module;
d->stream_props = stream_props;
if ((str = pw_properties_get(props, "latency_msec")) != NULL)
spa_atou32(str, &d->latency_msec, 0);
pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec);
return module;
out:

View file

@ -215,8 +215,7 @@ struct module *create_module_tunnel_source(struct impl *impl, const char *argume
d->module = module;
d->stream_props = stream_props;
if ((str = pw_properties_get(props, "latency_msec")) != NULL)
spa_atou32(str, &d->latency_msec, 0);
pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec);
return module;
out:

View file

@ -638,7 +638,6 @@ struct module *create_module_zeroconf_publish(struct impl *impl, const char *arg
struct module *module;
struct module_zeroconf_publish_data *d;
struct pw_properties *props = NULL;
const char *port;
int res;
PW_LOG_TOPIC_INIT(mod_topic);
@ -661,11 +660,7 @@ struct module *create_module_zeroconf_publish(struct impl *impl, const char *arg
d = module->user_data;
d->module = module;
if ((port = pw_properties_get(props, "port")) == NULL)
d->port = PW_PROTOCOL_PULSE_DEFAULT_PORT;
else
d->port = atoi(port);
d->port = pw_properties_get_uint32(props, "port", PW_PROTOCOL_PULSE_DEFAULT_PORT);
return module;
out:

View file

@ -62,7 +62,7 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define DEFAULT_FORMAT "S16"
#define DEFAULT_RATE "44100"
#define DEFAULT_CHANNELS "2"
#define DEFAULT_CHANNELS 2
#define DEFAULT_POSITION "[ FL FR ]"
#define DEFAULT_LATENCY "1024/48000"
@ -74,7 +74,7 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
"[ playback.node=<sink-target> ] " \
"[ audio.rate=<sample-rate, default:"DEFAULT_RATE"> ] " \
"[ audio.format=<format, default:"DEFAULT_FORMAT"> ] " \
"[ audio.channels=<channels, default:"DEFAULT_CHANNELS"> ] " \
"[ audio.channels=<channels, default: 2> ] " \
"[ audio.position=<position, default:"DEFAULT_POSITION"> ] " \
"[ server.address=<[ tcp:[<ip>:]<port>[,...] ], default:"DEFAULT_SERVER">" \
@ -722,10 +722,8 @@ static int parse_params(struct impl *impl)
struct spa_json it[2];
char value[512];
if ((str = pw_properties_get(impl->props, "capture")) != NULL)
impl->capture = pw_properties_parse_bool(str);
if ((str = pw_properties_get(impl->props, "playback")) != NULL)
impl->playback = pw_properties_parse_bool(str);
pw_properties_get_bool(impl->props, "capture", &impl->capture);
pw_properties_get_bool(impl->props, "playback", &impl->playback);
if (!impl->playback && !impl->capture) {
pw_log_error("missing capture or playback param");
return -EINVAL;
@ -745,9 +743,7 @@ static int parse_params(struct impl *impl)
pw_log_error("invalid rate '%s'", str);
return -EINVAL;
}
if ((str = pw_properties_get(impl->props, "audio.channels")) == NULL)
str = DEFAULT_CHANNELS;
impl->info.channels = atoi(str);
impl->info.channels = pw_properties_get_uint32(impl->props, "audio.channels", DEFAULT_CHANNELS);
if (impl->info.channels == 0) {
pw_log_error("invalid channels '%s'", str);
return -EINVAL;

View file

@ -727,10 +727,8 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->format = id;
}
if ((str = pw_properties_get(props, PW_KEY_AUDIO_RATE)) != NULL)
info->rate = atoi(str);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_CHANNELS)) != NULL)
info->channels = atoi(str);
info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str));
}
@ -803,9 +801,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
}
}
impl->latency_msec = DEFAULT_LATENCY_MSEC;
if ((str = pw_properties_get(props, "pulse.latency")) != NULL)
spa_atou32(str, &impl->latency_msec, 0);
impl->latency_msec = pw_properties_get_uint32(props, "pulse.latency", DEFAULT_LATENCY_MSEC);
if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL)
pw_properties_set(props, PW_KEY_NODE_GROUP, "pipewire.dummy");