< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.MediaEncoding.DownMixAlgorithmsHelper
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 37
Coverable lines: 37
Total lines: 74
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 13
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%
InferChannelLayout(...)0%182130%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using MediaBrowser.Model.Entities;
 3
 4namespace MediaBrowser.Controller.MediaEncoding;
 5
 6/// <summary>
 7/// Describes the downmix algorithms capabilities.
 8/// </summary>
 9public static class DownMixAlgorithmsHelper
 10{
 11    /// <summary>
 12    /// The filter string of the DownMixStereoAlgorithms.
 13    /// The index is the tuple of (algorithm, layout).
 14    /// </summary>
 015    public static readonly Dictionary<(DownMixStereoAlgorithms, string), string> AlgorithmFilterStrings = new()
 016    {
 017        { (DownMixStereoAlgorithms.Dave750, "5.1"), "pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.
 018        // Use AC-4 algorithm to downmix 7.1 inputs to 5.1 first
 019        { (DownMixStereoAlgorithms.Dave750, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707
 020        { (DownMixStereoAlgorithms.NightmodeDialogue, "5.1"), "pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5" }
 021        // Use AC-4 algorithm to downmix 7.1 inputs to 5.1 first
 022        { (DownMixStereoAlgorithms.NightmodeDialogue, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c
 023        { (DownMixStereoAlgorithms.Rfc7845, "3.0"), "pan=stereo|c0=0.414214*c2+0.585786*c0|c1=0.414214*c2+0.585786*c1" }
 024        { (DownMixStereoAlgorithms.Rfc7845, "quad"), "pan=stereo|c0=0.422650*c0+0.366025*c2+0.211325*c3|c1=0.422650*c1+0
 025        { (DownMixStereoAlgorithms.Rfc7845, "5.0"), "pan=stereo|c0=0.460186*c2+0.650802*c0+0.563611*c3+0.325401*c4|c1=0.
 026        { (DownMixStereoAlgorithms.Rfc7845, "5.1"), "pan=stereo|c0=0.374107*c2+0.529067*c0+0.458186*c4+0.264534*c5+0.374
 027        { (DownMixStereoAlgorithms.Rfc7845, "6.1"), "pan=stereo|c0=0.321953*c2+0.455310*c0+0.394310*c5+0.227655*c6+0.278
 028        { (DownMixStereoAlgorithms.Rfc7845, "7.1"), "pan=stereo|c0=0.274804*c2+0.388631*c0+0.336565*c6+0.194316*c7+0.336
 029        { (DownMixStereoAlgorithms.Ac4, "3.0"), "pan=stereo|c0=c0+0.707*c2|c1=c1+0.707*c2" },
 030        { (DownMixStereoAlgorithms.Ac4, "5.0"), "pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4" },
 031        { (DownMixStereoAlgorithms.Ac4, "5.1"), "pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5" },
 032        { (DownMixStereoAlgorithms.Ac4, "7.0"), "pan=5.0(side)|c0=c0|c1=c1|c2=c2|c3=0.707*c3+0.707*c5|c4=0.707*c4+0.707*
 033        { (DownMixStereoAlgorithms.Ac4, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+
 034    };
 35
 36    /// <summary>
 37    /// Get the audio channel layout string from the audio stream
 38    /// If the input audio string does not have a valid layout string, guess from channel count.
 39    /// </summary>
 40    /// <param name="audioStream">The audio stream to get layout.</param>
 41    /// <returns>Channel Layout string.</returns>
 42    public static string InferChannelLayout(MediaStream audioStream)
 43    {
 044        if (!string.IsNullOrWhiteSpace(audioStream.ChannelLayout))
 45        {
 46            // Note: BDMVs do not derive this string from ffmpeg, which would cause ambiguity with 4-channel audio
 47            // "quad" => 2 front and 2 rear, "4.0" => 3 front and 1 rear
 48            // BDMV will always use "4.0" in this case
 49            // Because the quad layout is super rare in BDs, we will use "4.0" as is here
 050            return audioStream.ChannelLayout;
 51        }
 52
 053        if (audioStream.Channels is null)
 54        {
 055            return string.Empty;
 56        }
 57
 58        // When we don't have definitive channel layout, we have to guess from the channel count
 59        // Guessing is not always correct, but for most videos we don't have to guess like this as the definitive layout
 060        var inferredLayout = audioStream.Channels.Value switch
 061        {
 062            1 => "mono",
 063            2 => "stereo",
 064            3 => "2.1", // Could also be 3.0, prefer 2.1
 065            4 => "4.0", // Could also be quad (with rear left and rear right) and 3.1 with LFE. prefer 4.0 with front ce
 066            5 => "5.0",
 067            6 => "5.1", // Could also be 6.0 or hexagonal, prefer 5.1
 068            7 => "6.1", // Could also be 7.0, prefer 6.1
 069            8 => "7.1", // Could also be 8.0, prefer 7.1
 070            _ => string.Empty // Return empty string for not supported layout
 071        };
 072        return inferredLayout;
 73    }
 74}