예제 #1
0
        /// <summary>
        /// Parses the int values of port.
        /// </summary>
        /// <param name="stringValue">A string value.</param>
        /// <returns>The port couple</returns>
        public static PortCouple Parse(string stringValue)
        {
            if (stringValue == null)
            {
                throw new ArgumentNullException("stringValue");
            }
            Contract.Requires(!string.IsNullOrEmpty(stringValue));

            string[] values = stringValue.Split('-');

            int tempValue;

            int.TryParse(values[0], out tempValue);
            PortCouple result = new PortCouple(tempValue);

            tempValue = 0;
            if (values.Length > 1)
            {
                int.TryParse(values[1], out tempValue);
            }

            result.Second = tempValue;

            return(result);
        }
예제 #2
0
 public void PortCoupleTwoPort()
 {
     var pc = new PortCouple(1212,1215);
     Assert.AreEqual(1212, pc.First);
     Assert.IsTrue(pc.IsSecondPortPresent);
     Assert.AreEqual(1215,pc.Second);
 }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// Parses the int values of port.
        /// </summary>
        /// <param name="stringValue">A string value.</param>
        /// <returns>The port couple</returns>
        public static PortCouple Parse(string stringValue)
        {
            if (stringValue == null)
                throw new ArgumentNullException("stringValue");
            Contract.Requires(!string.IsNullOrEmpty(stringValue));

            string[] values = stringValue.Split('-');

            int tempValue;

            int.TryParse(values[0], out tempValue);
            PortCouple result = new PortCouple(tempValue);

            tempValue = 0;
            if (values.Length > 1)
                int.TryParse(values[1], out tempValue);

            result.Second = tempValue;

            return result;
        }
예제 #5
0
 public void ToStringTwoPort()
 {
     var pc = new PortCouple(1212,1215);
     Assert.AreEqual("1212-1215", pc.ToString());
 }
예제 #6
0
 public void ToStringOnePort()
 {
     var pc = new PortCouple(1212);
     Assert.AreEqual("1212", pc.ToString());
 }
예제 #7
0
 public void PortCoupleOnePort()
 {
     var pc = new PortCouple(1212);
     Assert.AreEqual(1212, pc.First);
     Assert.IsFalse(pc.IsSecondPortPresent);
 }