[vlc-commits] commit: rtsp: clean up multicast parameters (Pierre Ynard )

git at videolan.org git at videolan.org
Tue Dec 14 17:35:31 CET 2010


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Tue Dec 14 17:34:38 2010 +0100| [3ef18d45d0ee371b843658ad0069d44a5a5f3935] | committer: Pierre Ynard 

rtsp: clean up multicast parameters

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3ef18d45d0ee371b843658ad0069d44a5a5f3935
---

 modules/stream_out/rtp.c  |   25 ++++++++++---------------
 modules/stream_out/rtp.h  |    3 +--
 modules/stream_out/rtsp.c |   37 ++++++++++++++++++-------------------
 modules/stream_out/vod.c  |    2 +-
 4 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 42a9c89..80e17d0 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -316,7 +316,6 @@ struct sout_stream_sys_t
     uint16_t  i_port_video;
     uint8_t   proto;
     bool      rtcp_mux;
-    int       i_ttl:9;
     bool      b_latm;
 
     /* VoD */
@@ -502,14 +501,11 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_sys->i_ttl = var_GetInteger( p_stream, SOUT_CFG_PREFIX "ttl" );
-    if( p_sys->i_ttl == -1 )
+    int i_ttl = var_GetInteger( p_stream, SOUT_CFG_PREFIX "ttl" );
+    if( i_ttl != -1 )
     {
-        /* Normally, we should let the default hop limit up to the core,
-         * but we have to know it to write our RTSP headers properly,
-         * which is why we ask the core. FIXME: broken when neither
-         * sout-rtp-ttl nor ttl are set. */
-        p_sys->i_ttl = var_InheritInteger( p_stream, "ttl" );
+        var_Create( p_stream, "ttl", VLC_VAR_INTEGER );
+        var_SetInteger( p_stream, "ttl", i_ttl );
     }
 
     p_sys->b_latm = var_GetBool( p_stream, SOUT_CFG_PREFIX "mp4a-latm" );
@@ -1020,6 +1016,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
     id->i_seq_sent_next = id->i_sequence;
 
+    int mcast_fd = -1;
     if( p_sys->psz_destination != NULL )
     {
         /* Choose the port */
@@ -1094,9 +1091,8 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
             default:
             {
-                int ttl = (p_sys->i_ttl >= 0) ? p_sys->i_ttl : -1;
                 int fd = net_ConnectDgram( p_stream, p_sys->psz_destination,
-                                           i_port, ttl, p_sys->proto );
+                                           i_port, -1, p_sys->proto );
                 if( fd == -1 )
                 {
                     msg_Err( p_stream, "cannot create RTP socket" );
@@ -1107,6 +1103,8 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
                 setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 },
                             sizeof (int));
                 rtp_add_sink( id, fd, p_sys->rtcp_mux, NULL );
+                /* FIXME: test if this is multicast  */
+                mcast_fd = fd;
             }
         }
     }
@@ -1143,11 +1141,8 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
                                           p_sys->i_pts_offset );
 
     if( p_sys->rtsp != NULL )
-        id->rtsp_id = RtspAddId( p_sys->rtsp, id,
-                                 GetDWBE( id->ssrc ),
-                                 id->rtp_fmt.clock_rate,
-                                 p_sys->psz_destination,
-                                 p_sys->i_ttl, id->i_port, id->i_port + 1 );
+        id->rtsp_id = RtspAddId( p_sys->rtsp, id, GetDWBE( id->ssrc ),
+                                 id->rtp_fmt.clock_rate, mcast_fd );
 
     id->p_fifo = block_FifoNew();
     if( unlikely(id->p_fifo == NULL) )
diff --git a/modules/stream_out/rtp.h b/modules/stream_out/rtp.h
index e9c1655..f901249 100644
--- a/modules/stream_out/rtp.h
+++ b/modules/stream_out/rtp.h
@@ -31,8 +31,7 @@ void RtspUnsetup( rtsp_stream_t *rtsp );
 
 rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
                              uint32_t ssrc, unsigned clock_rate,
-                             const char *dst, int ttl,
-                             unsigned loport, unsigned hiport );
+                             int mcast_fd );
 void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t * );
 
 char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base );
diff --git a/modules/stream_out/rtsp.c b/modules/stream_out/rtsp.c
index 278da6e..29741f7 100644
--- a/modules/stream_out/rtsp.c
+++ b/modules/stream_out/rtsp.c
@@ -170,13 +170,11 @@ struct rtsp_stream_id_t
 {
     rtsp_stream_t    *stream;
     sout_stream_id_t *sout_id;
-    unsigned          clock_rate; /* needed to compute rtptime in RTP-Info */
     httpd_url_t      *url;
-    const char       *dst;
-    int               ttl;
     unsigned          track_id;
     uint32_t          ssrc;
-    uint16_t          loport, hiport;
+    unsigned          clock_rate; /* needed to compute rtptime in RTP-Info */
+    int               mcast_fd;
 };
 
 
@@ -226,9 +224,7 @@ char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base )
 
 rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
                              uint32_t ssrc, unsigned clock_rate,
-                             /* Multicast stuff - TODO: cleanup */
-                             const char *dst, int ttl,
-                             unsigned loport, unsigned hiport )
+                             int mcast_fd)
 {
     if (rtsp->track_id > 999)
     {
@@ -248,13 +244,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
     id->track_id = rtsp->track_id;
     id->ssrc = ssrc;
     id->clock_rate = clock_rate;
-    id->dst = dst;
-    if( id->dst != NULL )
-    {
-        id->ttl = ttl;
-        id->loport = loport;
-        id->hiport = hiport;
-    }
+    id->mcast_fd = mcast_fd;
 
     urlbuf = RtspAppendTrackPath( id, rtsp->psz_path );
     if( urlbuf == NULL )
@@ -684,7 +674,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                  tpt = transport_next( tpt ) )
             {
                 bool b_multicast = true, b_unsupp = false;
-                unsigned loport = 5004, hiport = 5005; /* from RFC3551 */
+                unsigned loport = 5004, hiport; /* from RFC3551 */
 
                 /* Check transport protocol. */
                 /* Currently, we only support RTP/AVP over UDP */
@@ -752,10 +742,19 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
 
                 if( b_multicast )
                 {
-                    const char *dst = id->dst;
-                    if( dst == NULL )
+                    char dst[NI_MAXNUMERICHOST];
+                    int dport, ttl;
+                    if( id->mcast_fd == -1 )
                         continue;
 
+                    net_GetPeerAddress(id->mcast_fd, dst, &dport);
+
+                    ttl = var_InheritInteger(owner, "ttl");
+                    if (ttl <= 0)
+                    /* FIXME: the TTL is left to the OS default, we can
+                     * only guess that it's 1. */
+                        ttl = 1;
+
                     if( psz_session == NULL )
                     {
                         /* Create a dummy session ID */
@@ -768,8 +767,8 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     httpd_MsgAdd( answer, "Transport",
                                   "RTP/AVP/UDP;destination=%s;port=%u-%u;"
                                   "ttl=%d;mode=play",
-                                  dst, id->loport, id->hiport,
-                                  ( id->ttl > 0 ) ? id->ttl : 1 );
+                                  dst, dport, dport + 1, ttl );
+                     /* FIXME: this doesn't work with RTP + RTCP mux */
                 }
                 else
                 {
diff --git a/modules/stream_out/vod.c b/modules/stream_out/vod.c
index a5c64cb..1773477 100644
--- a/modules/stream_out/vod.c
+++ b/modules/stream_out/vod.c
@@ -301,7 +301,7 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     {
         media_es_t *p_es = p_media->es[i];
         p_es->rtsp_id = RtspAddId(p_media->rtsp, NULL, 0,
-                                  p_es->rtp_fmt.clock_rate, NULL, 0, 0, 0);
+                                  p_es->rtp_fmt.clock_rate, -1);
         if (p_es->rtsp_id == NULL)
             goto error;
     }



More information about the vlc-commits mailing list