//
// Copyright (c) PlaceholderCompany. All rights reserved.
//
#pragma warning disable SA1615 // Element should be documented
namespace MediaBrowser.Model.Dlna;
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Xml.Serialization;
using MediaBrowser.Model.Extensions;
///
/// Defines the .
///
public class CodecProfile
{
///
/// Initializes a new instance of the class.
///
public CodecProfile()
{
this.Conditions = [];
this.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 List Conditions { get; set; } = [];
///
/// Gets or sets the list of to apply if this profile is met.
///
public List 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 codec to match (single codec or comma-separated list).
/// The container to match.
/// When true and Container is "hls", uses SubContainer instead of Container for matching.
/// True if both the codec and container conditions are met.
public bool ContainsAnyCodec(string? codec, string? container, bool useSubContainer = false)
{
if (codec is null)
{
return false;
}
var containerToCheck =
useSubContainer &&
string.Equals(this.Container, "hls", StringComparison.OrdinalIgnoreCase)
? this.SubContainer
: this.Container;
return ContainerHelper.ContainsContainer(containerToCheck, container)
&& ContainerHelper.ContainsContainer(this.Codec, codec);
}
///
/// Checks to see whether the codecs and containers contain the given parameters.
///
/// The list of codecs to match.
/// The container to match.
/// When true and Container is "hls", uses SubContainer instead of Container for matching.
/// True if both the codec and container conditions are met.
public bool ContainsAnyCodec(IReadOnlyList codecs, string? container, bool useSubContainer = false)
{
if (codecs == null || codecs.Count == 0)
{
return false;
}
// Join codecs with comma to match ContainerHelper's expected format
var codecString = string.Join(',', codecs);
return ContainsAnyCodec(codecString, container, useSubContainer);
}
}