aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dlna/CodecProfile.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2024-09-17 20:29:43 +0200
committerShadowghost <Ghost_of_Stone@web.de>2024-09-17 20:35:23 +0200
commit2351eeba561905bafae48a948f3126797c284766 (patch)
tree073f5b523d88eac9c98a23852e0b4ffc3f02b8ae /MediaBrowser.Model/Dlna/CodecProfile.cs
parent41ac5f8d76ce11a852e4dafbf20ad57d63d55f96 (diff)
Rework PR 6203
Diffstat (limited to 'MediaBrowser.Model/Dlna/CodecProfile.cs')
-rw-r--r--MediaBrowser.Model/Dlna/CodecProfile.cs136
1 files changed, 78 insertions, 58 deletions
diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs
index 07c1a29a4..da34eddcd 100644
--- a/MediaBrowser.Model/Dlna/CodecProfile.cs
+++ b/MediaBrowser.Model/Dlna/CodecProfile.cs
@@ -1,74 +1,94 @@
-#nullable disable
-#pragma warning disable CS1591
-
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Xml.Serialization;
-using Jellyfin.Extensions;
+using MediaBrowser.Model.Extensions;
+
+namespace MediaBrowser.Model.Dlna;
-namespace MediaBrowser.Model.Dlna
+/// <summary>
+/// Defines the <see cref="CodecProfile"/>.
+/// </summary>
+public class CodecProfile
{
- public class CodecProfile
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CodecProfile"/> class.
+ /// </summary>
+ public CodecProfile()
{
- public CodecProfile()
- {
- Conditions = Array.Empty<ProfileCondition>();
- ApplyConditions = Array.Empty<ProfileCondition>();
- }
-
- [XmlAttribute("type")]
- public CodecType Type { get; set; }
-
- public ProfileCondition[] Conditions { get; set; }
-
- public ProfileCondition[] ApplyConditions { get; set; }
-
- [XmlAttribute("codec")]
- public string Codec { get; set; }
+ Conditions = [];
+ ApplyConditions = [];
+ }
- [XmlAttribute("container")]
- public string Container { get; set; }
+ /// <summary>
+ /// Gets or sets the <see cref="CodecType"/> which this container must meet.
+ /// </summary>
+ [XmlAttribute("type")]
+ public CodecType Type { get; set; }
- [XmlAttribute("subcontainer")]
- public string SubContainer { get; set; }
+ /// <summary>
+ /// Gets or sets the list of <see cref="ProfileCondition"/> which this profile must meet.
+ /// </summary>
+ public ProfileCondition[] Conditions { get; set; }
- public string[] GetCodecs()
- {
- return ContainerProfile.SplitValue(Codec);
- }
+ /// <summary>
+ /// Gets or sets the list of <see cref="ProfileCondition"/> to apply if this profile is met.
+ /// </summary>
+ public ProfileCondition[] ApplyConditions { get; set; }
- private bool ContainsContainer(string container, bool useSubContainer = false)
- {
- var containerToCheck = useSubContainer && string.Equals(Container, "hls", StringComparison.OrdinalIgnoreCase) ? SubContainer : Container;
- return ContainerProfile.ContainsContainer(containerToCheck, container);
- }
+ /// <summary>
+ /// Gets or sets the codec(s) that this profile applies to.
+ /// </summary>
+ [XmlAttribute("codec")]
+ public string? Codec { get; set; }
- public bool ContainsAnyCodec(string codec, string container, bool useSubContainer = false)
- {
- return ContainsAnyCodec(ContainerProfile.SplitValue(codec), container, useSubContainer);
- }
+ /// <summary>
+ /// Gets or sets the container(s) which this profile will be applied to.
+ /// </summary>
+ [XmlAttribute("container")]
+ public string? Container { get; set; }
- public bool ContainsAnyCodec(string[] codec, string container, bool useSubContainer = false)
- {
- if (!ContainsContainer(container, useSubContainer))
- {
- return false;
- }
+ /// <summary>
+ /// Gets or sets the sub-container(s) which this profile will be applied to.
+ /// </summary>
+ [XmlAttribute("subcontainer")]
+ public string? SubContainer { get; set; }
- var codecs = GetCodecs();
- if (codecs.Length == 0)
- {
- return true;
- }
+ /// <summary>
+ /// Checks to see whether the codecs and containers contain the given parameters.
+ /// </summary>
+ /// <param name="codecs">The codecs to match.</param>
+ /// <param name="container">The container to match.</param>
+ /// <param name="useSubContainer">Consider sub-containers.</param>
+ /// <returns>True if both conditions are met.</returns>
+ public bool ContainsAnyCodec(IReadOnlyList<string> 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));
+ }
- foreach (var val in codec)
- {
- if (codecs.Contains(val, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
+ /// <summary>
+ /// Checks to see whether the codecs and containers contain the given parameters.
+ /// </summary>
+ /// <param name="codec">The codec to match.</param>
+ /// <param name="container">The container to match.</param>
+ /// <param name="useSubContainer">Consider sub-containers.</param>
+ /// <returns>True if both conditions are met.</returns>
+ public bool ContainsAnyCodec(string? codec, string? container, bool useSubContainer = false)
+ {
+ return ContainsAnyCodec(codec.AsSpan(), container, useSubContainer);
+ }
- return false;
- }
+ /// <summary>
+ /// Checks to see whether the codecs and containers contain the given parameters.
+ /// </summary>
+ /// <param name="codec">The codec to match.</param>
+ /// <param name="container">The container to match.</param>
+ /// <param name="useSubContainer">Consider sub-containers.</param>
+ /// <returns>True if both conditions are met.</returns>
+ public bool ContainsAnyCodec(ReadOnlySpan<char> 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);
}
}