]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
SAT>IP Server: Allow to change the RTP source address, fixes #4752
authorJaroslav Kysela <perex@perex.cz>
Thu, 21 Dec 2017 16:47:37 +0000 (17:47 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 21 Dec 2017 16:47:37 +0000 (17:47 +0100)
From: Mono Polimorph

src/satip/rtsp.c
src/satip/server.c
src/satip/server.h

index 7667684be7cdc53b15640c97b655b3e17983ba55..01c4bc5391398fe4775d772bce92a43ae31e024a 100644 (file)
@@ -80,6 +80,7 @@ static uint32_t session_number;
 static uint16_t stream_id;
 static char *rtsp_ip = NULL;
 static char *rtsp_nat_ip = NULL;
+static char *rtp_src_ip = NULL;
 static int rtsp_port = -1;
 static int rtsp_nat_port = -1;
 static int rtsp_descramble = 1;
@@ -1497,7 +1498,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
       !rs->rtp_udp_bound) {
     if (udp_bind_double(&rs->udp_rtp, &rs->udp_rtcp,
                         LS_SATIPS, "rtsp", "rtcp",
-                        rtsp_ip, 0, NULL,
+                        (rtp_src_ip != NULL && rtp_src_ip[0] != '\0') ? rtp_src_ip : rtsp_ip, 0, NULL,
                         4*1024, 4*1024,
                         RTP_BUFSIZE, RTCP_BUFSIZE)) {
       errcode = HTTP_STATUS_INTERNAL;
@@ -1767,7 +1768,7 @@ rtsp_close_sessions(void)
  */
 void satip_server_rtsp_init
   (const char *bindaddr, int port, int descramble, int rewrite_pmt, int muxcnf,
-   const char *nat_ip, int nat_port)
+   const char *rtp_src, const char *nat_ip, int nat_port)
 {
   static tcp_server_ops_t ops = {
     .start  = rtsp_serve,
@@ -1797,6 +1798,9 @@ void satip_server_rtsp_init
   rtsp_descramble = descramble;
   rtsp_rewrite_pmt = rewrite_pmt;
   rtsp_muxcnf = muxcnf;
+  s = rtp_src_ip;
+  rtp_src_ip = rtp_src ? strdup(rtp_src) : NULL;
+  free(s);
   s = rtsp_nat_ip;
   rtsp_nat_ip = nat_ip ? strdup(nat_ip) : NULL;
   free(s);
@@ -1825,8 +1829,9 @@ void satip_server_rtsp_done(void)
   rtsp_port = -1;
   rtsp_nat_port = -1;
   free(rtsp_ip);
+  free(rtp_src_ip);
   free(rtsp_nat_ip);
-  rtsp_ip = rtsp_nat_ip = NULL;
+  rtsp_ip = rtp_src_ip = rtsp_nat_ip = NULL;
   satip_rtp_done();
   pthread_mutex_unlock(&global_lock);
 }
index 7c9c242b7988cf666b80ff37a5c7cb7e08cfb47f..d1b0c1f457f35e0a025f54ed76df703377b3ee2f 100644 (file)
@@ -786,6 +786,19 @@ const idclass_t satip_server_class = {
       .opts   = PO_EXPERT,
       .group  = 2,
     },
+    {
+      .type   = PT_STR,
+      .id     = "satip_rtp_src_ip",
+      .name   = N_("RTP Local bind IP address"),
+      .desc   = N_("Bind RTP source address of the outgoing RTP packets "
+                   "to specific local IP address "
+                   "(empty = same IP as the listening RTSP; "
+                   "0.0.0.0 = IP in network of default gateway; "
+                   "or write here a valid local IP address)."),
+      .off    = offsetof(struct satip_server_conf, satip_rtp_src_ip),
+      .opts   = PO_EXPERT,
+      .group  = 2,
+    },
 
 
 
@@ -954,7 +967,7 @@ static void satip_server_init_common(const char *prefix, int announce)
   struct sockaddr_storage http;
   char http_ip[128];
   int descramble, rewrite_pmt, muxcnf;
-  char *nat_ip;
+  char *nat_ip, *rtp_src_ip;
   int nat_port;
 
   if (satip_server_rtsp_port <= 0)
@@ -979,13 +992,14 @@ static void satip_server_init_common(const char *prefix, int announce)
   muxcnf = satip_server_conf.satip_muxcnf;
   nat_ip = strdup(satip_server_conf.satip_nat_ip ?: "");
   nat_port = satip_server_conf.satip_nat_rtsp ?: satip_server_rtsp_port;
+  rtp_src_ip = strdup(satip_server_conf.satip_rtp_src_ip ?: "");
 
   if (announce)
     pthread_mutex_unlock(&global_lock);
 
   pthread_mutex_lock(&satip_server_reinit);
 
-  satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, nat_ip, nat_port);
+  satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, rtp_src_ip, nat_ip, nat_port);
   satip_server_info(prefix, descramble, muxcnf);
 
   if (announce)
@@ -997,6 +1011,7 @@ static void satip_server_init_common(const char *prefix, int announce)
     pthread_mutex_lock(&global_lock);
 
   free(nat_ip);
+  free(rtp_src_ip);
 }
 
 /*
index 5b9ecbdb352d5d61d88526d3f3ad9ca96e30c3f5..0fa5909280e4d69067d0f3459b27dde98aea25d7 100644 (file)
@@ -68,6 +68,7 @@ struct satip_server_conf {
   char *satip_nat_ip;
   int satip_nat_rtsp;
   int satip_nat_name_force;
+  char *satip_rtp_src_ip;
 };
 
 extern struct satip_server_conf satip_server_conf;
@@ -98,6 +99,7 @@ int satip_rtsp_delsys(int fe, int *findex, const char **ftype);
 
 void satip_server_rtsp_init(const char *bindaddr, int port,
                             int descramble, int rewrite_pmt, int muxcnf,
+                            const char *rtp_src,
                             const char *nat_ip, int nat_port);
 void satip_server_rtsp_register(void);
 void satip_server_rtsp_done(void);