]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtcp.c
Fix RTSP server
[vlc] / modules / stream_out / rtcp.c
index b5ed1c3e938ad6394bad1a12720a743996ec5e26..f9ead76e617bcbe333a078b2c85d488c836e89f9 100644 (file)
  * Preamble
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_block.h>
 
 #include <vlc_network.h>
-
-
-#include <vlc_url.h>
 #include <vlc_sout.h>
 #include "rtp.h"
 
@@ -59,21 +60,45 @@ struct rtcp_sender_t
 };
 
 
-rtcp_sender_t *OpenRTCP (vlc_object_t *obj, int rtp_fd,
-                         int proto, uint16_t dport)
+rtcp_sender_t *OpenRTCP (vlc_object_t *obj, int rtp_fd, int proto,
+                         vlc_bool_t mux)
 {
     rtcp_sender_t *rtcp;
     uint8_t *ptr;
-    char src[NI_MAXNUMERICHOST], dst[NI_MAXNUMERICHOST];
-    int sport;
     int fd;
+    char src[NI_MAXNUMERICHOST];
+    int sport;
 
-    if (net_GetSockAddress (rtp_fd, src, &sport)
-     || net_GetPeerAddress (rtp_fd, dst, NULL))
+    if (net_GetSockAddress (rtp_fd, src, &sport))
         return NULL;
 
-    sport++;
-    fd = net_OpenDgram (obj, src, sport, dst, dport, AF_UNSPEC, proto);
+    if (mux)
+    {
+        /* RTP/RTCP mux: duplicate the socket */
+#ifndef WIN32
+        fd = dup (rtp_fd);
+#else
+        WSAPROTOCOL_INFO info;
+        WSADuplicateSocket (rtp_fd, GetCurrentProcessId (), &info);
+        fd = WSASocket (info.iAddressFamily, info.iSocketType, info.iProtocol,
+                        &info, 0, 0);
+#endif
+    }
+    else
+    {
+        /* RTCP on a separate port */
+        char dst[NI_MAXNUMERICHOST];
+        int dport;
+
+        if (net_GetPeerAddress (rtp_fd, dst, &dport))
+            return NULL;
+
+        sport++;
+        dport++;
+
+        fd = net_OpenDgram (obj, src, sport, dst, dport, AF_UNSPEC, proto);
+    }
+
     if (fd == -1)
         return NULL;
 
@@ -124,10 +149,10 @@ rtcp_sender_t *OpenRTCP (vlc_object_t *obj, int rtp_fd,
 
     while ((ptr - sdes) & 3) /* 32-bits padding */
         *ptr++ = 0;
-    SetWBE (lenptr, ptr - sdes);
+    SetWBE (lenptr, (ptr - sdes - 1) >> 2);
 
     rtcp->length = ptr - rtcp->payload;
-    return VLC_SUCCESS;
+    return rtcp;
 }