]> git.sesse.net Git - vlc/blobdiff - modules/misc/rtsp.c
vod: removing more unused stuff
[vlc] / modules / misc / rtsp.c
index 1a7a416e1b58c97fd7d4e3552906806ef0754e59..ca1b5bfe79b098485944f27f86d5deb7ef480022 100644 (file)
 #include <vlc_sout.h>
 #include <vlc_block.h>
 
-#include "vlc_httpd.h"
-#include "vlc_vod.h"
-#include "vlc_url.h"
+#include <vlc_httpd.h>
+#include <vlc_vod.h>
+#include <vlc_url.h>
 #include <vlc_network.h>
 #include <vlc_charset.h>
 #include <vlc_strings.h>
 
 #include <errno.h>
+
 #ifndef WIN32
 # include <locale.h>
 #endif
 
+#ifdef HAVE_XLOCALE_H
+# include <xlocale.h>
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -61,8 +66,8 @@ static void Close( vlc_object_t * );
     "interfaces (address 0.0.0.0), on port 554, with no path.\nTo listen " \
     "only on the local interface, use \"localhost\" as address." )
 
-#define THROTLE_TEXT N_( "Maximum number of connections" )
-#define THROTLE_LONGTEXT N_( "This limits the maximum number of clients " \
+#define THROTTLE_TEXT N_( "Maximum number of connections" )
+#define THROTTLE_LONGTEXT N_( "This limits the maximum number of clients " \
     "that can connect to the RTSP VOD. 0 means no limit."  )
 
 #define RAWMUX_TEXT N_( "MUX for RAW RTSP transport" )
@@ -74,22 +79,22 @@ static void Close( vlc_object_t * );
     "the timeout option entirely. This is needed by some IPTV STBs (such as " \
     "those made by HansunTech) which get confused by it. The default is 5." )
 
-vlc_module_begin();
-    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 );
-    set_callbacks( Open, Close );
-    add_shortcut( "rtsp" );
-    add_string ( "rtsp-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true );
+vlc_module_begin ()
+    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 )
+    set_callbacks( Open, Close )
+    add_shortcut( "rtsp" )
+    add_string ( "rtsp-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true )
     add_string( "rtsp-raw-mux", "ts", NULL, RAWMUX_TEXT,
-                RAWMUX_TEXT, true );
-    add_integer( "rtsp-throttle-users", 0, NULL, THROTLE_TEXT,
-                                           THROTLE_LONGTEXT, true );
+                RAWMUX_TEXT, true )
+    add_integer( "rtsp-throttle-users", 0, NULL, THROTTLE_TEXT,
+                 THROTTLE_LONGTEXT, true )
     add_integer( "rtsp-session-timeout", 5, NULL, SESSION_TIMEOUT_TEXT,
-                 SESSION_TIMEOUT_LONGTEXT, true );
-vlc_module_end();
+                 SESSION_TIMEOUT_LONGTEXT, true )
+vlc_module_end ()
 
 /*****************************************************************************
  * Exported prototypes
@@ -100,7 +105,6 @@ typedef struct media_es_t media_es_t;
 typedef struct
 {
     media_es_t *p_media_es;
-    char *psz_ip;
     int i_port;
 
 } rtsp_client_es_t;
@@ -108,7 +112,6 @@ typedef struct
 typedef struct
 {
     char *psz_session;
-    int64_t i_last; /* for timeout */
 
     bool b_playing; /* is it in "play" state */
     bool b_paused; /* is it in "pause" state */
@@ -129,7 +132,6 @@ struct media_es_t
     vod_media_t *p_media;
 
     es_format_t fmt;
-    int         i_port;
     uint8_t     i_payload_type;
     char        *psz_rtpmap;
     char        *psz_fmtp;
@@ -149,17 +151,11 @@ struct vod_media_t
     char         *psz_rtsp_control_v6;
     char         *psz_rtsp_path;
 
-    int  i_port;
-    int  i_port_audio;
-    int  i_port_video;
-    int  i_ttl;
     int  i_payload_type;
 
     int64_t i_sdp_id;
     int     i_sdp_version;
 
-    bool b_multicast;
-
     vlc_mutex_t lock;
 
     /* ES list */
@@ -173,10 +169,6 @@ struct vod_media_t
     rtsp_client_t **rtsp;
 
     /* Infos */
-    char *psz_session_name;
-    char *psz_session_description;
-    char *psz_session_url;
-    char *psz_session_email;
     mtime_t i_length;
 };
 
@@ -214,16 +206,31 @@ typedef enum
     RTSP_CMD_TYPE_SEEK,
     RTSP_CMD_TYPE_REWIND,
     RTSP_CMD_TYPE_FORWARD,
+
+    RTSP_CMD_TYPE_ADD,
+    RTSP_CMD_TYPE_DEL,
 } rtsp_cmd_type_t;
 
+/* */
+typedef struct
+{
+    int i_type;
+    int i_media_id;
+    vod_media_t *p_media;
+    char *psz_session;
+    char *psz_arg;
+    double f_arg;
+} rtsp_cmd_t;
+
 static vod_media_t *MediaNew( vod_t *, const char *, input_item_t * );
 static void         MediaDel( vod_t *, vod_media_t * );
+static void         MediaAskDel ( vod_t *, vod_media_t * );
 static int          MediaAddES( vod_t *, vod_media_t *, es_format_t * );
 static void         MediaDelES( vod_t *, vod_media_t *, es_format_t * );
 
-static void CommandThread( vlc_object_t *p_this );
-static void CommandPush( vod_t *, rtsp_cmd_type_t, vod_media_t *, const char *psz_session,
-                         double f_arg, const char *psz_arg );
+static void* CommandThread( vlc_object_t *p_this );
+static void  CommandPush( vod_t *, rtsp_cmd_type_t, vod_media_t *, const char *psz_session,
+                          double f_arg, const char *psz_arg );
 
 static rtsp_client_t *RtspClientNew( vod_media_t *, char * );
 static rtsp_client_t *RtspClientGet( vod_media_t *, const char * );
@@ -255,8 +262,8 @@ static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
 static int Open( vlc_object_t *p_this )
 {
     vod_t *p_vod = (vod_t *)p_this;
-    vod_sys_t *p_sys = 0;
-    char *psz_url = 0;
+    vod_sys_t *p_sys = NULL;
+    char *psz_url = NULL;
     vlc_url_t url;
 
     psz_url = config_GetPsz( p_vod, "rtsp-host" );
@@ -297,13 +304,13 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_media_id = 0;
 
     p_vod->pf_media_new = MediaNew;
-    p_vod->pf_media_del = MediaDel;
+    p_vod->pf_media_del = MediaAskDel;
     p_vod->pf_media_add_es = MediaAddES;
     p_vod->pf_media_del_es = MediaDelES;
 
     p_sys->p_fifo_cmd = block_FifoNew();
     if( vlc_thread_create( p_vod, "rtsp vod thread", CommandThread,
-                           VLC_THREAD_PRIORITY_LOW, false ) )
+                           VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_vod, "cannot spawn rtsp vod thread" );
         block_FifoRelease( p_sys->p_fifo_cmd );
@@ -332,12 +339,24 @@ static void Close( vlc_object_t * p_this )
 {
     vod_t *p_vod = (vod_t *)p_this;
     vod_sys_t *p_sys = p_vod->p_sys;
+    block_t *p_block_cmd;
+    rtsp_cmd_t cmd;
 
     /* Stop command thread */
     vlc_object_kill( p_vod );
     CommandPush( p_vod, RTSP_CMD_TYPE_NONE, NULL, NULL, 0.0, NULL );
     vlc_thread_join( p_vod );
 
+    while( block_FifoCount( p_sys->p_fifo_cmd ) > 0 )
+    {
+         p_block_cmd = block_FifoGet( p_sys->p_fifo_cmd );
+         memcpy( &cmd, p_block_cmd->p_buffer, sizeof(cmd) );
+         block_Release( p_block_cmd );
+         if ( cmd.i_type == RTSP_CMD_TYPE_DEL )
+             MediaDel(p_vod, cmd.p_media);
+         free( cmd.psz_session );
+         free( cmd.psz_arg );
+    }
     block_FifoRelease( p_sys->p_fifo_cmd );
 
     httpd_HostDelete( p_sys->p_rtsp_host );
@@ -363,17 +382,16 @@ static void Close( vlc_object_t * p_this )
 static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
                               input_item_t *p_item )
 {
-    vod_sys_t *p_sys = p_vod->p_sys;
-    vod_media_t *p_media = malloc( sizeof(vod_media_t) );
     int i;
+    vod_sys_t *p_sys = p_vod->p_sys;
 
+    vod_media_t *p_media = calloc( 1, sizeof(vod_media_t) );
     if( !p_media )
         return NULL;
 
-    memset( p_media, 0, sizeof(vod_media_t) );
     p_media->id = p_sys->i_media_id++;
     TAB_INIT( p_media->i_es, p_media->es );
-    p_media->psz_mux = 0;
+    p_media->psz_mux = NULL;
     TAB_INIT( p_media->i_rtsp, p_media->rtsp );
     p_media->b_raw = false;
 
@@ -397,11 +415,21 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     if( asprintf( &p_media->psz_rtsp_control_v4,
                "a=control:rtsp://%%s:%d%s/trackID=%%d\r\n",
                p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
+    {
+        httpd_UrlDelete( p_media->p_rtsp_url );
+        free( p_media->psz_rtsp_path );
+        free( p_media );
         return NULL;
+    }
     if( asprintf( &p_media->psz_rtsp_control_v6,
                "a=control:rtsp://[%%s]:%d%s/trackID=%%d\r\n",
               p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
+    {
+        httpd_UrlDelete( p_media->p_rtsp_url );
+        free( p_media->psz_rtsp_path );
+        free( p_media );
         return NULL;
+    }
 
     httpd_UrlCatch( p_media->p_rtsp_url, HTTPD_MSG_SETUP,
                     RtspCallback, (void*)p_media );
@@ -418,19 +446,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
 
     p_media->p_vod = p_vod;
 
-    vlc_mutex_lock( &p_sys->lock_media );
-    TAB_APPEND( p_sys->i_media, p_sys->media, p_media );
-    vlc_mutex_unlock( &p_sys->lock_media );
-
     vlc_mutex_init( &p_media->lock );
-    p_media->psz_session_name = strdup("");
-    p_media->psz_session_description = strdup("");
-    p_media->psz_session_url = strdup("");
-    p_media->psz_session_email = strdup("");
-
-    p_media->i_port_audio = 1234;
-    p_media->i_port_video = 1236;
-    p_media->i_port       = 1238;
+
     p_media->i_payload_type = 96;
 
     p_media->i_sdp_id = mdate();
@@ -445,9 +462,15 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     }
     vlc_mutex_unlock( &p_item->lock );
 
+    CommandPush( p_vod, RTSP_CMD_TYPE_ADD, p_media, NULL, 0.0, NULL );
     return p_media;
 }
 
+static void MediaAskDel ( vod_t *p_vod, vod_media_t *p_media )
+{
+    CommandPush( p_vod, RTSP_CMD_TYPE_DEL, p_media, NULL, 0.0, NULL );
+}
+
 static void MediaDel( vod_t *p_vod, vod_media_t *p_media )
 {
     vod_sys_t *p_sys = p_vod->p_sys;
@@ -458,11 +481,12 @@ static void MediaDel( vod_t *p_vod, vod_media_t *p_media )
     TAB_REMOVE( p_sys->i_media, p_sys->media, p_media );
     vlc_mutex_unlock( &p_sys->lock_media );
 
+    httpd_UrlDelete( p_media->p_rtsp_url );
+
     while( p_media->i_rtsp > 0 )
         RtspClientDel( p_media, p_media->rtsp[0] );
     TAB_CLEAN( p_media->i_rtsp, p_media->rtsp );
 
-    httpd_UrlDelete( p_media->p_rtsp_url );
     free( p_media->psz_rtsp_path );
     free( p_media->psz_rtsp_control_v6 );
     free( p_media->psz_rtsp_control_v4 );
@@ -473,21 +497,16 @@ static void MediaDel( vod_t *p_vod, vod_media_t *p_media )
 
     vlc_mutex_destroy( &p_media->lock );
 
-    free( p_media->psz_session_name );
-    free( p_media->psz_session_description );
-    free( p_media->psz_session_url );
-    free( p_media->psz_session_email );
     free( p_media->psz_mux );
     free( p_media );
 }
 
 static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
 {
-    media_es_t *p_es = malloc( sizeof(media_es_t) );
     char *psz_urlc;
-
-    if( !p_es ) return VLC_ENOMEM;
-    memset( p_es, 0, sizeof(media_es_t) );
+    media_es_t *p_es = calloc( 1, sizeof(media_es_t) );
+    if( !p_es )
+        return VLC_ENOMEM;
 
     free( p_media->psz_mux );
     p_media->psz_mux = NULL;
@@ -503,7 +522,7 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
 
     switch( p_fmt->i_codec )
     {
-        case VLC_FOURCC( 's', '1', '6', 'b' ):
+        case VLC_CODEC_S16B:
             if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 44100 )
             {
                 p_es->i_payload_type = 11;
@@ -517,34 +536,34 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
             {
                 p_es->i_payload_type = p_media->i_payload_type++;
             }
-            p_es->psz_rtpmap = malloc( strlen( "L16/*/*" ) + 20+1 );
-            sprintf( p_es->psz_rtpmap, "L16/%d/%d", p_fmt->audio.i_rate,
-                    p_fmt->audio.i_channels );
+            if( asprintf( &p_es->psz_rtpmap, "L16/%d/%d", p_fmt->audio.i_rate,
+                          p_fmt->audio.i_channels ) == -1 )
+                p_es->psz_rtpmap = NULL;
             break;
-        case VLC_FOURCC( 'u', '8', ' ', ' ' ):
+        case VLC_CODEC_U8:
             p_es->i_payload_type = p_media->i_payload_type++;
-            p_es->psz_rtpmap = malloc( strlen( "L8/*/*" ) + 20+1 );
-            sprintf( p_es->psz_rtpmap, "L8/%d/%d", p_fmt->audio.i_rate,
-                    p_fmt->audio.i_channels );
+            if( asprintf( &p_es->psz_rtpmap, "L8/%d/%d", p_fmt->audio.i_rate,
+                          p_fmt->audio.i_channels ) == -1 )
+                p_es->psz_rtpmap = NULL;
             break;
-        case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
-        case VLC_FOURCC( 'm', 'p', '3', ' ' ):
+        case VLC_CODEC_MPGA:
             p_es->i_payload_type = 14;
             p_es->psz_rtpmap = strdup( "MPA/90000" );
             break;
-        case VLC_FOURCC( 'm', 'p', 'g', 'v' ):
+        case VLC_CODEC_MPGV:
             p_es->i_payload_type = 32;
             p_es->psz_rtpmap = strdup( "MPV/90000" );
             break;
-        case VLC_FOURCC( 'a', '5', '2', ' ' ):
+        case VLC_CODEC_A52:
             p_es->i_payload_type = p_media->i_payload_type++;
-            asprintf( &p_es->psz_rtpmap, "ac3/%d", p_fmt->audio.i_rate );
+            if( asprintf( &p_es->psz_rtpmap, "ac3/%d", p_fmt->audio.i_rate ) == -1 )
+                p_es->psz_rtpmap = NULL;
             break;
-        case VLC_FOURCC( 'H', '2', '6', '3' ):
+        case VLC_CODEC_H263:
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( "H263-1998/90000" );
             break;
-        case VLC_FOURCC( 'h', '2', '6', '4' ):
+        case VLC_CODEC_H264:
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( "H264/90000" );
             p_es->psz_fmtp = NULL;
@@ -577,11 +596,13 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
                     }
                     if( i_nal_type == 7 )
                     {
+                        free( p_64_sps );
                         p_64_sps = vlc_b64_encode_binary( &p_buffer[4], i_size - 4 );
                         sprintf_hexa( hexa, &p_buffer[5], 3 );
                     }
                     else if( i_nal_type == 8 )
                     {
+                        free( p_64_pps );
                         p_64_pps = vlc_b64_encode_binary( &p_buffer[4], i_size - 4 );
                     }
                     i_buffer -= i_size;
@@ -608,32 +629,32 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
             if( !p_es->psz_fmtp )
                 p_es->psz_fmtp = strdup( "packetization-mode=1" );
             break;
-        case VLC_FOURCC( 'm', 'p', '4', 'v' ):
+        case VLC_CODEC_MP4V:
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( "MP4V-ES/90000" );
             if( p_fmt->i_extra > 0 )
             {
                 char *p_hexa = malloc( 2 * p_fmt->i_extra + 1 );
-                p_es->psz_fmtp = malloc( 100 + 2 * p_fmt->i_extra );
                 sprintf_hexa( p_hexa, p_fmt->p_extra, p_fmt->i_extra );
-                sprintf( p_es->psz_fmtp,
-                        "profile-level-id=3; config=%s;", p_hexa );
+                if( asprintf( &p_es->psz_fmtp,
+                              "profile-level-id=3; config=%s;", p_hexa ) == -1 )
+                    p_es->psz_fmtp = NULL;
                 free( p_hexa );
             }
             break;
-        case VLC_FOURCC( 'm', 'p', '4', 'a' ):
+        case VLC_CODEC_MP4A:
             p_es->i_payload_type = p_media->i_payload_type++;
-            p_es->psz_rtpmap = malloc( strlen( "mpeg4-generic/" ) + 12 );
-            sprintf( p_es->psz_rtpmap, "mpeg4-generic/%d", p_fmt->audio.i_rate );
+            if( asprintf( &p_es->psz_rtpmap, "mpeg4-generic/%d", p_fmt->audio.i_rate ) == -1 )
+                p_es->psz_rtpmap = NULL;
             if( p_fmt->i_extra > 0 )
             {
                 char *p_hexa = malloc( 2 * p_fmt->i_extra + 1 );
-                p_es->psz_fmtp = malloc( 200 + 2 * p_fmt->i_extra );
                 sprintf_hexa( p_hexa, p_fmt->p_extra, p_fmt->i_extra );
-                sprintf( p_es->psz_fmtp,
-                        "streamtype=5; profile-level-id=15; mode=AAC-hbr; "
-                        "config=%s; SizeLength=13;IndexLength=3; "
-                        "IndexDeltaLength=3; Profile=1;", p_hexa );
+                if( asprintf( &p_es->psz_fmtp,
+                              "streamtype=5; profile-level-id=15; mode=AAC-hbr; "
+                              "config=%s; SizeLength=13;IndexLength=3; "
+                              "IndexDeltaLength=3; Profile=1;", p_hexa ) == -1 )
+                    p_es->psz_fmtp = NULL;
                 free( p_hexa );
             }
             break;
@@ -647,13 +668,13 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( "MP2P/90000" );
             break;
-        case VLC_FOURCC( 's', 'a', 'm', 'r' ):
+        case VLC_CODEC_AMR_NB:
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ?
                                     "AMR/8000/2" : "AMR/8000" );
             p_es->psz_fmtp = strdup( "octet-align=1" );
             break;
-        case VLC_FOURCC( 's', 'a', 'w', 'b' ):
+        case VLC_CODEC_AMR_WB:
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ?
                                     "AMR-WB/16000/2" : "AMR-WB/16000" );
@@ -694,34 +715,6 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
     p_es->p_vod = p_vod;
     p_es->p_media = p_media;
 
-#if 0
-    /* Choose the port */
-    if( p_fmt->i_cat == AUDIO_ES && p_media->i_port_audio > 0 )
-    {
-        p_es->i_port = p_media->i_port_audio;
-        p_media->i_port_audio = 0;
-    }
-    else if( p_fmt->i_cat == VIDEO_ES && p_media->i_port_video > 0 )
-    {
-        p_es->i_port = p_media->i_port_video;
-        p_media->i_port_video = 0;
-    }
-    while( !p_es->i_port )
-    {
-        if( p_media->i_port != p_media->i_port_audio &&
-            p_media->i_port != p_media->i_port_video )
-        {
-            p_es->i_port = p_media->i_port;
-            p_media->i_port += 2;
-            break;
-        }
-        p_media->i_port += 2;
-    }
-#else
-
-    p_es->i_port = 0;
-#endif
-
     vlc_mutex_lock( &p_media->lock );
     TAB_APPEND( p_media->i_es, p_media->es, p_es );
     vlc_mutex_unlock( &p_media->lock );
@@ -763,17 +756,6 @@ static void MediaDelES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt)
     free( p_es );
 }
 
-/* */
-typedef struct
-{
-    int i_type;
-    int i_media_id;
-    //vod_media_t *p_media;
-    char *psz_session;
-    char *psz_arg;
-    double f_arg;
-} rtsp_cmd_t;
-
 static void CommandPush( vod_t *p_vod, rtsp_cmd_type_t i_type, vod_media_t *p_media, const char *psz_session,
                          double f_arg, const char *psz_arg )
 {
@@ -782,6 +764,7 @@ static void CommandPush( vod_t *p_vod, rtsp_cmd_type_t i_type, vod_media_t *p_me
 
     memset( &cmd, 0, sizeof(cmd) );
     cmd.i_type = i_type;
+    cmd.p_media = p_media;
     if( p_media )
         cmd.i_media_id = p_media->id;
     if( psz_session )
@@ -796,10 +779,11 @@ static void CommandPush( vod_t *p_vod, rtsp_cmd_type_t i_type, vod_media_t *p_me
     block_FifoPut( p_vod->p_sys->p_fifo_cmd, p_cmd );
 }
 
-static void CommandThread( vlc_object_t *p_this )
+static void* CommandThread( vlc_object_t *p_this )
 {
     vod_t *p_vod = (vod_t*)p_this;
     vod_sys_t *p_sys = p_vod->p_sys;
+    int canc = vlc_savecancel ();
 
     while( vlc_object_alive (p_vod) )
     {
@@ -817,6 +801,20 @@ static void CommandThread( vlc_object_t *p_this )
         if( cmd.i_type == RTSP_CMD_TYPE_NONE )
             break;
 
+        if ( cmd.i_type == RTSP_CMD_TYPE_ADD )
+        {
+            vlc_mutex_lock( &p_sys->lock_media );
+            TAB_APPEND( p_sys->i_media, p_sys->media, cmd.p_media );
+            vlc_mutex_unlock( &p_sys->lock_media );
+            goto next;
+        }
+
+        if ( cmd.i_type == RTSP_CMD_TYPE_DEL )
+        {
+            MediaDel(p_vod, cmd.p_media);
+            goto next;
+        }
+
         /* */
         vlc_mutex_lock( &p_sys->lock_media );
         for( i = 0; i < p_sys->i_media; i++ )
@@ -825,7 +823,10 @@ static void CommandThread( vlc_object_t *p_this )
                 break;
         }
         if( i >= p_sys->i_media )
+        {
+            vlc_mutex_unlock( &p_sys->lock_media );
             goto next;
+        }
         p_media = p_sys->media[i];
 
         switch( cmd.i_type )
@@ -861,12 +862,15 @@ static void CommandThread( vlc_object_t *p_this )
         default:
             break;
         }
+        vlc_mutex_unlock( &p_sys->lock_media );
 
     next:
-        vlc_mutex_unlock( &p_sys->lock_media );
         free( cmd.psz_session );
         free( cmd.psz_arg );
     }
+
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 /****************************************************************************
@@ -874,10 +878,10 @@ static void CommandThread( vlc_object_t *p_this )
  ****************************************************************************/
 static rtsp_client_t *RtspClientNew( vod_media_t *p_media, char *psz_session )
 {
-    rtsp_client_t *p_rtsp = malloc( sizeof(rtsp_client_t) );
+    rtsp_client_t *p_rtsp = calloc( 1, sizeof(rtsp_client_t) );
 
-    if( !p_rtsp ) return NULL;
-    memset( p_rtsp, 0, sizeof(rtsp_client_t) );
+    if( !p_rtsp )
+        return NULL;
     p_rtsp->es = 0;
 
     p_rtsp->psz_session = psz_session;
@@ -909,12 +913,12 @@ static void RtspClientDel( vod_media_t *p_media, rtsp_client_t *p_rtsp )
     msg_Dbg( p_media->p_vod, "closing session: %s, connections: %d",
              p_rtsp->psz_session, p_media->p_vod->p_sys->i_throttle_users );
 
-    while( p_rtsp->i_es-- )
+    while( p_rtsp->i_es )
     {
-        free( p_rtsp->es[p_rtsp->i_es]->psz_ip );
+        p_rtsp->i_es--;
         free( p_rtsp->es[p_rtsp->i_es] );
-        if( !p_rtsp->i_es ) free( p_rtsp->es );
     }
+    free( p_rtsp->es );
 
     TAB_REMOVE( p_media->i_rtsp, p_media->rtsp, p_rtsp );
 
@@ -1121,9 +1125,8 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                     f_pos /= ((double)(p_media->i_length))/1000 /1000 / 100;
                     CommandPush( p_vod, RTSP_CMD_TYPE_SEEK, p_media,
                                  psz_session, f_pos, NULL );
-                    break;
                 }
-                if( psz_scale )
+                else if( psz_scale )
                 {
                     double f_scale = 0.0;
                     char *end;
@@ -1366,6 +1369,13 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                     psz_session = psz_new;
 
                     p_rtsp = RtspClientNew( p_media, psz_new );
+                    if( !p_rtsp )
+                    {
+                        answer->i_status = 454;
+                        answer->i_body = 0;
+                        answer->p_body = NULL;
+                        break;
+                    }
                 }
                 else
                 {
@@ -1388,7 +1398,6 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                     break;
                 }
                 p_rtsp_es->i_port = i_port;
-                p_rtsp_es->psz_ip = strdup( ip );
                 p_rtsp_es->p_media_es = p_es;
                 TAB_APPEND( p_rtsp->i_es, p_rtsp->es, p_rtsp_es );
 
@@ -1471,7 +1480,6 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             {
                 if( p_rtsp->es[i]->p_media_es == p_es )
                 {
-                    free( p_rtsp->es[i]->psz_ip );
                     TAB_REMOVE( p_rtsp->i_es, p_rtsp->es, p_rtsp->es[i] );
                     break;
                 }
@@ -1546,10 +1554,6 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
     /* Calculate size */
     i_size = sizeof( "v=0\r\n" ) +
         sizeof( "o=- * * IN IP4 \r\n" ) + 10 + NI_MAXNUMERICHOST +
-        sizeof( "s=*\r\n" ) + strlen( p_media->psz_session_name ) +
-        sizeof( "i=*\r\n" ) + strlen( p_media->psz_session_description ) +
-        sizeof( "u=*\r\n" ) + strlen( p_media->psz_session_url ) +
-        sizeof( "e=*\r\n" ) + strlen( p_media->psz_session_email ) +
         sizeof( "c=IN IP4 0.0.0.0\r\n" ) + 20 + 10 +
         sizeof( "t=0 0\r\n" ) + /* FIXME */
         sizeof( "a=tool:"PACKAGE_STRING"\r\n" ) +
@@ -1579,14 +1583,6 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
     p += sprintf( p, "v=0\r\n" );
     p += sprintf( p, "o=- %"PRId64" %d IN IP%c %s\r\n",
                   p_media->i_sdp_id, p_media->i_sdp_version, ipv, ip );
-    if( *p_media->psz_session_name )
-        p += sprintf( p, "s=%s\r\n", p_media->psz_session_name );
-    if( *p_media->psz_session_description )
-        p += sprintf( p, "i=%s\r\n", p_media->psz_session_description );
-    if( *p_media->psz_session_url )
-        p += sprintf( p, "u=%s\r\n", p_media->psz_session_url );
-    if( *p_media->psz_session_email )
-        p += sprintf( p, "e=%s\r\n", p_media->psz_session_email );
 
     p += sprintf( p, "c=IN IP%c %s\r\n", ipv, ipv == '6' ? "::" : "0.0.0.0" );
     p += sprintf( p, "t=0 0\r\n" ); /* FIXME */
@@ -1606,12 +1602,12 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
         if( p_es->fmt.i_cat == AUDIO_ES )
         {
             p += sprintf( p, "m=audio %d RTP/AVP %d\r\n",
-                          p_es->i_port, p_es->i_payload_type );
+                          0 /* p_es->i_port */, p_es->i_payload_type );
         }
         else if( p_es->fmt.i_cat == VIDEO_ES )
         {
             p += sprintf( p, "m=video %d RTP/AVP %d\r\n",
-                          p_es->i_port, p_es->i_payload_type );
+                          0 /* p_es->i_port */, p_es->i_payload_type );
         }
         else
         {