chiark / gitweb /
lib/uaudio-rtp.c: Set the send buffer for the IPv6 on-demand socket.
[disorder] / lib / uaudio-rtp.c
index b41bdda5366a56f4b9e04b91da489e5c8ae32267..ff7e839c30982081d0db5fe67d5a5ae36390cc12 100644 (file)
 static int rtp_payload;
 
 /** @brief RTP output socket */
-static int rtp_fd;
+static int rtp_fd = -1;
 
 /** @brief RTP output socket (IPv6) */
 static int rtp_fd6;
+/** @brief RTP unicast output socket (IPv6) */
+static int rtp_fd6 = -1;
 
 /** @brief RTP SSRC */
 static uint32_t rtp_id;
@@ -75,9 +77,6 @@ static uint16_t rtp_sequence;
  */
 static int rtp_errors;
 
-/** @brief Set while paused */
-static volatile int rtp_paused;
-
 /** @brief RTP mode */
 static int rtp_mode;
 
@@ -245,11 +244,29 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) {
   return nsamples;
 }
 
+static void hack_send_buffer_size(int fd, const char *what) {
+  int sndbuf, target_sndbuf = 131072;
+  socklen_t len = sizeof sndbuf;
+
+  if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF,
+                &sndbuf, &len) < 0)
+    disorder_fatal(errno, "error getting SO_SNDBUF on %s socket", what);
+  if(target_sndbuf > sndbuf) {
+    if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
+                  &target_sndbuf, sizeof target_sndbuf) < 0)
+      disorder_error(errno, "error setting SO_SNDBUF on %s socket to %d",
+                     what, target_sndbuf);
+    else
+      disorder_info("changed socket send buffer size on %socket from %d to %d",
+                    what, sndbuf, target_sndbuf);
+  } else
+    disorder_info("default socket send buffer on %s socket is %d",
+                  what, sndbuf);
+}
+
 static void rtp_open(void) {
   struct addrinfo *dres, *sres;
   static const int one = 1;
-  int sndbuf, target_sndbuf = 131072;
-  socklen_t len;
   struct netaddress dst[1], src[1];
   const char *mode;
   
@@ -372,20 +389,9 @@ static void rtp_open(void) {
     break;
   }
   }
-  /* Enlarge the socket buffer */
-  len = sizeof sndbuf;
-  if(getsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF,
-                &sndbuf, &len) < 0)
-    disorder_fatal(errno, "error getting SO_SNDBUF");
-  if(target_sndbuf > sndbuf) {
-    if(setsockopt(rtp_fd, SOL_SOCKET, SO_SNDBUF,
-                  &target_sndbuf, sizeof target_sndbuf) < 0)
-      disorder_error(errno, "error setting SO_SNDBUF to %d", target_sndbuf);
-    else
-      disorder_info("changed socket send buffer size from %d to %d",
-                    sndbuf, target_sndbuf);
-  } else
-    disorder_info("default socket send buffer is %d", sndbuf);
+  /* Enlarge the socket buffers */
+  hack_send_buffer_size(rtp_fd, "master socket");
+  hack_send_buffer_size(rtp_fd6, "IPv6 on-demand socket");
   /* We might well want to set additional broadcast- or multicast-related
    * options here */
   if(rtp_mode != RTP_REQUEST) {
@@ -443,12 +449,8 @@ static void rtp_start(uaudio_callback *callback,
 
 static void rtp_stop(void) {
   uaudio_thread_stop();
-  close(rtp_fd);
-  rtp_fd = -1;
-  if(rtp_fd6 >= 0) {
-    close(rtp_fd6);
-    rtp_fd6 = -1;
-  }
+  close(rtp_fd); rtp_fd = -1;
+  if(rtp_fd6 >= 0) { close(rtp_fd6); rtp_fd6 = -1; }
 }
 
 static void rtp_configure(void) {