]> code.delx.au - pulseaudio/blobdiff - src/modules/module-zeroconf-discover.c
bluetooth: Don't mark device valid before it has an adapter
[pulseaudio] / src / modules / module-zeroconf-discover.c
index 4e76f4489065293efe602a638f7500453f325eae..77782ad1e33d4b63e1217fcdf8210915e03a1c64 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -7,7 +5,7 @@
 
   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
+  published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #include <avahi-common/malloc.h>
 
 #include <pulse/xmalloc.h>
-#include <pulse/util.h>
 
-#include <pulsecore/sink.h>
-#include <pulsecore/source.h>
-#include <pulsecore/native-common.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/log.h>
-#include <pulsecore/core-subscribe.h>
 #include <pulsecore/hashmap.h>
 #include <pulsecore/modargs.h>
 #include <pulsecore/namereg.h>
@@ -56,7 +49,7 @@
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Discovery");
 PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_LOAD_ONCE(TRUE);
+PA_MODULE_LOAD_ONCE(true);
 
 #define SERVICE_TYPE_SINK "_pulse-sink._tcp"
 #define SERVICE_TYPE_SOURCE "_non-monitor._sub._pulse-source._tcp"
@@ -160,40 +153,37 @@ static void resolver_cb(
         pa_sample_spec ss;
         pa_channel_map cm;
         AvahiStringList *l;
-        pa_bool_t channel_map_set = FALSE;
+        bool channel_map_set = false;
         pa_module *m;
 
         ss = u->core->default_sample_spec;
-        pa_assert_se(pa_channel_map_init_auto(&cm, ss.channels, PA_CHANNEL_MAP_AUX));
-        pa_channel_map_init_auto(&cm, ss.channels, PA_CHANNEL_MAP_DEFAULT);
+        cm = u->core->default_channel_map;
 
         for (l = txt; l; l = l->next) {
             char *key, *value;
             pa_assert_se(avahi_string_list_get_pair(l, &key, &value, NULL) == 0);
 
-            if (strcmp(key, "device") == 0) {
+            if (pa_streq(key, "device")) {
                 pa_xfree(device);
                 device = value;
                 value = NULL;
-            } else if (strcmp(key, "rate") == 0)
-                ss.rate = atoi(value);
-            else if (strcmp(key, "channels") == 0)
-                ss.channels = atoi(value);
-            else if (strcmp(key, "format") == 0)
+            } else if (pa_streq(key, "rate"))
+                ss.rate = (uint32_t) atoi(value);
+            else if (pa_streq(key, "channels"))
+                ss.channels = (uint8_t) atoi(value);
+            else if (pa_streq(key, "format"))
                 ss.format = pa_parse_sample_format(value);
-            else if (strcmp(key, "channel_map") == 0) {
+            else if (pa_streq(key, "channel_map")) {
                 pa_channel_map_parse(&cm, value);
-                channel_map_set = TRUE;
+                channel_map_set = true;
             }
 
             avahi_free(key);
             avahi_free(value);
         }
 
-        if (!channel_map_set && cm.channels != ss.channels) {
-            pa_assert_se(pa_channel_map_init_auto(&cm, ss.channels, PA_CHANNEL_MAP_AUX));
-            pa_channel_map_init_auto(&cm, ss.channels, PA_CHANNEL_MAP_DEFAULT);
-        }
+        if (!channel_map_set && cm.channels != ss.channels)
+            pa_channel_map_init_extend(&cm, ss.channels, PA_CHANNEL_MAP_DEFAULT);
 
         if (!pa_sample_spec_valid(&ss)) {
             pa_log("Service '%s' contains an invalid sample specification.", name);
@@ -237,7 +227,7 @@ static void resolver_cb(
                                  t, dname,
                                  pa_channel_map_snprint(cmt, sizeof(cmt), &cm));
 
-        pa_log_debug("Loading module-tunnel-%s with arguments '%s'", module_name, args);
+        pa_log_debug("Loading %s with arguments '%s'", module_name, args);
 
         if ((m = pa_module_load(u->core, module_name, args))) {
             tnl->module_index = m->index;
@@ -284,14 +274,14 @@ static void browser_cb(
                 pa_log("avahi_service_resolver_new() failed: %s", avahi_strerror(avahi_client_errno(u->client)));
 
         /* We ignore the returned resolver object here, since the we don't
-         * need to attach any special data to it, and we can still destory
+         * need to attach any special data to it, and we can still destroy
          * it from the callback */
 
     } else if (event == AVAHI_BROWSER_REMOVE) {
         struct tunnel *t2;
 
         if ((t2 = pa_hashmap_get(u->tunnels, t))) {
-            pa_module_unload_by_index(u->core, t2->module_index);
+            pa_module_unload_request_by_index(u->core, t2->module_index, true);
             pa_hashmap_remove(u->tunnels, t2);
             tunnel_free(t2);
         }
@@ -324,7 +314,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda
                               browser_cb, u))) {
 
                     pa_log("avahi_service_browser_new() failed: %s", avahi_strerror(avahi_client_errno(c)));
-                    pa_module_unload_request(u->module);
+                    pa_module_unload_request(u->module, true);
                 }
             }
 
@@ -339,7 +329,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda
                               browser_cb, u))) {
 
                     pa_log("avahi_service_browser_new() failed: %s", avahi_strerror(avahi_client_errno(c)));
-                    pa_module_unload_request(u->module);
+                    pa_module_unload_request(u->module, true);
                 }
             }
 
@@ -353,7 +343,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("avahi_client_new() failed: %s", avahi_strerror(error));
-                    pa_module_unload_request(u->module);
+                    pa_module_unload_request(u->module, true);
                 }
             }
 
@@ -432,11 +422,11 @@ void pa__done(pa_module*m) {
         struct tunnel *t;
 
         while ((t = pa_hashmap_steal_first(u->tunnels))) {
-            pa_module_unload_by_index(u->core, t->module_index);
+            pa_module_unload_request_by_index(u->core, t->module_index, true);
             tunnel_free(t);
         }
 
-        pa_hashmap_free(u->tunnels, NULL, NULL);
+        pa_hashmap_free(u->tunnels);
     }
 
     pa_xfree(u);