using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace Inspectron.HawkEye.RTSP.Sdp { public class H264Parameters : IDictionary { private readonly Dictionary parameters = new Dictionary(); public List SpropParameterSets { get { List result = new List(); if (ContainsKey("sprop-parameter-sets")&& this["sprop-parameter-sets"] != null) { result.AddRange(this["sprop-parameter-sets"].Split(',').Select(x => Convert.FromBase64String(x))); } return result; } } public static H264Parameters Parse(String parameterString) { var result = new H264Parameters(); foreach (var pair in parameterString.Split(';').Select(x => x.Trim().Split(new char[] { '=' }, 2))) { if(!string.IsNullOrWhiteSpace(pair[0])) result[pair[0]] = pair.Length > 1 ? pair[1] : null; } return result; } public override string ToString() { return parameters.Select(p => p.Key + (p.Value != null ? "=" + p.Value : string.Empty)).Aggregate((x, y) => x + ";" + y); } public String this[String index] { get { return parameters[index]; } set { parameters[index] = value; } } public int Count { get { return parameters.Count; } } public bool IsReadOnly { get { return ((IDictionary)parameters).IsReadOnly; } } public ICollection Keys { get { return ((IDictionary)parameters).Keys; } } public ICollection Values { get { return ((IDictionary)parameters).Values; } } public void Add(KeyValuePair item) { ((IDictionary)parameters).Add(item); } public void Add(string key, string value) { parameters.Add(key, value); } public void Clear() { parameters.Clear(); } public bool Contains(KeyValuePair item) { return ((IDictionary)parameters).Contains(item); } public bool ContainsKey(string key) { return parameters.ContainsKey(key); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { ((IDictionary)parameters).CopyTo(array, arrayIndex); } public IEnumerator> GetEnumerator() { return ((IDictionary)parameters).GetEnumerator(); } public bool Remove(KeyValuePair item) { return ((IDictionary)parameters).Remove(item); } public bool Remove(string key) { return parameters.Remove(key); } public bool TryGetValue(string key, out string value) { return parameters.TryGetValue(key, out value); } IEnumerator IEnumerable.GetEnumerator() { return ((IDictionary)parameters).GetEnumerator(); } } }