Project

General

Profile

Feature #4752

SAT>IP: Server RTP bind address

Added by Mono Polimorph almost 7 years ago. Updated almost 7 years ago.

Status:
Fixed
Priority:
Normal
Category:
SAT>IP
Target version:
-
Start date:
2017-11-30
Due date:
% Done:

100%

Estimated time:

Description

Hi Jaroslav,

Another new patch! This time the patch adds the option for selecting the RTP Bind Address (like with the SAT>IP Client with the option of IP Bind Address). However, in this case is for selecting the SOURCE address of the outgoing packets from the SAT>IP server. This is useful in case of tunneled RTSP connections and/or multiple network interfaces.

The patch isn't intrusive: if you don't add any address the code will be executed like as now. Also, if you set "0.0.0.0" instead of an specific address then the bind is done over the default interface.

I hope you agree and commit this patch. ;)
Regards!

diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c
index 06fbe87..842a01d 100644
--- a/src/satip/rtsp.c
+++ b/src/satip/rtsp.c
@@ -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;
@@ -1766,7 +1767,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,
@@ -1796,6 +1797,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);
@@ -1824,8 +1828,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);
 }
diff --git a/src/satip/server.c b/src/satip/server.c
index ba05491..c2e09d0 100644
--- a/src/satip/server.c
+++ b/src/satip/server.c
@@ -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);
 }

 /*
diff --git a/src/satip/server.h b/src/satip/server.h
index 5b9ecbd..0fa5909 100644
--- a/src/satip/server.h
+++ b/src/satip/server.h
@@ -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);

Files

History

#1

Updated by Mono Polimorph almost 7 years ago

Hi Jarsolav,

Why this patch is needed? Because if you use tunnels for the RTSP connection, then you need the option for setting the SOURCE address of the RTP stream. This patch only adds the option of setting this value.

As you can see the patch is simple. Please, comment if you like to modify something; or commit it! ;)

Thank you!

#2

Updated by Jaroslav Kysela almost 7 years ago

  • Status changed from New to Fixed
  • % Done changed from 0 to 100

Applied in changeset commit:tvheadend|12ecdd001dd4fb23acaac2b879aff90fbdeb6076.

#3

Updated by Mono Polimorph almost 7 years ago

Jaroslav Kysela wrote:

Applied in changeset commit:tvheadend|12ecdd001dd4fb23acaac2b879aff90fbdeb6076.

Thank you, another time! ;)

Also available in: Atom PDF