]> 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>
Tue, 12 Sep 2017 12:12:11 +0000 (14:12 +0200)
src/satip/rtsp.c

index f0d7beb4e83f793370e012bbbb42a4bb3f6bfaa6..e3de7d4eed3e3c3ec0daebaf5d2edcd5c8d71612 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;
@@ -1401,7 +1402,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,
@@ -1412,9 +1414,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)
@@ -1622,6 +1629,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);