chiark / gitweb /
lib/configuration.c, lib/uaudio-rtp.c: Allow tweaking MTU-discovery.
[disorder] / lib / uaudio-rtp.c
index 8559bb228dbaa7c97c15e9bb50c84ca250189111..9e7abde229dbb22a411ea4c81830c2aa84720daf 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,8 @@ static const char *const rtp_options[] = {
   "multicast-ttl",
   "multicast-loop",
   "rtp-mode",
+  "rtp-max-payload",
+  "rtp-mtu-discovery",
   NULL
 };
 
@@ -270,6 +265,10 @@ static void rtp_open(void) {
   static const int one = 1;
   struct netaddress dst[1], src[1];
   const char *mode;
+#ifdef IP_MTU_DISCOVER
+  const char *mtu_disc;
+  int opt;
+#endif
   
   /* Get the mode */
   mode = uaudio_get("rtp-mode", "auto");
@@ -326,6 +325,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,
@@ -399,6 +401,19 @@ static void rtp_open(void) {
       disorder_fatal(errno, "error connecting broadcast socket to %s", 
                      format_sockaddr(dres->ai_addr));
   }
+#ifdef IP_MTU_DISCOVER
+  mtu_disc = uaudio_get("rtp-mtu-discovery", "default");
+  do {
+    if(!strcmp(mtu_disc, "yes")) opt = IP_PMTUDISC_DO;
+    else if(!strcmp(mtu_disc, "no")) opt = IP_PMTUDISC_DONT;
+    else break;
+    if(setsockopt(rtp_fd4, IPPROTO_IP, IP_MTU_DISCOVER, &opt, sizeof opt))
+      disorder_fatal(errno, "error setting MTU discovery");
+    if(sres->ai_family == AF_INET &&
+        setsockopt(rtp_fd, IPPROTO_IP, IP_MTU_DISCOVER, &opt, sizeof opt))
+      disorder_fatal(errno, "error setting MTU discovery");
+  } while (0);
+#endif
   if(config->rtp_verbose)
     disorder_info("RTP: prepared socket");
 }
@@ -437,7 +452,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 +479,9 @@ 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);
+  uaudio_set("rtp-mtu-discovery", config->rtp_mtu_discovery);
   if(config->rtp_verbose)
     disorder_info("RTP: configured");
 }