2004-12-11 16:48:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of polypaudio.
|
|
|
|
|
|
|
|
|
|
polypaudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
polypaudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with polypaudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2006-02-16 19:19:58 +00:00
|
|
|
#include <polypcore/howl-wrap.h>
|
|
|
|
|
#include <polypcore/xmalloc.h>
|
|
|
|
|
#include <polypcore/autoload.h>
|
|
|
|
|
#include <polypcore/sink.h>
|
|
|
|
|
#include <polypcore/source.h>
|
|
|
|
|
#include <polypcore/native-common.h>
|
|
|
|
|
#include <polypcore/util.h>
|
|
|
|
|
#include <polypcore/log.h>
|
|
|
|
|
#include <polypcore/subscribe.h>
|
|
|
|
|
#include <polypcore/dynarray.h>
|
|
|
|
|
#include <polypcore/endianmacros.h>
|
|
|
|
|
#include <polypcore/modargs.h>
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
#include "module-zeroconf-publish-symdef.h"
|
|
|
|
|
|
|
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering")
|
|
|
|
|
PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher")
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION)
|
2004-12-15 01:02:50 +00:00
|
|
|
PA_MODULE_USAGE("port=<IP port number>")
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
#define SERVICE_NAME_SINK "_polypaudio-sink._tcp"
|
|
|
|
|
#define SERVICE_NAME_SOURCE "_polypaudio-source._tcp"
|
|
|
|
|
#define SERVICE_NAME_SERVER "_polypaudio-server._tcp"
|
|
|
|
|
|
2004-12-15 01:02:50 +00:00
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"port",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service {
|
|
|
|
|
sw_discovery_oid oid;
|
|
|
|
|
char *name;
|
|
|
|
|
int published; /* 0 -> not yet registered, 1 -> registered with data from real device, 2 -> registered with data from autoload device */
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
int valid;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_namereg_type type;
|
2004-12-11 16:48:45 +00:00
|
|
|
uint32_t index;
|
|
|
|
|
} loaded;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
int valid;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_namereg_type type;
|
2004-12-11 16:48:45 +00:00
|
|
|
uint32_t index;
|
|
|
|
|
} autoload;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *core;
|
|
|
|
|
pa_howl_wrapper *howl_wrapper;
|
|
|
|
|
pa_hashmap *services;
|
|
|
|
|
pa_dynarray *sink_dynarray, *source_dynarray, *autoload_dynarray;
|
|
|
|
|
pa_subscription *subscription;
|
2004-12-15 01:02:50 +00:00
|
|
|
|
|
|
|
|
uint16_t port;
|
|
|
|
|
sw_discovery_oid server_oid;
|
2004-12-11 16:48:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static sw_result publish_reply(sw_discovery discovery, sw_discovery_publish_status status, sw_discovery_oid oid, sw_opaque extra) {
|
|
|
|
|
return SW_OKAY;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description, pa_typeid_t *ret_typeid) {
|
2004-12-12 22:58:53 +00:00
|
|
|
assert(u && s && s->loaded.valid && ret_ss && ret_description && ret_typeid);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if (s->loaded.type == PA_NAMEREG_SINK) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index);
|
2004-12-11 16:48:45 +00:00
|
|
|
assert(sink);
|
|
|
|
|
*ret_ss = sink->sample_spec;
|
2004-12-12 22:58:53 +00:00
|
|
|
*ret_description = sink->description;
|
|
|
|
|
*ret_typeid = sink->typeid;
|
2004-12-11 16:48:45 +00:00
|
|
|
} else if (s->loaded.type == PA_NAMEREG_SOURCE) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index);
|
2004-12-11 16:48:45 +00:00
|
|
|
assert(source);
|
|
|
|
|
*ret_ss = source->sample_spec;
|
2004-12-12 22:58:53 +00:00
|
|
|
*ret_description = source->description;
|
|
|
|
|
*ret_typeid = source->typeid;
|
2004-12-11 16:48:45 +00:00
|
|
|
} else
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void txt_record_server_data(pa_core *c, sw_text_record t) {
|
2004-12-12 22:58:53 +00:00
|
|
|
char s[256];
|
|
|
|
|
assert(c);
|
|
|
|
|
|
|
|
|
|
sw_text_record_add_key_and_string_value(t, "server-version", PACKAGE_NAME" "PACKAGE_VERSION);
|
|
|
|
|
sw_text_record_add_key_and_string_value(t, "user-name", pa_get_user_name(s, sizeof(s)));
|
|
|
|
|
sw_text_record_add_key_and_string_value(t, "fqdn", pa_get_fqdn(s, sizeof(s)));
|
|
|
|
|
snprintf(s, sizeof(s), "0x%08x", c->cookie);
|
|
|
|
|
sw_text_record_add_key_and_string_value(t, "cookie", s);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
static int publish_service(struct userdata *u, struct service *s) {
|
|
|
|
|
char t[256];
|
|
|
|
|
char hn[256];
|
|
|
|
|
int r = -1;
|
|
|
|
|
sw_text_record txt;
|
|
|
|
|
int free_txt = 0;
|
2004-12-16 20:08:50 +00:00
|
|
|
assert(u && s);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if ((s->published == 1 && s->loaded.valid) ||
|
|
|
|
|
(s->published == 2 && s->autoload.valid && !s->loaded.valid))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (s->published) {
|
|
|
|
|
sw_discovery_cancel(pa_howl_wrapper_get_discovery(u->howl_wrapper), s->oid);
|
|
|
|
|
s->published = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-15 01:04:13 +00:00
|
|
|
snprintf(t, sizeof(t), "Networked Audio Device %s on %s", s->name, pa_get_host_name(hn, sizeof(hn)));
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if (sw_text_record_init(&txt) != SW_OKAY) {
|
|
|
|
|
pa_log(__FILE__": sw_text_record_init() failed\n");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
free_txt = 1;
|
|
|
|
|
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "device", s->name);
|
2004-12-12 22:58:53 +00:00
|
|
|
|
|
|
|
|
txt_record_server_data(u->core, txt);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if (s->loaded.valid) {
|
2004-12-12 22:58:53 +00:00
|
|
|
char z[64], *description;
|
|
|
|
|
pa_typeid_t typeid;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sample_spec ss;
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 22:58:53 +00:00
|
|
|
get_service_data(u, s, &ss, &description, &typeid);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
snprintf(z, sizeof(z), "%u", ss.rate);
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "rate", z);
|
|
|
|
|
snprintf(z, sizeof(z), "%u", ss.channels);
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "channels", z);
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "format", pa_sample_format_to_string(ss.format));
|
2004-12-12 22:58:53 +00:00
|
|
|
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "description", description);
|
|
|
|
|
|
|
|
|
|
snprintf(z, sizeof(z), "0x%8x", typeid);
|
|
|
|
|
sw_text_record_add_key_and_string_value(txt, "typeid", z);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if (sw_discovery_publish(pa_howl_wrapper_get_discovery(u->howl_wrapper), 0, t,
|
|
|
|
|
s->loaded.type == PA_NAMEREG_SINK ? SERVICE_NAME_SINK : SERVICE_NAME_SOURCE,
|
2004-12-15 01:02:50 +00:00
|
|
|
NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt),
|
2004-12-11 16:48:45 +00:00
|
|
|
publish_reply, s, &s->oid) != SW_OKAY) {
|
|
|
|
|
pa_log(__FILE__": failed to register sink on zeroconf.\n");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s->published = 1;
|
|
|
|
|
} else if (s->autoload.valid) {
|
|
|
|
|
|
|
|
|
|
if (sw_discovery_publish(pa_howl_wrapper_get_discovery(u->howl_wrapper), 0, t,
|
|
|
|
|
s->autoload.type == PA_NAMEREG_SINK ? SERVICE_NAME_SINK : SERVICE_NAME_SOURCE,
|
2004-12-15 01:02:50 +00:00
|
|
|
NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt),
|
2004-12-11 16:48:45 +00:00
|
|
|
publish_reply, s, &s->oid) != SW_OKAY) {
|
|
|
|
|
pa_log(__FILE__": failed to register sink on zeroconf.\n");
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s->published = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
|
|
if (!s->published) {
|
|
|
|
|
/* Remove this service */
|
|
|
|
|
pa_hashmap_remove(u->services, s->name);
|
|
|
|
|
pa_xfree(s->name);
|
|
|
|
|
pa_xfree(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (free_txt)
|
|
|
|
|
sw_text_record_fina(txt);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct service *get_service(struct userdata *u, const char *name) {
|
|
|
|
|
struct service *s;
|
|
|
|
|
|
|
|
|
|
if ((s = pa_hashmap_get(u->services, name)))
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
|
|
s = pa_xmalloc(sizeof(struct service));
|
|
|
|
|
s->published = 0;
|
|
|
|
|
s->name = pa_xstrdup(name);
|
|
|
|
|
s->loaded.valid = s->autoload.valid = 0;
|
|
|
|
|
|
|
|
|
|
pa_hashmap_put(u->services, s->name, s);
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static int publish_sink(struct userdata *u, pa_sink *s) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
|
|
|
|
assert(u && s);
|
|
|
|
|
|
|
|
|
|
svc = get_service(u, s->name);
|
|
|
|
|
if (svc->loaded.valid)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->loaded.valid = 1;
|
|
|
|
|
svc->loaded.type = PA_NAMEREG_SINK;
|
|
|
|
|
svc->loaded.index = s->index;
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
pa_dynarray_put(u->sink_dynarray, s->index, svc);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static int publish_source(struct userdata *u, pa_source *s) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
|
|
|
|
assert(u && s);
|
|
|
|
|
|
|
|
|
|
svc = get_service(u, s->name);
|
|
|
|
|
if (svc->loaded.valid)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->loaded.valid = 1;
|
|
|
|
|
svc->loaded.type = PA_NAMEREG_SOURCE;
|
|
|
|
|
svc->loaded.index = s->index;
|
2004-12-12 15:56:22 +00:00
|
|
|
|
|
|
|
|
pa_dynarray_put(u->source_dynarray, s->index, svc);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static int publish_autoload(struct userdata *u, pa_autoload_entry *s) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
|
|
|
|
assert(u && s);
|
|
|
|
|
|
|
|
|
|
svc = get_service(u, s->name);
|
|
|
|
|
if (svc->autoload.valid)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->autoload.valid = 1;
|
|
|
|
|
svc->autoload.type = s->type;
|
|
|
|
|
svc->autoload.index = s->index;
|
2004-12-12 15:56:22 +00:00
|
|
|
|
|
|
|
|
pa_dynarray_put(u->autoload_dynarray, s->index, svc);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
static int remove_sink(struct userdata *u, uint32_t index) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
2004-12-12 15:56:22 +00:00
|
|
|
assert(u && index != PA_INVALID_INDEX);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if (!(svc = pa_dynarray_get(u->sink_dynarray, index)))
|
2004-12-11 16:48:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SINK)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->loaded.valid = 0;
|
2004-12-12 15:56:22 +00:00
|
|
|
pa_dynarray_put(u->sink_dynarray, index, NULL);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
static int remove_source(struct userdata *u, uint32_t index) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
2004-12-12 15:56:22 +00:00
|
|
|
assert(u && index != PA_INVALID_INDEX);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if (!(svc = pa_dynarray_get(u->source_dynarray, index)))
|
2004-12-11 16:48:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SOURCE)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->loaded.valid = 0;
|
2004-12-12 15:56:22 +00:00
|
|
|
pa_dynarray_put(u->source_dynarray, index, NULL);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
static int remove_autoload(struct userdata *u, uint32_t index) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct service *svc;
|
2004-12-12 15:56:22 +00:00
|
|
|
assert(u && index != PA_INVALID_INDEX);
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if (!(svc = pa_dynarray_get(u->autoload_dynarray, index)))
|
2004-12-11 16:48:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if (!svc->autoload.valid)
|
2004-12-11 16:48:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
svc->autoload.valid = 0;
|
2004-12-12 15:56:22 +00:00
|
|
|
pa_dynarray_put(u->autoload_dynarray, index, NULL);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return publish_service(u, svc);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_t index, void *userdata) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
assert(u && c);
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)
|
2004-12-11 16:48:45 +00:00
|
|
|
case PA_SUBSCRIPTION_EVENT_SINK: {
|
2004-12-12 15:56:22 +00:00
|
|
|
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sink *sink;
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if ((sink = pa_idxset_get_by_index(c->sinks, index))) {
|
2004-12-11 16:48:45 +00:00
|
|
|
if (publish_sink(u, sink) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2004-12-12 15:56:22 +00:00
|
|
|
} else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
|
|
|
|
|
if (remove_sink(u, index) < 0)
|
|
|
|
|
goto fail;
|
2004-12-11 16:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
case PA_SUBSCRIPTION_EVENT_SOURCE:
|
2004-12-11 16:48:45 +00:00
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_source *source;
|
2004-12-12 15:56:22 +00:00
|
|
|
|
|
|
|
|
if ((source = pa_idxset_get_by_index(c->sources, index))) {
|
2004-12-11 16:48:45 +00:00
|
|
|
if (publish_source(u, source) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2004-12-12 15:56:22 +00:00
|
|
|
} else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
|
|
|
|
|
if (remove_source(u, index) < 0)
|
|
|
|
|
goto fail;
|
2004-12-11 16:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
case PA_SUBSCRIPTION_EVENT_AUTOLOAD:
|
|
|
|
|
if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_autoload_entry *autoload;
|
2004-12-12 15:56:22 +00:00
|
|
|
|
|
|
|
|
if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, index))) {
|
2004-12-11 16:48:45 +00:00
|
|
|
if (publish_autoload(u, autoload) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2004-12-12 15:56:22 +00:00
|
|
|
} else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
|
|
|
|
|
if (remove_autoload(u, index) < 0)
|
|
|
|
|
goto fail;
|
2004-12-11 16:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
if (u->subscription) {
|
|
|
|
|
pa_subscription_free(u->subscription);
|
|
|
|
|
u->subscription = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
int pa__init(pa_core *c, pa_module*m) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct userdata *u;
|
2004-12-15 01:02:50 +00:00
|
|
|
uint32_t index, port = PA_NATIVE_DEFAULT_PORT;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_sink *sink;
|
|
|
|
|
pa_source *source;
|
|
|
|
|
pa_autoload_entry *autoload;
|
|
|
|
|
pa_modargs *ma = NULL;
|
2004-12-15 01:02:50 +00:00
|
|
|
char t[256], hn[256];
|
|
|
|
|
int free_txt = 0;
|
|
|
|
|
sw_text_record txt;
|
|
|
|
|
|
|
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
|
|
|
|
pa_log(__FILE__": failed to parse module arguments.\n");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) {
|
|
|
|
|
pa_log(__FILE__": invalid port specified.\n");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
m->userdata = u = pa_xmalloc(sizeof(struct userdata));
|
|
|
|
|
u->core = c;
|
2004-12-15 01:02:50 +00:00
|
|
|
u->port = (uint16_t) port;
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
if (!(u->howl_wrapper = pa_howl_wrapper_get(c)))
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
2004-12-12 15:56:22 +00:00
|
|
|
u->sink_dynarray = pa_dynarray_new();
|
|
|
|
|
u->source_dynarray = pa_dynarray_new();
|
|
|
|
|
u->autoload_dynarray = pa_dynarray_new();
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
u->subscription = pa_subscription_new(c,
|
|
|
|
|
PA_SUBSCRIPTION_MASK_SINK|
|
|
|
|
|
PA_SUBSCRIPTION_MASK_SOURCE|
|
|
|
|
|
PA_SUBSCRIPTION_MASK_AUTOLOAD, subscribe_callback, u);
|
|
|
|
|
|
|
|
|
|
for (sink = pa_idxset_first(c->sinks, &index); sink; sink = pa_idxset_next(c->sinks, &index))
|
|
|
|
|
if (publish_sink(u, sink) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index))
|
|
|
|
|
if (publish_source(u, source) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (c->autoload_idxset)
|
|
|
|
|
for (autoload = pa_idxset_first(c->autoload_idxset, &index); autoload; autoload = pa_idxset_next(c->autoload_idxset, &index))
|
|
|
|
|
if (publish_autoload(u, autoload) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2004-12-15 01:04:13 +00:00
|
|
|
snprintf(t, sizeof(t), "Networked Audio Server on %s", pa_get_host_name(hn, sizeof(hn)));
|
2004-12-15 01:02:50 +00:00
|
|
|
|
|
|
|
|
if (sw_text_record_init(&txt) != SW_OKAY) {
|
|
|
|
|
pa_log(__FILE__": sw_text_record_init() failed\n");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
free_txt = 1;
|
|
|
|
|
|
|
|
|
|
txt_record_server_data(u->core, txt);
|
|
|
|
|
|
|
|
|
|
if (sw_discovery_publish(pa_howl_wrapper_get_discovery(u->howl_wrapper), 0, t,
|
|
|
|
|
SERVICE_NAME_SERVER,
|
|
|
|
|
NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt),
|
|
|
|
|
publish_reply, u, &u->server_oid) != SW_OKAY) {
|
|
|
|
|
pa_log(__FILE__": failed to register server on zeroconf.\n");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw_text_record_fina(txt);
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
pa__done(c, m);
|
2004-12-15 01:02:50 +00:00
|
|
|
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
|
|
|
|
if (free_txt)
|
|
|
|
|
sw_text_record_fina(txt);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void service_free(void *p, void *userdata) {
|
|
|
|
|
struct service *s = p;
|
|
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
assert(s && u);
|
|
|
|
|
sw_discovery_cancel(pa_howl_wrapper_get_discovery(u->howl_wrapper), s->oid);
|
|
|
|
|
pa_xfree(s->name);
|
|
|
|
|
pa_xfree(s);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa__done(pa_core *c, pa_module*m) {
|
2004-12-11 16:48:45 +00:00
|
|
|
struct userdata*u;
|
|
|
|
|
assert(c && m);
|
|
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (u->services)
|
|
|
|
|
pa_hashmap_free(u->services, service_free, u);
|
|
|
|
|
|
2004-12-12 15:56:22 +00:00
|
|
|
if (u->sink_dynarray)
|
|
|
|
|
pa_dynarray_free(u->sink_dynarray, NULL, NULL);
|
|
|
|
|
if (u->source_dynarray)
|
|
|
|
|
pa_dynarray_free(u->source_dynarray, NULL, NULL);
|
|
|
|
|
if (u->autoload_dynarray)
|
|
|
|
|
pa_dynarray_free(u->autoload_dynarray, NULL, NULL);
|
|
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
if (u->subscription)
|
|
|
|
|
pa_subscription_free(u->subscription);
|
|
|
|
|
|
|
|
|
|
if (u->howl_wrapper)
|
|
|
|
|
pa_howl_wrapper_unref(u->howl_wrapper);
|
2004-12-12 15:56:22 +00:00
|
|
|
|
2004-12-11 16:48:45 +00:00
|
|
|
|
|
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|
|
|
|
|
|