pipewire-pulse: add zeroconf module

This commit is contained in:
Wim Taymans 2021-05-14 11:39:44 +02:00
parent 5c152bab23
commit 170294d7ac
5 changed files with 142 additions and 1 deletions

View file

@ -142,6 +142,7 @@ pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse'
'module-protocol-pulse/modules/module-simple-protocol-tcp.c',
'module-protocol-pulse/modules/module-tunnel-sink.c',
'module-protocol-pulse/modules/module-tunnel-source.c',
'module-protocol-pulse/modules/module-zeroconf-discover.c',
],
c_args : pipewire_module_c_args,
include_directories : [configinc, spa_inc],

View file

@ -223,6 +223,7 @@ static const struct module_info module_list[] = {
{ "module-simple-protocol-tcp", create_module_simple_protocol_tcp, },
{ "module-tunnel-sink", create_module_tunnel_sink, },
{ "module-tunnel-source", create_module_tunnel_source, },
{ "module-zeroconf-discover", create_module_zeroconf_discover, },
{ NULL, }
};

View file

@ -0,0 +1,138 @@
/* PipeWire
*
* Copyright © 2021 Wim Taymans <wim.taymans@gmail.com>
*
* 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 <spa/utils/hook.h>
#include <pipewire/pipewire.h>
#include <pipewire/private.h>
#include "../defs.h"
#include "../module.h"
#include "registry.h"
#define ERROR_RETURN(str) \
{ \
pw_log_error(str); \
res = -EINVAL; \
goto out; \
}
struct module_zeroconf_discover_data {
struct module *module;
struct spa_hook mod_listener;
struct pw_impl_module *mod;
};
static void module_destroy(void *data)
{
struct module_zeroconf_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_zeroconf_discover_load(struct client *client, struct module *module)
{
struct module_zeroconf_discover_data *data = module->user_data;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-zeroconf-discover",
NULL, NULL);
if (data->mod == NULL)
return -errno;
pw_impl_module_add_listener(data->mod,
&data->mod_listener,
&module_events, data);
pw_log_info("loaded module %p id:%u name:%s", module, module->idx, module->name);
module_emit_loaded(module, 0);
return 0;
}
static int module_zeroconf_discover_unload(struct client *client, struct module *module)
{
struct module_zeroconf_discover_data *d = module->user_data;
pw_log_info("unload module %p id:%u name:%s", module, module->idx, module->name);
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_zeroconf_discover_methods = {
VERSION_MODULE_METHODS,
.load = module_zeroconf_discover_load,
.unload = module_zeroconf_discover_unload,
};
static const struct spa_dict_item module_zeroconf_discover_info[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.con>" },
{ PW_KEY_MODULE_DESCRIPTION, "mDNS/DNS-SD Service Discovery" },
{ PW_KEY_MODULE_USAGE, "" },
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
};
struct module *create_module_zeroconf_discover(struct impl *impl, const char *argument)
{
struct module *module;
struct module_zeroconf_discover_data *d;
struct pw_properties *props = NULL;
int res;
props = pw_properties_new_dict(&SPA_DICT_INIT_ARRAY(module_zeroconf_discover_info));
if (props == NULL) {
res = -errno;
goto out;
}
if (argument != NULL)
module_args_add_props(props, argument);
module = module_new(impl, &module_zeroconf_discover_methods, sizeof(*d));
if (module == NULL) {
res = -errno;
goto out;
}
module->props = props;
d = module->user_data;
d->module = module;
return module;
out:
if (props)
pw_properties_free(props);
errno = -res;
return NULL;
}

View file

@ -39,5 +39,6 @@ struct module *create_module_tunnel_sink(struct impl *impl, const char *argument
struct module *create_module_tunnel_source(struct impl *impl, const char *argument);
struct module *create_module_simple_protocol_tcp(struct impl *impl, const char *argument);
struct module *create_module_pipe_sink(struct impl *impl, const char *argument);
struct module *create_module_zeroconf_discover(struct impl *impl, const char *argument);
#endif

View file

@ -479,7 +479,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_log_debug("module %p: new %s", impl, args);
if (args)
if (args == NULL)
args = "";
props = pw_properties_new_string(args);