X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fstream_out%2Frtsp.c;h=a1cc95317051da7d790541f7943e66f8f86d9a59;hb=f90b7fec4f984a41ada5cef87e7fe39a393b558a;hp=a09e67406c153625b86b317b7448b311957f1834;hpb=b8c1216a38d25e7d261119af30bff6ad21b5c032;p=vlc diff --git a/modules/stream_out/rtsp.c b/modules/stream_out/rtsp.c index a09e67406c..a1cc953170 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 @@ -48,6 +52,7 @@ struct rtsp_stream_t httpd_host_t *host; httpd_url_t *url; char *psz_path; + unsigned track_id; unsigned port; int sessionc; @@ -68,40 +73,35 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url ) rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) ); if( rtsp == NULL || ( url->i_port > 99999 ) ) + { + free( rtsp ); return NULL; + } rtsp->owner = p_stream; rtsp->sessionc = 0; rtsp->sessionv = NULL; - vlc_mutex_init( p_stream, &rtsp->lock ); - - msg_Dbg( p_stream, "rtsp setup: %s : %d / %s\n", - url->psz_host, url->i_port, url->psz_path ); + rtsp->host = NULL; + rtsp->url = NULL; + rtsp->psz_path = NULL; + rtsp->track_id = 0; + vlc_mutex_init( &rtsp->lock ); rtsp->port = (url->i_port > 0) ? url->i_port : 554; - if( url->psz_path != NULL ) - rtsp->psz_path = strdup( url->psz_path + 1 ); - else - rtsp->psz_path = NULL; - -#if 0 - if( asprintf( &rtsp->psz_control, "rtsp://%s:%d%s", - url->psz_host, url->i_port > 0 ? url->i_port : 554, - rtsp->psz_path ) == -1 ) - { - rtsp->psz_control = NULL; + rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" ); + if( rtsp->psz_path == NULL ) goto error; - } -#endif + + msg_Dbg( p_stream, "RTSP stream: host %s port %d at %s", + url->psz_host, rtsp->port, rtsp->psz_path ); rtsp->host = httpd_HostNew( VLC_OBJECT(p_stream), url->psz_host, rtsp->port ); if( rtsp->host == NULL ) goto error; - rtsp->url = httpd_UrlNewUnique( rtsp->host, - url->psz_path ? url->psz_path : "/", NULL, - NULL, NULL ); + rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path, + NULL, NULL, NULL ); if( rtsp->url == NULL ) goto error; @@ -122,16 +122,19 @@ error: void RtspUnsetup( rtsp_stream_t *rtsp ) { - while( rtsp->sessionc > 0 ) - RtspClientDel( rtsp, rtsp->sessionv[0] ); - if( rtsp->url ) httpd_UrlDelete( rtsp->url ); + while( rtsp->sessionc > 0 ) + RtspClientDel( rtsp, rtsp->sessionv[0] ); + if( rtsp->host ) httpd_HostDelete( rtsp->host ); + free( rtsp->psz_path ); vlc_mutex_destroy( &rtsp->lock ); + + free( rtsp ); } @@ -142,7 +145,9 @@ struct rtsp_stream_id_t httpd_url_t *url; const char *dst; int ttl; - unsigned loport, hiport; + unsigned track_id; + uint32_t ssrc; + uint16_t loport, hiport; }; @@ -163,19 +168,31 @@ struct rtsp_session_t /* Unicast session track */ struct rtsp_strack_t { - sout_stream_id_t *id; - sout_access_out_t *access; - vlc_bool_t playing; + rtsp_stream_id_t *id; + int fd; + bool playing; }; +char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base ) +{ + const char *sep = strlen( base ) > 0 && base[strlen( base ) - 1] == '/' ? + "" : "/"; + char *url; + + if( asprintf( &url, "%s%strackID=%u", base, sep, id->track_id ) == -1 ) + url = NULL; + return url; +} + + rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, - unsigned num, + uint32_t ssrc, /* Multicast stuff - TODO: cleanup */ const char *dst, int ttl, unsigned loport, unsigned hiport ) { - char urlbuf[sizeof( "//trackID=123" ) + strlen( rtsp->psz_path )]; + char *urlbuf; rtsp_stream_id_t *id = malloc( sizeof( *id ) ); httpd_url_t *url; @@ -184,6 +201,8 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, id->stream = rtsp; id->sout_id = sid; + id->track_id = rtsp->track_id; + id->ssrc = ssrc; /* TODO: can we assume that this need not be strdup'd? */ id->dst = dst; if( id->dst != NULL ) @@ -193,10 +212,16 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, id->hiport = hiport; } - snprintf( urlbuf, sizeof( urlbuf ), "/%s/trackID=%u", rtsp->psz_path, - num ); - msg_Dbg( rtsp->owner, "RTSP: adding %s\n", urlbuf ); + urlbuf = RtspAppendTrackPath( id, rtsp->psz_path ); + if( urlbuf == NULL ) + { + free( id ); + return NULL; + } + + msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf ); url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL ); + free( urlbuf ); if( url == NULL ) { @@ -211,12 +236,16 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid, httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id ); httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id ); + rtsp->track_id++; + return id; } void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id ) { + httpd_UrlDelete( id->url ); + vlc_mutex_lock( &rtsp->lock ); for( int i = 0; i < rtsp->sessionc; i++ ) { @@ -224,18 +253,16 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id ) for( int j = 0; j < ses->trackc; j++ ) { - if( ses->trackv[j].id == id->sout_id ) + if( ses->trackv[j].id == id ) { rtsp_strack_t *tr = ses->trackv + j; - sout_AccessOutDelete( tr->access ); + rtp_del_sink( tr->id->sout_id, tr->fd ); REMOVE_ELEM( ses->trackv, ses->trackc, j ); - /* FIXME: are we supposed to notify the client? */ } } } vlc_mutex_unlock( &rtsp->lock ); - httpd_UrlDelete( id->url ); free( id ); } @@ -293,166 +320,13 @@ void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session ) TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session ); for( i = 0; i < session->trackc; i++ ) - { - rtp_del_sink( session->trackv[i].id, session->trackv[i].access ); - sout_AccessOutDelete( session->trackv[i].access ); - } + rtp_del_sink( session->trackv[i].id->sout_id, session->trackv[i].fd ); free( session->trackv ); free( session ); } -/** Aggregate RTSP callback */ -static int RtspCallback( httpd_callback_sys_t *p_args, - httpd_client_t *cl, - httpd_message_t *answer, - const httpd_message_t *query ) -{ - rtsp_stream_t *rtsp = (rtsp_stream_t *)p_args; - const char *psz_session = NULL, *psz; - - if( answer == NULL || query == NULL ) - { - return VLC_SUCCESS; - } - - answer->i_proto = HTTPD_PROTO_RTSP; - answer->i_version= query->i_version; - answer->i_type = HTTPD_MSG_ANSWER; - answer->i_body = 0; - answer->p_body = NULL; - - if( httpd_MsgGet( query, "Require" ) != NULL ) - { - answer->i_status = 551; - httpd_MsgAdd( answer, "Unsupported", "%s", - httpd_MsgGet( query, "Require" ) ); - } - else - switch( query->i_type ) - { - case HTTPD_MSG_DESCRIBE: - { - 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 != NULL ) ? rtsp->psz_path : "" ); - else - sprintf( control, "rtsp://%s:%u/%s", ip, rtsp->port, - ( rtsp->psz_path != NULL ) ? 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 ); - break; - } - - case HTTPD_MSG_SETUP: - answer->i_status = 459; - break; - - case HTTPD_MSG_PLAY: - { - rtsp_session_t *ses; - answer->i_status = 200; - - psz_session = httpd_MsgGet( query, "Session" ); - if( httpd_MsgGet( query, "Range" ) != NULL ) - { - answer->i_status = 456; /* cannot seek */ - break; - } - - vlc_mutex_lock( &rtsp->lock ); - ses = RtspClientGet( rtsp, psz_session ); - if( ses != NULL ) - { - for( int i = 0; i < ses->trackc; i++ ) - { - rtsp_strack_t *tr = ses->trackv + i; - if( !tr->playing ) - { - tr->playing = VLC_TRUE; - rtp_add_sink( tr->id, tr->access ); - } - } - } - vlc_mutex_unlock( &rtsp->lock ); - - if( httpd_MsgGet( query, "Scale" ) != NULL ) - httpd_MsgAdd( answer, "Scale", "1." ); - break; - } - - case HTTPD_MSG_PAUSE: - answer->i_status = 405; - httpd_MsgAdd( answer, "Allow", - "DESCRIBE, TEARDOWN, PLAY, GET_PARAMETER" ); - break; - - case HTTPD_MSG_GETPARAMETER: - if( query->i_body > 0 ) - { - answer->i_status = 451; - break; - } - - answer->i_status = 200; - break; - - case HTTPD_MSG_TEARDOWN: - { - rtsp_session_t *ses; - - /* for now only multicast so easy again */ - answer->i_status = 200; - - psz_session = httpd_MsgGet( query, "Session" ); - - vlc_mutex_lock( &rtsp->lock ); - ses = RtspClientGet( rtsp, psz_session ); - if( ses != NULL ) - RtspClientDel( rtsp, ses ); - vlc_mutex_unlock( &rtsp->lock ); - break; - } - - default: - return VLC_EGENERIC; - } - - httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); - httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); - - psz = httpd_MsgGet( query, "Cseq" ); - if( psz != NULL ) - httpd_MsgAdd( answer, "Cseq", "%s", psz ); - psz = httpd_MsgGet( query, "Timestamp" ); - if( psz != NULL ) - httpd_MsgAdd( answer, "Timestamp", "%s", psz ); - - httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" ); - - if( psz_session ) - httpd_MsgAdd( answer, "Session", "%s;timeout=5", psz_session ); - return VLC_SUCCESS; -} - - /** Finds the next transport choice */ static inline const char *transport_next( const char *str ) { @@ -479,30 +353,72 @@ static inline const char *parameter_next( const char *str ) } -/** Non-aggregate RTSP callback */ -static int RtspCallbackId( httpd_callback_sys_t *p_args, - httpd_client_t *cl, - httpd_message_t *answer, - const httpd_message_t *query ) +/** RTSP requests handler + * @param id selected track for non-aggregate URLs, + * NULL for aggregate URLs + */ +static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, + httpd_client_t *cl, + httpd_message_t *answer, + const httpd_message_t *query ) { - rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; - rtsp_stream_t *rtsp = id->stream; - sout_stream_t *p_stream = id->stream->owner; + sout_stream_t *p_stream = rtsp->owner; char psz_sesbuf[17]; - const char *psz_session, *psz; + 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 ) + 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; - psz_session = httpd_MsgGet( query, "Session" ); + httpd_MsgAdd( answer, "Server", "VLC/%s", VERSION ); + + /* 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; @@ -512,15 +428,41 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, else switch( query->i_type ) { + case HTTPD_MSG_DESCRIBE: + { /* Aggregate-only */ + if( id != NULL ) + { + answer->i_status = 460; + break; + } + + answer->i_status = 200; + httpd_MsgAdd( answer, "Content-Type", "%s", "application/sdp" ); + httpd_MsgAdd( answer, "Content-Base", "%s", control ); + 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; + } + case HTTPD_MSG_SETUP: - { + /* Non-aggregate-only */ + if( id == NULL ) + { + answer->i_status = 459; + break; + } + + psz_session = httpd_MsgGet( query, "Session" ); answer->i_status = 461; for( const char *tpt = httpd_MsgGet( query, "Transport" ); 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. */ @@ -539,12 +481,13 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, 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 ) + if( sscanf( opt, "client_port=%u-%u", &loport, &hiport ) + == 2 ) ; else if( strncmp( opt, "mode=", 5 ) == 0 ) @@ -553,7 +496,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, && strncasecmp( opt + 5, "\"PLAY\"", 6 ) ) { /* Not playing?! */ - b_unsupp = VLC_TRUE; + b_unsupp = true; break; } } @@ -561,7 +504,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, if( strncmp( opt,"destination=", 12 ) == 0 ) { answer->i_status = 403; - b_unsupp = VLC_TRUE; + b_unsupp = true; } else { @@ -578,7 +521,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, * * "interleaved" is not implemented. */ - b_unsupp = VLC_TRUE; + b_unsupp = true; break; } } @@ -592,6 +535,13 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, if( dst == NULL ) continue; + if( psz_session == NULL ) + { + /* Create a dummy session ID */ + snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%lu", + vlc_mrand48() ); + psz_session = psz_sesbuf; + } answer->i_status = 200; httpd_MsgAdd( answer, "Transport", @@ -602,10 +552,10 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, } else { - char ip[NI_MAXNUMERICHOST], url[NI_MAXNUMERICHOST + 8]; - static const char access[] = "udp{raw,rtcp}"; + char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST]; rtsp_session_t *ses = NULL; - rtsp_strack_t track = { id->sout_id, NULL, VLC_FALSE }; + rtsp_strack_t track = { id, -1, false }; + int sport; if( httpd_ClientIP( cl, ip ) == NULL ) { @@ -613,29 +563,27 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, continue; } - snprintf( url, sizeof( url ), - ( strchr( ip, ':' ) != NULL ) ? "[%s]:%d" : "%s:%d", - ip, loport ); - - track.access = sout_AccessOutNew( p_stream->p_sout, - access, url ); - if( track.access == NULL ) + track.fd = net_ConnectDgram( p_stream, ip, loport, -1, + IPPROTO_UDP ); + if( track.fd == -1 ) { msg_Err( p_stream, - "cannot create access output for %s://%s", - access, url ); + "cannot create RTP socket for %s port %u", + ip, loport ); answer->i_status = 500; continue; } - char *src = var_GetNonEmptyString( track.access, "src-addr" ); - int sport = var_GetInteger( track.access, "src-port" ); + /* Ignore any unexpected incoming packet */ + setsockopt (track.fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 }, + sizeof (int)); + net_GetSockAddress( track.fd, src, &sport ); vlc_mutex_lock( &rtsp->lock ); 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; } @@ -652,12 +600,13 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, } } - INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc, track ); + INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc, + track ); vlc_mutex_unlock( &rtsp->lock ); httpd_ServerIP( cl, ip ); - if( ( src != NULL ) && strcmp( src, ip ) ) + if( strcmp( src, ip ) ) { /* Specify source IP if it is different from the RTSP * control connection server address */ @@ -667,25 +616,25 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, httpd_MsgAdd( answer, "Transport", "RTP/AVP/UDP;unicast;source=%s;" "client_port=%u-%u;server_port=%u-%u;" - "mode=play", - src, loport, loport + 1, sport, sport + 1 ); + "ssrc=%08X;mode=play", + src, loport, loport + 1, sport, + 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; - free( src ); } break; } break; - } case HTTPD_MSG_PLAY: { @@ -693,9 +642,10 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, 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; } @@ -703,15 +653,42 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, ses = RtspClientGet( rtsp, psz_session ); if( ses != NULL ) { + /* The "trackID" part must match what is done in + * RtspAppendTrackPath() */ + /* FIXME: we really need to limit the number of tracks... */ + char info[ses->trackc * ( strlen( control ) + + sizeof("url=/trackID=123;seq=65535;" + "rtptime=4294967295, ") ) + 1]; + size_t infolen = 0; + int64_t ts = rtp_get_ts( rtsp->owner ); + for( int i = 0; i < ses->trackc; i++ ) { rtsp_strack_t *tr = ses->trackv + i; - if( !tr->playing && ( tr->id == id->sout_id ) ) + if( ( id == NULL ) || ( tr->id == id ) ) { - tr->playing = VLC_TRUE; - rtp_add_sink( tr->id, tr->access ); + uint16_t seq; + if( !tr->playing ) + { + tr->playing = true; + rtp_add_sink( tr->id->sout_id, tr->fd, false, + &seq ); + } + else + seq = rtp_get_seq( tr->id->sout_id ); + char *url = RtspAppendTrackPath( tr->id, control ); + infolen += sprintf( info + infolen, + "url=%s;seq=%u;rtptime=%u, ", + url != NULL ? url : "", seq, + rtp_compute_ts( tr->id->sout_id, ts ) ); + free( url ); } } + if( infolen > 0 ) + { + info[infolen - 2] = '\0'; /* remove trailing ", " */ + httpd_MsgAdd( answer, "RTP-Info", "%s", info ); + } } vlc_mutex_unlock( &rtsp->lock ); @@ -723,7 +700,8 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, case HTTPD_MSG_PAUSE: answer->i_status = 405; httpd_MsgAdd( answer, "Allow", - "SETUP, TEARDOWN, PLAY, GET_PARAMETER" ); + "%s, TEARDOWN, PLAY, GET_PARAMETER", + ( id != NULL ) ? "SETUP" : "DESCRIBE" ); break; case HTTPD_MSG_GETPARAMETER: @@ -733,6 +711,7 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, break; } + psz_session = httpd_MsgGet( query, "Session" ); answer->i_status = 200; break; @@ -748,12 +727,14 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, ses = RtspClientGet( rtsp, psz_session ); if( ses != NULL ) { + if( id == NULL ) /* Delete the entire session */ + RtspClientDel( rtsp, ses ); + else /* Delete one track from the session */ for( int i = 0; i < ses->trackc; i++ ) { - if( ses->trackv[i].id == id->sout_id ) + if( ses->trackv[i].id == id ) { - rtp_del_sink( id->sout_id, ses->trackv[i].access ); - sout_AccessOutDelete( ses->trackv[i].access ); + rtp_del_sink( id->sout_id, ses->trackv[i].fd ); REMOVE_ELEM( ses->trackv, ses->trackc, i ); } } @@ -763,21 +744,42 @@ static int RtspCallbackId( httpd_callback_sys_t *p_args, } default: - answer->i_status = 460; - break; + return VLC_EGENERIC; } + if( psz_session ) + httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session ); + + httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); + httpd_MsgAdd( answer, "Cache-Control", "no-cache" ); + psz = httpd_MsgGet( query, "Cseq" ); if( psz != NULL ) httpd_MsgAdd( answer, "Cseq", "%s", psz ); psz = httpd_MsgGet( query, "Timestamp" ); if( psz != NULL ) httpd_MsgAdd( answer, "Timestamp", "%s", psz ); - httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING ); - httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); - httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" ); - if( psz_session ) - httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session ); return VLC_SUCCESS; } + + +/** Aggregate RTSP callback */ +static int RtspCallback( httpd_callback_sys_t *p_args, + httpd_client_t *cl, + httpd_message_t *answer, + const httpd_message_t *query ) +{ + return RtspHandler( (rtsp_stream_t *)p_args, NULL, cl, answer, query ); +} + + +/** Non-aggregate RTSP callback */ +static int RtspCallbackId( httpd_callback_sys_t *p_args, + httpd_client_t *cl, + httpd_message_t *answer, + const httpd_message_t *query ) +{ + rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; + return RtspHandler( id->stream, id, cl, answer, query ); +}