lib/configuration.c, lib/uaudio-rtp.c: Allow configuring payload size.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 3 Jun 2020 19:58:08 +0000 (20:58 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 6 Jun 2020 17:07:12 +0000 (18:07 +0100)
This is useful in unicast (or multicast-routing?) situations where
packets will traverse networks with unusually small MTU.

doc/disorder_config.5.in
lib/configuration.c
lib/configuration.h
lib/uaudio-rtp.c

index e57e06a..0822669 100644 (file)
@@ -686,6 +686,16 @@ The default value is
 This option is experimental,
 and may change or be removed in a future release.
 .TP
+.B rtp_max_payload \fBYTES\fR
+Don't send RTP packets with a UDP payload larger than
+.I BYTES
+(including the 12-byte RTP header).  If you know that you will be transmitting
+RTP over networks with an unusually low MTU size, then it is probably useful to
+set this option.
+.IP
+This option is experimental,
+and may change or be removed in a future release.
+.TP
 .B rtp_minbuffer \fIFRAMES\fR
 Set
 .BR disorder-playrtp (1)'s
index d1f14e9..a87957e 100644 (file)
@@ -1093,6 +1093,7 @@ static const struct conf conf[] = {
   { C(replay_min),       &type_integer,          validate_non_negative },
   { C(rtp_always_request), &type_boolean,       validate_any },
   { C(rtp_delay_threshold), &type_integer,       validate_positive },
+  { C(rtp_max_payload),         &type_integer,          validate_positive },
   { C(rtp_maxbuffer),   &type_integer,          validate_non_negative },
   { C(rtp_minbuffer),   &type_integer,          validate_non_negative },
   { C(rtp_mode),         &type_string,           validate_any },
@@ -1409,6 +1410,7 @@ static struct config *config_default(void) {
   c->listen.af = -1;
   c->connect.af = -1;
   c->rtp_mode = xstrdup("auto");
+  c->rtp_max_payload = -1;
   return c;
 }
 
index 5c33047..2b0db52 100644 (file)
@@ -259,6 +259,16 @@ struct config {
   /** @brief Whether to loop back multicast packets */
   int multicast_loop;
 
+  /** @brief Maximum size of RTP payload to send
+   *
+   * 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.
+   */
+  long rtp_max_payload;
+
   /** @brief Login lifetime in seconds */
   long cookie_login_lifetime;
 
index 8559bb2..73677d5 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
 };
 
@@ -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");
 }