using System; using System.Collections.Generic; using System.Linq; using System.Xml.Serialization; using MediaBrowser.Model.Extensions; namespace MediaBrowser.Model.Dlna; /// /// Defines the . /// public class CodecProfile { /// /// Initializes a new instance of the class. /// public CodecProfile() { Conditions = []; ApplyConditions = []; } /// /// Gets or sets the which this container must meet. /// [XmlAttribute("type")] public CodecType Type { get; set; } /// /// Gets or sets the list of which this profile must meet. /// public ProfileCondition[] Conditions { get; set; } /// /// Gets or sets the list of to apply if this profile is met. /// public ProfileCondition[] ApplyConditions { get; set; } /// /// Gets or sets the codec(s) that this profile applies to. /// [XmlAttribute("codec")] public string? Codec { get; set; } /// /// Gets or sets the container(s) which this profile will be applied to. /// [XmlAttribute("container")] public string? Container { get; set; } /// /// Gets or sets the sub-container(s) which this profile will be applied to. /// [XmlAttribute("subcontainer")] public string? SubContainer { get; set; } /// /// Checks to see whether the codecs and containers contain the given parameters. /// /// The codecs to match. /// The container to match. /// Consider sub-containers. /// True if both conditions are met. public bool ContainsAnyCodec(IReadOnlyList codecs, string? container, bool useSubContainer = false) { var containerToCheck = useSubContainer && string.Equals(Container, "hls", StringComparison.OrdinalIgnoreCase) ? SubContainer : Container; return ContainerHelper.ContainsContainer(containerToCheck, container) && codecs.Any(c => ContainerHelper.ContainsContainer(Codec, false, c)); } /// /// Checks to see whether the codecs and containers contain the given parameters. /// /// The codec to match. /// The container to match. /// Consider sub-containers. /// True if both conditions are met. public bool ContainsAnyCodec(string? codec, string? container, bool useSubContainer = false) { return ContainsAnyCodec(codec.AsSpan(), container, useSubContainer); } /// /// Checks to see whether the codecs and containers contain the given parameters. /// /// The codec to match. /// The container to match. /// Consider sub-containers. /// True if both conditions are met. public bool ContainsAnyCodec(ReadOnlySpan codec, string? container, bool useSubContainer = false) { var containerToCheck = useSubContainer && string.Equals(Container, "hls", StringComparison.OrdinalIgnoreCase) ? SubContainer : Container; return ContainerHelper.ContainsContainer(containerToCheck, container) && ContainerHelper.ContainsContainer(Codec, false, codec); } }