CSharpRTMP.Core.Protocols.Rtsp.BaseRtspAppProtocolHandler.HandleRTSPRequestSetupInbound C# (CSharp) Method

HandleRTSPRequestSetupInbound() private method

private HandleRTSPRequestSetupInbound ( RtspProtocol @from, Variant requestHeaders, string requestContent ) : bool
@from RtspProtocol
requestHeaders Variant
requestContent string
return bool
        private bool HandleRTSPRequestSetupInbound(RtspProtocol @from, Variant requestHeaders, string requestContent)
        {
            //1. get the transport line and split it into parts
            if (requestHeaders[RTSP_HEADERS, RTSP_HEADERS_TRANSPORT] == null)
            {
                FATAL("No transport line");
                return false;
            }
            string transportLine = requestHeaders[RTSP_HEADERS, RTSP_HEADERS_TRANSPORT];
            Variant transport = Variant.Get();
            if (!SDP.ParseTransportLine(transportLine, transport))
            {
                FATAL("Unable to parse transport line");
                return false;
            }

            //2. Check and see if it has RTP/AVP/TCP,RTP/AVP/UDP or RTP/AVP
            if ((transport["rtp/avp/tcp"] == null)
                    && (transport["rtp/avp/udp"] == null)
                    && (transport["rtp/avp"] == null))
            {
                FATAL("Invalid transport line: {0}", (transportLine));
                return false;
            }

            //3. Check to see if it has either client_port OR interleaved
            if ((transport["client_port"] == null)
                    && (transport["interleaved"] == null))
            {
                FATAL("Invalid transport line: {0}", (transportLine));
                return false;
            }
            if ((transport["client_port"] != null)
                    && (transport["interleaved"]!=null))
            {
                FATAL("Invalid transport line: {0}", (transportLine));
                return false;
            }

            //4. Get the InboundConnectivity
            InboundConnectivity pConnectivity = from.InboundConnectivity;

            //4. Find the track inside the pendingTracks collection and setup the ports or channels
            if (from.CustomParameters["pendingTracks"] != VariantType.Map)
            {
                FATAL("Invalid state. No pending tracks");
                return false;
            }
            string controlUri = requestHeaders[RTSP_FIRST_LINE,RTSP_URL];


            var track =
                @from.CustomParameters["pendingTracks"].Children.Values.SingleOrDefault(x => x["controlUri"] == controlUri);
                    
            if (track == null)
            {
                FATAL("track {0} not found", (controlUri));
                return false;
            }
                if (transport["client_port"]!=null)
                {
                    track["portsOrChannels"] = transport["client_port"];
                    track["isTcp"] =false;
                }
                else
                {
                    track["portsOrChannels"] = transport["interleaved"];
                    track["isTcp"] = true;
                }
                if (!pConnectivity.AddTrack(track, (bool)track["isAudio"]))
                {
                    FATAL("Unable to add audio track");
                    return false;
                }
                transportLine = pConnectivity.GetTransportHeaderLine(track["isAudio"], false);
  
            //5. Create a session
            from.GenerateSessionId();

            //6. prepare the response
            from.PushResponseFirstLine(RTSP_VERSION_1_0, 200, "OK");
            from.PushResponseHeader(RTSP_HEADERS_TRANSPORT, transportLine);

            //7. Send it
            return from.SendResponseMessage();
        }