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) void select_best(struct selector *s, struct pw_manager_object *o)
{ {
const char *str;
int32_t prio = 0; int32_t prio = 0;
if (o->props && if (o->props &&
(str = pw_properties_get(o->props, PW_KEY_PRIORITY_SESSION)) != NULL) { pw_properties_fetch_int32(o->props, PW_KEY_PRIORITY_SESSION, &prio) == 0) {
prio = pw_properties_parse_int(str);
if (s->best == NULL || prio > s->score) { if (s->best == NULL || prio > s->score) {
s->best = o; s->best = o;
s->score = prio; 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) bool collect_is_linked(struct pw_manager *m, uint32_t obj_id, enum pw_direction direction)
{ {
struct pw_manager_object *o; struct pw_manager_object *o;
const char *str;
uint32_t in_node, out_node; uint32_t in_node, out_node;
spa_list_for_each(o, &m->object_list, link) { spa_list_for_each(o, &m->object_list, link) {
if (o->props == NULL || !pw_manager_object_is_link(o)) if (o->props == NULL || !pw_manager_object_is_link(o))
continue; 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; 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) || if ((direction == PW_DIRECTION_OUTPUT && obj_id == out_node) ||
(direction == PW_DIRECTION_INPUT && obj_id == in_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 *find_linked(struct pw_manager *m, uint32_t obj_id, enum pw_direction direction)
{ {
struct pw_manager_object *o, *p; struct pw_manager_object *o, *p;
const char *str;
uint32_t in_node, out_node; uint32_t in_node, out_node;
spa_list_for_each(o, &m->object_list, link) { spa_list_for_each(o, &m->object_list, link) {
if (o->props == NULL || !pw_manager_object_is_link(o)) if (o->props == NULL || !pw_manager_object_is_link(o))
continue; 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; 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) { if (direction == PW_DIRECTION_OUTPUT && obj_id == out_node) {
struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, }; 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->module = module;
d->stream_props = stream_props; d->stream_props = stream_props;
if ((str = pw_properties_get(props, "latency_msec")) != NULL) pw_properties_fetch_uint32(props, "latency_msec", &d->latency_msec);
spa_atou32(str, &d->latency_msec, 0);
return module; return module;
out: out:

View file

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

View file

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

View file

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

View file

@ -727,10 +727,8 @@ static void parse_audio_info(struct pw_properties *props, struct spa_audio_info_
info->format = id; info->format = id;
} }
if ((str = pw_properties_get(props, PW_KEY_AUDIO_RATE)) != NULL) info->rate = pw_properties_get_uint32(props, PW_KEY_AUDIO_RATE, info->rate);
info->rate = atoi(str); info->channels = pw_properties_get_uint32(props, PW_KEY_AUDIO_CHANNELS, info->channels);
if ((str = pw_properties_get(props, PW_KEY_AUDIO_CHANNELS)) != NULL)
info->channels = atoi(str);
if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL) if ((str = pw_properties_get(props, SPA_KEY_AUDIO_POSITION)) != NULL)
parse_position(info, str, strlen(str)); 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; impl->latency_msec = pw_properties_get_uint32(props, "pulse.latency", DEFAULT_LATENCY_MSEC);
if ((str = pw_properties_get(props, "pulse.latency")) != NULL)
spa_atou32(str, &impl->latency_msec, 0);
if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL) if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL)
pw_properties_set(props, PW_KEY_NODE_GROUP, "pipewire.dummy"); pw_properties_set(props, PW_KEY_NODE_GROUP, "pipewire.dummy");