/*****************************************************************************
* rtsp.c: rtsp VoD server module
*****************************************************************************
- * Copyright (C) 2003-2004 VideoLAN
+ * Copyright (C) 2003-2004 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
#define HOST_TEXT N_( "Host address" )
#define HOST_LONGTEXT N_( \
- "You can set the address, port and path the rtsp interface will bind to." )
-
+ "You can set the address, port and path the rtsp interface will bind to." \
+ "\n Syntax is address:port/path. Default is to bind to any address "\
+ "on port 554, with no path." )
vlc_module_begin();
+ set_shortname( _("RTSP VoD" ) );
set_description( _("RTSP VoD server") );
set_category( CAT_SOUT );
set_subcategory( SUBCAT_SOUT_VOD );
char *psz_rtsp_control;
char *psz_rtsp_path;
- char *psz_destination;
int i_port;
int i_port_audio;
int i_port_video;
static int RtspCallbackES( httpd_callback_sys_t *, httpd_client_t *,
httpd_message_t *, httpd_message_t * );
-static char *SDPGenerate( vod_media_t *, char * );
+static char *SDPGenerate( const vod_media_t *, httpd_client_t *cl );
static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
{
vlc_UrlParse( &url, psz_url, 0 );
if( psz_url ) free( psz_url );
- if( !url.psz_host || !*url.psz_host )
- {
- if( url.psz_host ) free( url.psz_host );
- url.psz_host = strdup( "localhost" );
- }
if( url.i_port <= 0 ) url.i_port = 554;
p_vod->p_sys = p_sys = malloc( sizeof( vod_sys_t ) );
asprintf( &p_media->psz_rtsp_path, "%s%s", p_sys->psz_path, psz_name );
p_media->p_rtsp_url =
- httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, 0, 0 );
+ httpd_UrlNewUnique( p_sys->p_rtsp_host, p_media->psz_rtsp_path, NULL,
+ NULL, NULL );
if( !p_media->p_rtsp_url )
{
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' ):
+ 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' ):
+ 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" );
+ p_es->psz_fmtp = strdup( "octet-align=1" );
+ break;
default:
msg_Err( p_vod, "cannot add this stream (unsupported "
}
p_es->p_rtsp_url =
- httpd_UrlNewUnique( p_vod->p_sys->p_rtsp_host, psz_urlc, 0, 0 );
+ httpd_UrlNewUnique( p_vod->p_sys->p_rtsp_host, psz_urlc, NULL, NULL,
+ NULL );
if( !p_es->p_rtsp_url )
{
{
vod_media_t *p_media = (vod_media_t*)p_args;
vod_t *p_vod = p_media->p_vod;
- char *psz_destination = p_media->psz_destination;
char *psz_session = NULL;
rtsp_client_t *p_rtsp;
case HTTPD_MSG_DESCRIBE:
{
char *psz_sdp =
- SDPGenerate( p_media, psz_destination ?
- psz_destination : "0.0.0.0" );
+ SDPGenerate( p_media, cl );
answer->i_status = 200;
answer->psz_status = strdup( "OK" );
httpd_MsgAdd( answer, "Content-type", "%s", "application/sdp" );
- answer->p_body = psz_sdp;
+ answer->p_body = (uint8_t *)psz_sdp;
answer->i_body = strlen( psz_sdp );
break;
}
case HTTPD_MSG_PLAY:
{
- char *psz_output, *ip;
+ char *psz_output, ip[NI_MAXNUMERICHOST];
int i, i_port_audio = 0, i_port_video = 0;
/* for now only multicast so easy */
}
else if( p_rtsp->b_playing ) break;
- if( !(ip = httpd_ClientIP( cl )) ) break;
+ if( httpd_ClientIP( cl, ip ) == NULL ) break;
p_rtsp->b_playing = VLC_TRUE;
vod_MediaControl( p_vod, p_media, psz_session, VOD_MEDIA_PLAY,
psz_output );
free( psz_output );
- free( ip );
break;
}
psz_transport = httpd_MsgGet( query, "Transport" );
fprintf( stderr, "HTTPD_MSG_SETUP: transport=%s\n", psz_transport );
- if( strstr( psz_transport, "multicast" ) && p_media->psz_destination )
- {
- fprintf( stderr, "HTTPD_MSG_SETUP: multicast\n" );
- answer->i_status = 200;
- answer->psz_status = strdup( "OK" );
- answer->i_body = 0;
- answer->p_body = NULL;
-
- psz_session = httpd_MsgGet( query, "Session" );
- if( !psz_session || !*psz_session )
- {
- asprintf( &psz_session, "%d", rand() );
- }
-
- httpd_MsgAdd( answer, "Transport",
- "RTP/AVP/UDP;destination=%s;port=%d-%d;ttl=%d",
- p_media->psz_destination, p_media->i_port,
- p_media->i_port+1, p_media->i_ttl );
- }
- else if( strstr( psz_transport, "unicast" ) &&
- strstr( psz_transport, "client_port=" ) )
+ if( strstr( psz_transport, "unicast" ) &&
+ strstr( psz_transport, "client_port=" ) )
{
rtsp_client_t *p_rtsp;
rtsp_client_es_t *p_rtsp_es;
- char *ip = httpd_ClientIP( cl );
+ char ip[NI_MAXNUMERICHOST];
int i_port = atoi( strstr( psz_transport, "client_port=" ) +
strlen("client_port=") );
- if( !ip )
+ if( httpd_ClientIP( cl, ip ) == NULL )
{
- answer->i_status = 400;
+ answer->i_status = 500;
answer->psz_status = strdup( "Internal server error" );
answer->i_body = 0;
answer->p_body = NULL;
if( !p_rtsp )
{
/* FIXME right error code */
- answer->i_status = 400;
+ answer->i_status = 454;
answer->psz_status = strdup( "Unknown session id" );
answer->i_body = 0;
answer->p_body = NULL;
}
else /* TODO strstr( psz_transport, "interleaved" ) ) */
{
- answer->i_status = 400;
- answer->psz_status = strdup( "Bad Request" );
+ answer->i_status = 461;
+ answer->psz_status = strdup( "Unsupported Transport" );
answer->i_body = 0;
answer->p_body = NULL;
}
break;
case HTTPD_MSG_PLAY:
+ /* This is kind of a kludge. Should we only support Aggregate
+ * Operations ? */
psz_session = httpd_MsgGet( query, "Session" );
msg_Dbg( p_vod, "HTTPD_MSG_PLAY for session: %s", psz_session );
}
}
- answer->i_status = 460;
- answer->psz_status = strdup( "Only Aggregate Operation Allowed" );
+ answer->i_status = 200;
+ answer->psz_status = strdup( "OK" );
answer->i_body = 0;
answer->p_body = NULL;
break;
case HTTPD_MSG_PAUSE:
+ /* This is kind of a kludge. Should we only support Aggregate
+ * Operations ? */
psz_session = httpd_MsgGet( query, "Session" );
msg_Dbg( p_vod, "HTTPD_MSG_PAUSE for session: %s", psz_session );
- answer->i_status = 460;
- answer->psz_status = strdup( "Only Aggregate Operation Allowed" );
+ p_rtsp = RtspClientGet( p_media, psz_session );
+ if( !p_rtsp ) break;
+
+ vod_MediaControl( p_vod, p_media, psz_session, VOD_MEDIA_PAUSE );
+ p_rtsp->b_paused = VLC_TRUE;
+
+ answer->i_status = 200;
+ answer->psz_status = strdup( "OK" );
answer->i_body = 0;
answer->p_body = NULL;
break;
* SDPGenerate: TODO
* FIXME: need to be moved to a common place ?
*****************************************************************************/
-static char *SDPGenerate( vod_media_t *p_media, char *psz_destination )
+static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
{
int i, i_size;
- char *p, *psz_sdp;
+ char *p, *psz_sdp, *ip;
/* Calculate size */
i_size = strlen( "v=0\r\n" ) +
strlen( "e=*\r\n" ) + strlen( p_media->psz_session_email ) +
strlen( "t=0 0\r\n" ) + /* FIXME */
strlen( "a=tool:"PACKAGE_STRING"\r\n" ) +
- strlen( "c=IN IP4 */*\r\n" ) + 20 + 10 +
- strlen( psz_destination ? psz_destination : "0.0.0.0" ) +
+ strlen( "c=IN IPn */*\r\n" ) + 20 + 10 + NI_MAXNUMERICHOST +
strlen( "a=range:npt=0-1000000000.000\r\n" );
for( i = 0; i < p_media->i_es; i++ )
p += sprintf( p, "t=0 0\r\n" ); /* FIXME */
p += sprintf( p, "a=tool:"PACKAGE_STRING"\r\n" );
- p += sprintf( p, "c=IN IP4 %s/%d\r\n", psz_destination ?
- psz_destination : "0.0.0.0", p_media->i_ttl );
+ p += sprintf( p, "c=IN IP4 0.0.0.0\r\n" );
if( p_media->i_length > 0 )
p += sprintf( p, "a=range:npt=0-%.3f\r\n",