- sout_stream_t *p_stream = (sout_stream_t*)p_args;
- sout_stream_sys_t *p_sys = p_stream->p_sys;
- char *psz_destination = p_sys->psz_destination;
- char *psz_session = NULL;
- char *psz_cseq = NULL;
- int i_cseq = 0;
-
- 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;
-
- switch( query->i_type )
- {
- case HTTPD_MSG_DESCRIBE:
- {
- char *psz_sdp = SDPGenerate( p_stream, psz_destination ? psz_destination : "0.0.0.0", VLC_TRUE );
-
- answer->i_status = 200;
- answer->psz_status = strdup( "OK" );
- httpd_MsgAdd( answer, "Content-type", "%s", "application/sdp" );
-
- answer->p_body = (uint8_t *)psz_sdp;
- answer->i_body = strlen( psz_sdp );
- break;
- }
-
- case HTTPD_MSG_PLAY:
- {
- rtsp_client_t *rtsp;
- /* for now only multicast so easy */
- answer->i_status = 200;
- answer->psz_status = strdup( "OK" );
- answer->i_body = 0;
- answer->p_body = NULL;
-
- psz_session = httpd_MsgGet( query, "Session" );
- rtsp = RtspClientGet( p_stream, psz_session );
- if( rtsp && !rtsp->b_playing )
- {
- int i_id;
- /* FIXME */
- rtsp->b_playing = VLC_TRUE;
-
- vlc_mutex_lock( &p_sys->lock_es );
- for( i_id = 0; i_id < rtsp->i_id; i_id++ )
- {
- sout_stream_id_t *id = rtsp->id[i_id];
- int i;
-
- for( i = 0; i < p_sys->i_es; i++ )
- {
- if( id == p_sys->es[i] )
- break;
- }
- if( i >= p_sys->i_es ) continue;
-
- vlc_mutex_lock( &id->lock_rtsp );
- TAB_APPEND( id->i_rtsp_access, id->rtsp_access, rtsp->access[i_id] );
- vlc_mutex_unlock( &id->lock_rtsp );
- }
- vlc_mutex_unlock( &p_sys->lock_es );
- }
- break;
- }
- case HTTPD_MSG_PAUSE:
- /* FIXME */
- return VLC_EGENERIC;
- case HTTPD_MSG_TEARDOWN:
- {
- rtsp_client_t *rtsp;
-
- /* for now only multicast so easy again */
- answer->i_status = 200;
- answer->psz_status = strdup( "OK" );
- answer->i_body = 0;
- answer->p_body = NULL;
-
- psz_session = httpd_MsgGet( query, "Session" );
- rtsp = RtspClientGet( p_stream, psz_session );
- if( rtsp )
- {
- int i_id;
-
- vlc_mutex_lock( &p_sys->lock_es );
- for( i_id = 0; i_id < rtsp->i_id; i_id++ )
- {
- sout_stream_id_t *id = rtsp->id[i_id];
- int i;
-
- for( i = 0; i < p_sys->i_es; i++ )
- {
- if( id == p_sys->es[i] )
- break;
- }
- if( i >= p_sys->i_es ) continue;
-
- vlc_mutex_lock( &id->lock_rtsp );
- TAB_REMOVE( id->i_rtsp_access, id->rtsp_access, rtsp->access[i_id] );
- vlc_mutex_unlock( &id->lock_rtsp );
- }
- vlc_mutex_unlock( &p_sys->lock_es );
-
- RtspClientDel( p_stream, rtsp );
- }
- break;
- }
-
- default:
- return VLC_EGENERIC;
- }
- httpd_MsgAdd( answer, "Server", PACKAGE_STRING );
- httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
- psz_cseq = httpd_MsgGet( query, "Cseq" );
- if( psz_cseq )
- i_cseq = atoi( psz_cseq );
- else
- i_cseq = 0;
- httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
- httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
-
- if( psz_session )
- {
- httpd_MsgAdd( answer, "Session", "%s;timeout=5", psz_session );
- }