CodecProfile.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Linq;
  5. using System.Xml.Serialization;
  6. namespace MediaBrowser.Model.Dlna
  7. {
  8. public class CodecProfile
  9. {
  10. [XmlAttribute("type")]
  11. public CodecType Type { get; set; }
  12. public ProfileCondition[] Conditions { get; set; }
  13. public ProfileCondition[] ApplyConditions { get; set; }
  14. [XmlAttribute("codec")]
  15. public string Codec { get; set; }
  16. [XmlAttribute("container")]
  17. public string Container { get; set; }
  18. public CodecProfile()
  19. {
  20. Conditions = Array.Empty<ProfileCondition>();
  21. ApplyConditions = Array.Empty<ProfileCondition>();
  22. }
  23. public string[] GetCodecs()
  24. {
  25. return ContainerProfile.SplitValue(Codec);
  26. }
  27. private bool ContainsContainer(string container)
  28. {
  29. return ContainerProfile.ContainsContainer(Container, container);
  30. }
  31. public bool ContainsAnyCodec(string codec, string container)
  32. {
  33. return ContainsAnyCodec(ContainerProfile.SplitValue(codec), container);
  34. }
  35. public bool ContainsAnyCodec(string[] codec, string container)
  36. {
  37. if (!ContainsContainer(container))
  38. {
  39. return false;
  40. }
  41. var codecs = GetCodecs();
  42. if (codecs.Length == 0)
  43. {
  44. return true;
  45. }
  46. foreach (var val in codec)
  47. {
  48. if (codecs.Contains(val, StringComparer.OrdinalIgnoreCase))
  49. {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. }
  56. }