]> git.sesse.net Git - vlc/blobdiff - modules/misc/rtsp.c
Qt: style the about dialog scrollbars
[vlc] / modules / misc / rtsp.c
index 54e3a26f2f7195f7b51d5e1d7696a563e264cdc1..333d449d8d90d918647e8661dfdbaff2f0f1632b 100644 (file)
@@ -44,7 +44,7 @@
 #include <vlc_strings.h>
 #include <vlc_rand.h>
 
-#ifndef WIN32
+#ifndef _WIN32
 # include <locale.h>
 #endif
 
 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,
@@ -113,6 +105,7 @@ typedef struct
     char *psz_session;
 
     bool b_playing; /* is it in "play" state */
+    int i_port_raw;
 
     int i_es;
     rtsp_client_es_t **es;
@@ -172,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;
 
@@ -186,6 +178,7 @@ struct vod_sys_t
     vod_media_t **media;
 
     /* */
+    vlc_thread_t thread;
     block_fifo_t *p_fifo_cmd;
 };
 
@@ -223,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 );
@@ -265,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;
@@ -279,17 +270,14 @@ 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 );
+    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 );
 
@@ -300,7 +288,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 );
@@ -331,9 +319,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 )
     {
@@ -385,8 +372,7 @@ static vod_media_t *MediaNew( vod_t *p_vod, const char *psz_name,
                   p_sys->psz_path, psz_name ) <0 )
         return NULL;
     p_media->p_rtsp_url =
-        httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, NULL,
-                            NULL, NULL );
+        httpd_UrlNew( p_sys->p_rtsp_host, p_media->psz_rtsp_path, NULL, NULL );
 
     if( !p_media->p_rtsp_url )
     {
@@ -399,8 +385,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 );
@@ -408,8 +394,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 );
@@ -691,8 +677,7 @@ static int MediaAddES( vod_t *p_vod, vod_media_t *p_media, es_format_t *p_fmt )
     }
 
     p_es->p_rtsp_url =
-        httpd_UrlNewUnique( p_vod->p_sys->p_rtsp_host, psz_urlc, NULL, NULL,
-                            NULL );
+        httpd_UrlNew( p_vod->p_sys->p_rtsp_host, psz_urlc, NULL, NULL );
 
     if( !p_es->p_rtsp_url )
     {
@@ -770,19 +755,19 @@ static void CommandPush( vod_t *p_vod, rtsp_cmd_type_t i_type, vod_media_t *p_me
     if( psz_arg )
         cmd.psz_arg = strdup(psz_arg);
 
-    p_cmd = block_New( p_vod, sizeof(rtsp_cmd_t) );
+    p_cmd = block_Alloc( sizeof(rtsp_cmd_t) );
     memcpy( p_cmd->p_buffer, &cmd, sizeof(cmd) );
 
     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;
@@ -951,7 +936,6 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
     const char *psz_session = NULL;
     const char *psz_cseq = NULL;
     rtsp_client_t *p_rtsp;
-    int i_port = 0;
     int i_cseq = 0;
 
     if( answer == NULL || query == NULL ) return VLC_SUCCESS;
@@ -982,8 +966,8 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             {
                 rtsp_client_t *p_rtsp = NULL;
                 char ip[NI_MAXNUMERICHOST];
-                i_port = atoi( strstr( psz_transport, "client_port=" ) +
-                                strlen("client_port=") );
+                int i_port = atoi( strstr( psz_transport, "client_port=" ) +
+                                   strlen("client_port=") );
 
                 if( strstr( psz_transport, "MP2T/H2221/UDP" ) ||
                     strstr( psz_transport, "RAW/RAW/UDP" ) )
@@ -992,7 +976,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;
@@ -1047,6 +1031,8 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
 
                 if( p_media->b_raw )
                 {
+                    p_rtsp->i_port_raw = i_port;
+
                     if( strstr( psz_transport, "MP2T/H2221/UDP" ) )
                     {
                         httpd_MsgAdd( answer, "Transport",
@@ -1146,7 +1132,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;
 
@@ -1165,7 +1151,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
                 {
                     if( asprintf( &psz_output,
                               "std{access=udp,dst=%s:%i,mux=%s}",
-                              ip, i_port, p_media->psz_mux ) < 0 )
+                              ip, p_rtsp->i_port_raw, p_media->psz_mux ) < 0 )
                         return VLC_ENOMEM;
                 }
                 else
@@ -1316,7 +1302,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;
@@ -1453,9 +1439,10 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
 
             for( int i = 0; i < p_rtsp->i_es; i++ )
             {
-                if( p_rtsp->es[i]->p_media_es == p_es )
+                rtsp_client_es_t *es = p_rtsp->es[i];
+                if( es->p_media_es == p_es )
                 {
-                    TAB_REMOVE( p_rtsp->i_es, p_rtsp->es, p_rtsp->es[i] );
+                    TAB_REMOVE( p_rtsp->i_es, p_rtsp->es, es );
                     break;
                 }
             }
@@ -1514,8 +1501,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 );
@@ -1570,7 +1558,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;