]> code.delx.au - pulseaudio/blobdiff - src/modules/raop/raop_client.c
Remove pa_bool_t and replace it with bool.
[pulseaudio] / src / modules / raop / raop_client.c
index 4d2ad6ea3d80e16288c87d0074ddc57f7d16a1d7..98a98224acccd2f0ac4f6984647eb1de1d3d2426 100644 (file)
@@ -47,6 +47,7 @@
 #include <pulsecore/iochannel.h>
 #include <pulsecore/socket-util.h>
 #include <pulsecore/log.h>
+#include <pulsecore/parseaddr.h>
 #include <pulsecore/macro.h>
 #include <pulsecore/memchunk.h>
 #include <pulsecore/random.h>
 #define VOLUME_MIN -144
 #define VOLUME_MAX 0
 
+#define RAOP_PORT 5000
 
 struct pa_raop_client {
     pa_core *core;
     char *host;
+    uint16_t port;
     char *sid;
     pa_rtsp_client *rtsp;
 
@@ -110,7 +113,7 @@ static inline void bit_writer(uint8_t **buffer, uint8_t *bit_pos, int *size, uin
     if (!data_bit_len)
         return;
 
-    /* If bit pos is zero, we will definatly use at least one bit from the current byte so size increments. */
+    /* If bit pos is zero, we will definately use at least one bit from the current byte so size increments. */
     if (!*bit_pos)
         *size += 1;
 
@@ -128,7 +131,7 @@ static inline void bit_writer(uint8_t **buffer, uint8_t *bit_pos, int *size, uin
             **buffer = bit_data;
         /* If our data fits exactly into the current byte, we need to increment our pointer */
         if (0 == bit_overflow) {
-            /* Do not increment size as it will be incremeneted on next call as bit_pos is zero */
+            /* Do not increment size as it will be incremented on next call as bit_pos is zero */
             *buffer += 1;
             *bit_pos = 0;
         } else {
@@ -218,8 +221,7 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata
 
     c->fd = pa_iochannel_get_send_fd(io);
 
-    pa_iochannel_set_noclose(io, TRUE);
-    pa_iochannel_socket_set_sndbuf(io, 1024);
+    pa_iochannel_set_noclose(io, true);
     pa_iochannel_free(io);
 
     pa_make_tcp_socket_low_delay(c->fd);
@@ -300,11 +302,11 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
                 while ((token = pa_split(aj, delimiters, &token_state))) {
                     if ((pc = strstr(token, "="))) {
                       *pc = 0;
-                      if (!strcmp(token, "type") && !strcmp(pc+1, "digital")) {
+                      if (pa_streq(token, "type") && pa_streq(pc+1, "digital")) {
                           c->jack_type = JACK_TYPE_DIGITAL;
                       }
                     } else {
-                        if (!strcmp(token,"connected"))
+                        if (pa_streq(token, "connected"))
                             c->jack_status = JACK_STATUS_CONNECTED;
                     }
                     pa_xfree(token);
@@ -321,7 +323,7 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
             uint32_t port = pa_rtsp_serverport(c->rtsp);
             pa_log_debug("RAOP: RECORDED");
 
-            if (!(c->sc = pa_socket_client_new_string(c->core->mainloop, TRUE, c->host, port))) {
+            if (!(c->sc = pa_socket_client_new_string(c->core->mainloop, true, c->host, port))) {
                 pa_log("failed to connect to server '%s:%d'", c->host, port);
                 return;
             }
@@ -364,14 +366,23 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
 }
 
 pa_raop_client* pa_raop_client_new(pa_core *core, const char* host) {
+    pa_parsed_address a;
     pa_raop_client* c = pa_xnew0(pa_raop_client, 1);
 
     pa_assert(core);
     pa_assert(host);
 
+    if (pa_parse_address(host, &a) < 0 || a.type == PA_PARSED_ADDRESS_UNIX)
+        return NULL;
+
     c->core = core;
     c->fd = -1;
-    c->host = pa_xstrdup(host);
+
+    c->host = pa_xstrdup(a.path_or_host);
+    if (a.port)
+        c->port = a.port;
+    else
+        c->port = RAOP_PORT;
 
     if (pa_raop_connect(c)) {
         pa_raop_client_free(c);
@@ -380,17 +391,17 @@ pa_raop_client* pa_raop_client_new(pa_core *core, const char* host) {
     return c;
 }
 
-
 void pa_raop_client_free(pa_raop_client* c) {
     pa_assert(c);
 
     if (c->rtsp)
         pa_rtsp_client_free(c->rtsp);
+    if (c->sid)
+        pa_xfree(c->sid);
     pa_xfree(c->host);
     pa_xfree(c);
 }
 
-
 int pa_raop_connect(pa_raop_client* c) {
     char *sci;
     struct {
@@ -406,7 +417,7 @@ int pa_raop_connect(pa_raop_client* c) {
         return 0;
     }
 
-    c->rtsp = pa_rtsp_client_new(c->core->mainloop, c->host, 5000, "iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)");
+    c->rtsp = pa_rtsp_client_new(c->core->mainloop, c->host, c->port, "iTunes/4.6 (Macintosh; U; PPC Mac OS X 10.3)");
 
     /* Initialise the AES encryption system */
     pa_random(c->aes_iv, sizeof(c->aes_iv));
@@ -424,7 +435,6 @@ int pa_raop_connect(pa_raop_client* c) {
     return pa_rtsp_connect(c->rtsp);
 }
 
-
 int pa_raop_flush(pa_raop_client* c) {
     pa_assert(c);
 
@@ -432,7 +442,6 @@ int pa_raop_flush(pa_raop_client* c) {
     return 0;
 }
 
-
 int pa_raop_client_set_volume(pa_raop_client* c, pa_volume_t volume) {
     int rv;
     double db;
@@ -454,7 +463,6 @@ int pa_raop_client_set_volume(pa_raop_client* c, pa_volume_t volume) {
     return rv;
 }
 
-
 int pa_raop_client_encode_sample(pa_raop_client* c, pa_memchunk* raw, pa_memchunk* encoded) {
     uint16_t len;
     size_t bufmax;
@@ -522,7 +530,7 @@ int pa_raop_client_encode_sample(pa_raop_client* c, pa_memchunk* raw, pa_memchun
     pa_memblock_release(raw->memblock);
     encoded->length = header_size + size;
 
-    /* store the lenght (endian swapped: make this better) */
+    /* store the length (endian swapped: make this better) */
     len = size + header_size - 4;
     *(b + 2) = len >> 8;
     *(b + 3) = len & 0xff;
@@ -536,7 +544,6 @@ int pa_raop_client_encode_sample(pa_raop_client* c, pa_memchunk* raw, pa_memchun
     return 0;
 }
 
-
 void pa_raop_client_set_callback(pa_raop_client* c, pa_raop_client_cb_t callback, void *userdata) {
     pa_assert(c);