-/** Aggregate RTSP callback */
-static int RtspCallback( httpd_callback_sys_t *p_args,
- httpd_client_t *cl,
- httpd_message_t *answer, 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;
- }
- //fprintf( stderr, "RtspCallback query: type=%d\n", query->i_type );
-
- 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( query, "Unsupported", "%s",
- httpd_MsgGet( query, "Require" ) );
- }
- else
- switch( query->i_type )
- {
- case HTTPD_MSG_DESCRIBE:
- {
- char *psz_sdp = SDPGenerate( rtsp->owner, rtsp->psz_control );
-
- answer->i_status = 200;
- httpd_MsgAdd( answer, "Content-Type", "%s", "application/sdp" );
- httpd_MsgAdd( answer, "Content-Base", "%s", rtsp->psz_control );
- answer->p_body = (uint8_t *)psz_sdp;
- answer->i_body = strlen( psz_sdp );
- 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, PLAY, TEARDOWN" );
- 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;
-}
-
-