private bool HandleRTSPRequestAnnounce(RtspProtocol pFrom, Variant requestHeaders, string requestContent)
{
//1. Make sure we ONLY handle application/sdp
if ((string)requestHeaders[RTSP_HEADERS,RTSP_HEADERS_CONTENT_TYPE]!= RTSP_HEADERS_ACCEPT_APPLICATIONSDP)
{
FATAL("Invalid ANNOUNCE request:\n{0}", (requestHeaders.ToString()));
return false;
}
//2. Get the SDP
var sdp = pFrom.InboundSDP;
//3. Parse the SDP
if (!SDP.ParseSDP(sdp, requestContent))
{
FATAL("Unable to parse the SDP");
return false;
}
//4. Get the first video track
var videoTrack = sdp.GetVideoTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
var audioTrack = sdp.GetAudioTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
//5. Store the tracks inside the session for later use
if (audioTrack != VariantType.Null)
{
pFrom.CustomParameters["pendingTracks",audioTrack["globalTrackIndex"]] = audioTrack;
}
if (videoTrack != VariantType.Null)
{
pFrom.CustomParameters["pendingTracks",videoTrack["globalTrackIndex"]] = videoTrack;
}
//6. Mark this connection as inbound connection
pFrom.CustomParameters["isInbound"] = true;
//7. Save the streamName
string streamName = sdp.GetStreamName();
if (streamName == "")
{
streamName = $"rtsp_stream_{pFrom.Id}";
}
pFrom.CustomParameters["sdpStreamName"] = streamName;
streamName = new Uri(requestHeaders[RTSP_FIRST_LINE, RTSP_URL],UriKind.Absolute).Segments.Last();
//8. Save the bandwidth hint
pFrom.CustomParameters["sdpBandwidthHint"] = sdp.GetTotalBandwidth();
//9. Get the inbound connectivity
InboundConnectivity pInboundConnectivity = pFrom.GetInboundConnectivity(
streamName,
sdp.GetTotalBandwidth(),Application.Configuration[CONF_APPLICATION_RTCPDETECTIONINTERVAL]);
if (pInboundConnectivity == null)
{
FATAL("Unable to create inbound connectivity");
return false;
}
//8. Send back the response
pFrom.PushResponseFirstLine(RTSP_VERSION_1_0, 200, "OK");
return pFrom.SendResponseMessage();
}