]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtp.c
rtp sout: factor out some SDP code
[vlc] / modules / stream_out / rtp.c
index ace40571e4f3c5420943203bb24af57ddcb7f006..a6b4fd647f26570d1cd5d7d7f959abe3c7a47874 100644 (file)
@@ -49,8 +49,6 @@
 #ifdef HAVE_UNISTD_H
 #   include <sys/types.h>
 #   include <unistd.h>
-#   include <fcntl.h>
-#   include <sys/stat.h>
 #endif
 #ifdef HAVE_ARPA_INET_H
 #   include <arpa/inet.h>
@@ -459,10 +457,10 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->i_ttl == -1 )
     {
         /* Normally, we should let the default hop limit up to the core,
-         * but we have to know it to build our SDP properly, which is why
-         * we ask the core. FIXME: broken when neither sout-rtp-ttl nor
-         * ttl are set. */
-        p_sys->i_ttl = config_GetInt( p_stream, "ttl" );
+         * 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" );
     }
 
     p_sys->b_latm = var_GetBool( p_stream, SOUT_CFG_PREFIX "mp4a-latm" );
@@ -786,12 +784,29 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
     if( rtsp_url != NULL )
         sdp_AddAttribute ( &psz_sdp, "control", "%s", rtsp_url );
 
+    const char *proto = "RTP/AVP"; /* protocol */
+    if( rtsp_url == NULL )
+    {
+        switch( p_sys->proto )
+        {
+            case IPPROTO_UDP:
+                break;
+            case IPPROTO_TCP:
+                proto = "TCP/RTP/AVP";
+                break;
+            case IPPROTO_DCCP:
+                proto = "DCCP/RTP/AVP";
+                break;
+            case IPPROTO_UDPLITE:
+                return psz_sdp;
+        }
+    }
+
     /* FIXME: locking?! */
     for( i = 0; i < p_sys->i_es; i++ )
     {
         sout_stream_id_t *id = p_sys->es[i];
         const char *mime_major; /* major MIME type */
-        const char *proto = "RTP/AVP"; /* protocol */
 
         switch( id->i_cat )
         {
@@ -808,23 +823,6 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
                 continue;
         }
 
-        if( rtsp_url == NULL )
-        {
-            switch( p_sys->proto )
-            {
-                case IPPROTO_UDP:
-                    break;
-                case IPPROTO_TCP:
-                    proto = "TCP/RTP/AVP";
-                    break;
-                case IPPROTO_DCCP:
-                    proto = "DCCP/RTP/AVP";
-                    break;
-                case IPPROTO_UDPLITE:
-                    continue;
-            }
-        }
-
         sdp_AddMedia( &psz_sdp, mime_major, proto, inclport * id->i_port,
                       id->i_payload_type, false, id->i_bitrate,
                       id->psz_enc, id->i_clock_rate, id->i_channels,
@@ -835,11 +833,12 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
 
         if( rtsp_url != NULL )
         {
-            assert( strlen( rtsp_url ) > 0 );
-            bool addslash = ( rtsp_url[strlen( rtsp_url ) - 1] != '/' );
-            sdp_AddAttribute ( &psz_sdp, "control",
-                               addslash ? "%s/trackID=%u" : "%strackID=%u",
-                               rtsp_url, i );
+            char *track_url = RtspAppendTrackPath( id->rtsp_id, rtsp_url );
+            if( track_url != NULL )
+            {
+                sdp_AddAttribute ( &psz_sdp, "control", "%s", track_url );
+                free( track_url );
+            }
         }
         else
         {
@@ -979,7 +978,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         id->i_bitrate = 0;
     }
 
-    id->i_mtu = config_GetInt( p_stream, "mtu" );
+    id->i_mtu = var_InheritInteger( p_stream, "mtu" );
     if( id->i_mtu <= 12 + 16 )
         id->i_mtu = 576 - 20 - 8; /* pessimistic */
     msg_Dbg( p_stream, "maximum RTP packet size: %d bytes", id->i_mtu );
@@ -1237,12 +1236,11 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 
         case VLC_CODEC_MP4V:
         {
-            char hexa[2*p_fmt->i_extra +1];
-
             id->psz_enc = "MP4V-ES";
             id->pf_packetize = rtp_packetize_split;
             if( p_fmt->i_extra > 0 )
             {
+                char hexa[2*p_fmt->i_extra +1];
                 sprintf_hexa( hexa, p_fmt->p_extra, p_fmt->i_extra );
                 if( asprintf( &id->psz_fmtp,
                               "profile-level-id=3; config=%s;", hexa ) == -1 )