X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fstream_out%2Frtsp.c;h=30e35526bc87da2150294ab9287a93cafb915265;hb=688f0a8d8913f20ac5d3e27bf4f2bbe35c9f5de7;hp=da2fc9a46bfe081ad5bbd4499688272647201c53;hpb=ed8d5bcb8798ed7257c9b8d8f3f1cf8e5c49db09;p=vlc diff --git a/modules/stream_out/rtsp.c b/modules/stream_out/rtsp.c index da2fc9a46b..30e35526bc 100644 --- a/modules/stream_out/rtsp.c +++ b/modules/stream_out/rtsp.c @@ -4,7 +4,7 @@ * Copyright (C) 2003-2004 the VideoLAN team * Copyright © 2007 Rémi Denis-Courmont * - * $Id: rtp.c 21407 2007-08-22 20:10:41Z courmisch $ + * $Id$ * * Authors: Laurent Aimar * @@ -26,7 +26,11 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include @@ -80,7 +84,7 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url ) rtsp->host = NULL; rtsp->url = NULL; rtsp->psz_path = NULL; - vlc_mutex_init( p_stream, &rtsp->lock ); + vlc_mutex_init( &rtsp->lock ); rtsp->port = (url->i_port > 0) ? url->i_port : 554; rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" ); @@ -134,6 +138,8 @@ void RtspUnsetup( rtsp_stream_t *rtsp ) free( rtsp->psz_path ); vlc_mutex_destroy( &rtsp->lock ); + + free( rtsp ); } @@ -144,7 +150,8 @@ struct rtsp_stream_id_t httpd_url_t *url; const char *dst; int ttl; - unsigned loport, hiport; + uint32_t ssrc; + uint16_t loport, hiport; }; @@ -167,12 +174,12 @@ struct rtsp_strack_t { sout_stream_id_t *id; int fd; - vlc_bool_t playing; + bool playing; }; rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, - unsigned num, + unsigned num, uint32_t ssrc, /* Multicast stuff - TODO: cleanup */ const char *dst, int ttl, unsigned loport, unsigned hiport ) @@ -186,6 +193,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, id->stream = rtsp; id->sout_id = sid; + id->ssrc = ssrc; /* TODO: can we assume that this need not be strdup'd? */ id->dst = dst; if( id->dst != NULL ) @@ -195,6 +203,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, id->hiport = hiport; } + /* FIXME: num screws up if any ES has been removed and re-added */ snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path, num ); msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf ); @@ -339,17 +348,60 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, sout_stream_t *p_stream = rtsp->owner; char psz_sesbuf[17]; const char *psz_session = NULL, *psz; + char control[sizeof("rtsp://[]:12345") + NI_MAXNUMERICHOST + + strlen( rtsp->psz_path )]; + time_t now; + + time (&now); if( answer == NULL || query == NULL || cl == NULL ) return VLC_SUCCESS; + else + { + /* Build self-referential control URL */ + char ip[NI_MAXNUMERICHOST], *ptr; + + httpd_ServerIP( cl, ip ); + ptr = strchr( ip, '%' ); + if( ptr != NULL ) + *ptr = '\0'; + + if( strchr( ip, ':' ) != NULL ) + sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port, + rtsp->psz_path ); + else + sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port, + rtsp->psz_path ); + } /* */ answer->i_proto = HTTPD_PROTO_RTSP; - answer->i_version= query->i_version; + answer->i_version= 0; answer->i_type = HTTPD_MSG_ANSWER; answer->i_body = 0; answer->p_body = NULL; + httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); + + /* Date: is always allowed, and sometimes mandatory with RTSP/2.0. */ + struct tm ut; + if (gmtime_r (&now, &ut) != NULL) + { /* RFC1123 format, GMT is mandatory */ + static const char wdays[7][4] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + static const char mons[12][4] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + httpd_MsgAdd (answer, "Date", "%s, %02u %s %04u %02u:%02u:%02u GMT", + wdays[ut.tm_wday], ut.tm_mday, mons[ut.tm_mon], + 1900 + ut.tm_year, ut.tm_hour, ut.tm_min, ut.tm_sec); + } + + if( query->i_proto != HTTPD_PROTO_RTSP ) + { + answer->i_status = 505; + } + else if( httpd_MsgGet( query, "Require" ) != NULL ) { answer->i_status = 551; @@ -367,30 +419,14 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, break; } - char ip[NI_MAXNUMERICHOST], *ptr; - char control[sizeof("rtsp://[]:12345") + sizeof( ip ) - + strlen( rtsp->psz_path )]; - - /* Build self-referential URL */ - httpd_ServerIP( cl, ip ); - ptr = strchr( ip, '%' ); - if( ptr != NULL ) - *ptr = '\0'; - - if( strchr( ip, ':' ) != NULL ) - sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port, - rtsp->psz_path ); - else - sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port, - rtsp->psz_path ); - - ptr = SDPGenerate( rtsp->owner, control ); - answer->i_status = 200; httpd_MsgAdd( answer, "Content-Type", "%s", "application/sdp" ); httpd_MsgAdd( answer, "Content-Base", "%s", control ); - answer->p_body = (uint8_t *)ptr; - answer->i_body = strlen( ptr ); + answer->p_body = (uint8_t *)SDPGenerate( rtsp->owner, control ); + if( answer->p_body != NULL ) + answer->i_body = strlen( (char *)answer->p_body ); + else + answer->i_status = 500; break; } @@ -409,7 +445,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, tpt != NULL; tpt = transport_next( tpt ) ) { - vlc_bool_t b_multicast = VLC_TRUE, b_unsupp = VLC_FALSE; + bool b_multicast = true, b_unsupp = false; unsigned loport = 5004, hiport = 5005; /* from RFC3551 */ /* Check transport protocol. */ @@ -428,10 +464,10 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, opt = parameter_next( opt ) ) { if( strncmp( opt, "multicast", 9 ) == 0) - b_multicast = VLC_TRUE; + b_multicast = true; else if( strncmp( opt, "unicast", 7 ) == 0 ) - b_multicast = VLC_FALSE; + b_multicast = false; else if( sscanf( opt, "client_port=%u-%u", &loport, &hiport ) == 2 ) @@ -443,7 +479,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, && strncasecmp( opt + 5, "\"PLAY\"", 6 ) ) { /* Not playing?! */ - b_unsupp = VLC_TRUE; + b_unsupp = true; break; } } @@ -451,7 +487,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, if( strncmp( opt,"destination=", 12 ) == 0 ) { answer->i_status = 403; - b_unsupp = VLC_TRUE; + b_unsupp = true; } else { @@ -468,7 +504,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, * * "interleaved" is not implemented. */ - b_unsupp = VLC_TRUE; + b_unsupp = true; break; } } @@ -501,7 +537,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, { char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST]; rtsp_session_t *ses = NULL; - rtsp_strack_t track = { id->sout_id, -1, VLC_FALSE }; + rtsp_strack_t track = { id->sout_id, -1, false }; int sport; if( httpd_ClientIP( cl, ip ) == NULL ) @@ -527,7 +563,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, if( psz_session == NULL ) { ses = RtspClientNew( rtsp ); - snprintf( psz_sesbuf, sizeof( psz_sesbuf ), I64Fx, + snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%"PRIx64, ses->id ); psz_session = psz_sesbuf; } @@ -560,17 +596,18 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, httpd_MsgAdd( answer, "Transport", "RTP/AVP/UDP;unicast;source=%s;" "client_port=%u-%u;server_port=%u-%u;" - "mode=play", + "ssrc=%08X;mode=play", src, loport, loport + 1, sport, - sport + 1 ); + sport + 1, id->ssrc ); } else { httpd_MsgAdd( answer, "Transport", "RTP/AVP/UDP;unicast;" "client_port=%u-%u;server_port=%u-%u;" - "mode=play", - loport, loport + 1, sport, sport + 1 ); + "ssrc=%08X;mode=play", + loport, loport + 1, sport, sport + 1, + id->ssrc ); } answer->i_status = 200; @@ -585,9 +622,10 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, answer->i_status = 200; psz_session = httpd_MsgGet( query, "Session" ); - if( httpd_MsgGet( query, "Range" ) != NULL ) + const char *range = httpd_MsgGet (query, "Range"); + if (range && strncmp (range, "npt=", 4)) { - answer->i_status = 456; /* cannot seek */ + answer->i_status = 501; break; } @@ -595,16 +633,32 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, ses = RtspClientGet( rtsp, psz_session ); if( ses != NULL ) { + /* FIXME: we really need to limit the number of tracks... */ + char info[ses->trackc * ( strlen( control ) + + sizeof("/trackID=123;seq=65535, ") ) + 1]; + size_t infolen = 0; + for( int i = 0; i < ses->trackc; i++ ) { rtsp_strack_t *tr = ses->trackv + i; - if( !tr->playing - && ( ( id == NULL ) || ( tr->id == id->sout_id ) ) ) + if( ( id == NULL ) || ( tr->id == id->sout_id ) ) { - tr->playing = VLC_TRUE; - rtp_add_sink( tr->id, tr->fd ); + if( !tr->playing ) + { + tr->playing = true; + rtp_add_sink( tr->id, tr->fd, false ); + } + infolen += sprintf( info + infolen, + "%s/trackID=%u;seq=%u, ", control, + rtp_get_num( tr->id ), + rtp_get_seq( tr->id ) ); } } + if( infolen > 0 ) + { + info[infolen - 2] = '\0'; /* remove trailing ", " */ + httpd_MsgAdd( answer, "RTP-Info", "%s", info ); + } } vlc_mutex_unlock( &rtsp->lock ); @@ -663,7 +717,6 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, return VLC_EGENERIC; } - httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); if( psz_session ) httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session );