-/** 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;
-}
-
-