]> git.sesse.net Git - vlc/blobdiff - modules/misc/rtsp.c
GnuTLS: plugin needs crypt32 on Windows to use the certificate store
[vlc] / modules / misc / rtsp.c
index 98999db2728a536da6085a79ac37b037cb10c751..d052bfcb09d70052dfaab69f6fed2ae6854592b1 100644 (file)
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-#define HOST_TEXT N_( "RTSP host address" )
-#define HOST_LONGTEXT N_( \
-    "This defines the address, port and path the RTSP VOD server will listen " \
-    "on.\nSyntax is address:port/path. The default is to listen on all "\
-    "interfaces (address 0.0.0.0), on port 554, with no path.\nTo listen " \
-    "only on the local interface, use \"localhost\" as address." )
-
 #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."  )
@@ -86,7 +79,6 @@ vlc_module_begin ()
     set_capability( "vod server", 1 )
     set_callbacks( Open, Close )
     add_shortcut( "rtsp" )
-    add_string ( "rtsp-host", NULL, HOST_TEXT, HOST_LONGTEXT, true )
     add_string( "rtsp-raw-mux", "ts", RAWMUX_TEXT,
                 RAWMUX_TEXT, true )
     add_integer( "rtsp-throttle-users", 0, THROTTLE_TEXT,
@@ -173,7 +165,6 @@ struct vod_sys_t
     /* RTSP server */
     httpd_host_t *p_rtsp_host;
     char *psz_path;
-    int i_port;
     int i_throttle_users;
     int i_connections;
 
@@ -187,6 +178,7 @@ struct vod_sys_t
     vod_media_t **media;
 
     /* */
+    vlc_thread_t thread;
     block_fifo_t *p_fifo_cmd;
 };
 
@@ -224,7 +216,7 @@ 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* CommandThread( void * );
 static void  CommandPush( vod_t *, rtsp_cmd_type_t, vod_media_t *,
                           const char *psz_session, int64_t i_arg,
                           double f_arg, const char *psz_arg );
@@ -266,8 +258,6 @@ static int Open( vlc_object_t *p_this )
     vlc_UrlParse( &url, psz_url, 0 );
     free( psz_url );
 
-    if( url.i_port <= 0 ) url.i_port = 554;
-
     p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) );
     if( !p_sys ) goto error;
     p_sys->p_rtsp_host = 0;
@@ -280,17 +270,21 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->psz_raw_mux = var_CreateGetString( p_this, "rtsp-raw-mux" );
 
-    p_sys->p_rtsp_host =
-        httpd_HostNew( VLC_OBJECT(p_vod), url.psz_host, url.i_port );
+    var_Create( p_vod, "rtsp-host", VLC_VAR_STRING );
+    var_SetString( p_vod, "rtsp-host", url.psz_host );
+
+    if( url.i_port <= 0 ) url.i_port = 554;
+    var_Create( p_vod, "rtsp-port", VLC_VAR_INTEGER );
+    var_SetInteger( p_vod, "rtsp-port", url.i_port );
+
+    p_sys->p_rtsp_host = vlc_rtsp_HostNew( VLC_OBJECT(p_vod) );
     if( !p_sys->p_rtsp_host )
     {
-        msg_Err( p_vod, "cannot create RTSP server (%s:%i)",
-                 url.psz_host, url.i_port );
+        msg_Err( p_vod, "cannot create RTSP server" );
         goto error;
     }
 
     p_sys->psz_path = strdup( url.psz_path ? url.psz_path : "/" );
-    p_sys->i_port = url.i_port;
 
     vlc_UrlClean( &url );
 
@@ -301,7 +295,7 @@ static int Open( vlc_object_t *p_this )
     p_vod->pf_media_del = MediaAskDel;
 
     p_sys->p_fifo_cmd = block_FifoNew();
-    if( vlc_thread_create( p_vod, CommandThread, VLC_THREAD_PRIORITY_LOW ) )
+    if( vlc_clone( &p_sys->thread, CommandThread, p_vod, VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_vod, "cannot spawn rtsp vod thread" );
         block_FifoRelease( p_sys->p_fifo_cmd );
@@ -332,9 +326,8 @@ static void Close( vlc_object_t * p_this )
     vod_sys_t *p_sys = p_vod->p_sys;
 
     /* Stop command thread */
-    vlc_object_kill( p_vod );
     CommandPush( p_vod, RTSP_CMD_TYPE_NONE, NULL, NULL, 0, 0.0, NULL );
-    vlc_thread_join( p_vod );
+    vlc_join( p_sys->thread, NULL );
 
     while( block_FifoCount( p_sys->p_fifo_cmd ) > 0 )
     {
@@ -400,8 +393,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
     msg_Dbg( p_vod, "created RTSP url: %s", p_media->psz_rtsp_path );
 
     if( asprintf( &p_media->psz_rtsp_control_v4,
-               "rtsp://%%s:%d%s/trackID=%%d",
-               p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
+                  "rtsp://%%s:%%d%s/trackID=%%d",
+                  p_media->psz_rtsp_path ) < 0 )
     {
         httpd_UrlDelete( p_media->p_rtsp_url );
         free( p_media->psz_rtsp_path );
@@ -409,8 +402,8 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
         return NULL;
     }
     if( asprintf( &p_media->psz_rtsp_control_v6,
-               "rtsp://[%%s]:%d%s/trackID=%%d",
-              p_sys->i_port, p_media->psz_rtsp_path ) < 0 )
+                  "rtsp://[%%s]:%%d%s/trackID=%%d",
+                  p_media->psz_rtsp_path ) < 0 )
     {
         httpd_UrlDelete( p_media->p_rtsp_url );
         free( p_media->psz_rtsp_path );
@@ -777,13 +770,13 @@ 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( void *obj )
 {
-    vod_t *p_vod = (vod_t*)p_this;
+    vod_t *p_vod = (vod_t*)obj;
     vod_sys_t *p_sys = p_vod->p_sys;
     int canc = vlc_savecancel ();
 
-    while( vlc_object_alive (p_vod) )
+    for( ;; )
     {
         block_t *p_block_cmd = block_FifoGet( p_sys->p_fifo_cmd );
         rtsp_cmd_t cmd;
@@ -992,7 +985,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                     p_media->b_raw = true;
                 }
 
-                if( httpd_ClientIP( cl, ip ) == NULL )
+                if( httpd_ClientIP( cl, ip, NULL ) == NULL )
                 {
                     answer->i_status = 500;
                     answer->i_body = 0;
@@ -1148,7 +1141,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                 break;
             }
 
-            if( httpd_ClientIP( cl, ip ) == NULL ) break;
+            if( httpd_ClientIP( cl, ip, NULL ) == NULL ) break;
 
             p_rtsp->b_playing = true;
 
@@ -1318,7 +1311,7 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                 int i_port = atoi( strstr( psz_transport, "client_port=" ) +
                                    strlen("client_port=") );
 
-                if( httpd_ClientIP( cl, ip ) == NULL )
+                if( httpd_ClientIP( cl, ip, NULL ) == NULL )
                 {
                     answer->i_status = 500;
                     answer->i_body = 0;
@@ -1516,8 +1509,9 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
 {
     char *psz_sdp, ip[NI_MAXNUMERICHOST];
     const char *psz_control;
+    int port;
 
-    if( httpd_ServerIP( cl, ip ) == NULL )
+    if( httpd_ServerIP( cl, ip, &port ) == NULL )
         return NULL;
 
     bool ipv6 = ( strchr( ip, ':' ) != NULL );
@@ -1572,7 +1566,7 @@ static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
                       p_es->psz_ptname, p_es->i_clock_rate, p_es->i_channels,
                       p_es->psz_fmtp );
 
-        sdp_AddAttribute( &psz_sdp, "control", psz_control, ip, i );
+        sdp_AddAttribute( &psz_sdp, "control", psz_control, ip, port, i );
     }
 
     return psz_sdp;