CodecProfile.cs 2.1 KB

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