From e205b25d65ccb380fa158711e24d55b6de5d9bc1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 16 Feb 2006 19:19:58 +0000 Subject: Reorganised the source tree. We now have src/ with a couple of subdirs: * daemon/ - Contains the files specific to the polypaudio daemon. * modules/ - All loadable modules. * polyp/ - Files that are part of the public, application interface or are only used in libpolyp. * polypcore/ - All other shared files. * tests/ - Test programs. * utils/ - Utility programs. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@487 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 508 ++++++++++++++++++++++++++++++++++ 1 file changed, 508 insertions(+) create mode 100644 src/modules/module-zeroconf-publish.c (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c new file mode 100644 index 00000000..45d566ae --- /dev/null +++ b/src/modules/module-zeroconf-publish.c @@ -0,0 +1,508 @@ +/* $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 +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "module-zeroconf-publish-symdef.h" + +PA_MODULE_AUTHOR("Lennart Poettering") +PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher") +PA_MODULE_VERSION(PACKAGE_VERSION) +PA_MODULE_USAGE("port=") + +#define SERVICE_NAME_SINK "_polypaudio-sink._tcp" +#define SERVICE_NAME_SOURCE "_polypaudio-source._tcp" +#define SERVICE_NAME_SERVER "_polypaudio-server._tcp" + +static const char* const valid_modargs[] = { + "port", + NULL +}; + +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; + pa_namereg_type type; + uint32_t index; + } loaded; + + struct { + int valid; + pa_namereg_type type; + uint32_t index; + } autoload; +}; + +struct userdata { + pa_core *core; + pa_howl_wrapper *howl_wrapper; + pa_hashmap *services; + pa_dynarray *sink_dynarray, *source_dynarray, *autoload_dynarray; + pa_subscription *subscription; + + uint16_t port; + sw_discovery_oid server_oid; +}; + +static sw_result publish_reply(sw_discovery discovery, sw_discovery_publish_status status, sw_discovery_oid oid, sw_opaque extra) { + return SW_OKAY; +} + +static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description, pa_typeid_t *ret_typeid) { + assert(u && s && s->loaded.valid && ret_ss && ret_description && ret_typeid); + + if (s->loaded.type == PA_NAMEREG_SINK) { + pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index); + assert(sink); + *ret_ss = sink->sample_spec; + *ret_description = sink->description; + *ret_typeid = sink->typeid; + } else if (s->loaded.type == PA_NAMEREG_SOURCE) { + pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index); + assert(source); + *ret_ss = source->sample_spec; + *ret_description = source->description; + *ret_typeid = source->typeid; + } else + assert(0); +} + +static void txt_record_server_data(pa_core *c, sw_text_record t) { + 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); +} + +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; + assert(u && s); + + 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; + } + + snprintf(t, sizeof(t), "Networked Audio Device %s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); + + 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); + + txt_record_server_data(u->core, txt); + + if (s->loaded.valid) { + char z[64], *description; + pa_typeid_t typeid; + pa_sample_spec ss; + + get_service_data(u, s, &ss, &description, &typeid); + + 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)); + + 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); + + + 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, + NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), + 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, + NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), + 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; +} + +static int publish_sink(struct userdata *u, pa_sink *s) { + 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; + + pa_dynarray_put(u->sink_dynarray, s->index, svc); + + return publish_service(u, svc); +} + +static int publish_source(struct userdata *u, pa_source *s) { + 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; + + pa_dynarray_put(u->source_dynarray, s->index, svc); + + return publish_service(u, svc); +} + +static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { + 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; + + pa_dynarray_put(u->autoload_dynarray, s->index, svc); + + return publish_service(u, svc); +} + +static int remove_sink(struct userdata *u, uint32_t index) { + struct service *svc; + assert(u && index != PA_INVALID_INDEX); + + if (!(svc = pa_dynarray_get(u->sink_dynarray, index))) + return 0; + + if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SINK) + return 0; + + svc->loaded.valid = 0; + pa_dynarray_put(u->sink_dynarray, index, NULL); + + return publish_service(u, svc); +} + +static int remove_source(struct userdata *u, uint32_t index) { + struct service *svc; + assert(u && index != PA_INVALID_INDEX); + + if (!(svc = pa_dynarray_get(u->source_dynarray, index))) + return 0; + + if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SOURCE) + return 0; + + svc->loaded.valid = 0; + pa_dynarray_put(u->source_dynarray, index, NULL); + + return publish_service(u, svc); +} + +static int remove_autoload(struct userdata *u, uint32_t index) { + struct service *svc; + assert(u && index != PA_INVALID_INDEX); + + if (!(svc = pa_dynarray_get(u->autoload_dynarray, index))) + return 0; + + if (!svc->autoload.valid) + return 0; + + svc->autoload.valid = 0; + pa_dynarray_put(u->autoload_dynarray, index, NULL); + + return publish_service(u, svc); +} + +static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_t index, void *userdata) { + struct userdata *u = userdata; + assert(u && c); + + switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) + case PA_SUBSCRIPTION_EVENT_SINK: { + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { + pa_sink *sink; + + if ((sink = pa_idxset_get_by_index(c->sinks, index))) { + if (publish_sink(u, sink) < 0) + goto fail; + } + } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { + if (remove_sink(u, index) < 0) + goto fail; + } + + break; + + case PA_SUBSCRIPTION_EVENT_SOURCE: + + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { + pa_source *source; + + if ((source = pa_idxset_get_by_index(c->sources, index))) { + if (publish_source(u, source) < 0) + goto fail; + } + } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { + if (remove_source(u, index) < 0) + goto fail; + } + + break; + + case PA_SUBSCRIPTION_EVENT_AUTOLOAD: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { + pa_autoload_entry *autoload; + + if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, index))) { + if (publish_autoload(u, autoload) < 0) + goto fail; + } + } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { + if (remove_autoload(u, index) < 0) + goto fail; + } + + break; + } + + return; + +fail: + if (u->subscription) { + pa_subscription_free(u->subscription); + u->subscription = NULL; + } +} + +int pa__init(pa_core *c, pa_module*m) { + struct userdata *u; + uint32_t index, port = PA_NATIVE_DEFAULT_PORT; + pa_sink *sink; + pa_source *source; + pa_autoload_entry *autoload; + pa_modargs *ma = NULL; + 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; + } + + m->userdata = u = pa_xmalloc(sizeof(struct userdata)); + u->core = c; + u->port = (uint16_t) port; + + 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); + u->sink_dynarray = pa_dynarray_new(); + u->source_dynarray = pa_dynarray_new(); + u->autoload_dynarray = pa_dynarray_new(); + + 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; + + snprintf(t, sizeof(t), "Networked Audio Server on %s", pa_get_host_name(hn, sizeof(hn))); + + 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); + + return 0; + +fail: + pa__done(c, m); + + if (ma) + pa_modargs_free(ma); + + if (free_txt) + sw_text_record_fina(txt); + + 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); +} + +void pa__done(pa_core *c, pa_module*m) { + struct userdata*u; + assert(c && m); + + if (!(u = m->userdata)) + return; + + if (u->services) + pa_hashmap_free(u->services, service_free, u); + + 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); + + if (u->subscription) + pa_subscription_free(u->subscription); + + if (u->howl_wrapper) + pa_howl_wrapper_unref(u->howl_wrapper); + + + pa_xfree(u); +} + -- cgit From 5eda18bf608a325c136a450e58fa154eb0b270f4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 17 Feb 2006 12:10:58 +0000 Subject: Cleaned up the includes after the restructuring. Indicate which headers are public and which are internal through <> vs "". git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@500 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 45d566ae..d2858aac 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -37,11 +36,14 @@ #include #include #include -#include +#include #include -#include #include +#include "../polypcore/endianmacros.h" + +#include "howl-wrap.h" + #include "module-zeroconf-publish-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering") -- cgit From 7f68c913f1c54114a538ccca680db3a3ba4d6e26 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Feb 2006 20:11:56 +0000 Subject: revive howl support git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@566 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 65 ++++++++++++++++------------------- 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index d2858aac..d79355ce 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -67,13 +67,13 @@ struct service { struct { int valid; - pa_namereg_type type; + pa_namereg_type_t type; uint32_t index; } loaded; struct { int valid; - pa_namereg_type type; + pa_namereg_type_t type; uint32_t index; } autoload; }; @@ -93,21 +93,19 @@ static sw_result publish_reply(sw_discovery discovery, sw_discovery_publish_stat return SW_OKAY; } -static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description, pa_typeid_t *ret_typeid) { - assert(u && s && s->loaded.valid && ret_ss && ret_description && ret_typeid); +static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description) { + assert(u && s && s->loaded.valid && ret_ss && ret_description); if (s->loaded.type == PA_NAMEREG_SINK) { pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index); assert(sink); *ret_ss = sink->sample_spec; *ret_description = sink->description; - *ret_typeid = sink->typeid; } else if (s->loaded.type == PA_NAMEREG_SOURCE) { pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index); assert(source); *ret_ss = source->sample_spec; *ret_description = source->description; - *ret_typeid = source->typeid; } else assert(0); } @@ -154,10 +152,9 @@ static int publish_service(struct userdata *u, struct service *s) { if (s->loaded.valid) { char z[64], *description; - pa_typeid_t typeid; pa_sample_spec ss; - get_service_data(u, s, &ss, &description, &typeid); + get_service_data(u, s, &ss, &description); snprintf(z, sizeof(z), "%u", ss.rate); sw_text_record_add_key_and_string_value(txt, "rate", z); @@ -167,10 +164,6 @@ static int publish_service(struct userdata *u, struct service *s) { 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); - - 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, NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), @@ -210,7 +203,7 @@ finish: return r; } -struct service *get_service(struct userdata *u, const char *name) { +static struct service *get_service(struct userdata *u, const char *name) { struct service *s; if ((s = pa_hashmap_get(u->services, name))) @@ -277,55 +270,55 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { return publish_service(u, svc); } -static int remove_sink(struct userdata *u, uint32_t index) { +static int remove_sink(struct userdata *u, uint32_t idx) { struct service *svc; - assert(u && index != PA_INVALID_INDEX); + assert(u && idx != PA_INVALID_INDEX); - if (!(svc = pa_dynarray_get(u->sink_dynarray, index))) + if (!(svc = pa_dynarray_get(u->sink_dynarray, idx))) return 0; if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SINK) return 0; svc->loaded.valid = 0; - pa_dynarray_put(u->sink_dynarray, index, NULL); + pa_dynarray_put(u->sink_dynarray, idx, NULL); return publish_service(u, svc); } -static int remove_source(struct userdata *u, uint32_t index) { +static int remove_source(struct userdata *u, uint32_t idx) { struct service *svc; - assert(u && index != PA_INVALID_INDEX); + assert(u && idx != PA_INVALID_INDEX); - if (!(svc = pa_dynarray_get(u->source_dynarray, index))) + if (!(svc = pa_dynarray_get(u->source_dynarray, idx))) return 0; if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SOURCE) return 0; svc->loaded.valid = 0; - pa_dynarray_put(u->source_dynarray, index, NULL); + pa_dynarray_put(u->source_dynarray, idx, NULL); return publish_service(u, svc); } -static int remove_autoload(struct userdata *u, uint32_t index) { +static int remove_autoload(struct userdata *u, uint32_t idx) { struct service *svc; - assert(u && index != PA_INVALID_INDEX); + assert(u && idx != PA_INVALID_INDEX); - if (!(svc = pa_dynarray_get(u->autoload_dynarray, index))) + if (!(svc = pa_dynarray_get(u->autoload_dynarray, idx))) return 0; if (!svc->autoload.valid) return 0; svc->autoload.valid = 0; - pa_dynarray_put(u->autoload_dynarray, index, NULL); + pa_dynarray_put(u->autoload_dynarray, idx, NULL); return publish_service(u, svc); } -static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_t index, void *userdata) { +static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { struct userdata *u = userdata; assert(u && c); @@ -334,12 +327,12 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { pa_sink *sink; - if ((sink = pa_idxset_get_by_index(c->sinks, index))) { + if ((sink = pa_idxset_get_by_index(c->sinks, idx))) { if (publish_sink(u, sink) < 0) goto fail; } } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_sink(u, index) < 0) + if (remove_sink(u, idx) < 0) goto fail; } @@ -350,12 +343,12 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { pa_source *source; - if ((source = pa_idxset_get_by_index(c->sources, index))) { + if ((source = pa_idxset_get_by_index(c->sources, idx))) { if (publish_source(u, source) < 0) goto fail; } } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_source(u, index) < 0) + if (remove_source(u, idx) < 0) goto fail; } @@ -365,12 +358,12 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type t, uint32_ if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { pa_autoload_entry *autoload; - if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, index))) { + if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, idx))) { if (publish_autoload(u, autoload) < 0) goto fail; } } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_autoload(u, index) < 0) + if (remove_autoload(u, idx) < 0) goto fail; } @@ -388,7 +381,7 @@ fail: int pa__init(pa_core *c, pa_module*m) { struct userdata *u; - uint32_t index, port = PA_NATIVE_DEFAULT_PORT; + uint32_t idx, port = PA_NATIVE_DEFAULT_PORT; pa_sink *sink; pa_source *source; pa_autoload_entry *autoload; @@ -424,16 +417,16 @@ int pa__init(pa_core *c, pa_module*m) { 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)) + for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) if (publish_sink(u, sink) < 0) goto fail; - for (source = pa_idxset_first(c->sources, &index); source; source = pa_idxset_next(c->sources, &index)) + for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) 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)) + for (autoload = pa_idxset_first(c->autoload_idxset, &idx); autoload; autoload = pa_idxset_next(c->autoload_idxset, &idx)) if (publish_autoload(u, autoload) < 0) goto fail; -- cgit From 4a64b0d1167e980d81b798d813f35209895f0674 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Feb 2006 02:27:19 +0000 Subject: change pa_log() and friends to not require a trailing \n on all logged strings git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@574 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index d79355ce..f8607bef 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -141,7 +141,7 @@ static int publish_service(struct userdata *u, struct service *s) { snprintf(t, sizeof(t), "Networked Audio Device %s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); if (sw_text_record_init(&txt) != SW_OKAY) { - pa_log(__FILE__": sw_text_record_init() failed\n"); + pa_log(__FILE__": sw_text_record_init() failed"); goto finish; } free_txt = 1; @@ -168,7 +168,7 @@ static int publish_service(struct userdata *u, struct service *s) { s->loaded.type == PA_NAMEREG_SINK ? SERVICE_NAME_SINK : SERVICE_NAME_SOURCE, NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), publish_reply, s, &s->oid) != SW_OKAY) { - pa_log(__FILE__": failed to register sink on zeroconf.\n"); + pa_log(__FILE__": failed to register sink on zeroconf."); goto finish; } @@ -179,7 +179,7 @@ static int publish_service(struct userdata *u, struct service *s) { s->autoload.type == PA_NAMEREG_SINK ? SERVICE_NAME_SINK : SERVICE_NAME_SOURCE, NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), publish_reply, s, &s->oid) != SW_OKAY) { - pa_log(__FILE__": failed to register sink on zeroconf.\n"); + pa_log(__FILE__": failed to register sink on zeroconf."); goto finish; } @@ -391,12 +391,12 @@ int pa__init(pa_core *c, pa_module*m) { sw_text_record txt; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log(__FILE__": failed to parse module arguments.\n"); + pa_log(__FILE__": failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) { - pa_log(__FILE__": invalid port specified.\n"); + pa_log(__FILE__": invalid port specified."); goto fail; } @@ -433,7 +433,7 @@ int pa__init(pa_core *c, pa_module*m) { snprintf(t, sizeof(t), "Networked Audio Server on %s", pa_get_host_name(hn, sizeof(hn))); if (sw_text_record_init(&txt) != SW_OKAY) { - pa_log(__FILE__": sw_text_record_init() failed\n"); + pa_log(__FILE__": sw_text_record_init() failed"); goto fail; } free_txt = 1; @@ -444,7 +444,7 @@ int pa__init(pa_core *c, pa_module*m) { 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"); + pa_log(__FILE__": failed to register server on zeroconf."); goto fail; } -- cgit From d9cc2cfcb97c1b0449bcbfb6ab0301a58d77bd55 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 17 May 2006 16:34:18 +0000 Subject: Move xmalloc to the public side (libpolyp). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@908 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index f8607bef..e5dce755 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -29,7 +29,8 @@ #include #include -#include +#include + #include #include #include -- cgit From c47e937011f00eebab7230cedb58fd59f16487b4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 20:09:57 +0000 Subject: split polypcore/util.[ch] into polypcore/core-util.[ch] and polyp/util.[ch] git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@917 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index e5dce755..5c5db286 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include -- cgit From 97ec77c66060abac88305a0acd1c86312b8ae6f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 May 2006 15:56:28 +0000 Subject: add missing #include git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@946 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 5c5db286..bd4a2d97 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -30,6 +30,7 @@ #include #include +#include #include #include -- cgit From 8ca956892ef71cf93e97c8f94c4c64d979f9a128 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 31 May 2006 19:17:32 +0000 Subject: remove superfluous prefixes from service names git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@997 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index bd4a2d97..c07c95f3 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -140,7 +140,7 @@ static int publish_service(struct userdata *u, struct service *s) { s->published = 0; } - snprintf(t, sizeof(t), "Networked Audio Device %s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); + snprintf(t, sizeof(t), "%s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); if (sw_text_record_init(&txt) != SW_OKAY) { pa_log(__FILE__": sw_text_record_init() failed"); @@ -432,7 +432,7 @@ int pa__init(pa_core *c, pa_module*m) { if (publish_autoload(u, autoload) < 0) goto fail; - snprintf(t, sizeof(t), "Networked Audio Server on %s", pa_get_host_name(hn, sizeof(hn))); + snprintf(t, sizeof(t), "%s", pa_get_host_name(hn, sizeof(hn))); if (sw_text_record_init(&txt) != SW_OKAY) { pa_log(__FILE__": sw_text_record_init() failed"); -- cgit From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index c07c95f3..14cbef46 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + PulseAudio 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 + PulseAudio 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 + License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -29,20 +29,20 @@ #include #include -#include -#include +#include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "../polypcore/endianmacros.h" +#include "../pulsecore/endianmacros.h" #include "howl-wrap.h" @@ -53,9 +53,9 @@ PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher") PA_MODULE_VERSION(PACKAGE_VERSION) PA_MODULE_USAGE("port=") -#define SERVICE_NAME_SINK "_polypaudio-sink._tcp" -#define SERVICE_NAME_SOURCE "_polypaudio-source._tcp" -#define SERVICE_NAME_SERVER "_polypaudio-server._tcp" +#define SERVICE_NAME_SINK "_pulseaudio-sink._tcp" +#define SERVICE_NAME_SOURCE "_pulseaudio-source._tcp" +#define SERVICE_NAME_SERVER "_pulseaudio-server._tcp" static const char* const valid_modargs[] = { "port", -- cgit From 3cf16214334b4a1c51e56b0536abd8223d6813dd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 23:51:58 +0000 Subject: * more s/pulseaudio/PulseAudio/ replacements * name the per-user dir ~/.pulse (instead of .pulseaudio), just like /etc/pulse/ git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1039 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 14cbef46..32fb1f41 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -53,9 +53,9 @@ PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher") PA_MODULE_VERSION(PACKAGE_VERSION) PA_MODULE_USAGE("port=") -#define SERVICE_NAME_SINK "_pulseaudio-sink._tcp" -#define SERVICE_NAME_SOURCE "_pulseaudio-source._tcp" -#define SERVICE_NAME_SERVER "_pulseaudio-server._tcp" +#define SERVICE_NAME_SINK "_pulse-sink._tcp" +#define SERVICE_NAME_SOURCE "_pulse-source._tcp" +#define SERVICE_NAME_SERVER "_pulse-server._tcp" static const char* const valid_modargs[] = { "port", -- cgit From 3a816205ffde85bcf06c9ff55febc1ba69ce8de9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 13 Jul 2006 15:54:13 +0000 Subject: update module-zeroconf-publish to make use of the native AVAHI API, instead of HOWL git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1068 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 426 ++++++++++++++++++++++++---------- 1 file changed, 299 insertions(+), 127 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 32fb1f41..23a188b3 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -29,6 +29,11 @@ #include #include +#include +#include +#include +#include + #include #include @@ -41,10 +46,8 @@ #include #include #include - -#include "../pulsecore/endianmacros.h" - -#include "howl-wrap.h" +#include +#include #include "module-zeroconf-publish-symdef.h" @@ -53,9 +56,9 @@ PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher") PA_MODULE_VERSION(PACKAGE_VERSION) PA_MODULE_USAGE("port=") -#define SERVICE_NAME_SINK "_pulse-sink._tcp" -#define SERVICE_NAME_SOURCE "_pulse-source._tcp" -#define SERVICE_NAME_SERVER "_pulse-server._tcp" +#define SERVICE_TYPE_SINK "_pulse-sink._tcp" +#define SERVICE_TYPE_SOURCE "_pulse-source._tcp" +#define SERVICE_TYPE_SERVER "_pulse-server._tcp" static const char* const valid_modargs[] = { "port", @@ -63,9 +66,11 @@ static const char* const valid_modargs[] = { }; struct service { - sw_discovery_oid oid; + struct userdata *userdata; + AvahiEntryGroup *entry_group; + char *service_name; char *name; - int published; /* 0 -> not yet registered, 1 -> registered with data from real device, 2 -> registered with data from autoload device */ + enum { UNPUBLISHED, PUBLISHED_REAL, PUBLISHED_AUTOLOAD } published ; struct { int valid; @@ -82,19 +87,18 @@ struct service { struct userdata { pa_core *core; - pa_howl_wrapper *howl_wrapper; + AvahiPoll *avahi_poll; + AvahiClient *client; pa_hashmap *services; pa_dynarray *sink_dynarray, *source_dynarray, *autoload_dynarray; pa_subscription *subscription; + char *service_name; + + AvahiEntryGroup *main_entry_group; uint16_t port; - sw_discovery_oid server_oid; }; -static sw_result publish_reply(sw_discovery discovery, sw_discovery_publish_status status, sw_discovery_oid oid, sw_opaque extra) { - return SW_OKAY; -} - static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description) { assert(u && s && s->loaded.valid && ret_ss && ret_description); @@ -112,109 +116,144 @@ static void get_service_data(struct userdata *u, struct service *s, pa_sample_sp assert(0); } -static void txt_record_server_data(pa_core *c, sw_text_record t) { - char s[256]; +static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) { + char s[128]; 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); + l = avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "PACKAGE_VERSION); + l = avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, sizeof(s))); + l = avahi_string_list_add_pair(l, "fqdn", pa_get_fqdn(s, sizeof(s))); + l = avahi_string_list_add_printf(l, "cookie=0x%08x", c->cookie); + + return l; } -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; - assert(u && s); - - if ((s->published == 1 && s->loaded.valid) || - (s->published == 2 && s->autoload.valid && !s->loaded.valid)) - return 0; +static int publish_service(struct userdata *u, struct service *s); - if (s->published) { - sw_discovery_cancel(pa_howl_wrapper_get_discovery(u->howl_wrapper), s->oid); - s->published = 0; - } +static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { + struct service *s = userdata; - snprintf(t, sizeof(t), "%s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); + if (state == AVAHI_ENTRY_GROUP_COLLISION) { + char *t; - if (sw_text_record_init(&txt) != SW_OKAY) { - pa_log(__FILE__": sw_text_record_init() failed"); - goto finish; + t = avahi_alternative_service_name(s->service_name); + pa_xfree(s->service_name); + s->service_name = t; + + publish_service(s->userdata, s); } - free_txt = 1; +} + +static int publish_service(struct userdata *u, struct service *s) { + int r = -1; + AvahiStringList *txt = NULL; + + assert(u); + assert(s); - sw_text_record_add_key_and_string_value(txt, "device", s->name); + if (!u->client || avahi_client_get_state(u->client) != AVAHI_CLIENT_S_RUNNING) + return 0; + + if ((s->published == PUBLISHED_REAL && s->loaded.valid) || + (s->published == PUBLISHED_AUTOLOAD && s->autoload.valid && !s->loaded.valid)) + return 0; - txt_record_server_data(u->core, txt); + if (s->published != UNPUBLISHED) { + avahi_entry_group_reset(s->entry_group); + s->published = UNPUBLISHED; + } - if (s->loaded.valid) { - char z[64], *description; - pa_sample_spec ss; + if (s->loaded.valid || s->autoload.valid) { + pa_namereg_type_t type; - get_service_data(u, s, &ss, &description); + if (!s->entry_group) { + if (!(s->entry_group = avahi_entry_group_new(u->client, service_entry_group_callback, s))) { + pa_log("avahi_entry_group_new(): %s", avahi_strerror(avahi_client_errno(u->client))); + goto finish; + } + } + + txt = avahi_string_list_add_pair(txt, "device", s->name); + txt = txt_record_server_data(u->core, txt); + + if (s->loaded.valid) { + char *description; + pa_sample_spec ss; + + get_service_data(u, s, &ss, &description); + + txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); + txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); + txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); + txt = avahi_string_list_add_pair(txt, "description", description); - 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)); - - sw_text_record_add_key_and_string_value(txt, "description", description); - - 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, - NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), - publish_reply, s, &s->oid) != SW_OKAY) { - pa_log(__FILE__": failed to register sink on zeroconf."); + type = s->loaded.type; + } else if (s->autoload.valid) + type = s->autoload.type; + + if (avahi_entry_group_add_service_strlst( + s->entry_group, + AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + 0, + s->service_name, + type == PA_NAMEREG_SINK ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE, + NULL, + NULL, + u->port, + txt) < 0) { + + pa_log(__FILE__": avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(u->client))); 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, - NULL, NULL, u->port, sw_text_record_bytes(txt), sw_text_record_len(txt), - publish_reply, s, &s->oid) != SW_OKAY) { - pa_log(__FILE__": failed to register sink on zeroconf."); + + if (avahi_entry_group_commit(s->entry_group) < 0) { + pa_log(__FILE__": avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(u->client))); goto finish; } - - s->published = 2; + + if (s->loaded.valid) + s->published = PUBLISHED_REAL; + else if (s->autoload.valid) + s->published = PUBLISHED_AUTOLOAD; } - + r = 0; finish: - if (!s->published) { + if (s->published == UNPUBLISHED) { /* Remove this service */ + + if (s->entry_group) { + avahi_entry_group_free(s->entry_group); + } + pa_hashmap_remove(u->services, s->name); pa_xfree(s->name); + pa_xfree(s->service_name); pa_xfree(s); } - if (free_txt) - sw_text_record_fina(txt); + if (txt) + avahi_string_list_free(txt); return r; } static struct service *get_service(struct userdata *u, const char *name) { struct service *s; + char hn[64]; if ((s = pa_hashmap_get(u->services, name))) return s; - s = pa_xmalloc(sizeof(struct service)); - s->published = 0; + s = pa_xnew(struct service, 1); + s->userdata = u; + s->entry_group = NULL; + s->published = UNPUBLISHED; s->name = pa_xstrdup(name); s->loaded.valid = s->autoload.valid = 0; + s->service_name = pa_sprintf_malloc("%s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); pa_hashmap_put(u->services, s->name, s); @@ -227,7 +266,7 @@ static int publish_sink(struct userdata *u, pa_sink *s) { svc = get_service(u, s->name); if (svc->loaded.valid) - return 0; + return publish_service(u, svc); svc->loaded.valid = 1; svc->loaded.type = PA_NAMEREG_SINK; @@ -244,7 +283,7 @@ static int publish_source(struct userdata *u, pa_source *s) { svc = get_service(u, s->name); if (svc->loaded.valid) - return 0; + return publish_service(u, svc); svc->loaded.valid = 1; svc->loaded.type = PA_NAMEREG_SOURCE; @@ -261,7 +300,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { svc = get_service(u, s->name); if (svc->autoload.valid) - return 0; + return publish_service(u, svc); svc->autoload.valid = 1; svc->autoload.type = s->type; @@ -381,16 +420,164 @@ fail: } } -int pa__init(pa_core *c, pa_module*m) { - struct userdata *u; - uint32_t idx, port = PA_NATIVE_DEFAULT_PORT; +static int publish_main_service(struct userdata *u); + +static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { + struct userdata *u = userdata; + assert(u); + + if (state == AVAHI_ENTRY_GROUP_COLLISION) { + char *t; + + t = avahi_alternative_service_name(u->service_name); + pa_xfree(u->service_name); + u->service_name = t; + + publish_main_service(u); + } +} + +static int publish_main_service(struct userdata *u) { + AvahiStringList *txt = NULL; + int r = -1; + + if (!u->main_entry_group) { + if (!(u->main_entry_group = avahi_entry_group_new(u->client, main_entry_group_callback, u))) { + pa_log(__FILE__": avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + goto fail; + } + } else + avahi_entry_group_reset(u->main_entry_group); + + txt = txt_record_server_data(u->core, NULL); + + if (avahi_entry_group_add_service_strlst( + u->main_entry_group, + AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + 0, + u->service_name, + SERVICE_TYPE_SERVER, + NULL, + NULL, + u->port, + txt) < 0) { + + pa_log(__FILE__": avahi_entry_group_add_service_strlst() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + goto fail; + } + + if (avahi_entry_group_commit(u->main_entry_group) < 0) { + pa_log(__FILE__": avahi_entry_group_commit() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + goto fail; + } + + r = 0; + +fail: + avahi_string_list_free(txt); + + return r; +} + +static int publish_all_services(struct userdata *u) { pa_sink *sink; pa_source *source; pa_autoload_entry *autoload; + int r = -1; + uint32_t idx; + + assert(u); + + pa_log_debug(__FILE__": Publishing services in Zeroconf"); + + for (sink = pa_idxset_first(u->core->sinks, &idx); sink; sink = pa_idxset_next(u->core->sinks, &idx)) + if (publish_sink(u, sink) < 0) + goto fail; + + for (source = pa_idxset_first(u->core->sources, &idx); source; source = pa_idxset_next(u->core->sources, &idx)) + if (publish_source(u, source) < 0) + goto fail; + + if (u->core->autoload_idxset) + for (autoload = pa_idxset_first(u->core->autoload_idxset, &idx); autoload; autoload = pa_idxset_next(u->core->autoload_idxset, &idx)) + if (publish_autoload(u, autoload) < 0) + goto fail; + + if (publish_main_service(u) < 0) + goto fail; + + r = 0; + +fail: + return r; +} + +static void unpublish_all_services(struct userdata *u, int rem) { + void *state = NULL; + struct service *s; + + assert(u); + + pa_log_debug(__FILE__": Unpublishing services in Zeroconf"); + + while ((s = pa_hashmap_iterate(u->services, &state, NULL))) { + if (s->entry_group) { + if (rem) { + avahi_entry_group_free(s->entry_group); + s->entry_group = NULL; + } else + avahi_entry_group_reset(s->entry_group); + } + + s->published = UNPUBLISHED; + } + + if (u->main_entry_group) { + if (rem) { + avahi_entry_group_free(u->main_entry_group); + u->main_entry_group = NULL; + } else + avahi_entry_group_reset(u->main_entry_group); + } +} + +static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) { + struct userdata *u = userdata; + assert(c); + + u->client = c; + + switch (state) { + case AVAHI_CLIENT_S_RUNNING: + publish_all_services(u); + break; + + case AVAHI_CLIENT_S_COLLISION: + unpublish_all_services(u, 0); + break; + + case AVAHI_CLIENT_FAILURE: + if (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { + int error; + unpublish_all_services(u, 1); + avahi_client_free(u->client); + + if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) + pa_log(__FILE__": pa_avahi_client_new() failed: %s", avahi_strerror(error)); + } + + break; + + default: ; + } +} + +int pa__init(pa_core *c, pa_module*m) { + struct userdata *u; + uint32_t port = PA_NATIVE_DEFAULT_PORT; pa_modargs *ma = NULL; - char t[256], hn[256]; - int free_txt = 0; - sw_text_record txt; + char hn[256]; + int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log(__FILE__": failed to parse module arguments."); @@ -402,55 +589,31 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - m->userdata = u = pa_xmalloc(sizeof(struct userdata)); + m->userdata = u = pa_xnew(struct userdata, 1); u->core = c; u->port = (uint16_t) port; - if (!(u->howl_wrapper = pa_howl_wrapper_get(c))) - goto fail; - + u->avahi_poll = pa_avahi_poll_new(c->mainloop); + u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->sink_dynarray = pa_dynarray_new(); u->source_dynarray = pa_dynarray_new(); u->autoload_dynarray = pa_dynarray_new(); - + 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, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) - if (publish_sink(u, sink) < 0) - goto fail; + u->main_entry_group = NULL; - for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) - if (publish_source(u, source) < 0) - goto fail; + u->service_name = pa_xstrdup(pa_get_host_name(hn, sizeof(hn))); - if (c->autoload_idxset) - for (autoload = pa_idxset_first(c->autoload_idxset, &idx); autoload; autoload = pa_idxset_next(c->autoload_idxset, &idx)) - if (publish_autoload(u, autoload) < 0) - goto fail; - - snprintf(t, sizeof(t), "%s", pa_get_host_name(hn, sizeof(hn))); - - if (sw_text_record_init(&txt) != SW_OKAY) { - pa_log(__FILE__": sw_text_record_init() failed"); + if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { + pa_log(__FILE__": pa_avahi_client_new() failed: %s", avahi_strerror(error)); 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."); - goto fail; - } - - sw_text_record_fina(txt); pa_modargs_free(ma); return 0; @@ -460,9 +623,6 @@ fail: if (ma) pa_modargs_free(ma); - - if (free_txt) - sw_text_record_fina(txt); return -1; } @@ -470,8 +630,14 @@ fail: 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); + + assert(s); + assert(u); + + if (s->entry_group) + avahi_entry_group_free(s->entry_group); + + pa_xfree(s->service_name); pa_xfree(s->name); pa_xfree(s); } @@ -495,11 +661,17 @@ void pa__done(pa_core *c, pa_module*m) { if (u->subscription) pa_subscription_free(u->subscription); - - if (u->howl_wrapper) - pa_howl_wrapper_unref(u->howl_wrapper); + if (u->main_entry_group) + avahi_entry_group_free(u->main_entry_group); + if (u->client) + avahi_client_free(u->client); + + if (u->avahi_poll) + pa_avahi_poll_free(u->avahi_poll); + + pa_xfree(u->service_name); pa_xfree(u); } -- cgit From bfa6604b1ddc5e2c0f1aaa15330363724856359b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Aug 2006 23:58:55 +0000 Subject: don't set the sink/source descriptions manually, use the new functions pa_{sink,source}_set_description() instead git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1205 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 23a188b3..16315d35 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -185,7 +185,8 @@ static int publish_service(struct userdata *u, struct service *s) { txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); - txt = avahi_string_list_add_pair(txt, "description", description); + if (description) + txt = avahi_string_list_add_pair(txt, "description", description); type = s->loaded.type; } else if (s->autoload.valid) -- cgit From 3334814ebb3c955b696c413ac5246ddb09efefe2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 20:44:32 +0000 Subject: fix a segfault when registering a service with avahi fails git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1253 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 16315d35..24e324f8 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -225,9 +225,8 @@ finish: if (s->published == UNPUBLISHED) { /* Remove this service */ - if (s->entry_group) { + if (s->entry_group) avahi_entry_group_free(s->entry_group); - } pa_hashmap_remove(u->services, s->name); pa_xfree(s->name); @@ -263,6 +262,7 @@ static struct service *get_service(struct userdata *u, const char *name) { static int publish_sink(struct userdata *u, pa_sink *s) { struct service *svc; + int ret; assert(u && s); svc = get_service(u, s->name); @@ -273,13 +273,17 @@ static int publish_sink(struct userdata *u, pa_sink *s) { svc->loaded.type = PA_NAMEREG_SINK; svc->loaded.index = s->index; - pa_dynarray_put(u->sink_dynarray, s->index, svc); + if ((ret = publish_service(u, svc)) < 0) + return ret; - return publish_service(u, svc); + pa_dynarray_put(u->sink_dynarray, s->index, svc); + return ret; } static int publish_source(struct userdata *u, pa_source *s) { struct service *svc; + int ret; + assert(u && s); svc = get_service(u, s->name); @@ -292,11 +296,17 @@ static int publish_source(struct userdata *u, pa_source *s) { pa_dynarray_put(u->source_dynarray, s->index, svc); - return publish_service(u, svc); + if ((ret = publish_service(u, svc)) < 0) + return ret; + + pa_dynarray_put(u->sink_dynarray, s->index, svc); + return ret; } static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { struct service *svc; + int ret; + assert(u && s); svc = get_service(u, s->name); @@ -307,9 +317,11 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { svc->autoload.type = s->type; svc->autoload.index = s->index; - pa_dynarray_put(u->autoload_dynarray, s->index, svc); + if ((ret = publish_service(u, svc)) < 0) + return ret; - return publish_service(u, svc); + pa_dynarray_put(u->autoload_dynarray, s->index, svc); + return ret; } static int remove_sink(struct userdata *u, uint32_t idx) { @@ -653,6 +665,9 @@ void pa__done(pa_core *c, pa_module*m) { if (u->services) pa_hashmap_free(u->services, service_free, u); + if (u->subscription) + pa_subscription_free(u->subscription); + if (u->sink_dynarray) pa_dynarray_free(u->sink_dynarray, NULL, NULL); if (u->source_dynarray) @@ -660,8 +675,6 @@ void pa__done(pa_core *c, pa_module*m) { if (u->autoload_dynarray) pa_dynarray_free(u->autoload_dynarray, NULL, NULL); - if (u->subscription) - pa_subscription_free(u->subscription); if (u->main_entry_group) avahi_entry_group_free(u->main_entry_group); -- cgit From 1c3bfc44dcbd760687ea841d893c35db510804af Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 15 Aug 2006 18:15:00 +0000 Subject: use the description field of sinks/sources to name the zeroconf services, instead of the logical name git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1257 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 24e324f8..651a95b7 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -240,7 +240,7 @@ finish: return r; } -static struct service *get_service(struct userdata *u, const char *name) { +static struct service *get_service(struct userdata *u, const char *name, const char *description) { struct service *s; char hn[64]; @@ -253,7 +253,7 @@ static struct service *get_service(struct userdata *u, const char *name) { s->published = UNPUBLISHED; s->name = pa_xstrdup(name); s->loaded.valid = s->autoload.valid = 0; - s->service_name = pa_sprintf_malloc("%s on %s", s->name, pa_get_host_name(hn, sizeof(hn))); + s->service_name = pa_sprintf_malloc("%s on %s", description ? description : s->name, pa_get_host_name(hn, sizeof(hn))); pa_hashmap_put(u->services, s->name, s); @@ -265,7 +265,7 @@ static int publish_sink(struct userdata *u, pa_sink *s) { int ret; assert(u && s); - svc = get_service(u, s->name); + svc = get_service(u, s->name, s->description); if (svc->loaded.valid) return publish_service(u, svc); @@ -286,7 +286,7 @@ static int publish_source(struct userdata *u, pa_source *s) { assert(u && s); - svc = get_service(u, s->name); + svc = get_service(u, s->name, s->description); if (svc->loaded.valid) return publish_service(u, svc); @@ -309,7 +309,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { assert(u && s); - svc = get_service(u, s->name); + svc = get_service(u, s->name, NULL); if (svc->autoload.valid) return publish_service(u, svc); -- cgit From e385d93e5aad6a6fce754c00c804ff1d6a6746d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 21:38:40 +0000 Subject: remove all occurences of pa_logXXX(__FILE__": and replace them by pa_logXXX(" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1272 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 651a95b7..696d8afe 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -203,12 +203,12 @@ static int publish_service(struct userdata *u, struct service *s) { u->port, txt) < 0) { - pa_log(__FILE__": avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(u->client))); + pa_log("avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(u->client))); goto finish; } if (avahi_entry_group_commit(s->entry_group) < 0) { - pa_log(__FILE__": avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(u->client))); + pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(u->client))); goto finish; } @@ -456,7 +456,7 @@ static int publish_main_service(struct userdata *u) { if (!u->main_entry_group) { if (!(u->main_entry_group = avahi_entry_group_new(u->client, main_entry_group_callback, u))) { - pa_log(__FILE__": avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + pa_log("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client))); goto fail; } } else @@ -475,12 +475,12 @@ static int publish_main_service(struct userdata *u) { u->port, txt) < 0) { - pa_log(__FILE__": avahi_entry_group_add_service_strlst() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + pa_log("avahi_entry_group_add_service_strlst() failed: %s", avahi_strerror(avahi_client_errno(u->client))); goto fail; } if (avahi_entry_group_commit(u->main_entry_group) < 0) { - pa_log(__FILE__": avahi_entry_group_commit() failed: %s", avahi_strerror(avahi_client_errno(u->client))); + pa_log("avahi_entry_group_commit() failed: %s", avahi_strerror(avahi_client_errno(u->client))); goto fail; } @@ -501,7 +501,7 @@ static int publish_all_services(struct userdata *u) { assert(u); - pa_log_debug(__FILE__": Publishing services in Zeroconf"); + pa_log_debug("Publishing services in Zeroconf"); for (sink = pa_idxset_first(u->core->sinks, &idx); sink; sink = pa_idxset_next(u->core->sinks, &idx)) if (publish_sink(u, sink) < 0) @@ -531,7 +531,7 @@ static void unpublish_all_services(struct userdata *u, int rem) { assert(u); - pa_log_debug(__FILE__": Unpublishing services in Zeroconf"); + pa_log_debug("Unpublishing services in Zeroconf"); while ((s = pa_hashmap_iterate(u->services, &state, NULL))) { if (s->entry_group) { @@ -576,7 +576,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda avahi_client_free(u->client); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) - pa_log(__FILE__": pa_avahi_client_new() failed: %s", avahi_strerror(error)); + pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); } break; @@ -593,12 +593,12 @@ int pa__init(pa_core *c, pa_module*m) { int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log(__FILE__": failed to parse module arguments."); + pa_log("failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) { - pa_log(__FILE__": invalid port specified."); + pa_log("invalid port specified."); goto fail; } @@ -623,7 +623,7 @@ int pa__init(pa_core *c, pa_module*m) { u->service_name = pa_xstrdup(pa_get_host_name(hn, sizeof(hn))); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { - pa_log(__FILE__": pa_avahi_client_new() failed: %s", avahi_strerror(error)); + pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 108 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 696d8afe..10643808 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -2,17 +2,17 @@ /*** This file is part of PulseAudio. - + PulseAudio 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. - + PulseAudio 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 PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -153,7 +153,7 @@ static int publish_service(struct userdata *u, struct service *s) { if (!u->client || avahi_client_get_state(u->client) != AVAHI_CLIENT_S_RUNNING) return 0; - + if ((s->published == PUBLISHED_REAL && s->loaded.valid) || (s->published == PUBLISHED_AUTOLOAD && s->autoload.valid && !s->loaded.valid)) return 0; @@ -161,8 +161,8 @@ static int publish_service(struct userdata *u, struct service *s) { if (s->published != UNPUBLISHED) { avahi_entry_group_reset(s->entry_group); s->published = UNPUBLISHED; - } - + } + if (s->loaded.valid || s->autoload.valid) { pa_namereg_type_t type; @@ -172,26 +172,26 @@ static int publish_service(struct userdata *u, struct service *s) { goto finish; } } - + txt = avahi_string_list_add_pair(txt, "device", s->name); txt = txt_record_server_data(u->core, txt); - + if (s->loaded.valid) { char *description; pa_sample_spec ss; - + get_service_data(u, s, &ss, &description); - + txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); if (description) txt = avahi_string_list_add_pair(txt, "description", description); - + type = s->loaded.type; } else if (s->autoload.valid) type = s->autoload.type; - + if (avahi_entry_group_add_service_strlst( s->entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, @@ -202,24 +202,24 @@ static int publish_service(struct userdata *u, struct service *s) { NULL, u->port, txt) < 0) { - + pa_log("avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(u->client))); goto finish; } - + if (avahi_entry_group_commit(s->entry_group) < 0) { pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(u->client))); goto finish; } - + if (s->loaded.valid) s->published = PUBLISHED_REAL; else if (s->autoload.valid) s->published = PUBLISHED_AUTOLOAD; } - + r = 0; - + finish: if (s->published == UNPUBLISHED) { @@ -227,7 +227,7 @@ finish: if (s->entry_group) avahi_entry_group_free(s->entry_group); - + pa_hashmap_remove(u->services, s->name); pa_xfree(s->name); pa_xfree(s->service_name); @@ -236,17 +236,17 @@ finish: if (txt) avahi_string_list_free(txt); - + return r; } static struct service *get_service(struct userdata *u, const char *name, const char *description) { struct service *s; char hn[64]; - + if ((s = pa_hashmap_get(u->services, name))) return s; - + s = pa_xnew(struct service, 1); s->userdata = u; s->entry_group = NULL; @@ -283,7 +283,7 @@ static int publish_sink(struct userdata *u, pa_sink *s) { static int publish_source(struct userdata *u, pa_source *s) { struct service *svc; int ret; - + assert(u && s); svc = get_service(u, s->name, s->description); @@ -295,7 +295,7 @@ static int publish_source(struct userdata *u, pa_source *s) { svc->loaded.index = s->index; pa_dynarray_put(u->source_dynarray, s->index, svc); - + if ((ret = publish_service(u, svc)) < 0) return ret; @@ -306,7 +306,7 @@ static int publish_source(struct userdata *u, pa_source *s) { static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { struct service *svc; int ret; - + assert(u && s); svc = get_service(u, s->name, NULL); @@ -319,7 +319,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { if ((ret = publish_service(u, svc)) < 0) return ret; - + pa_dynarray_put(u->autoload_dynarray, s->index, svc); return ret; } @@ -336,14 +336,14 @@ static int remove_sink(struct userdata *u, uint32_t idx) { svc->loaded.valid = 0; pa_dynarray_put(u->sink_dynarray, idx, NULL); - + return publish_service(u, svc); } static int remove_source(struct userdata *u, uint32_t idx) { struct service *svc; assert(u && idx != PA_INVALID_INDEX); - + if (!(svc = pa_dynarray_get(u->source_dynarray, idx))) return 0; @@ -359,7 +359,7 @@ static int remove_source(struct userdata *u, uint32_t idx) { static int remove_autoload(struct userdata *u, uint32_t idx) { struct service *svc; assert(u && idx != PA_INVALID_INDEX); - + if (!(svc = pa_dynarray_get(u->autoload_dynarray, idx))) return 0; @@ -389,14 +389,14 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 if (remove_sink(u, idx) < 0) goto fail; } - + break; case PA_SUBSCRIPTION_EVENT_SOURCE: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { pa_source *source; - + if ((source = pa_idxset_get_by_index(c->sources, idx))) { if (publish_source(u, source) < 0) goto fail; @@ -405,13 +405,13 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 if (remove_source(u, idx) < 0) goto fail; } - + break; case PA_SUBSCRIPTION_EVENT_AUTOLOAD: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { pa_autoload_entry *autoload; - + if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, idx))) { if (publish_autoload(u, autoload) < 0) goto fail; @@ -420,7 +420,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 if (remove_autoload(u, idx) < 0) goto fail; } - + break; } @@ -453,7 +453,7 @@ static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState s static int publish_main_service(struct userdata *u) { AvahiStringList *txt = NULL; int r = -1; - + if (!u->main_entry_group) { if (!(u->main_entry_group = avahi_entry_group_new(u->client, main_entry_group_callback, u))) { pa_log("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client))); @@ -461,7 +461,7 @@ static int publish_main_service(struct userdata *u) { } } else avahi_entry_group_reset(u->main_entry_group); - + txt = txt_record_server_data(u->core, NULL); if (avahi_entry_group_add_service_strlst( @@ -474,18 +474,18 @@ static int publish_main_service(struct userdata *u) { NULL, u->port, txt) < 0) { - + pa_log("avahi_entry_group_add_service_strlst() failed: %s", avahi_strerror(avahi_client_errno(u->client))); goto fail; } - + if (avahi_entry_group_commit(u->main_entry_group) < 0) { pa_log("avahi_entry_group_commit() failed: %s", avahi_strerror(avahi_client_errno(u->client))); goto fail; } r = 0; - + fail: avahi_string_list_free(txt); @@ -498,7 +498,7 @@ static int publish_all_services(struct userdata *u) { pa_autoload_entry *autoload; int r = -1; uint32_t idx; - + assert(u); pa_log_debug("Publishing services in Zeroconf"); @@ -518,9 +518,9 @@ static int publish_all_services(struct userdata *u) { if (publish_main_service(u) < 0) goto fail; - + r = 0; - + fail: return r; } @@ -528,7 +528,7 @@ fail: static void unpublish_all_services(struct userdata *u, int rem) { void *state = NULL; struct service *s; - + assert(u); pa_log_debug("Unpublishing services in Zeroconf"); @@ -538,7 +538,7 @@ static void unpublish_all_services(struct userdata *u, int rem) { if (rem) { avahi_entry_group_free(s->entry_group); s->entry_group = NULL; - } else + } else avahi_entry_group_reset(s->entry_group); } @@ -559,12 +559,12 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda assert(c); u->client = c; - + switch (state) { case AVAHI_CLIENT_S_RUNNING: publish_all_services(u); break; - + case AVAHI_CLIENT_S_COLLISION: unpublish_all_services(u, 0); break; @@ -578,7 +578,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); } - + break; default: ; @@ -607,7 +607,7 @@ int pa__init(pa_core *c, pa_module*m) { u->port = (uint16_t) port; u->avahi_poll = pa_avahi_poll_new(c->mainloop); - + u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->sink_dynarray = pa_dynarray_new(); u->source_dynarray = pa_dynarray_new(); @@ -628,15 +628,15 @@ int pa__init(pa_core *c, pa_module*m) { } pa_modargs_free(ma); - + return 0; - + fail: pa__done(c, m); if (ma) pa_modargs_free(ma); - + return -1; } @@ -649,7 +649,7 @@ static void service_free(void *p, void *userdata) { if (s->entry_group) avahi_entry_group_free(s->entry_group); - + pa_xfree(s->service_name); pa_xfree(s->name); pa_xfree(s); @@ -674,14 +674,14 @@ void pa__done(pa_core *c, pa_module*m) { pa_dynarray_free(u->source_dynarray, NULL, NULL); if (u->autoload_dynarray) pa_dynarray_free(u->autoload_dynarray, NULL, NULL); - + if (u->main_entry_group) avahi_entry_group_free(u->main_entry_group); - + if (u->client) avahi_client_free(u->client); - + if (u->avahi_poll) pa_avahi_poll_free(u->avahi_poll); -- cgit From 06211b7c8fd329137ae9003818543912a87d9898 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 13 Feb 2007 15:35:19 +0000 Subject: Add copyright notices to all relevant files. (based on svn log) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1426 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 10643808..69508ad0 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -3,6 +3,8 @@ /*** This file is part of PulseAudio. + Copyright 2004-2006 Lennart Poettering + PulseAudio 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 -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 569 ++++++++++++++-------------------- 1 file changed, 226 insertions(+), 343 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 69508ad0..113686cf 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -26,7 +26,6 @@ #endif #include -#include #include #include #include @@ -35,11 +34,11 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -71,56 +70,52 @@ struct service { struct userdata *userdata; AvahiEntryGroup *entry_group; char *service_name; - char *name; - enum { UNPUBLISHED, PUBLISHED_REAL, PUBLISHED_AUTOLOAD } published ; - - struct { - int valid; - pa_namereg_type_t type; - uint32_t index; - } loaded; - - struct { - int valid; - pa_namereg_type_t type; - uint32_t index; - } autoload; + pa_object *device; }; struct userdata { pa_core *core; AvahiPoll *avahi_poll; AvahiClient *client; + pa_hashmap *services; - pa_dynarray *sink_dynarray, *source_dynarray, *autoload_dynarray; - pa_subscription *subscription; char *service_name; AvahiEntryGroup *main_entry_group; uint16_t port; + + pa_hook_slot *sink_new_slot, *source_new_slot, *sink_unlink_slot, *source_unlink_slot, *sink_changed_slot, *source_changed_slot; }; -static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description) { - assert(u && s && s->loaded.valid && ret_ss && ret_description); +static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_channel_map *ret_map, const char **ret_name, const char **ret_description) { + pa_assert(s); + pa_assert(ret_ss); + pa_assert(ret_description); + + if (pa_sink_isinstance(s->device)) { + pa_sink *sink = PA_SINK(s->device); - if (s->loaded.type == PA_NAMEREG_SINK) { - pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index); - assert(sink); *ret_ss = sink->sample_spec; + *ret_map = sink->channel_map; + *ret_name = sink->name; *ret_description = sink->description; - } else if (s->loaded.type == PA_NAMEREG_SOURCE) { - pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index); - assert(source); + + } else if (pa_source_isinstance(s->device)) { + pa_source *source = PA_SOURCE(s->device); + *ret_ss = source->sample_spec; + *ret_map = source->channel_map; + *ret_name = source->name; *ret_description = source->description; } else - assert(0); + pa_assert_not_reached(); } static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) { char s[128]; - assert(c); + + pa_assert(c); l = avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "PACKAGE_VERSION); l = avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, sizeof(s))); @@ -130,325 +125,217 @@ static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) { return l; } -static int publish_service(struct userdata *u, struct service *s); +static int publish_service(struct service *s); static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { struct service *s = userdata; - if (state == AVAHI_ENTRY_GROUP_COLLISION) { - char *t; + pa_assert(s); + + switch (state) { + + case AVAHI_ENTRY_GROUP_ESTABLISHED: + pa_log_info("Successfully established service %s.", s->service_name); + break; + + case AVAHI_ENTRY_GROUP_COLLISION: { + char *t; + + t = avahi_alternative_service_name(s->service_name); + pa_log_info("Name collision, renaming %s to %s.", s->service_name, t); + pa_xfree(s->service_name); + s->service_name = t; + + publish_service(s); + break; + } + + case AVAHI_ENTRY_GROUP_FAILURE: { + pa_log("Failed to register service: %s", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g)))); - t = avahi_alternative_service_name(s->service_name); - pa_xfree(s->service_name); - s->service_name = t; + avahi_entry_group_free(g); + s->entry_group = NULL; - publish_service(s->userdata, s); + break; + } + + case AVAHI_ENTRY_GROUP_UNCOMMITED: + case AVAHI_ENTRY_GROUP_REGISTERING: + ; } } -static int publish_service(struct userdata *u, struct service *s) { +static void service_free(struct service *s); + +static int publish_service(struct service *s) { int r = -1; AvahiStringList *txt = NULL; + const char *description = NULL, *name = NULL; + pa_sample_spec ss; + pa_channel_map map; + char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; - assert(u); - assert(s); + pa_assert(s); - if (!u->client || avahi_client_get_state(u->client) != AVAHI_CLIENT_S_RUNNING) + if (!s->userdata->client || avahi_client_get_state(s->userdata->client) != AVAHI_CLIENT_S_RUNNING) return 0; - if ((s->published == PUBLISHED_REAL && s->loaded.valid) || - (s->published == PUBLISHED_AUTOLOAD && s->autoload.valid && !s->loaded.valid)) - return 0; - - if (s->published != UNPUBLISHED) { + if (!s->entry_group) { + if (!(s->entry_group = avahi_entry_group_new(s->userdata->client, service_entry_group_callback, s))) { + pa_log("avahi_entry_group_new(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); + goto finish; + } + } else avahi_entry_group_reset(s->entry_group); - s->published = UNPUBLISHED; - } - if (s->loaded.valid || s->autoload.valid) { - pa_namereg_type_t type; + txt = txt_record_server_data(s->userdata->core, txt); - if (!s->entry_group) { - if (!(s->entry_group = avahi_entry_group_new(u->client, service_entry_group_callback, s))) { - pa_log("avahi_entry_group_new(): %s", avahi_strerror(avahi_client_errno(u->client))); - goto finish; - } - } + get_service_data(s, &ss, &map, &name, &description); + txt = avahi_string_list_add_pair(txt, "device", name); + txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); + txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); + txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); + txt = avahi_string_list_add_pair(txt, "channel_map", pa_channel_map_snprint(cm, sizeof(cm), &map)); - txt = avahi_string_list_add_pair(txt, "device", s->name); - txt = txt_record_server_data(u->core, txt); - - if (s->loaded.valid) { - char *description; - pa_sample_spec ss; - - get_service_data(u, s, &ss, &description); - - txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); - txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); - txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); - if (description) - txt = avahi_string_list_add_pair(txt, "description", description); - - type = s->loaded.type; - } else if (s->autoload.valid) - type = s->autoload.type; - - if (avahi_entry_group_add_service_strlst( - s->entry_group, - AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, - 0, - s->service_name, - type == PA_NAMEREG_SINK ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE, - NULL, - NULL, - u->port, - txt) < 0) { - - pa_log("avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(u->client))); - goto finish; - } + if (avahi_entry_group_add_service_strlst( + s->entry_group, + AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + 0, + s->service_name, + pa_sink_isinstance(s->device) ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE, + NULL, + NULL, + s->userdata->port, + txt) < 0) { - if (avahi_entry_group_commit(s->entry_group) < 0) { - pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(u->client))); - goto finish; - } + pa_log("avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); + goto finish; + } - if (s->loaded.valid) - s->published = PUBLISHED_REAL; - else if (s->autoload.valid) - s->published = PUBLISHED_AUTOLOAD; + if (avahi_entry_group_commit(s->entry_group) < 0) { + pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); + goto finish; } r = 0; + pa_log_debug("Successfully created entry group for %s.", s->service_name); finish: - if (s->published == UNPUBLISHED) { - /* Remove this service */ - - if (s->entry_group) - avahi_entry_group_free(s->entry_group); + /* Remove this service */ + if (r < 0) + service_free(s); - pa_hashmap_remove(u->services, s->name); - pa_xfree(s->name); - pa_xfree(s->service_name); - pa_xfree(s); - } - - if (txt) - avahi_string_list_free(txt); + avahi_string_list_free(txt); return r; } -static struct service *get_service(struct userdata *u, const char *name, const char *description) { +static struct service *get_service(struct userdata *u, pa_object *device) { struct service *s; - char hn[64]; + char hn[64], un[64]; + const char *n; + + pa_assert(u); + pa_object_assert_ref(device); - if ((s = pa_hashmap_get(u->services, name))) + if ((s = pa_hashmap_get(u->services, device))) return s; s = pa_xnew(struct service, 1); s->userdata = u; s->entry_group = NULL; - s->published = UNPUBLISHED; - s->name = pa_xstrdup(name); - s->loaded.valid = s->autoload.valid = 0; - s->service_name = pa_sprintf_malloc("%s on %s", description ? description : s->name, pa_get_host_name(hn, sizeof(hn))); - - pa_hashmap_put(u->services, s->name, s); - - return s; -} - -static int publish_sink(struct userdata *u, pa_sink *s) { - struct service *svc; - int ret; - assert(u && s); - - svc = get_service(u, s->name, s->description); - if (svc->loaded.valid) - return publish_service(u, svc); - - svc->loaded.valid = 1; - svc->loaded.type = PA_NAMEREG_SINK; - svc->loaded.index = s->index; - - if ((ret = publish_service(u, svc)) < 0) - return ret; - - pa_dynarray_put(u->sink_dynarray, s->index, svc); - return ret; -} - -static int publish_source(struct userdata *u, pa_source *s) { - struct service *svc; - int ret; - - assert(u && s); - - svc = get_service(u, s->name, s->description); - if (svc->loaded.valid) - return publish_service(u, svc); - - svc->loaded.valid = 1; - svc->loaded.type = PA_NAMEREG_SOURCE; - svc->loaded.index = s->index; + s->device = device; + + if (pa_sink_isinstance(device)) { + if (!(n = PA_SINK(device)->description)) + n = PA_SINK(device)->name; + } else { + if (!(n = PA_SOURCE(device)->description)) + n = PA_SOURCE(device)->name; + } - pa_dynarray_put(u->source_dynarray, s->index, svc); + s->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s: %s", + pa_get_user_name(un, sizeof(un)), + pa_get_host_name(hn, sizeof(hn)), + n), + AVAHI_LABEL_MAX-1); - if ((ret = publish_service(u, svc)) < 0) - return ret; + pa_hashmap_put(u->services, s->device, s); - pa_dynarray_put(u->sink_dynarray, s->index, svc); - return ret; + return s; } -static int publish_autoload(struct userdata *u, pa_autoload_entry *s) { - struct service *svc; - int ret; +static void service_free(struct service *s) { + pa_assert(s); - assert(u && s); + pa_hashmap_remove(s->userdata->services, s->device); - svc = get_service(u, s->name, NULL); - if (svc->autoload.valid) - return publish_service(u, svc); - - svc->autoload.valid = 1; - svc->autoload.type = s->type; - svc->autoload.index = s->index; - - if ((ret = publish_service(u, svc)) < 0) - return ret; + if (s->entry_group) { + pa_log_debug("Removing entry group for %s.", s->service_name); + avahi_entry_group_free(s->entry_group); + } - pa_dynarray_put(u->autoload_dynarray, s->index, svc); - return ret; + pa_xfree(s->service_name); + pa_xfree(s); } -static int remove_sink(struct userdata *u, uint32_t idx) { - struct service *svc; - assert(u && idx != PA_INVALID_INDEX); - - if (!(svc = pa_dynarray_get(u->sink_dynarray, idx))) - return 0; - - if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SINK) - return 0; +static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struct userdata *u) { + pa_assert(c); + pa_object_assert_ref(o); - svc->loaded.valid = 0; - pa_dynarray_put(u->sink_dynarray, idx, NULL); + publish_service(get_service(u, o)); - return publish_service(u, svc); + return PA_HOOK_OK; } -static int remove_source(struct userdata *u, uint32_t idx) { - struct service *svc; - assert(u && idx != PA_INVALID_INDEX); - - if (!(svc = pa_dynarray_get(u->source_dynarray, idx))) - return 0; +static pa_hook_result_t device_unlink_cb(pa_core *c, pa_object *o, struct userdata *u) { + struct service *s; - if (!svc->loaded.valid || svc->loaded.type != PA_NAMEREG_SOURCE) - return 0; + pa_assert(c); + pa_object_assert_ref(o); - svc->loaded.valid = 0; - pa_dynarray_put(u->source_dynarray, idx, NULL); + if ((s = pa_hashmap_get(u->services, o))) + service_free(s); - return publish_service(u, svc); + return PA_HOOK_OK; } -static int remove_autoload(struct userdata *u, uint32_t idx) { - struct service *svc; - assert(u && idx != PA_INVALID_INDEX); - - if (!(svc = pa_dynarray_get(u->autoload_dynarray, idx))) - return 0; - - if (!svc->autoload.valid) - return 0; - - svc->autoload.valid = 0; - pa_dynarray_put(u->autoload_dynarray, idx, NULL); - - return publish_service(u, svc); -} +static int publish_main_service(struct userdata *u); -static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { +static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { struct userdata *u = userdata; - assert(u && c); - - switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) - case PA_SUBSCRIPTION_EVENT_SINK: { - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { - pa_sink *sink; - - if ((sink = pa_idxset_get_by_index(c->sinks, idx))) { - if (publish_sink(u, sink) < 0) - goto fail; - } - } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_sink(u, idx) < 0) - goto fail; - } + pa_assert(u); - break; + switch (state) { - case PA_SUBSCRIPTION_EVENT_SOURCE: + case AVAHI_ENTRY_GROUP_ESTABLISHED: + pa_log_info("Successfully established main service."); + break; - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { - pa_source *source; + case AVAHI_ENTRY_GROUP_COLLISION: { + char *t; - if ((source = pa_idxset_get_by_index(c->sources, idx))) { - if (publish_source(u, source) < 0) - goto fail; - } - } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_source(u, idx) < 0) - goto fail; - } + t = avahi_alternative_service_name(u->service_name); + pa_log_info("Name collision: renaming main service %s to %s.", u->service_name, t); + pa_xfree(u->service_name); + u->service_name = t; + publish_main_service(u); break; + } - case PA_SUBSCRIPTION_EVENT_AUTOLOAD: - if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW) { - pa_autoload_entry *autoload; - - if ((autoload = pa_idxset_get_by_index(c->autoload_idxset, idx))) { - if (publish_autoload(u, autoload) < 0) - goto fail; - } - } else if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - if (remove_autoload(u, idx) < 0) - goto fail; - } + case AVAHI_ENTRY_GROUP_FAILURE: { + pa_log("Failed to register main service: %s", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g)))); + avahi_entry_group_free(g); + u->main_entry_group = NULL; break; - } - - return; - -fail: - if (u->subscription) { - pa_subscription_free(u->subscription); - u->subscription = NULL; - } -} - -static int publish_main_service(struct userdata *u); - -static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) { - struct userdata *u = userdata; - assert(u); - - if (state == AVAHI_ENTRY_GROUP_COLLISION) { - char *t; - - t = avahi_alternative_service_name(u->service_name); - pa_xfree(u->service_name); - u->service_name = t; + } - publish_main_service(u); + case AVAHI_ENTRY_GROUP_UNCOMMITED: + case AVAHI_ENTRY_GROUP_REGISTERING: + break; } } @@ -456,6 +343,8 @@ static int publish_main_service(struct userdata *u) { AvahiStringList *txt = NULL; int r = -1; + pa_assert(u); + if (!u->main_entry_group) { if (!(u->main_entry_group = avahi_entry_group_new(u->client, main_entry_group_callback, u))) { pa_log("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client))); @@ -464,7 +353,7 @@ static int publish_main_service(struct userdata *u) { } else avahi_entry_group_reset(u->main_entry_group); - txt = txt_record_server_data(u->core, NULL); + txt = txt_record_server_data(u->core, txt); if (avahi_entry_group_add_service_strlst( u->main_entry_group, @@ -497,26 +386,18 @@ fail: static int publish_all_services(struct userdata *u) { pa_sink *sink; pa_source *source; - pa_autoload_entry *autoload; int r = -1; uint32_t idx; - assert(u); + pa_assert(u); pa_log_debug("Publishing services in Zeroconf"); - for (sink = pa_idxset_first(u->core->sinks, &idx); sink; sink = pa_idxset_next(u->core->sinks, &idx)) - if (publish_sink(u, sink) < 0) - goto fail; - - for (source = pa_idxset_first(u->core->sources, &idx); source; source = pa_idxset_next(u->core->sources, &idx)) - if (publish_source(u, source) < 0) - goto fail; + for (sink = PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(u->core->sinks, &idx))) + publish_service(get_service(u, PA_OBJECT(sink))); - if (u->core->autoload_idxset) - for (autoload = pa_idxset_first(u->core->autoload_idxset, &idx); autoload; autoload = pa_idxset_next(u->core->autoload_idxset, &idx)) - if (publish_autoload(u, autoload) < 0) - goto fail; + for (source = PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(u->core->sources, &idx))) + publish_service(get_service(u, PA_OBJECT(source))); if (publish_main_service(u) < 0) goto fail; @@ -527,38 +408,44 @@ fail: return r; } -static void unpublish_all_services(struct userdata *u, int rem) { +static void unpublish_all_services(struct userdata *u, pa_bool_t rem) { void *state = NULL; struct service *s; - assert(u); + pa_assert(u); pa_log_debug("Unpublishing services in Zeroconf"); while ((s = pa_hashmap_iterate(u->services, &state, NULL))) { if (s->entry_group) { if (rem) { + pa_log_debug("Removing entry group for %s.", s->service_name); avahi_entry_group_free(s->entry_group); s->entry_group = NULL; - } else + } else { avahi_entry_group_reset(s->entry_group); + pa_log_debug("Resetting entry group for %s.", s->service_name); + } } - - s->published = UNPUBLISHED; } if (u->main_entry_group) { if (rem) { + pa_log_debug("Removing main entry group."); avahi_entry_group_free(u->main_entry_group); u->main_entry_group = NULL; - } else + } else { avahi_entry_group_reset(u->main_entry_group); + pa_log_debug("Resetting main entry group."); + } } } static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) { struct userdata *u = userdata; - assert(c); + + pa_assert(c); + pa_assert(u); u->client = c; @@ -568,13 +455,17 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda break; case AVAHI_CLIENT_S_COLLISION: - unpublish_all_services(u, 0); + pa_log_debug("Host name collision"); + unpublish_all_services(u, FALSE); break; case AVAHI_CLIENT_FAILURE: if (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) { int error; - unpublish_all_services(u, 1); + + pa_log_debug("Avahi daemon disconnected."); + + unpublish_all_services(u, TRUE); avahi_client_free(u->client); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) @@ -587,11 +478,12 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda } } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) { + struct userdata *u; uint32_t port = PA_NATIVE_DEFAULT_PORT; pa_modargs *ma = NULL; - char hn[256]; + char hn[256], un[256]; int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -599,30 +491,29 @@ int pa__init(pa_core *c, pa_module*m) { goto fail; } - if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) { + if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port <= 0 || port > 0xFFFF) { pa_log("invalid port specified."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); - u->core = c; + u->core = m->core; u->port = (uint16_t) port; - u->avahi_poll = pa_avahi_poll_new(c->mainloop); + u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); - u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); - u->sink_dynarray = pa_dynarray_new(); - u->source_dynarray = pa_dynarray_new(); - u->autoload_dynarray = pa_dynarray_new(); + u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); - u->subscription = pa_subscription_new(c, - PA_SUBSCRIPTION_MASK_SINK| - PA_SUBSCRIPTION_MASK_SOURCE| - PA_SUBSCRIPTION_MASK_AUTOLOAD, subscribe_callback, u); + u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_NEW_POST], (pa_hook_cb_t) device_new_or_changed_cb, u); + u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_DESCRIPTION_CHANGED], (pa_hook_cb_t) device_new_or_changed_cb, u); + u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], (pa_hook_cb_t) device_unlink_cb, u); + u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_NEW_POST], (pa_hook_cb_t) device_new_or_changed_cb, u); + u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_DESCRIPTION_CHANGED], (pa_hook_cb_t) device_new_or_changed_cb, u); + u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], (pa_hook_cb_t) device_unlink_cb, u); u->main_entry_group = NULL; - u->service_name = pa_xstrdup(pa_get_host_name(hn, sizeof(hn))); + u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", pa_get_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn))), AVAHI_LABEL_MAX); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); @@ -634,7 +525,7 @@ int pa__init(pa_core *c, pa_module*m) { return 0; fail: - pa__done(c, m); + pa__done(m); if (ma) pa_modargs_free(ma); @@ -642,41 +533,34 @@ fail: return -1; } -static void service_free(void *p, void *userdata) { - struct service *s = p; - struct userdata *u = userdata; - - assert(s); - assert(u); - - if (s->entry_group) - avahi_entry_group_free(s->entry_group); - - pa_xfree(s->service_name); - pa_xfree(s->name); - pa_xfree(s); -} - -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) { struct userdata*u; - assert(c && m); + pa_assert(m); if (!(u = m->userdata)) return; - if (u->services) - pa_hashmap_free(u->services, service_free, u); + if (u->services) { + struct service *s; - if (u->subscription) - pa_subscription_free(u->subscription); + while ((s = pa_hashmap_get_first(u->services))) + service_free(s); - 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); + pa_hashmap_free(u->services, NULL, NULL); + } + if (u->sink_new_slot) + pa_hook_slot_free(u->sink_new_slot); + if (u->source_new_slot) + pa_hook_slot_free(u->source_new_slot); + if (u->sink_changed_slot) + pa_hook_slot_free(u->sink_changed_slot); + if (u->source_changed_slot) + pa_hook_slot_free(u->source_changed_slot); + if (u->sink_unlink_slot) + pa_hook_slot_free(u->sink_unlink_slot); + if (u->source_unlink_slot) + pa_hook_slot_free(u->source_unlink_slot); if (u->main_entry_group) avahi_entry_group_free(u->main_entry_group); @@ -690,4 +574,3 @@ void pa__done(pa_core *c, pa_module*m) { pa_xfree(u->service_name); pa_xfree(u); } - -- cgit From 9f446590e3f5d9ee32b2591b2500464079ba3426 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Oct 2007 20:03:07 +0000 Subject: publish dns-sd subtypes to allow distinction of virtual, hardware and monitor sinks/source git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1982 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 72 +++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 113686cf..b9b9b22c 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -60,21 +60,35 @@ PA_MODULE_USAGE("port=") #define SERVICE_TYPE_SINK "_pulse-sink._tcp" #define SERVICE_TYPE_SOURCE "_pulse-source._tcp" #define SERVICE_TYPE_SERVER "_pulse-server._tcp" +#define SERVICE_SUBTYPE_SINK_HARDWARE "_hardware._sub."SERVICE_TYPE_SINK +#define SERVICE_SUBTYPE_SINK_VIRTUAL "_virtual._sub."SERVICE_TYPE_SINK +#define SERVICE_SUBTYPE_SOURCE_HARDWARE "_hardware._sub."SERVICE_TYPE_SOURCE +#define SERVICE_SUBTYPE_SOURCE_VIRTUAL "_virtual._sub."SERVICE_TYPE_SOURCE +#define SERVICE_SUBTYPE_SOURCE_MONITOR "_monitor._sub."SERVICE_TYPE_SOURCE +#define SERVICE_SUBTYPE_SOURCE_NON_MONITOR "_non-monitor._sub."SERVICE_TYPE_SOURCE static const char* const valid_modargs[] = { "port", NULL }; +enum service_subtype { + SUBTYPE_HARDWARE, + SUBTYPE_VIRTUAL, + SUBTYPE_MONITOR +}; + struct service { struct userdata *userdata; AvahiEntryGroup *entry_group; char *service_name; pa_object *device; + enum service_subtype subtype; }; struct userdata { pa_core *core; + pa_module *module; AvahiPoll *avahi_poll; AvahiClient *client; @@ -88,10 +102,11 @@ struct userdata { pa_hook_slot *sink_new_slot, *source_new_slot, *sink_unlink_slot, *source_unlink_slot, *sink_changed_slot, *source_changed_slot; }; -static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_channel_map *ret_map, const char **ret_name, const char **ret_description) { +static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_channel_map *ret_map, const char **ret_name, const char **ret_description, enum service_subtype *ret_subtype) { pa_assert(s); pa_assert(ret_ss); pa_assert(ret_description); + pa_assert(ret_subtype); if (pa_sink_isinstance(s->device)) { pa_sink *sink = PA_SINK(s->device); @@ -100,6 +115,7 @@ static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_chann *ret_map = sink->channel_map; *ret_name = sink->name; *ret_description = sink->description; + *ret_subtype = sink->flags & PA_SINK_HARDWARE ? SUBTYPE_HARDWARE : SUBTYPE_VIRTUAL; } else if (pa_source_isinstance(s->device)) { pa_source *source = PA_SOURCE(s->device); @@ -108,6 +124,8 @@ static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_chann *ret_map = source->channel_map; *ret_name = source->name; *ret_description = source->description; + *ret_subtype = source->monitor_of ? SUBTYPE_MONITOR : (source->flags & PA_SOURCE_HARDWARE ? SUBTYPE_HARDWARE : SUBTYPE_VIRTUAL); + } else pa_assert_not_reached(); } @@ -174,6 +192,13 @@ static int publish_service(struct service *s) { pa_sample_spec ss; pa_channel_map map; char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; + enum service_subtype subtype; + + const char * const subtype_text[] = { + [SUBTYPE_HARDWARE] = "hardware", + [SUBTYPE_VIRTUAL] = "virtual", + [SUBTYPE_MONITOR] = "monitor" + }; pa_assert(s); @@ -190,12 +215,13 @@ static int publish_service(struct service *s) { txt = txt_record_server_data(s->userdata->core, txt); - get_service_data(s, &ss, &map, &name, &description); + get_service_data(s, &ss, &map, &name, &description, &subtype); txt = avahi_string_list_add_pair(txt, "device", name); txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate); txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels); txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format)); txt = avahi_string_list_add_pair(txt, "channel_map", pa_channel_map_snprint(cm, sizeof(cm), &map)); + txt = avahi_string_list_add_pair(txt, "subtype", subtype_text[subtype]); if (avahi_entry_group_add_service_strlst( s->entry_group, @@ -212,6 +238,35 @@ static int publish_service(struct service *s) { goto finish; } + if (avahi_entry_group_add_service_subtype( + s->entry_group, + AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + 0, + s->service_name, + pa_sink_isinstance(s->device) ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE, + NULL, + pa_sink_isinstance(s->device) ? (subtype == SUBTYPE_HARDWARE ? SERVICE_SUBTYPE_SINK_HARDWARE : SERVICE_SUBTYPE_SINK_VIRTUAL) : + (subtype == SUBTYPE_HARDWARE ? SERVICE_SUBTYPE_SOURCE_HARDWARE : (subtype == SUBTYPE_VIRTUAL ? SERVICE_SUBTYPE_SOURCE_VIRTUAL : SERVICE_SUBTYPE_SOURCE_MONITOR))) < 0) { + + pa_log("avahi_entry_group_add_service_subtype(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); + goto finish; + } + + if (pa_source_isinstance(s->device) && subtype != SUBTYPE_MONITOR) { + if (avahi_entry_group_add_service_subtype( + s->entry_group, + AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + 0, + s->service_name, + SERVICE_TYPE_SOURCE, + NULL, + SERVICE_SUBTYPE_SOURCE_NON_MONITOR) < 0) { + + pa_log("avahi_entry_group_add_service_subtype(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); + goto finish; + } + } + if (avahi_entry_group_commit(s->entry_group) < 0) { pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(s->userdata->client))); goto finish; @@ -468,8 +523,10 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda unpublish_all_services(u, TRUE); avahi_client_free(u->client); - if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) - pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); + if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { + pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); + pa_module_unload_request(u->module); + } } break; @@ -487,17 +544,18 @@ int pa__init(pa_module*m) { int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log("failed to parse module arguments."); + pa_log("Failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port <= 0 || port > 0xFFFF) { - pa_log("invalid port specified."); + pa_log("Invalid port specified."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; + u->module = m; u->port = (uint16_t) port; u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); @@ -516,7 +574,7 @@ int pa__init(pa_module*m) { u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", pa_get_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn))), AVAHI_LABEL_MAX); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { - pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); + pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } -- cgit From 33c238b7ef4b6c00f46714f14b3c6e1f29af6fde Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Oct 2007 21:23:08 +0000 Subject: ignore network sinks/sources git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1988 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index b9b9b22c..8e0419df 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -335,11 +335,24 @@ static void service_free(struct service *s) { pa_xfree(s); } +static pa_bool_t is_network(pa_object *o) { + pa_object_assert_ref(o); + + if (pa_sink_isinstance(o)) + return !!(PA_SINK(o)->flags & PA_SINK_NETWORK); + + if (pa_source_isinstance(o)) + return !!(PA_SOURCE(o)->flags & PA_SOURCE_NETWORK); + + pa_assert_not_reached(); +} + static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struct userdata *u) { pa_assert(c); pa_object_assert_ref(o); - publish_service(get_service(u, o)); + if (!is_network(o)) + publish_service(get_service(u, o)); return PA_HOOK_OK; } @@ -449,10 +462,12 @@ static int publish_all_services(struct userdata *u) { pa_log_debug("Publishing services in Zeroconf"); for (sink = PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(u->core->sinks, &idx))) - publish_service(get_service(u, PA_OBJECT(sink))); + if (!is_network(PA_OBJECT(sink))) + publish_service(get_service(u, PA_OBJECT(sink))); for (source = PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(u->core->sources, &idx))) - publish_service(get_service(u, PA_OBJECT(source))); + if (!is_network(PA_OBJECT(source))) + publish_service(get_service(u, PA_OBJECT(source))); if (publish_main_service(u) < 0) goto fail; -- cgit From e406bbaa62e5e93fd9ec844513f0848eda034a9b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Oct 2007 23:54:46 +0000 Subject: don't announce monitor sources git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1990 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 8e0419df..818a1b28 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -335,14 +335,14 @@ static void service_free(struct service *s) { pa_xfree(s); } -static pa_bool_t is_network(pa_object *o) { +static pa_bool_t shall_ignore(pa_object *o) { pa_object_assert_ref(o); if (pa_sink_isinstance(o)) return !!(PA_SINK(o)->flags & PA_SINK_NETWORK); if (pa_source_isinstance(o)) - return !!(PA_SOURCE(o)->flags & PA_SOURCE_NETWORK); + return PA_SOURCE(o)->monitor_of || (PA_SOURCE(o)->flags & PA_SOURCE_NETWORK); pa_assert_not_reached(); } @@ -351,7 +351,7 @@ static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struc pa_assert(c); pa_object_assert_ref(o); - if (!is_network(o)) + if (!shall_ignore(o)) publish_service(get_service(u, o)); return PA_HOOK_OK; @@ -462,11 +462,11 @@ static int publish_all_services(struct userdata *u) { pa_log_debug("Publishing services in Zeroconf"); for (sink = PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(u->core->sinks, &idx))) - if (!is_network(PA_OBJECT(sink))) + if (!shall_ignore(PA_OBJECT(sink))) publish_service(get_service(u, PA_OBJECT(sink))); for (source = PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(u->core->sources, &idx))) - if (!is_network(PA_OBJECT(source))) + if (!shall_ignore(PA_OBJECT(source))) publish_service(get_service(u, PA_OBJECT(source))); if (publish_main_service(u) < 0) -- cgit From e313fe1b3d0d9f9945c41c151d72edbe9cf1ec54 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 18:25:40 +0000 Subject: tag modules that may only be loaded once at most especially, and enforce that in the module loader git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-zeroconf-publish.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/modules/module-zeroconf-publish.c') diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 818a1b28..46969a24 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -52,10 +52,11 @@ #include "module-zeroconf-publish-symdef.h" -PA_MODULE_AUTHOR("Lennart Poettering") -PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher") -PA_MODULE_VERSION(PACKAGE_VERSION) -PA_MODULE_USAGE("port=") +PA_MODULE_AUTHOR("Lennart Poettering"); +PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher"); +PA_MODULE_VERSION(PACKAGE_VERSION); +PA_MODULE_LOAD_ONCE(TRUE); +PA_MODULE_USAGE("port="); #define SERVICE_TYPE_SINK "_pulse-sink._tcp" #define SERVICE_TYPE_SOURCE "_pulse-source._tcp" -- cgit