modules: add pulse.latency to module-zeroconf-discover

To set latency to remote streams.
Also add latency_msec argument to the pulseaudio module for this.

See #2755
This commit is contained in:
Wim Taymans 2022-10-12 12:18:47 +02:00
parent 6f235f344f
commit aed56719f2
2 changed files with 31 additions and 4 deletions

View file

@ -40,6 +40,8 @@ struct module_zeroconf_discover_data {
struct spa_hook mod_listener; struct spa_hook mod_listener;
struct pw_impl_module *mod; struct pw_impl_module *mod;
uint32_t latency_msec;
}; };
static void module_destroy(void *data) static void module_destroy(void *data)
@ -58,10 +60,25 @@ static const struct pw_impl_module_events module_events = {
static int module_zeroconf_discover_load(struct client *client, struct module *module) static int module_zeroconf_discover_load(struct client *client, struct module *module)
{ {
struct module_zeroconf_discover_data *data = module->user_data; struct module_zeroconf_discover_data *data = module->user_data;
FILE *f;
char *args;
size_t size;
if ((f = open_memstream(&args, &size)) == NULL)
return -errno;
fprintf(f, "{");
if (data->latency_msec > 0)
fprintf(f, " pulse.latency = %u ", data->latency_msec);
fprintf(f, "}");
fclose(f);
data->mod = pw_context_load_module(module->impl->context, data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-zeroconf-discover", "libpipewire-module-zeroconf-discover",
NULL, NULL); args, NULL);
free(args);
if (data->mod == NULL) if (data->mod == NULL)
return -errno; return -errno;
@ -88,7 +105,8 @@ static int module_zeroconf_discover_unload(struct module *module)
static const struct spa_dict_item module_zeroconf_discover_info[] = { static const struct spa_dict_item module_zeroconf_discover_info[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.con>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.con>" },
{ PW_KEY_MODULE_DESCRIPTION, "mDNS/DNS-SD Service Discovery" }, { PW_KEY_MODULE_DESCRIPTION, "mDNS/DNS-SD Service Discovery" },
{ PW_KEY_MODULE_USAGE, "" }, { PW_KEY_MODULE_USAGE,
"latency_msec=<fixed latency in ms> " },
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
@ -96,9 +114,12 @@ static int module_zeroconf_discover_prepare(struct module * const module)
{ {
PW_LOG_TOPIC_INIT(mod_topic); PW_LOG_TOPIC_INIT(mod_topic);
struct pw_properties * const props = module->props;
struct module_zeroconf_discover_data * const data = module->user_data; struct module_zeroconf_discover_data * const data = module->user_data;
data->module = module; data->module = module;
pw_properties_fetch_uint32(props, "latency_msec", &data->latency_msec);
return 0; return 0;
} }

View file

@ -54,7 +54,10 @@
* audio to/from remote PulseAudio servers. It also works with * audio to/from remote PulseAudio servers. It also works with
* module-protocol-pulse. * module-protocol-pulse.
* *
* This module has no options. * ## Module Options
*
* - `pulse.latency`: the latency to end-to-end latency in milliseconds to
* maintain (Default 200ms).
* *
* ## Example configuration * ## Example configuration
* *
@ -72,7 +75,7 @@
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME); PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic #define PW_LOG_TOPIC_DEFAULT mod_topic
#define MODULE_USAGE " " #define MODULE_USAGE "pulse.latency=<latency in msec> "
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
@ -348,6 +351,9 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
_("%s on %s"), desc, fqdn); _("%s on %s"), desc, fqdn);
} }
if ((str = pw_properties_get(impl->properties, "pulse.latency")) != NULL)
pw_properties_set(props, "pulse.latency", str);
if ((f = open_memstream(&args, &size)) == NULL) { if ((f = open_memstream(&args, &size)) == NULL) {
pw_log_error("Can't open memstream: %m"); pw_log_error("Can't open memstream: %m");
goto done; goto done;