< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Dlna.ResolutionNormalizer
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 77
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
Normalize(...)0%272160%
GetResolutionConfiguration(...)0%4260%

File(s)

/srv/git/jellyfin/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System;
 5
 6namespace MediaBrowser.Model.Dlna
 7{
 8    public static class ResolutionNormalizer
 9    {
 010        private static readonly ResolutionConfiguration[] Configurations =
 011            new[]
 012            {
 013                new ResolutionConfiguration(426, 320000),
 014                new ResolutionConfiguration(640, 400000),
 015                new ResolutionConfiguration(720, 950000),
 016                new ResolutionConfiguration(1280, 2500000),
 017                new ResolutionConfiguration(1920, 4000000),
 018                new ResolutionConfiguration(2560, 20000000),
 019                new ResolutionConfiguration(3840, 35000000)
 020            };
 21
 22        public static ResolutionOptions Normalize(
 23            int? inputBitrate,
 24            int outputBitrate,
 25            int? maxWidth,
 26            int? maxHeight)
 27        {
 28            // If the bitrate isn't changing, then don't downscale the resolution
 029            if (inputBitrate.HasValue && outputBitrate >= inputBitrate.Value)
 30            {
 031                if (maxWidth.HasValue || maxHeight.HasValue)
 32                {
 033                    return new ResolutionOptions
 034                    {
 035                        MaxWidth = maxWidth,
 036                        MaxHeight = maxHeight
 037                    };
 38                }
 39            }
 40
 041            var resolutionConfig = GetResolutionConfiguration(outputBitrate);
 042            if (resolutionConfig is not null)
 43            {
 044                var originvalValue = maxWidth;
 45
 046                maxWidth = Math.Min(resolutionConfig.MaxWidth, maxWidth ?? resolutionConfig.MaxWidth);
 047                if (!originvalValue.HasValue || originvalValue.Value != maxWidth.Value)
 48                {
 049                    maxHeight = null;
 50                }
 51            }
 52
 053            return new ResolutionOptions
 054            {
 055                MaxWidth = maxWidth,
 056                MaxHeight = maxHeight
 057            };
 58        }
 59
 60        private static ResolutionConfiguration GetResolutionConfiguration(int outputBitrate)
 61        {
 062            ResolutionConfiguration previousOption = null;
 63
 064            foreach (var config in Configurations)
 65            {
 066                if (outputBitrate <= config.MaxBitrate)
 67                {
 068                    return previousOption ?? config;
 69                }
 70
 071                previousOption = config;
 72            }
 73
 074            return null;
 75        }
 76    }
 77}