]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
satip server: don't bind more times to the UDP ports
authorJaroslav Kysela <perex@perex.cz>
Tue, 12 Sep 2017 12:11:27 +0000 (14:11 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 18 Sep 2017 13:14:37 +0000 (15:14 +0200)
src/satip/rtsp.c

index 03d7ad1f77f1782855a1fe9a726b8e6c40e69755..9720cf43f7ac94546a7b3c316d10c958e2610bbe 100644 (file)
@@ -67,6 +67,7 @@ typedef struct session {
   profile_chain_t prch;
   th_subscription_t *subs;
   int rtp_peer_port;
+  int rtp_udp_bound;
   udp_connection_t *udp_rtp;
   udp_connection_t *udp_rtcp;
   void *rtp_handle;
@@ -1398,7 +1399,8 @@ rtsp_process_play(http_connection_t *hc, int cmd)
 
   if (errcode) goto error;
 
-  if (cmd == RTSP_CMD_SETUP && rs->rtp_peer_port != RTSP_TCP_DATA) {
+  if (cmd == RTSP_CMD_SETUP && rs->rtp_peer_port != RTSP_TCP_DATA &&
+      !rs->rtp_udp_bound) {
     if (udp_bind_double(&rs->udp_rtp, &rs->udp_rtcp,
                         LS_SATIPS, "rtsp", "rtcp",
                         rtsp_ip, 0, NULL,
@@ -1409,9 +1411,14 @@ rtsp_process_play(http_connection_t *hc, int cmd)
     }
     if (udp_connect(rs->udp_rtp,  "RTP",  hc->hc_peer_ipstr, rs->rtp_peer_port) ||
         udp_connect(rs->udp_rtcp, "RTCP", hc->hc_peer_ipstr, rs->rtp_peer_port + 1)) {
+      udp_close(rs->udp_rtp);
+      rs->udp_rtp = NULL;
+      udp_close(rs->udp_rtcp);
+      rs->udp_rtcp = NULL;
       errcode = HTTP_STATUS_INTERNAL;
       goto error;
     }
+    rs->rtp_udp_bound = 1;
   }
 
   if (cmd == RTSP_CMD_SETUP && rs->rtp_peer_port == RTSP_TCP_DATA)
@@ -1619,6 +1626,7 @@ rtsp_close_session(session_t *rs)
   rs->udp_rtp = NULL;
   udp_close(rs->udp_rtcp);
   rs->udp_rtcp = NULL;
+  rs->rtp_udp_bound = 0;
   rs->shutdown_on_close = NULL;
   rs->tcp_data = NULL;
   pthread_mutex_lock(&global_lock);