public static SdpOrigin Parse(string line) { var tokens = line.Split(SEPARATOR, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length != 6) { throw new ArgumentException(); } int offset = 0; var result = new SdpOrigin { User = tokens[offset++], Id = int.Parse(tokens[offset++]), Version = int.Parse(tokens[offset++]), NetType = tokens[offset++], AddrType = tokens[offset++], Address = IPAddress.Parse(tokens[offset++]), }; return(result); }
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; }