]> git.sesse.net Git - vlc/blobdiff - modules/misc/rtsp.c
Fix memleaks (corner case).
[vlc] / modules / misc / rtsp.c
index 27bf61830e50da6362ec8dca25f2da9dc028514c..ae7e27754ca80d9f696871d82b9dae1048624f8b 100644 (file)
@@ -30,7 +30,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_sout.h>
 #include <vlc_block.h>
@@ -71,8 +72,8 @@ static void Close( vlc_object_t * );
     "those made by HansunTech) which get confused by it. The default is 5." )
 
 vlc_module_begin();
-    set_shortname( _("RTSP VoD" ) );
-    set_description( _("RTSP VoD server") );
+    set_shortname( N_("RTSP VoD" ) );
+    set_description( N_("RTSP VoD server") );
     set_category( CAT_SOUT );
     set_subcategory( SUBCAT_SOUT_VOD );
     set_capability( "vod server", 1 );
@@ -287,7 +288,7 @@ static int Open( vlc_object_t *p_this )
 
     vlc_UrlClean( &url );
 
-    vlc_mutex_init( p_vod, &p_sys->lock_media );
+    vlc_mutex_init( &p_sys->lock_media );
 
     TAB_INIT( p_sys->i_media, p_sys->media );
     p_sys->i_media_id = 0;
@@ -297,7 +298,7 @@ static int Open( vlc_object_t *p_this )
     p_vod->pf_media_add_es = MediaAddES;
     p_vod->pf_media_del_es = MediaDelES;
 
-    p_sys->p_fifo_cmd = block_FifoNew( p_vod );
+    p_sys->p_fifo_cmd = block_FifoNew();
     if( vlc_thread_create( p_vod, "rtsp vod thread", CommandThread,
                            VLC_THREAD_PRIORITY_LOW, false ) )
     {
@@ -364,10 +365,7 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     int i;
 
     if( !p_media )
-    {
-        msg_Err( p_vod, "not enough memory" );
         return NULL;
-    }
 
     memset( p_media, 0, sizeof(vod_media_t) );
     p_media->id = p_sys->i_media_id++;
@@ -421,7 +419,7 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     TAB_APPEND( p_sys->i_media, p_sys->media, p_media );
     vlc_mutex_unlock( &p_sys->lock_media );
 
-    vlc_mutex_init( p_vod, &p_media->lock );
+    vlc_mutex_init( &p_media->lock );
     p_media->psz_session_name = strdup("");
     p_media->psz_session_description = strdup("");
     p_media->psz_session_url = strdup("");
@@ -494,7 +492,10 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
     /* TODO: update SDP, etc... */
     if( asprintf( &psz_urlc, "%s/trackID=%d",
               p_media->psz_rtsp_path, p_media->i_es ) < 0 )
+    {
+        free( p_es );
         return VLC_ENOMEM;
+    }
     msg_Dbg( p_vod, "  - ES %4.4s (%s)", (char *)&p_fmt->i_codec, psz_urlc );
 
     switch( p_fmt->i_codec )
@@ -524,6 +525,7 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
                     p_fmt->audio.i_channels );
             break;
         case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
+        case VLC_FOURCC( 'm', 'p', '3', ' ' ):
             p_es->i_payload_type = 14;
             p_es->psz_rtpmap = strdup( "MPA/90000" );
             break;
@@ -533,7 +535,7 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
             break;
         case VLC_FOURCC( 'a', '5', '2', ' ' ):
             p_es->i_payload_type = p_media->i_payload_type++;
-            p_es->psz_rtpmap = strdup( "ac3/90000" );
+            asprintf( &p_es->psz_rtpmap, "ac3/%d", p_fmt->audio.i_rate );
             break;
         case VLC_FOURCC( 'H', '2', '6', '3' ):
             p_es->i_payload_type = p_media->i_payload_type++;
@@ -584,11 +586,19 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
                 }
                 /* */
                 if( p_64_sps && p_64_pps )
+                {
                     if( asprintf( &p_es->psz_fmtp,
                                   "packetization-mode=1;profile-level-id=%s;"
                                   "sprop-parameter-sets=%s,%s;", hexa, p_64_sps,
                                   p_64_pps ) < 0 )
+                    {
+                        free( p_64_sps );
+                        free( p_64_pps );
+                        free( psz_urlc );
+                        free( p_es );
                         return VLC_ENOMEM;
+                    }
+                }
                 free( p_64_sps );
                 free( p_64_pps );
             }
@@ -650,6 +660,7 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
         default:
             msg_Err( p_vod, "cannot add this stream (unsupported "
                     "codec: %4.4s)", (char*)&p_fmt->i_codec );
+            free( psz_urlc );
             free( p_es );
             return VLC_EGENERIC;
     }
@@ -1018,19 +1029,19 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                     if( strstr( psz_transport, "MP2T/H2221/UDP" ) )
                     {
                         httpd_MsgAdd( answer, "Transport",
-                                      "MP2T/H2221/UDP;client_port=%d-%d",
+                                      "MP2T/H2221/UDP;unicast;client_port=%d-%d",
                                       i_port, i_port + 1 );
                     }
                     else if( strstr( psz_transport, "RAW/RAW/UDP" ) )
                     {
                         httpd_MsgAdd( answer, "Transport",
-                                      "RAW/RAW/UDP;client_port=%d-%d",
+                                      "RAW/RAW/UDP;unicast;client_port=%d-%d",
                                       i_port, i_port + 1 );
                     }
                 }
                 else
                     httpd_MsgAdd( answer, "Transport",
-                                  "RTP/AVP/UDP;client_port=%d-%d",
+                                  "RTP/AVP/UDP;unicast;client_port=%d-%d",
                                   i_port, i_port + 1 );
             }
             else /* TODO  strstr( psz_transport, "interleaved" ) ) */