module-raop: improve properties

Try to make a better NODE_NAME and NODE_DESCRIPTION using the
hostname and ip version.
This commit is contained in:
Wim Taymans 2023-03-14 10:34:45 +01:00
parent 51a970f5b7
commit 98222ab2ae
2 changed files with 19 additions and 12 deletions

View file

@ -282,6 +282,7 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
struct pw_impl_module *mod; struct pw_impl_module *mod;
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
char at[AVAHI_ADDRESS_STR_MAX]; char at[AVAHI_ADDRESS_STR_MAX];
int ipv;
if (event != AVAHI_RESOLVER_FOUND) { if (event != AVAHI_RESOLVER_FOUND) {
pw_log_error("Resolving of '%s' failed: %s", name, pw_log_error("Resolving of '%s' failed: %s", name,
@ -302,17 +303,20 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
avahi_address_snprint(at, sizeof(at), a); avahi_address_snprint(at, sizeof(at), a);
pw_properties_setf(props, "raop.hostname", "%s", at); pw_properties_setf(props, "raop.ip", "%s", at);
pw_properties_setf(props, "raop.port", "%u", port); pw_properties_setf(props, "raop.port", "%u", port);
pw_properties_setf(props, "raop.hostname", "%s", host_name);
ipv = protocol == AVAHI_PROTO_INET ? 4 : 6;
if ((str = strstr(name, "@"))) { if ((str = strstr(name, "@"))) {
str++; str++;
if (strlen(str) > 0) if (strlen(str) > 0)
pw_properties_set(props, PW_KEY_NODE_DESCRIPTION, str); name = str;
else
pw_properties_setf(props, PW_KEY_NODE_DESCRIPTION,
"RAOP on %s", host_name);
} }
pw_properties_setf(props, PW_KEY_NODE_DESCRIPTION,
"RAOP on %s (IPv%d)", name, ipv);
pw_properties_setf(props, PW_KEY_NODE_NAME, "raop_sink.%s.%s.ipv%d",
name, host_name, ipv);
for (l = txt; l; l = l->next) { for (l = txt; l; l = l->next) {
char *key, *value; char *key, *value;

View file

@ -53,6 +53,7 @@
* *
* Options specific to the behavior of this module * Options specific to the behavior of this module
* *
* - `raop.ip`: The ip address of the remote end.
* - `raop.hostname`: The hostname of the remote end. * - `raop.hostname`: The hostname of the remote end.
* - `raop.port`: The port of the remote end. * - `raop.port`: The port of the remote end.
* - `raop.transport`: The data transport to use, one of "udp" or "tcp". Defaults * - `raop.transport`: The data transport to use, one of "udp" or "tcp". Defaults
@ -84,6 +85,7 @@
* { name = libpipewire-module-raop-sink * { name = libpipewire-module-raop-sink
* args = { * args = {
* # Set the remote address to tunnel to * # Set the remote address to tunnel to
* raop.ip = "127.0.0.1"
* raop.hostname = "my-raop-device" * raop.hostname = "my-raop-device"
* raop.port = 8190 * raop.port = 8190
* #raop.transport = "udp" * #raop.transport = "udp"
@ -138,7 +140,8 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define DEFAULT_LATENCY 22050 #define DEFAULT_LATENCY 22050
#define MODULE_USAGE "[ raop.hostname=<name of host> ] " \ #define MODULE_USAGE "[ raop.ip=<ip address of host> ] " \
"[ raop.hostname=<name of host> ] " \
"[ raop.port=<remote port> ] " \ "[ raop.port=<remote port> ] " \
"[ raop.transport=<transport, default:udp> ] " \ "[ raop.transport=<transport, default:udp> ] " \
"[ raop.encryption.type=<encryption, default:none> ] " \ "[ raop.encryption.type=<encryption, default:none> ] " \
@ -587,7 +590,7 @@ static int connect_socket(struct impl *impl, int type, int fd, uint16_t port)
size_t salen; size_t salen;
int res, af; int res, af;
host = pw_properties_get(impl->props, "raop.hostname"); host = pw_properties_get(impl->props, "raop.ip");
if (host == NULL) if (host == NULL)
return -EINVAL; return -EINVAL;
@ -1052,7 +1055,7 @@ static int rtsp_do_announce(struct impl *impl)
char local_ip[256]; char local_ip[256];
int min_latency; int min_latency;
min_latency = DEFAULT_LATENCY; min_latency = DEFAULT_LATENCY;
host = pw_properties_get(impl->props, "raop.hostname"); host = pw_properties_get(impl->props, "raop.ip");
if (impl->protocol == PROTO_TCP) if (impl->protocol == PROTO_TCP)
frames = FRAMES_PER_TCP_PACKET; frames = FRAMES_PER_TCP_PACKET;
@ -1406,7 +1409,7 @@ static int rtsp_do_connect(struct impl *impl)
return 0; return 0;
} }
hostname = pw_properties_get(impl->props, "raop.hostname"); hostname = pw_properties_get(impl->props, "raop.ip");
port = pw_properties_get(impl->props, "raop.port"); port = pw_properties_get(impl->props, "raop.port");
if (hostname == NULL || port == NULL) if (hostname == NULL || port == NULL)
return -EINVAL; return -EINVAL;
@ -1673,8 +1676,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
{ {
struct pw_context *context = pw_impl_module_get_context(module); struct pw_context *context = pw_impl_module_get_context(module);
struct pw_properties *props = NULL; struct pw_properties *props = NULL;
uint32_t id = pw_global_get_id(pw_impl_module_get_global(module));
uint32_t pid = getpid();
struct impl *impl; struct impl *impl;
const char *str; const char *str;
int res; int res;
@ -1719,7 +1720,9 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Sink"); pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Sink");
if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL) if (pw_properties_get(props, PW_KEY_NODE_NAME) == NULL)
pw_properties_setf(props, PW_KEY_NODE_NAME, "raop-sink-%u-%u", pid, id); pw_properties_setf(props, PW_KEY_NODE_NAME, "raop_output.%s",
pw_properties_get(props, "raop.hostname"));
if (pw_properties_get(props, PW_KEY_NODE_DESCRIPTION) == NULL) if (pw_properties_get(props, PW_KEY_NODE_DESCRIPTION) == NULL)
pw_properties_set(props, PW_KEY_NODE_DESCRIPTION, pw_properties_set(props, PW_KEY_NODE_DESCRIPTION,
pw_properties_get(props, PW_KEY_NODE_NAME)); pw_properties_get(props, PW_KEY_NODE_NAME));