/// <summary> /// Parses the specified SDP. /// </summary> /// <param name="sdp">The input SDP text.</param> public void Parse(string sdp) { sdp = sdp.Replace("\r\n", "\n"); sdp = sdp.Replace("\r", "\n"); sdp = sdp.Trim(); foreach (String line in sdp.Split('\n')) { //Per line parsing string[] values = line.Split("=".ToCharArray(), 2); string k = values[0]; string currentObject = ""; switch (k) { case "o": Originator = new SDPOriginator(values[1]); currentObject = Originator.ToString(); break; case "c": Connection = new SDPConnection(values[1]); currentObject = Connection.ToString(); break; case "m": { SDPMedia currentMedia = new SDPMedia(values[1]); Media.Add(currentMedia); currentObject = currentMedia.ToString(); } break; default: currentObject = values[1]; break; } if (k == "m") { SDPMedia obj = Media.Last(); } else if (Media.Count > 0) { SDPMedia obj = Media.Last(); if (k == "a" && values[1].StartsWith("rtpmap:")) { string[] split = values[1].Remove(0, 7).Split(" ".ToCharArray(), 2); string pt = split[0]; string[] rest = split[1].Split("/".ToCharArray(), 2); string name = rest[0]; string rate = null; string parameters = null; if (rest.Length > 1) { string[] final = rest[1].Split("/".ToCharArray(), 2); rate = final[0]; parameters = null; if (final.Length > 1) { parameters = final[1]; } } foreach (SDPMediaFormat f in obj.Mediaformats) { if (f.Pt == pt) { f.Name = name; if (rate != null) { f.Rate = rate; } if (parameters != null) { f.Parameters = parameters; } } } } else { if (!Multiple.Contains(k)) { obj.OtherAttributes.Add(k, currentObject); } else { if (!obj.OtherAttributes.ContainsKey(k)) { obj.OtherAttributes.Add(k, currentObject); } //TODO HANDLE multiple attributes of the same type; //if (obj.properties.ContainsKey(k)) //{ // obj[k, true].Add(current_attribute); //} //else //{ // obj[k, true] = new List<AttributeClass>(); // obj[k, true].Add(current_attribute); //} } } } else { if (k != "o" && k != "c") { SDP obj = this; if (!Multiple.Contains(k)) { obj.Other.Add(k, currentObject); } else { obj.Other.Add(k, currentObject); //TODO HANDLE multiple attributes of the same type; //if (obj.properties.ContainsKey(k)) //{ // obj[k, true].Add(current_attribute); //} //else //{ // obj[k, true] = new List<AttributeClass>(); // obj[k, true].Add(current_attribute); //} } } } } }