Exemple #1
0
        private static void ReadTransport(RtspTransport returnValue, string [] transportProtocolPart)
        {
            TransportType transport;

            if (!Enum.TryParse <TransportType> (transportProtocolPart [0], out transport))
            {
                throw new ArgumentException("Transport type invalid", "aTransportString");
            }
            returnValue.Transport = transport;
        }
Exemple #2
0
        private static void ReadProfile(RtspTransport returnValue, string [] transportProtocolPart)
        {
            ProfileType profile;

            if (transportProtocolPart.Length < 2 || !Enum.TryParse <ProfileType> (transportProtocolPart [1], out profile))
            {
                throw new ArgumentException("Transport profile type invalid", "aTransportString");
            }
            returnValue.Profile = profile;
        }
Exemple #3
0
        public void AddTransport(RtspTransport newTransport)
        {
            string actualTransport = string.Empty;

            if (Headers.ContainsKey(RtspHeaderNames.Transport))
            {
                actualTransport = Headers [RtspHeaderNames.Transport] + ",";
            }

            Headers [RtspHeaderNames.Transport] = actualTransport + newTransport;
        }
Exemple #4
0
 private static void ReadLowerTransport(RtspTransport returnValue, string [] transportProtocolPart)
 {
     if (transportProtocolPart.Length == 3)
     {
         LowerTransportType lowerTransport;
         if (!Enum.TryParse <LowerTransportType> (transportProtocolPart [2], out lowerTransport))
         {
             throw new ArgumentException("Lower transport type invalid", "aTransportString");
         }
         returnValue.LowerTransport = lowerTransport;
     }
 }
Exemple #5
0
        /// <summary>
        /// Parses the specified transport string.
        /// </summary>
        /// <param name="aTransportString">A transport string.</param>
        /// <returns>The transport class.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="aTransportString"/> is null.</exception>
        public static RtspTransport Parse(string aTransportString)
        {
            if (aTransportString == null)
            {
                throw new ArgumentNullException("aTransportString");
            }
            Contract.EndContractBlock();

            RtspTransport returnValue = new RtspTransport();

            string [] transportPart         = aTransportString.Split(';');
            string [] transportProtocolPart = transportPart [0].Split('/');

            ReadTransport(returnValue, transportProtocolPart);
            ReadProfile(returnValue, transportProtocolPart);
            ReadLowerTransport(returnValue, transportProtocolPart);

            foreach (string part in transportPart)
            {
                string [] subPart = part.Split('=');

                switch (subPart [0].ToUpperInvariant())
                {
                case "UNICAST":
                    returnValue.IsMulticast = false;
                    break;

                case "MULTICAST":
                    returnValue.IsMulticast = true;
                    break;

                case "DESTINATION":
                    if (subPart.Length == 2)
                    {
                        returnValue.Destination = subPart [1];
                    }
                    break;

                case "SOURCE":
                    if (subPart.Length == 2)
                    {
                        returnValue.Source = subPart [1];
                    }
                    break;

                case "INTERLEAVED":
                    returnValue.IsMulticast = false;
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("interleaved value invalid", "aTransportString");
                    }

                    returnValue.Interleaved = PortCouple.Parse(subPart [1]);
                    break;

                case "APPEND":
                    returnValue.IsAppend = true;
                    break;

                case "TTL":
                    int ttl = 0;
                    if (subPart.Length < 2 || !int.TryParse(subPart [1], out ttl))
                    {
                        throw new ArgumentException("TTL value invalid", "aTransportString");
                    }
                    returnValue.TTL = ttl;
                    break;

                case "LAYERS":
                    int layers = 0;
                    if (subPart.Length < 2 || !int.TryParse(subPart [1], out layers))
                    {
                        throw new ArgumentException("Layers value invalid", "aTransportString");
                    }
                    returnValue.TTL = layers;
                    break;

                case "PORT":
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("Port value invalid", "aTransportString");
                    }
                    returnValue.Port = PortCouple.Parse(subPart [1]);
                    break;

                case "CLIENT_PORT":
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("client_port value invalid", "aTransportString");
                    }
                    returnValue.ClientPort = PortCouple.Parse(subPart [1]);
                    break;

                case "SERVER_PORT":
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("server_port value invalid", "aTransportString");
                    }
                    returnValue.ServerPort = PortCouple.Parse(subPart [1]);
                    break;

                case "SSRC":
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("ssrc value invalid", "aTransportString");
                    }
                    returnValue.SSrc = subPart [1];
                    break;

                case "MODE":
                    if (subPart.Length < 2)
                    {
                        throw new ArgumentException("mode value invalid", "aTransportString");
                    }
                    returnValue.Mode = subPart [1];
                    break;

                default:
                    // TODO log invalid part
                    break;
                }
            }
            return(returnValue);
        }