#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." )
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,
char *psz_session;
bool b_playing; /* is it in "play" state */
+ int i_port_raw;
int i_es;
rtsp_client_es_t **es;
/* RTSP server */
httpd_host_t *p_rtsp_host;
char *psz_path;
- int i_port;
int i_throttle_users;
int i_connections;
vod_media_t **media;
/* */
+ vlc_thread_t thread;
block_fifo_t *p_fifo_cmd;
};
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 );
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;
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 );
p_vod->pf_media_del = MediaAskDel;
p_sys->p_fifo_cmd = block_FifoNew();
- if( vlc_thread_create( p_vod, "rtsp vod thread", 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 );
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 )
{
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 )
{
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 );
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 );
}
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 )
{
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;
switch( cmd.i_type )
{
case RTSP_CMD_TYPE_PLAY:
+ cmd.i_arg = -1;
vod_MediaControl( p_vod, p_media, cmd.psz_session,
- VOD_MEDIA_PLAY, cmd.psz_arg );
+ VOD_MEDIA_PLAY, cmd.psz_arg, &cmd.i_arg );
break;
case RTSP_CMD_TYPE_PAUSE:
+ cmd.i_arg = -1;
vod_MediaControl( p_vod, p_media, cmd.psz_session,
- VOD_MEDIA_PAUSE );
+ VOD_MEDIA_PAUSE, &cmd.i_arg );
break;
case RTSP_CMD_TYPE_STOP:
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;
{
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" ) )
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;
if( p_media->b_raw )
{
+ p_rtsp->i_port_raw = i_port;
+
if( strstr( psz_transport, "MP2T/H2221/UDP" ) )
{
httpd_MsgAdd( answer, "Transport",
break;
}
- if( httpd_ClientIP( cl, ip ) == NULL ) break;
+ if( httpd_ClientIP( cl, ip, NULL ) == NULL ) break;
p_rtsp->b_playing = true;
{
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
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;
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;
}
}
{
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 );
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;