aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dlna/CodecProfile.cs
blob: 07c1a29a4f4a0b1b0c764460591d16751493324f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#nullable disable
#pragma warning disable CS1591

using System;
using System.Xml.Serialization;
using Jellyfin.Extensions;

namespace MediaBrowser.Model.Dlna
{
    public class 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; }

        [XmlAttribute("container")]
        public string Container { get; set; }

        [XmlAttribute("subcontainer")]
        public string SubContainer { get; set; }

        public string[] GetCodecs()
        {
            return ContainerProfile.SplitValue(Codec);
        }

        private bool ContainsContainer(string container, bool useSubContainer = false)
        {
            var containerToCheck = useSubContainer && string.Equals(Container, "hls", StringComparison.OrdinalIgnoreCase) ? SubContainer : Container;
            return ContainerProfile.ContainsContainer(containerToCheck, container);
        }

        public bool ContainsAnyCodec(string codec, string container, bool useSubContainer = false)
        {
            return ContainsAnyCodec(ContainerProfile.SplitValue(codec), container, useSubContainer);
        }

        public bool ContainsAnyCodec(string[] codec, string container, bool useSubContainer = false)
        {
            if (!ContainsContainer(container, useSubContainer))
            {
                return false;
            }

            var codecs = GetCodecs();
            if (codecs.Length == 0)
            {
                return true;
            }

            foreach (var val in codec)
            {
                if (codecs.Contains(val, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }
    }
}