1 /*****************************************************************************
2 * rtsp.c: RTSP support for RTP stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2004, 2010 the VideoLAN team
5 * Copyright © 2007 Rémi Denis-Courmont
9 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include <vlc_common.h>
37 #include <vlc_httpd.h>
39 #include <vlc_charset.h>
41 #include <vlc_network.h>
56 typedef struct rtsp_session_t rtsp_session_t;
62 vod_media_t *vod_media;
70 rtsp_session_t **sessionv;
77 static int RtspCallback( httpd_callback_sys_t *p_args,
78 httpd_client_t *cl, httpd_message_t *answer,
79 const httpd_message_t *query );
80 static int RtspCallbackId( httpd_callback_sys_t *p_args,
81 httpd_client_t *cl, httpd_message_t *answer,
82 const httpd_message_t *query );
83 static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session );
85 static void RtspTimeOut( void *data );
87 rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
88 const vlc_url_t *url )
90 rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) );
92 if( rtsp == NULL || ( url->i_port > 99999 ) )
99 rtsp->vod_media = media;
101 rtsp->sessionv = NULL;
104 rtsp->psz_path = NULL;
106 vlc_mutex_init( &rtsp->lock );
108 rtsp->timeout = var_InheritInteger(owner, "rtsp-timeout");
109 if (rtsp->timeout > 0)
111 if (vlc_timer_create(&rtsp->timer, RtspTimeOut, rtsp))
115 rtsp->port = (url->i_port > 0) ? url->i_port : 554;
116 rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
117 if( rtsp->psz_path == NULL )
120 msg_Dbg( owner, "RTSP stream: host %s port %d at %s",
121 url->psz_host, rtsp->port, rtsp->psz_path );
123 rtsp->host = httpd_HostNew( VLC_OBJECT(owner), url->psz_host,
125 if( rtsp->host == NULL )
128 rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path,
130 if( rtsp->url == NULL )
133 httpd_UrlCatch( rtsp->url, HTTPD_MSG_DESCRIBE, RtspCallback, (void*)rtsp );
134 httpd_UrlCatch( rtsp->url, HTTPD_MSG_SETUP, RtspCallback, (void*)rtsp );
135 httpd_UrlCatch( rtsp->url, HTTPD_MSG_PLAY, RtspCallback, (void*)rtsp );
136 httpd_UrlCatch( rtsp->url, HTTPD_MSG_PAUSE, RtspCallback, (void*)rtsp );
137 httpd_UrlCatch( rtsp->url, HTTPD_MSG_GETPARAMETER, RtspCallback,
139 httpd_UrlCatch( rtsp->url, HTTPD_MSG_TEARDOWN, RtspCallback, (void*)rtsp );
148 void RtspUnsetup( rtsp_stream_t *rtsp )
151 httpd_UrlDelete( rtsp->url );
154 httpd_HostDelete( rtsp->host );
156 while( rtsp->sessionc > 0 )
157 RtspClientDel( rtsp, rtsp->sessionv[0] );
159 if (rtsp->timeout > 0)
160 vlc_timer_destroy(rtsp->timer);
162 free( rtsp->psz_path );
163 vlc_mutex_destroy( &rtsp->lock );
169 struct rtsp_stream_id_t
171 rtsp_stream_t *stream;
172 sout_stream_id_t *sout_id;
173 unsigned clock_rate; /* needed to compute rtptime in RTP-Info */
179 uint16_t loport, hiport;
183 typedef struct rtsp_strack_t rtsp_strack_t;
185 /* For unicast streaming */
186 struct rtsp_session_t
188 rtsp_stream_t *stream;
190 mtime_t last_seen; /* for timeouts */
191 bool vod_started; /* true if the VoD media instance was created */
193 /* output (id-access) */
195 rtsp_strack_t *trackv;
199 /* Unicast session track */
202 rtsp_stream_id_t *id;
203 sout_stream_id_t *sout_id;
204 int setup_fd; /* socket created by the SETUP request */
205 int rtp_fd; /* socket used by the RTP output */
211 static void RtspTrackClose( rtsp_strack_t *tr );
213 char *RtspAppendTrackPath( rtsp_stream_id_t *id, const char *base )
215 const char *sep = strlen( base ) > 0 && base[strlen( base ) - 1] == '/' ?
219 if( asprintf( &url, "%s%strackID=%u", base, sep, id->track_id ) == -1 )
225 rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
226 uint32_t ssrc, unsigned clock_rate,
227 /* Multicast stuff - TODO: cleanup */
228 const char *dst, int ttl,
229 unsigned loport, unsigned hiport )
232 rtsp_stream_id_t *id = malloc( sizeof( *id ) );
240 id->track_id = rtsp->track_id;
242 id->clock_rate = clock_rate;
243 /* TODO: can we assume that this need not be strdup'd? */
245 if( id->dst != NULL )
252 urlbuf = RtspAppendTrackPath( id, rtsp->psz_path );
259 msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
260 url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
269 httpd_UrlCatch( url, HTTPD_MSG_DESCRIBE, RtspCallbackId, (void *)id );
270 httpd_UrlCatch( url, HTTPD_MSG_SETUP, RtspCallbackId, (void *)id );
271 httpd_UrlCatch( url, HTTPD_MSG_PLAY, RtspCallbackId, (void *)id );
272 httpd_UrlCatch( url, HTTPD_MSG_PAUSE, RtspCallbackId, (void *)id );
273 httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id );
274 httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id );
282 void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id )
284 httpd_UrlDelete( id->url );
286 vlc_mutex_lock( &rtsp->lock );
287 for( int i = 0; i < rtsp->sessionc; i++ )
289 rtsp_session_t *ses = rtsp->sessionv[i];
291 for( int j = 0; j < ses->trackc; j++ )
293 if( ses->trackv[j].id == id )
295 rtsp_strack_t *tr = ses->trackv + j;
296 RtspTrackClose( tr );
297 REMOVE_ELEM( ses->trackv, ses->trackc, j );
302 vlc_mutex_unlock( &rtsp->lock );
307 /** rtsp must be locked */
308 static void RtspUpdateTimer( rtsp_stream_t *rtsp )
310 if (rtsp->timeout <= 0)
314 for (int i = 0; i < rtsp->sessionc; i++)
316 if (timeout == 0 || rtsp->sessionv[i]->last_seen < timeout)
317 timeout = rtsp->sessionv[i]->last_seen;
320 timeout += rtsp->timeout * CLOCK_FREQ;
321 vlc_timer_schedule(rtsp->timer, true, timeout, 0);
325 static void RtspTimeOut( void *data )
327 rtsp_stream_t *rtsp = data;
329 vlc_mutex_lock(&rtsp->lock);
330 mtime_t now = mdate();
331 for (int i = rtsp->sessionc - 1; i >= 0; i--)
333 if (rtsp->sessionv[i]->last_seen + rtsp->timeout * CLOCK_FREQ < now)
335 if (rtsp->vod_media != NULL)
338 snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%"PRIx64,
339 rtsp->sessionv[i]->id );
340 vod_stop(rtsp->vod_media, psz_sesbuf);
342 RtspClientDel(rtsp, rtsp->sessionv[i]);
345 RtspUpdateTimer(rtsp);
346 vlc_mutex_unlock(&rtsp->lock);
350 /** rtsp must be locked */
352 rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp )
354 rtsp_session_t *s = malloc( sizeof( *s ) );
359 vlc_rand_bytes (&s->id, sizeof (s->id));
360 s->vod_started = false;
364 TAB_APPEND( rtsp->sessionc, rtsp->sessionv, s );
370 /** rtsp must be locked */
372 rtsp_session_t *RtspClientGet( rtsp_stream_t *rtsp, const char *name )
382 id = strtoull( name, &end, 0x10 );
386 /* FIXME: use a hash/dictionary */
387 for( i = 0; i < rtsp->sessionc; i++ )
389 if( rtsp->sessionv[i]->id == id )
390 return rtsp->sessionv[i];
396 /** rtsp must be locked */
398 void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session )
401 TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
403 for( i = 0; i < session->trackc; i++ )
404 RtspTrackClose( &session->trackv[i] );
406 free( session->trackv );
411 /** rtsp must be locked */
412 static void RtspClientAlive( rtsp_session_t *session )
414 if (session->stream->timeout <= 0)
417 session->last_seen = mdate();
418 RtspUpdateTimer(session->stream);
422 /* Attach a starting VoD RTP id to its RTSP track, and let it
423 * initialize with the parameters of the SETUP request */
424 int RtspTrackAttach( rtsp_stream_t *rtsp, const char *name,
425 rtsp_stream_id_t *id, sout_stream_id_t *sout_id,
426 uint32_t *ssrc, uint16_t *seq_init )
428 int val = VLC_EGENERIC;
429 rtsp_session_t *session;
431 vlc_mutex_lock(&rtsp->lock);
432 session = RtspClientGet(rtsp, name);
437 for (int i = 0; session->trackc; i++)
439 rtsp_strack_t *tr = session->trackv + i;
443 #if !defined(WIN32) || defined(UNDER_CE)
444 rtp_fd = vlc_dup(tr->setup_fd);
446 WSAPROTOCOL_INFO info;
447 WSADuplicateSocket (tr->setup_fd, GetCurrentProcessId (), &info);
448 rtp_fd = WSASocket (info.iAddressFamily, info.iSocketType,
449 info.iProtocol, &info, 0, 0);
454 /* Ignore any unexpected incoming packet */
455 /* XXX: is this needed again? */
456 setsockopt (rtp_fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 },
460 *ssrc = ntohl(tr->ssrc);
461 *seq_init = tr->seq_init;
462 rtp_add_sink(sout_id, rtp_fd, false, &seq);
463 /* To avoid race conditions, sout_id->i_seq_sent_next must
464 * be set here and now. Make sure the caller did its job
465 * properly when passing seq_init. */
466 assert(tr->seq_init == seq);
469 tr->sout_id = sout_id;
478 vlc_mutex_unlock(&rtsp->lock);
483 /* Remove references to the RTP id when it is stopped */
484 void RtspTrackDetach( rtsp_stream_t *rtsp, const char *name,
485 sout_stream_id_t *sout_id )
487 rtsp_session_t *session;
489 vlc_mutex_lock(&rtsp->lock);
490 session = RtspClientGet(rtsp, name);
495 for (int i = 0; session->trackc; i++)
497 rtsp_strack_t *tr = session->trackv + i;
498 if (tr->sout_id == sout_id)
502 rtp_del_sink(sout_id, tr->rtp_fd);
508 vlc_mutex_unlock(&rtsp->lock);
512 /** rtsp must be locked */
513 static void RtspTrackClose( rtsp_strack_t *tr )
515 if (tr->sout_id != NULL)
516 rtp_del_sink(tr->sout_id, tr->rtp_fd);
517 /* rtp_fd is duplicated from setup_fd only in VoD mode. */
518 if (tr->id->stream->vod_media != NULL)
519 net_Close(tr->setup_fd);
523 /** Finds the next transport choice */
524 static inline const char *transport_next( const char *str )
526 /* Looks for comma */
527 str = strchr( str, ',' );
529 return NULL; /* No more transport options */
531 str++; /* skips comma */
532 while( strchr( "\r\n\t ", *str ) )
535 return (*str) ? str : NULL;
539 /** Finds the next transport parameter */
540 static inline const char *parameter_next( const char *str )
542 while( strchr( ",;", *str ) == NULL )
545 return (*str == ';') ? (str + 1) : NULL;
549 static int64_t ParseNPT (const char *str)
551 locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
552 locale_t oldloc = uselocale (loc);
556 if (sscanf (str, "%u:%u:%f", &hour, &min, &sec) == 3)
557 sec += ((hour * 60) + min) * 60;
559 if (sscanf (str, "%f", &sec) != 1)
562 if (loc != (locale_t)0)
567 return sec * CLOCK_FREQ;
571 /** RTSP requests handler
572 * @param id selected track for non-aggregate URLs,
573 * NULL for aggregate URLs
575 static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
577 httpd_message_t *answer,
578 const httpd_message_t *query )
580 vlc_object_t *owner = rtsp->owner;
582 const char *psz_session = NULL, *psz;
583 char control[sizeof("rtsp://[]:12345") + NI_MAXNUMERICHOST
584 + strlen( rtsp->psz_path )];
585 bool vod = rtsp->vod_media != NULL;
590 if( answer == NULL || query == NULL || cl == NULL )
594 /* Build self-referential control URL */
595 char ip[NI_MAXNUMERICHOST], *ptr;
597 httpd_ServerIP( cl, ip );
598 ptr = strchr( ip, '%' );
602 if( strchr( ip, ':' ) != NULL )
603 sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port,
606 sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port,
611 answer->i_proto = HTTPD_PROTO_RTSP;
612 answer->i_version= 0;
613 answer->i_type = HTTPD_MSG_ANSWER;
615 answer->p_body = NULL;
617 httpd_MsgAdd( answer, "Server", "VLC/%s", VERSION );
619 /* Date: is always allowed, and sometimes mandatory with RTSP/2.0. */
621 if (gmtime_r (&now, &ut) != NULL)
622 { /* RFC1123 format, GMT is mandatory */
623 static const char wdays[7][4] = {
624 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
625 static const char mons[12][4] = {
626 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
627 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
628 httpd_MsgAdd (answer, "Date", "%s, %02u %s %04u %02u:%02u:%02u GMT",
629 wdays[ut.tm_wday], ut.tm_mday, mons[ut.tm_mon],
630 1900 + ut.tm_year, ut.tm_hour, ut.tm_min, ut.tm_sec);
633 if( query->i_proto != HTTPD_PROTO_RTSP )
635 answer->i_status = 505;
638 if( httpd_MsgGet( query, "Require" ) != NULL )
640 answer->i_status = 551;
641 httpd_MsgAdd( answer, "Unsupported", "%s",
642 httpd_MsgGet( query, "Require" ) );
645 switch( query->i_type )
647 case HTTPD_MSG_DESCRIBE:
648 { /* Aggregate-only */
651 answer->i_status = 460;
655 answer->i_status = 200;
656 httpd_MsgAdd( answer, "Content-Type", "%s", "application/sdp" );
657 httpd_MsgAdd( answer, "Content-Base", "%s", control );
659 answer->p_body = (uint8_t *) ( vod ?
660 SDPGenerateVoD( rtsp->vod_media, control ) :
661 SDPGenerate( (sout_stream_t *)owner, control ) );
662 if( answer->p_body != NULL )
663 answer->i_body = strlen( (char *)answer->p_body );
665 answer->i_status = 500;
669 case HTTPD_MSG_SETUP:
670 /* Non-aggregate-only */
673 answer->i_status = 459;
677 psz_session = httpd_MsgGet( query, "Session" );
678 answer->i_status = 461;
680 for( const char *tpt = httpd_MsgGet( query, "Transport" );
682 tpt = transport_next( tpt ) )
684 bool b_multicast = true, b_unsupp = false;
685 unsigned loport = 5004, hiport = 5005; /* from RFC3551 */
687 /* Check transport protocol. */
688 /* Currently, we only support RTP/AVP over UDP */
689 if( strncmp( tpt, "RTP/AVP", 7 ) )
692 if( strncmp( tpt, "/UDP", 4 ) == 0 )
694 if( strchr( ";,", *tpt ) == NULL )
697 /* Parse transport options */
698 for( const char *opt = parameter_next( tpt );
700 opt = parameter_next( opt ) )
702 if( strncmp( opt, "multicast", 9 ) == 0)
705 if( strncmp( opt, "unicast", 7 ) == 0 )
708 if( sscanf( opt, "client_port=%u-%u", &loport, &hiport )
712 if( strncmp( opt, "mode=", 5 ) == 0 )
714 if( strncasecmp( opt + 5, "play", 4 )
715 && strncasecmp( opt + 5, "\"PLAY\"", 6 ) )
723 if( strncmp( opt,"destination=", 12 ) == 0 )
725 answer->i_status = 403;
731 * Every other option is unsupported:
733 * "source" and "append" are invalid (server-only);
734 * "ssrc" also (as clarified per RFC2326bis).
736 * For multicast, "port", "layers", "ttl" are set by the
737 * stream output configuration.
739 * For unicast, we want to decide "server_port" values.
741 * "interleaved" is not implemented.
753 const char *dst = id->dst;
757 if( psz_session == NULL )
759 /* Create a dummy session ID */
760 snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%lu",
762 psz_session = psz_sesbuf;
764 answer->i_status = 200;
766 httpd_MsgAdd( answer, "Transport",
767 "RTP/AVP/UDP;destination=%s;port=%u-%u;"
769 dst, id->loport, id->hiport,
770 ( id->ttl > 0 ) ? id->ttl : 1 );
774 char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST];
775 rtsp_session_t *ses = NULL;
779 if( httpd_ClientIP( cl, ip ) == NULL )
781 answer->i_status = 500;
785 fd = net_ConnectDgram( owner, ip, loport, -1,
790 "cannot create RTP socket for %s port %u",
792 answer->i_status = 500;
796 /* Ignore any unexpected incoming packet */
797 setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 },
799 net_GetSockAddress( fd, src, &sport );
801 rtsp_strack_t track = { .id = id, .sout_id = id->sout_id,
802 .setup_fd = fd, .playing = false };
806 vlc_rand_bytes (&track.seq_init, sizeof (track.seq_init));
807 vlc_rand_bytes (&track.ssrc, sizeof (track.ssrc));
812 track.rtp_fd = track.setup_fd;
816 vlc_mutex_lock( &rtsp->lock );
817 if( psz_session == NULL )
819 ses = RtspClientNew( rtsp );
820 snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%"PRIx64,
822 psz_session = psz_sesbuf;
826 /* FIXME: we probably need to remove an access out,
827 * if there is already one for the same ID */
828 ses = RtspClientGet( rtsp, psz_session );
831 answer->i_status = 454;
832 vlc_mutex_unlock( &rtsp->lock );
837 RtspClientAlive(ses);
839 INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc,
841 vlc_mutex_unlock( &rtsp->lock );
843 httpd_ServerIP( cl, ip );
845 if( strcmp( src, ip ) )
847 /* Specify source IP if it is different from the RTSP
848 * control connection server address */
849 char *ptr = strchr( src, '%' );
850 if( ptr != NULL ) *ptr = '\0'; /* remove scope ID */
852 httpd_MsgAdd( answer, "Transport",
853 "RTP/AVP/UDP;unicast;source=%s;"
854 "client_port=%u-%u;server_port=%u-%u;"
855 "ssrc=%08X;mode=play",
856 src, loport, loport + 1, sport,
861 httpd_MsgAdd( answer, "Transport",
862 "RTP/AVP/UDP;unicast;"
863 "client_port=%u-%u;server_port=%u-%u;"
864 "ssrc=%08X;mode=play",
865 loport, loport + 1, sport, sport + 1,
869 answer->i_status = 200;
878 answer->i_status = 200;
880 psz_session = httpd_MsgGet( query, "Session" );
881 const char *range = httpd_MsgGet (query, "Range");
882 if (range != NULL && strncmp (range, "npt=", 4))
884 answer->i_status = 501;
888 vlc_mutex_lock( &rtsp->lock );
889 ses = RtspClientGet( rtsp, psz_session );
892 /* The "trackID" part must match what is done in
893 * RtspAppendTrackPath() */
894 /* FIXME: we really need to limit the number of tracks... */
895 char info[ses->trackc * ( strlen( control )
896 + sizeof("url=/trackID=123;seq=65535;"
897 "rtptime=4294967295, ") ) + 1];
899 RtspClientAlive(ses);
901 sout_stream_id_t *sout_id = NULL;
904 /* We don't keep a reference to the sout_stream_t,
905 * so we check if a sout_id is available instead.
906 * FIXME: this is broken if the stream is still
907 * running but with no track set up; but this case
908 * is already broken anyway (see below). */
909 for (int i = 0; i < ses->trackc; i++)
911 sout_id = ses->trackv[i].sout_id;
916 int64_t ts = rtp_get_ts(vod ? NULL : (sout_stream_t *)owner,
917 sout_id, rtsp->vod_media, psz_session);
919 for( int i = 0; i < ses->trackc; i++ )
921 rtsp_strack_t *tr = ses->trackv + i;
922 if( ( id == NULL ) || ( tr->id == id ) )
928 /* TODO: if the RTP stream output is already
929 * started, it won't pick up newly set-up
930 * tracks, so we need to call rtp_add_sink()
936 rtp_add_sink( tr->sout_id, tr->rtp_fd,
942 assert( tr->sout_id != NULL );
943 seq = rtp_get_seq( tr->sout_id );
945 char *url = RtspAppendTrackPath( tr->id, control );
946 infolen += sprintf( info + infolen,
947 "url=%s;seq=%u;rtptime=%u, ",
948 url != NULL ? url : "", seq,
949 rtp_compute_ts( tr->id->clock_rate, ts ) );
955 info[infolen - 2] = '\0'; /* remove trailing ", " */
956 httpd_MsgAdd( answer, "RTP-Info", "%s", info );
960 /* TODO: fix that crap, this is barely RTSP */
961 if (!ses->vod_started)
963 vod_start(rtsp->vod_media, psz_session);
964 ses->vod_started = true;
970 int64_t time = ParseNPT (range + 4);
971 vod_seek(rtsp->vod_media, psz_session, time);
973 /* This is the thing to do to unpause... */
974 vod_start(rtsp->vod_media, psz_session);
978 vlc_mutex_unlock( &rtsp->lock );
980 if( httpd_MsgGet( query, "Scale" ) != NULL )
981 httpd_MsgAdd( answer, "Scale", "1." );
985 case HTTPD_MSG_PAUSE:
989 answer->i_status = 405;
990 httpd_MsgAdd( answer, "Allow",
991 "%s, TEARDOWN, PLAY, GET_PARAMETER",
992 ( id != NULL ) ? "SETUP" : "DESCRIBE" );
997 answer->i_status = 200;
998 psz_session = httpd_MsgGet( query, "Session" );
999 vlc_mutex_lock( &rtsp->lock );
1000 ses = RtspClientGet( rtsp, psz_session );
1003 vod_pause(rtsp->vod_media, psz_session);
1004 RtspClientAlive(ses);
1006 vlc_mutex_unlock( &rtsp->lock );
1010 case HTTPD_MSG_GETPARAMETER:
1011 if( query->i_body > 0 )
1013 answer->i_status = 451;
1017 psz_session = httpd_MsgGet( query, "Session" );
1018 answer->i_status = 200;
1019 vlc_mutex_lock( &rtsp->lock );
1020 rtsp_session_t *ses = RtspClientGet( rtsp, psz_session );
1022 RtspClientAlive(ses);
1023 vlc_mutex_unlock( &rtsp->lock );
1026 case HTTPD_MSG_TEARDOWN:
1028 rtsp_session_t *ses;
1030 answer->i_status = 200;
1032 psz_session = httpd_MsgGet( query, "Session" );
1034 vlc_mutex_lock( &rtsp->lock );
1035 ses = RtspClientGet( rtsp, psz_session );
1038 if( id == NULL ) /* Delete the entire session */
1040 RtspClientDel( rtsp, ses );
1042 vod_stop(rtsp->vod_media, psz_session);
1043 RtspUpdateTimer(rtsp);
1045 else /* Delete one track from the session */
1047 for( int i = 0; i < ses->trackc; i++ )
1049 if( ses->trackv[i].id == id )
1051 RtspTrackClose( &ses->trackv[i] );
1052 REMOVE_ELEM( ses->trackv, ses->trackc, i );
1055 RtspClientAlive(ses);
1058 vlc_mutex_unlock( &rtsp->lock );
1063 return VLC_EGENERIC;
1068 if (rtsp->timeout > 0)
1069 httpd_MsgAdd( answer, "Session", "%s;timeout=%d", psz_session,
1072 httpd_MsgAdd( answer, "Session", "%s", psz_session );
1075 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
1076 httpd_MsgAdd( answer, "Cache-Control", "no-cache" );
1078 psz = httpd_MsgGet( query, "Cseq" );
1080 httpd_MsgAdd( answer, "Cseq", "%s", psz );
1081 psz = httpd_MsgGet( query, "Timestamp" );
1083 httpd_MsgAdd( answer, "Timestamp", "%s", psz );
1089 /** Aggregate RTSP callback */
1090 static int RtspCallback( httpd_callback_sys_t *p_args,
1092 httpd_message_t *answer,
1093 const httpd_message_t *query )
1095 return RtspHandler( (rtsp_stream_t *)p_args, NULL, cl, answer, query );
1099 /** Non-aggregate RTSP callback */
1100 static int RtspCallbackId( httpd_callback_sys_t *p_args,
1102 httpd_message_t *answer,
1103 const httpd_message_t *query )
1105 rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args;
1106 return RtspHandler( id->stream, id, cl, answer, query );