diff --git a/src/modules/meson.build b/src/modules/meson.build index e9f0bae40..5ee4aa732 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -236,6 +236,7 @@ pipewire_module_protocol_pulse_sources = [ 'module-protocol-pulse/modules/module-null-sink.c', 'module-protocol-pulse/modules/module-pipe-source.c', 'module-protocol-pulse/modules/module-pipe-sink.c', + 'module-protocol-pulse/modules/module-raop-discover.c', 'module-protocol-pulse/modules/module-remap-sink.c', 'module-protocol-pulse/modules/module-remap-source.c', 'module-protocol-pulse/modules/module-simple-protocol-tcp.c', diff --git a/src/modules/module-protocol-pulse/module.c b/src/modules/module-protocol-pulse/module.c index 01a8233c3..2a2434b22 100644 --- a/src/modules/module-protocol-pulse/module.c +++ b/src/modules/module-protocol-pulse/module.c @@ -252,6 +252,7 @@ static const struct module_info module_list[] = { { "module-native-protocol-tcp", create_module_native_protocol_tcp, }, { "module-pipe-source", create_module_pipe_source, }, { "module-pipe-sink", create_module_pipe_sink, }, + { "module-raop-discover", create_module_raop_discover, }, { "module-remap-sink", create_module_remap_sink, }, { "module-remap-source", create_module_remap_source, }, { "module-simple-protocol-tcp", create_module_simple_protocol_tcp, }, diff --git a/src/modules/module-protocol-pulse/modules/module-raop-discover.c b/src/modules/module-protocol-pulse/modules/module-raop-discover.c new file mode 100644 index 000000000..1fec2ae71 --- /dev/null +++ b/src/modules/module-protocol-pulse/modules/module-raop-discover.c @@ -0,0 +1,134 @@ +/* PipeWire + * + * Copyright © 2021 Wim Taymans + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "../defs.h" +#include "../module.h" +#include "registry.h" + +#define NAME "raop-discover" + +PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME); +#define PW_LOG_TOPIC_DEFAULT mod_topic + + +struct module_raop_discover_data { + struct module *module; + + struct spa_hook mod_listener; + struct pw_impl_module *mod; +}; + +static void module_destroy(void *data) +{ + struct module_raop_discover_data *d = data; + spa_hook_remove(&d->mod_listener); + d->mod = NULL; + module_schedule_unload(d->module); +} + +static const struct pw_impl_module_events module_events = { + PW_VERSION_IMPL_MODULE_EVENTS, + .destroy = module_destroy +}; + +static int module_raop_discover_load(struct client *client, struct module *module) +{ + struct module_raop_discover_data *data = module->user_data; + + data->mod = pw_context_load_module(module->impl->context, + "libpipewire-module-raop-discover", + NULL, NULL); + if (data->mod == NULL) + return -errno; + + pw_impl_module_add_listener(data->mod, + &data->mod_listener, + &module_events, data); + + return 0; +} + +static int module_raop_discover_unload(struct client *client, struct module *module) +{ + struct module_raop_discover_data *d = module->user_data; + + if (d->mod) { + spa_hook_remove(&d->mod_listener); + pw_impl_module_destroy(d->mod); + d->mod = NULL; + } + + return 0; +} + +static const struct module_methods module_raop_discover_methods = { + VERSION_MODULE_METHODS, + .load = module_raop_discover_load, + .unload = module_raop_discover_unload, +}; + +static const struct spa_dict_item module_raop_discover_info[] = { + { PW_KEY_MODULE_AUTHOR, "Wim Taymans " }, + { PW_KEY_MODULE_DESCRIPTION, "mDNS/DNS-SD Service Discovery of RAOP devices" }, + { PW_KEY_MODULE_USAGE, "" }, + { PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, +}; + +struct module *create_module_raop_discover(struct impl *impl, const char *argument) +{ + struct module *module; + struct module_raop_discover_data *d; + struct pw_properties *props = NULL; + int res; + + PW_LOG_TOPIC_INIT(mod_topic); + + props = pw_properties_new_dict(&SPA_DICT_INIT_ARRAY(module_raop_discover_info)); + if (props == NULL) { + res = -errno; + goto out; + } + if (argument != NULL) + module_args_add_props(props, argument); + + module = module_new(impl, &module_raop_discover_methods, sizeof(*d)); + if (module == NULL) { + res = -errno; + goto out; + } + + module->props = props; + d = module->user_data; + d->module = module; + + return module; +out: + pw_properties_free(props); + errno = -res; + return NULL; +} diff --git a/src/modules/module-protocol-pulse/modules/registry.h b/src/modules/module-protocol-pulse/modules/registry.h index 3b79455e9..6c7f461c5 100644 --- a/src/modules/module-protocol-pulse/modules/registry.h +++ b/src/modules/module-protocol-pulse/modules/registry.h @@ -35,6 +35,7 @@ struct module *create_module_ladspa_source(struct impl *impl, const char *argume struct module *create_module_loopback(struct impl *impl, const char *argument); struct module *create_module_native_protocol_tcp(struct impl *impl, const char *argument); struct module *create_module_null_sink(struct impl *impl, const char *argument); +struct module *create_module_raop_discover(struct impl *impl, const char *argument); struct module *create_module_remap_sink(struct impl *impl, const char *argument); struct module *create_module_remap_source(struct impl *impl, const char *argument); struct module *create_module_tunnel_sink(struct impl *impl, const char *argument);