chiark / gitweb /
lib/configuration.c, lib/uaudio-rtp.c: Allow configuring payload size.
[disorder] / lib / uaudio-rtp.c
index c7be1d7b1e77f212c24519b9e949175e14b9592e..73677d595daf4037e40bca043b1e7cd6f7bcfa62 100644 (file)
 #include "timeval.h"
 #include "configuration.h"
 
-/** @brief Bytes to send per network packet
- *
- * This is the maximum number of bytes we pass to write(2); to determine actual
- * packet sizes, add a UDP header and an IP header (and a link layer header if
- * it's the link layer size you care about).
- *
- * Don't make this too big or arithmetic will start to overflow.
- */
-#define NETWORK_BYTES (1500-8/*UDP*/-40/*IP*/-8/*conservatism*/)
+/** @brief Bytes to send per network packet */
+static int rtp_max_payload;
 
 /** @brief RTP payload type */
 static int rtp_payload;
@@ -107,6 +100,7 @@ static const char *const rtp_options[] = {
   "multicast-ttl",
   "multicast-loop",
   "rtp-mode",
+  "rtp-max-payload",
   NULL
 };
 
@@ -209,23 +203,23 @@ static size_t rtp_play(void *buffer, size_t nsamples, unsigned flags) {
     uaudio_schedule_sent(nsamples);
     return nsamples;
   }
-  if(rtp_mode == RTP_REQUEST) {
-    struct rtp_recipient *r;
-    struct msghdr m;
-    memset(&m, 0, sizeof m);
-    m.msg_iov = vec;
-    m.msg_iovlen = 2;
-    pthread_mutex_lock(&rtp_lock);
-    for(r = rtp_recipient_list; r; r = r->next) {
-      m.msg_name = &r->sa;
-      m.msg_namelen = r->sa.ss_family == AF_INET ? 
-        sizeof(struct sockaddr_in) : sizeof (struct sockaddr_in6);
-      sendmsg(r->sa.ss_family == AF_INET ? rtp_fd4 : rtp_fd6,
-              &m, MSG_DONTWAIT|MSG_NOSIGNAL);
-      // TODO similar error handling to other case?
-    }
-    pthread_mutex_unlock(&rtp_lock);
-  } else {
+  /* Send stuff to explicitly registerd unicast addresses unconditionally */
+  struct rtp_recipient *r;
+  struct msghdr m;
+  memset(&m, 0, sizeof m);
+  m.msg_iov = vec;
+  m.msg_iovlen = 2;
+  pthread_mutex_lock(&rtp_lock);
+  for(r = rtp_recipient_list; r; r = r->next) {
+    m.msg_name = &r->sa;
+    m.msg_namelen = r->sa.ss_family == AF_INET ? 
+      sizeof(struct sockaddr_in) : sizeof (struct sockaddr_in6);
+    sendmsg(r->sa.ss_family == AF_INET ? rtp_fd4 : rtp_fd6,
+            &m, MSG_DONTWAIT|MSG_NOSIGNAL);
+    // TODO similar error handling to other case?
+  }
+  pthread_mutex_unlock(&rtp_lock);
+  if(rtp_mode != RTP_REQUEST) {
     int written_bytes;
     do {
       written_bytes = writev(rtp_fd, vec, 2);
@@ -326,6 +320,9 @@ static void rtp_open(void) {
         rtp_mode = RTP_UNICAST;
     }
   }
+  rtp_max_payload = atoi(uaudio_get("rtp-max-payload", "-1"));
+  if(rtp_max_payload < 0)
+    rtp_max_payload = 1500 - 8/*UDP*/ - 40/*IP*/ - 8/*conservatism*/;
   /* Create the sockets */
   if(rtp_mode != RTP_REQUEST) {
     if((rtp_fd = socket(dres->ai_family,
@@ -437,7 +434,7 @@ static void rtp_start(uaudio_callback *callback,
                       userdata,
                       rtp_play,
                       256 / uaudio_sample_size,
-                      (NETWORK_BYTES - sizeof(struct rtp_header))
+                      (rtp_max_payload - sizeof(struct rtp_header))
                       / uaudio_sample_size,
                       0);
   if(config->rtp_verbose)
@@ -464,6 +461,8 @@ static void rtp_configure(void) {
   snprintf(buffer, sizeof buffer, "%ld", config->multicast_ttl);
   uaudio_set("multicast-ttl", buffer);
   uaudio_set("multicast-loop", config->multicast_loop ? "yes" : "no");
+  snprintf(buffer, sizeof buffer, "%ld", config->rtp_max_payload);
+  uaudio_set("rtp-max-payload", buffer);
   if(config->rtp_verbose)
     disorder_info("RTP: configured");
 }