CodecProfile.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using MediaBrowser.Model.Extensions;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using MediaBrowser.Model.Dlna;
  5. namespace MediaBrowser.Model.Dlna
  6. {
  7. public class CodecProfile
  8. {
  9. [XmlAttribute("type")]
  10. public CodecType Type { get; set; }
  11. public ProfileCondition[] Conditions { get; set; }
  12. public ProfileCondition[] ApplyConditions { get; set; }
  13. [XmlAttribute("codec")]
  14. public string Codec { get; set; }
  15. [XmlAttribute("container")]
  16. public string Container { get; set; }
  17. public CodecProfile()
  18. {
  19. Conditions = new ProfileCondition[] {};
  20. ApplyConditions = new ProfileCondition[] { };
  21. }
  22. private static List<string> SplitValue(string value)
  23. {
  24. List<string> list = new List<string>();
  25. foreach (string i in (value ?? string.Empty).Split(','))
  26. {
  27. if (!string.IsNullOrEmpty(i)) list.Add(i);
  28. }
  29. return list;
  30. }
  31. public List<string> GetCodecs()
  32. {
  33. return SplitValue(Codec);
  34. }
  35. private bool ContainsContainer(string container)
  36. {
  37. return ContainerProfile.ContainsContainer(Container, container);
  38. }
  39. public bool ContainsCodec(string codec, string container)
  40. {
  41. if (!ContainsContainer(container))
  42. {
  43. return false;
  44. }
  45. List<string> codecs = GetCodecs();
  46. return codecs.Count == 0 || ListHelper.ContainsIgnoreCase(codecs, SplitValue(codec)[0]);
  47. //return codecs.Count == 0 || SplitValue(codec).Any(i => ListHelper.ContainsIgnoreCase(codecs, i));
  48. }
  49. }
  50. }