/// <summary>
        /// Selects the transport based on the configuration of the system..
        /// </summary>
        /// <param name="requestSetup">The request setup message.</param>
        /// <returns>The selected transport</returns>
        /// <remarks>
        /// The transport is selected by taking the first supported transport
        /// in order of appearence.
        /// </remarks>
        private static RtspTransport SelectTransport(RtspRequestSetup requestSetup)
        {
            RtspTransport selectedTransport  = null;
            const bool    acceptTCP          = false;
            const bool    acceptUDPUnicast   = true;
            const bool    acceptUDPMulticast = true;

            foreach (RtspTransport proposedTransport in requestSetup.GetTransports())
            {
                if (acceptTCP && proposedTransport.LowerTransport == RtspTransport.LowerTransportType.TCP)
                {
                    selectedTransport = proposedTransport;
                    break;
                }
                if (acceptUDPMulticast && proposedTransport.LowerTransport == RtspTransport.LowerTransportType.UDP &&
                    proposedTransport.IsMulticast)
                {
                    selectedTransport = proposedTransport;
                    break;
                }
                if (acceptUDPUnicast && proposedTransport.LowerTransport == RtspTransport.LowerTransportType.UDP &&
                    !proposedTransport.IsMulticast)
                {
                    selectedTransport = proposedTransport;
                    break;
                }
            }
            return(selectedTransport);
        }
Example #2
0
        internal RtspResponse HandleSetup(RtspRequestSetup request)
        {
            Contract.Requires(request != null);
            Contract.Ensures(Contract.Result <RtspResponse>() != null);

            var response = request.CreateResponse();

            if (string.IsNullOrEmpty(response.Session))
            {
                // TODO Allocate a real session ID
                response.Session = sessionGenerator.Next().ToString();
            }

            RtspPushDescription description;

            if (!PushDescriptions.TryGetValue(request.RtspUri.AbsolutePath, out description))
            {
                response.ReturnCode = 404;
                return(response);
            }


            bool configok = false;

            foreach (var transport in request.GetTransports())
            {
                if (transport.LowerTransport == RtspTransport.LowerTransportType.UDP &&
                    !transport.IsMulticast
                    )
                {
                    var forwarder = new UDPForwarder();
                    description.AddForwarders(response.Session, request.RtspUri.AbsolutePath, forwarder);
                    transport.ServerPort = new PortCouple(forwarder.ListenVideoPort);
                    response.Headers[RtspHeaderNames.Transport] = transport.ToString();
                    configok = true;
                }
            }

            if (!configok)
            {
                response.ReturnCode = 461;
            }
            return(response);
        }