Exemplo n.º 1
0
        public static SdpConnectionData Parse(string line)
        {
            var tokens = line.Split(SEPARATOR, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length != 3)
            {
                throw new ArgumentException();
            }

            int offset = 0;
            var result = new SdpConnectionData
            {
                NetType  = tokens[offset++],
                AddrType = tokens[offset++],
            };

            tokens         = tokens[offset++].Split(DELIMITER, StringSplitOptions.RemoveEmptyEntries);
            result.Address = IPAddress.Parse(tokens[0]);
            if (tokens.Length == 2)
            {
                result.TimeToLive = byte.Parse(tokens[1]);
            }

            return(result);
        }
Exemplo n.º 2
0
 static SdpMessage()
 {
     _builder = new PacketBuilder <SdpMessage>(6)
     {
         new SdpTag("v", (packet) => packet.Version, (packet, value) => packet.Version         = value),
         new SdpTag("o", (packet) => packet.Origin.Pack(), (packet, value) => packet.Origin    = SdpOrigin.Parse(value)),
         new SdpTag("s", (packet) => packet.SessionName, (packet, value) => packet.SessionName = value),
         new SdpTag("c", (packet) => packet.ConnectionData.Pack(), (packet, value) => packet.ConnectionData = SdpConnectionData.Parse(value)),
         new SdpTag("t", (packet) => packet.Timing.Pack(), (packet, value) => packet.Timing = SdpTiming.Parse(value)),
         new SdpGrp("m", 3)
         {
             new SdpTag(p => p.Container.Kind.Pack(), (p, v) => p.Container.Kind = v.Unpack <MediaKind>()),
             new SdpGrp(2)
             {
                 new SdpTag(p => p.Container.Port.ToString(), (p, v) => p.Container.Port           = int.Parse(v)),
                 new SdpTag(p => p.Container.PortCount.ToString(), (p, v) => p.Container.PortCount = int.Parse(v)),
             }
             .SetParam(p =>
             {
                 p.Builder.Separator         = "/";
                 p.Builder.TrailingSeparator = false;
             }),
             new SdpTag(p => p.Container.Protocol, (p, v) => p.Container.Protocol = v),
             new SdpTag(p => string.Join(SPACE, p.Container.Formats.Keys), (p, v) => p.Container.Add(new SdpMediaFormat {
                 PayloadType = byte.Parse(v)
             })),
         }
         .SetParam(p =>
         {
             p.Builder.Separator         = SPACE;
             p.Builder.TrailingSeparator = false;
         }),
     };
     _builder.Encoding          = Encoding.ASCII;
     _builder.Equal             = EQUAL;
     _builder.Separator         = SPACE + CRLF;
     _builder.TrailingSeparator = true;
 }