]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtp.c
SDP: fix ordering of b= and a=
[vlc] / modules / stream_out / rtp.c
index 22def1bf5b9380784571e21bd4fec4781b522228..dee1aeca83cbfebd596b531bcbbd279c7ab05f05 100644 (file)
@@ -390,13 +390,9 @@ static int Open( vlc_object_t *p_this )
     /* must not exceed 999 once formatted */
 
     if( val.i_int < 0 )
-    {
-        msg_Warn( p_stream, "illegal TTL %d, using 1", val.i_int );
-        val.i_int = -1;
-    }
+        msg_Warn( p_stream, "illegal TTL %d, the SDP advertised value will be faked", val.i_int );
     p_sys->i_ttl = val.i_int;
 
-
     var_Get( p_stream, SOUT_CFG_PREFIX "mp4a-latm", &val );
     p_sys->b_latm = val.b_bool;
 
@@ -536,8 +532,7 @@ static int Open( vlc_object_t *p_this )
           a= source-filter: we need our source address
            a= x-plgroup: (missing)
            RTP packets need to get the correct src IP address  */
-        if( (ipv == 4)
-        && net_AddressIsMulticast( (vlc_object_t *)p_stream, p_sys->psz_destination ) )
+        if( ipv == 4 && net_AddressIsMulticast( VLC_OBJECT(p_stream), p_sys->psz_destination ) )
         {
             snprintf( psz_ttl, sizeof( psz_ttl ), "/%d", p_sys->i_ttl );
             psz_ttl[sizeof( psz_ttl ) - 1] = '\0';
@@ -648,53 +643,37 @@ static void Close( vlc_object_t * p_this )
     }
 
     while( p_sys->i_rtsp > 0 )
-    {
         RtspClientDel( p_stream, p_sys->rtsp[0] );
-    }
 
     vlc_mutex_destroy( &p_sys->lock_sdp );
 
     if( p_sys->p_httpd_file )
-    {
         httpd_FileDelete( p_sys->p_httpd_file );
-    }
+
     if( p_sys->p_httpd_host )
-    {
         httpd_HostDelete( p_sys->p_httpd_host );
-    }
+
     if( p_sys->p_rtsp_url )
-    {
         httpd_UrlDelete( p_sys->p_rtsp_url );
-    }
+
     if( p_sys->p_rtsp_host )
-    {
         httpd_HostDelete( p_sys->p_rtsp_host );
-    }
+
     if( p_sys->psz_session_name )
-    {
         free( p_sys->psz_session_name );
-        p_sys->psz_session_name = NULL;
-    }
+
     if( p_sys->psz_session_description )
-    {
         free( p_sys->psz_session_description );
-        p_sys->psz_session_description = NULL;
-    }
+
     if( p_sys->psz_session_url )
-    {
         free( p_sys->psz_session_url );
-        p_sys->psz_session_url = NULL;
-    }
+
     if( p_sys->psz_session_email )
-    {
         free( p_sys->psz_session_email );
-        p_sys->psz_session_email = NULL;
-    }
+
     if( p_sys->psz_sdp )
-    {
         free( p_sys->psz_sdp );
-        p_sys->psz_sdp = NULL;
-    }
+
     if( p_sys->b_export_sdp_file )
     {
 #ifdef HAVE_UNISTD_H
@@ -702,6 +681,8 @@ static void Close( vlc_object_t * p_this )
 #endif
         free( p_sys->psz_sdp_file );
     }
+    if( p_sys->psz_destination )
+        free( p_sys->psz_destination );
     free( p_sys );
 }
 
@@ -811,6 +792,10 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
         sout_stream_id_t *id = p_sys->es[i];
 
         i_size += strlen( "m=**d*o * RTP/AVP *\r\n" ) + 10 + 10;
+        if ( id->i_bitrate )
+        {
+            i_size += strlen( "b=AS: *\r\n") + 10;
+        }
         if( id->psz_rtpmap )
         {
             i_size += strlen( "a=rtpmap:* *\r\n" ) + strlen( id->psz_rtpmap )+10;
@@ -819,10 +804,6 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
         {
             i_size += strlen( "a=fmtp:* *\r\n" ) + strlen( id->psz_fmtp ) + 10;
         }
-        if ( id->i_bitrate)
-        {
-            i_size += strlen( "b=AS: *\r\n") + 10;
-        }
         if( b_rtsp )
         {
             i_size += strlen( "a=control:*/trackID=*\r\n" ) + strlen( p_sys->psz_rtsp_control ) + 10;
@@ -839,7 +820,7 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
     p += sprintf( p, "v=0\r\n" );
     p += sprintf( p, "o=- "I64Fd" %d IN IP%c %s\r\n",
                   p_sys->i_sdp_id, p_sys->i_sdp_version,
-                  ipv, ipv == '6' ? "::" : "127.0.0.1" );
+                  ipv, ipv == '6' ? "::1" : "127.0.0.1" );
     if( *p_sys->psz_session_name )
         p += sprintf( p, "s=%s\r\n", p_sys->psz_session_name );
     if( *p_sys->psz_session_description )
@@ -854,16 +835,13 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
 
     p += sprintf( p, "c=IN IP%c %s", ipv, psz_destination );
 
-    if( net_AddressIsMulticast( (vlc_object_t *)p_stream, psz_destination ) )
-    {
-        /* Add the ttl if it is a multicast address */
-        /* FIXME: 1 is not a correct default value in the case of IPv6 */
-        p += sprintf( p, "/%d\r\n", p_sys->i_ttl ?: 1 );
-    }
-    else
+    if( ( ipv == 4 )
+     && net_AddressIsMulticast( (vlc_object_t *)p_stream, psz_destination ) )
     {
-        p += sprintf( p, "\r\n" );
+        /* Add the deprecated TTL field if it is an IPv4 multicast address */
+        p += sprintf( p, "/%d", p_sys->i_ttl ?: 1 );
     }
+    p += sprintf( p, "\r\n" );
 
     for( i = 0; i < p_sys->i_es; i++ )
     {
@@ -883,6 +861,10 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
         {
             continue;
         }
+        if ( id->i_bitrate )
+        {
+            p += sprintf(p,"b=AS:%d\r\n",id->i_bitrate);
+        }
         if( id->psz_rtpmap )
         {
             p += sprintf( p, "a=rtpmap:%d %s\r\n", id->i_payload_type,
@@ -893,10 +875,6 @@ static char *SDPGenerate( const sout_stream_t *p_stream,
             p += sprintf( p, "a=fmtp:%d %s\r\n", id->i_payload_type,
                           id->psz_fmtp );
         }
-        if ( id->i_bitrate)
-        {
-            p += sprintf(p,"b=AS:%d\r\n",id->i_bitrate);
-        }
         if( b_rtsp )
         {
             p += sprintf( p, "a=control:/trackID=%d\r\n", i );
@@ -1825,7 +1803,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args,
                 httpd_MsgAdd( answer, "Transport",
                               "RTP/AVP/UDP;destination=%s;port=%d-%d;ttl=%d",
                               id->psz_destination, id->i_port,id->i_port+1,
-                              p_sys->i_ttl );
+                              p_sys->i_ttl > 0 ? p_sys->i_ttl : 1);
             }
             else if( strstr( psz_transport, "unicast" ) && strstr( psz_transport, "client_port=" ) )
             {