public bool IsSameSession(SessionDescription sd) { if (sd == null) { return(false); } return(Origin.IsSameSession(sd.Origin)); }
public bool IsUpdateOf(SessionDescription sd) { if (sd == null) { return(false); } return(Origin.IsUpdateOf(sd.Origin)); }
public SessionAnnouncement(SessionDescription sessionDescription, NetworkInterface inter) { if (sessionDescription.Announcement != null) { throw new ArgumentException("sessionDescription"); } SessionDescription = sessionDescription; SessionDescription.Announcement = this; NetworkInterface = inter; }
public SessionAnnouncement(SessionDescription sessionDescription, NetworkInterface inter) { if (sessionDescription.Announcement != null) { throw new ArgumentException("sessionDescription"); } SessionDescription = sessionDescription; SessionDescription.Announcement = this; NetworkInterface = inter; }
public SdpSession(Origin o, NetworkInterface inter) { SessionDescription = new SessionDescription(); SessionDescription.Origin = o; NetworkInterface = inter; }
internal AttributeDictionary(SessionDescription sd) { SessionDescription = sd; Media = null; }
public bool IsUpdateOf(SessionDescription sd) { if (sd == null) { return false; } return Origin.IsUpdateOf(sd.Origin); }
public bool IsSameSession(SessionDescription sd) { if (sd == null) { return false; } return Origin.IsSameSession(sd.Origin); }
public static SessionDescription Load(TextReader reader, LoadOptions loadOptions) { SessionDescription sd = new SessionDescription(false); Media media = null; string line = reader.ReadLine(); while (line != null) { if ((line.Length == 0) && ((loadOptions & LoadOptions.IgnoreEmptyLines) != 0)) { goto nextline; } if (line.Length < 3) { goto invalidline; } if (line[1] != '=') { goto invalidline; } string value = line.Substring(2); string[] parts = null; int sep = -1; try { switch (line[0]) { case 'v': if (media != null) { goto invalidline; } int version = -1; Grammar.ValidateDigits(value, false); if (!int.TryParse(value, out version)) { goto invalidline; } if ((loadOptions & LoadOptions.IgnoreUnsupportedVersion) == 0) { if (version != 0) { goto notsupported; } } sd.Version = version; break; case 'o': if (media != null) { goto invalidline; } sd.Origin = Origin.Parse(value); break; case 's': if (media != null) { goto invalidline; } sd.Name = value; break; case 'i': if (media == null) { sd.Information = value; } else { media.Information = value; } break; case 'u': if (media != null) { goto invalidline; } sd.Uri = new Uri(value); break; case 'e': if (media != null) { goto invalidline; } sd.EMails.Add(value); break; case 'p': if (media != null) { goto invalidline; } sd.PhoneNumbers.Add(value); break; case 'c': if (media == null) { if (sd.HasConnection) { goto invalidline; } } Connection conn = new Connection(); parts = value.Split(' '); if (parts.Length != 3) { goto invalidline; } string networkType = parts[0]; string addressType = parts[1]; parts = parts[2].Split('/'); if (parts.Length > 3) { goto invalidline; } conn.SetAddress(networkType, addressType, parts[0]); conn.Address = parts[0]; conn.AddressCount = 1; if (parts.Length >= 2) { uint ttl = 0; if (!uint.TryParse(parts[1], out ttl)) { goto invalidline; } conn.Ttl = ttl; if (parts.Length == 3) { uint addressCount = 0; if (!uint.TryParse(parts[2], out addressCount)) { goto invalidline; } conn.AddressCount = addressCount; } if (conn.AddressType == "IP6") { if (parts.Length == 3) { goto invalidline; } conn.AddressCount = conn.Ttl; conn.Ttl = 0; } } if (media != null) { media.Connections.Add(conn); } else { sd.Connection = conn; } break; case 'b': sep = value.IndexOf(':'); if (sep == -1) { goto invalidline; } string type = value.Substring(0, sep); string bw = value.Substring(sep + 1); Grammar.ValidateDigits(bw, false); uint bwValue = 0; if (!uint.TryParse(bw, out bwValue)) { goto invalidline; } if (media != null) { media.Bandwidths.Add(new Bandwidth(type, bwValue)); } else { sd.Bandwidths.Add(new Bandwidth(type, bwValue)); } break; case 'a': sep = value.IndexOf(':'); string attrName; string attrValue; if (sep != -1) { attrName = value.Substring(0, sep); attrValue = value.Substring(sep + 1); } else { attrName = value; attrValue = null; } if (media != null) { media.Attributes.Add(attrName, attrValue); } else { sd.Attributes.Add(attrName, attrValue); } break; case 't': if (media != null) { goto invalidline; } parts = value.Split(' '); if (parts.Length != 2) { goto invalidline; } Grammar.ValidateTime(parts[0]); double startTime = 0; if (!double.TryParse(parts[0], out startTime)) { goto invalidline; } Grammar.ValidateTime(parts[1]); double stopTime = 0; if (!double.TryParse(parts[1], out stopTime)) { goto invalidline; } DateTime startDateTime = Time.Zero; DateTime stopDateTime = Time.Zero; if (startTime != 0) { startDateTime = Time.Zero + TimeSpan.FromSeconds(startTime); } if (stopTime != 0) { stopDateTime = Time.Zero + TimeSpan.FromSeconds(stopTime); } sd.Times.Add(new Time(startDateTime, stopDateTime)); break; case 'm': parts = value.Split(' '); if (parts.Length < 4) { goto invalidline; } string mediaType = parts[0]; string protocol = parts[2]; var formats = parts.Skip(3).ToList(); parts = parts[1].Split('/'); if (parts.Length > 2) { goto invalidline; } uint port = 0; uint portCount = 1; Grammar.ValidateDigits(parts[0], false); if (!uint.TryParse(parts[0], out port)) { goto invalidline; } if (parts.Length == 2) { Grammar.ValidateDigits(parts[1], true); if (!uint.TryParse(parts[1], out portCount)) { goto invalidline; } } media = new Media(mediaType, port, portCount, protocol, formats); sd.Medias.Add(media); break; case 'z': case 'k': case 'r': if ((loadOptions & LoadOptions.IgnoreUnsupportedLines) == 0) { goto notsupported; } break; default: if ((loadOptions & LoadOptions.IgnoreUnknownLines) == 0) { goto invalidline; } break; } } catch { goto invalidline; } nextline: line = reader.ReadLine(); continue; invalidline: throw new SdpException(string.Format("Invalid Line {0}", line)); notsupported: throw new SdpException(string.Format("Unsupported line {0}", line)); } if (sd.Version == -1) { throw new SdpException("Version ('v=') is required"); } if (!sd.HasOrigin) { throw new SdpException("Origin ('o=') is required"); } if (sd.Name == null) { throw new SdpException("Name ('s=') is required"); } if (!sd.HasTimes) { throw new SdpException("Time ('t=') is required"); } return sd; }
public SdpSession(Origin o, NetworkInterface inter) { SessionDescription = new SessionDescription(); SessionDescription.Origin = o; NetworkInterface = inter; }
public MediaCollection(SessionDescription sd) { SessionDescription = sd; }
internal void OnSessionAnnounce(NetworkInterfaceHandler interfaceHandler, Announcement announcement) { lock (_sessionData) { AnnouncementIdentifier id = new AnnouncementIdentifier(interfaceHandler.NetworkInterface, announcement); SessionData sessionData = null; bool knownAnnouncement = _announcements.TryGetValue(id, out sessionData); if (!knownAnnouncement) { announcement.Decompress(); Stream stream = new MemoryStream(announcement.Payload.Array, announcement.Payload.Offset, announcement.Payload.Count); SessionDescription description = SessionDescription.Load(stream); description.SetReadOnly(); SdpSession session = new SdpSession(description, interfaceHandler.NetworkInterface); SessionAnnouncement sessionAnnouncement = null; if (_sessionData.TryGetValue(session, out sessionData)) { sessionAnnouncement = sessionData.Session; } if (sessionData != null) { if (description.IsUpdateOf(sessionAnnouncement.SessionDescription)) { sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface); SessionAnnouncement oldAnnouncement = sessionData.Session; sessionData.Session = sessionAnnouncement; _announcements.Remove(sessionData.Id); sessionData.Id = id; SynchronizationContextPost(o => { lock (Sessions) { Sessions.Replace(oldAnnouncement, sessionAnnouncement); } }); } } else { sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface); sessionData = new SessionData() { Session = sessionAnnouncement, Timer = new Timer(OnTimeOut, session, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite), Id = id }; _sessionData.Add(session, sessionData); _announcements.Add(id, sessionData); SynchronizationContextPost(o => { lock (Sessions) { Sessions.Add(sessionAnnouncement); } }); } } sessionData.TimeOutTime = DateTime.Now + DefaultTimeOut; sessionData.Timer.Change(DefaultTimeOut, TimeSpan.FromMilliseconds(-1)); } }
public BandwidthCollection(SessionDescription sessionDescription) { SessionDescription = sessionDescription; }
public static SessionDescription Load(TextReader reader, LoadOptions loadOptions) { SessionDescription sd = new SessionDescription(false); Media media = null; string line = reader.ReadLine(); while (line != null) { if ((line.Length == 0) && ((loadOptions & LoadOptions.IgnoreEmptyLines) != 0)) { goto nextline; } if (line.Length < 3) { goto invalidline; } if (line[1] != '=') { goto invalidline; } string value = line.Substring(2); string[] parts = null; int sep = -1; try { switch (line[0]) { case 'v': if (media != null) { goto invalidline; } int version = -1; Grammar.ValidateDigits(value, false); if (!int.TryParse(value, out version)) { goto invalidline; } if ((loadOptions & LoadOptions.IgnoreUnsupportedVersion) == 0) { if (version != 0) { goto notsupported; } } sd.Version = version; break; case 'o': if (media != null) { goto invalidline; } sd.Origin = Origin.Parse(value); break; case 's': if (media != null) { goto invalidline; } sd.Name = value; break; case 'i': if (media == null) { sd.Information = value; } else { media.Information = value; } break; case 'u': if (media != null) { goto invalidline; } sd.Uri = new Uri(value); break; case 'e': if (media != null) { goto invalidline; } sd.EMails.Add(value); break; case 'p': if (media != null) { goto invalidline; } sd.PhoneNumbers.Add(value); break; case 'c': if (media == null) { if (sd.HasConnection) { goto invalidline; } } Connection conn = new Connection(); parts = value.Split(' '); if (parts.Length != 3) { goto invalidline; } string networkType = parts[0]; string addressType = parts[1]; parts = parts[2].Split('/'); if (parts.Length > 3) { goto invalidline; } conn.SetAddress(networkType, addressType, parts[0]); conn.Address = parts[0]; conn.AddressCount = 1; if (parts.Length >= 2) { uint ttl = 0; if (!uint.TryParse(parts[1], out ttl)) { goto invalidline; } conn.Ttl = ttl; if (parts.Length == 3) { uint addressCount = 0; if (!uint.TryParse(parts[2], out addressCount)) { goto invalidline; } conn.AddressCount = addressCount; } if (conn.AddressType == "IP6") { if (parts.Length == 3) { goto invalidline; } conn.AddressCount = conn.Ttl; conn.Ttl = 0; } } if (media != null) { media.Connections.Add(conn); } else { sd.Connection = conn; } break; case 'b': sep = value.IndexOf(':'); if (sep == -1) { goto invalidline; } string type = value.Substring(0, sep); string bw = value.Substring(sep + 1); Grammar.ValidateDigits(bw, false); uint bwValue = 0; if (!uint.TryParse(bw, out bwValue)) { goto invalidline; } if (media != null) { media.Bandwidths.Add(new Bandwidth(type, bwValue)); } else { sd.Bandwidths.Add(new Bandwidth(type, bwValue)); } break; case 'a': sep = value.IndexOf(':'); string attrName; string attrValue; if (sep != -1) { attrName = value.Substring(0, sep); attrValue = value.Substring(sep + 1); } else { attrName = value; attrValue = null; } if (media != null) { media.Attributes.Add(attrName, attrValue); } else { sd.Attributes.Add(attrName, attrValue); } break; case 't': if (media != null) { goto invalidline; } parts = value.Split(' '); if (parts.Length != 2) { goto invalidline; } Grammar.ValidateTime(parts[0]); double startTime = 0; if (!double.TryParse(parts[0], out startTime)) { goto invalidline; } Grammar.ValidateTime(parts[1]); double stopTime = 0; if (!double.TryParse(parts[1], out stopTime)) { goto invalidline; } DateTime startDateTime = Time.Zero; DateTime stopDateTime = Time.Zero; if (startTime != 0) { startDateTime = Time.Zero + TimeSpan.FromSeconds(startTime); } if (stopTime != 0) { stopDateTime = Time.Zero + TimeSpan.FromSeconds(stopTime); } sd.Times.Add(new Time(startDateTime, stopDateTime)); break; case 'm': parts = value.Split(' '); if (parts.Length < 4) { goto invalidline; } string mediaType = parts[0]; string protocol = parts[2]; var formats = parts.Skip(3).ToList(); parts = parts[1].Split('/'); if (parts.Length > 2) { goto invalidline; } uint port = 0; uint portCount = 1; Grammar.ValidateDigits(parts[0], false); if (!uint.TryParse(parts[0], out port)) { goto invalidline; } if (parts.Length == 2) { Grammar.ValidateDigits(parts[1], true); if (!uint.TryParse(parts[1], out portCount)) { goto invalidline; } } media = new Media(mediaType, port, portCount, protocol, formats); sd.Medias.Add(media); break; case 'z': case 'k': case 'r': if ((loadOptions & LoadOptions.IgnoreUnsupportedLines) == 0) { goto notsupported; } break; default: if ((loadOptions & LoadOptions.IgnoreUnknownLines) == 0) { goto invalidline; } break; } } catch { goto invalidline; } nextline: line = reader.ReadLine(); continue; invalidline: throw new SdpException(string.Format("Invalid Line {0}", line)); notsupported: throw new SdpException(string.Format("Unsupported line {0}", line)); } if (sd.Version == -1) { throw new SdpException("Version ('v=') is required"); } if (!sd.HasOrigin) { throw new SdpException("Origin ('o=') is required"); } if (sd.Name == null) { throw new SdpException("Name ('s=') is required"); } if (!sd.HasTimes) { throw new SdpException("Time ('t=') is required"); } return(sd); }
public override bool Equals(object obj) { SessionDescription sd = obj as SessionDescription; return(this == sd); }
public SdpSession(SessionDescription sd, NetworkInterface inter) { SessionDescription = sd; NetworkInterface = inter; }
public TimeCollection(SessionDescription sessionDescription) { SessionDescription = sessionDescription; }
internal AttributeDictionary(SessionDescription sd) { SessionDescription = sd; Media = null; }
public SdpSession(SessionDescription sd, NetworkInterface inter) { SessionDescription = sd; NetworkInterface = inter; }
public StringCollection(Type type, SessionDescription sessionDescription) { _type = type; SessionDescription = sessionDescription; }