[PATCH 03/25] raop: Parse server capabilities on discovery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Blanchard <tinram@xxxxxx>

During the discovery phase, raop servers send theirs capabilities
(supported encryption, audio codec...). These should be passed to the
raop sink via module's arguments.
---
 src/modules/raop/module-raop-discover.c | 93 +++++++++++++++++++++++++++++----
 1 file changed, 83 insertions(+), 10 deletions(-)

diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index 4137cf7..6fec06c 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -140,7 +140,10 @@ static void resolver_cb(
         void *userdata) {
     struct userdata *u = userdata;
     struct tunnel *tnl;
-    char *device = NULL, *nicename, *dname, *vname, *args;
+    char *nicename, *dname, *vname, *args;
+    char *tp = NULL, *et = NULL, *cn = NULL;
+    char *ch = NULL, *ss = NULL, *sr = NULL;
+    char *t = NULL;
     char at[AVAHI_ADDRESS_STR_MAX];
     AvahiStringList *l;
     pa_module *m;
@@ -168,8 +171,47 @@ static void resolver_cb(
         pa_assert_se(avahi_string_list_get_pair(l, &key, &value, NULL) == 0);
 
         pa_log_debug("Found key: '%s' with value: '%s'", key, value);
-        if (pa_streq(key, "device")) {
-            device = value;
+
+        if (pa_streq(key, "tp")) {
+            /* Transport protocol */
+            tp = value;
+            value = NULL;
+        } else if (pa_streq(key, "et")) {
+            /* Supported encryption types:
+             *  - 0 = none,
+             *  - 1 = RSA,
+             *  - 2 = FairPlay,
+             *  - 3 = MFiSAP,
+             *  - 4 = FairPlay SAPv2.5. */
+             if (pa_str_in_list(value, ",", "1"))
+                 et = strdup("RSA");
+             else
+                 et = strdup("none");
+        } else if (pa_streq(key, "cn")) {
+            /* Suported audio codecs:
+             *  - 0 = PCM,
+             *  - 1 = ALAC,
+             *  - 2 = AAC,
+             *  - 3 = AAC ELD. */
+            cn = strdup("PCM");
+        } else if (pa_streq(key, "md")) {
+            /* Supported metadata types:
+             *  - 0 = text,
+             *  - 1 = artwork,
+             *  - 2 = progress. */
+        } else if (pa_streq(key, "pw")) {
+            /* Requires password ? (true/false) */
+        } else if (pa_streq(key, "ch")) {
+            /* Number of channels */
+            ch = value;
+            value = NULL;
+        } else if (pa_streq(key, "ss")) {
+            /* Sample size */
+            ss = value;
+            value = NULL;
+        } else if (pa_streq(key, "sr")) {
+            /* Sample rate */
+            sr = value;
             value = NULL;
         }
 
@@ -177,19 +219,13 @@ static void resolver_cb(
         avahi_free(value);
     }
 
-    if (device)
-        dname = pa_sprintf_malloc("raop.%s.%s", host_name, device);
-    else
-        dname = pa_sprintf_malloc("raop.%s", host_name);
-
+    dname = pa_sprintf_malloc("raop_output.%s", host_name);
     if (!(vname = pa_namereg_make_valid_name(dname))) {
         pa_log("Cannot construct valid device name from '%s'.", dname);
-        avahi_free(device);
         pa_xfree(dname);
         goto finish;
     }
 
-    avahi_free(device);
     pa_xfree(dname);
 
     if (nicename) {
@@ -207,6 +243,43 @@ static void resolver_cb(
                                  vname);
     }
 
+    if (tp != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s protocol=%s", args, tp);
+        avahi_free(tp);
+        pa_xfree(t);
+    }
+    if (et != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s encryption=%s", args, et);
+        pa_xfree(et);
+        pa_xfree(t);
+    }
+    if (cn != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s codec=%s", args, cn);
+        pa_xfree(cn);
+        pa_xfree(t);
+    }
+    if (ch != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s channels=%s", args, ch);
+        avahi_free(ch);
+        pa_xfree(t);
+    }
+    if (ss != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s format=%s", args, ss);
+        avahi_free(ss);
+        pa_xfree(t);
+    }
+    if (sr != NULL) {
+        t = args;
+        args = pa_sprintf_malloc("%s rate=%s", args, sr);
+        avahi_free(sr);
+        pa_xfree(t);
+    }
+
     pa_log_debug("Loading module-raop-sink with arguments '%s'", args);
 
     if ((m = pa_module_load(u->core, "module-raop-sink", args))) {
-- 
1.8.1.2



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux