< Summary - Jellyfin

Information
Class: MediaBrowser.MediaEncoding.Encoder.ApplePlatformHelper
Assembly: MediaBrowser.MediaEncoding
File(s): /srv/git/jellyfin/MediaBrowser.MediaEncoding/Encoder/ApplePlatformHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 86
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/26/2026 - 12:14:14 AM Line coverage: 0% (0/26) Branch coverage: 0% (0/8) Total lines: 876/19/2026 - 12:16:12 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/10) Total lines: 86 3/26/2026 - 12:14:14 AM Line coverage: 0% (0/26) Branch coverage: 0% (0/8) Total lines: 876/19/2026 - 12:16:12 AM Line coverage: 0% (0/28) Branch coverage: 0% (0/10) Total lines: 86

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
GetSysctlValue(...)0%7280%
HasAv1HardwareAccel(...)0%620%

File(s)

/srv/git/jellyfin/MediaBrowser.MediaEncoding/Encoder/ApplePlatformHelper.cs

#LineLine coverage
 1#pragma warning disable CA1031
 2
 3using System;
 4using System.Buffers;
 5using System.Linq;
 6using System.Runtime.InteropServices;
 7using System.Runtime.Versioning;
 8using System.Text;
 9using Microsoft.Extensions.Logging;
 10
 11namespace MediaBrowser.MediaEncoding.Encoder;
 12
 13/// <summary>
 14/// Helper class for Apple platform specific operations.
 15/// </summary>
 16[SupportedOSPlatform("macos")]
 17public static partial class ApplePlatformHelper
 18{
 019    private static readonly string[] _av1DecodeBlacklistedCpuClass = ["M1", "M2"];
 20
 21    internal static string GetSysctlValue(string name)
 22    {
 023        nuint length = 0;
 24        // Get length of the value
 025        int osStatus = sysctlbyname(name, Span<byte>.Empty, ref length, IntPtr.Zero, 0);
 026        if (osStatus != 0 || length == 0)
 27        {
 028            throw new NotSupportedException($"Failed to get sysctl value for {name} with error {osStatus}");
 29        }
 30
 031        byte[] buffer = ArrayPool<byte>.Shared.Rent((int)length);
 32        try
 33        {
 034            osStatus = sysctlbyname(name, buffer.AsSpan()[..(int)length], ref length, IntPtr.Zero, 0);
 035            if (osStatus != 0)
 36            {
 037                throw new NotSupportedException($"Failed to get sysctl value for {name} with error {osStatus}");
 38            }
 39
 040            if (length < 1)
 41            {
 042                return string.Empty;
 43            }
 44
 045            ReadOnlySpan<byte> data = buffer.AsSpan()[..(int)(length - 1)];
 046            return Encoding.UTF8.GetString(data);
 47        }
 48        finally
 49        {
 050            ArrayPool<byte>.Shared.Return(buffer);
 051        }
 052    }
 53
 54    /// <summary>
 55    /// Check if the current system has hardware acceleration for AV1 decoding.
 56    /// </summary>
 57    /// <param name="logger">The logger used for error logging.</param>
 58    /// <returns>Boolean indicates the hwaccel support.</returns>
 59    public static bool HasAv1HardwareAccel(ILogger logger)
 60    {
 061        if (!RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64))
 62        {
 063            return false;
 64        }
 65
 66        try
 67        {
 068            string cpuBrandString = GetSysctlValue("machdep.cpu.brand_string");
 069            return !_av1DecodeBlacklistedCpuClass.Any(blacklistedCpuClass => cpuBrandString.Contains(blacklistedCpuClass
 70        }
 071        catch (NotSupportedException e)
 72        {
 073            logger.LogError("Error getting CPU brand string: {Message}", e.Message);
 074        }
 075        catch (Exception e)
 76        {
 077            logger.LogError("Unknown error occured: {Exception}", e);
 078        }
 79
 080        return false;
 081    }
 82
 83    [LibraryImport("libc", EntryPoint = "sysctlbyname", SetLastError = true)]
 84    [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
 85    internal static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, Span<byte> oldp, ref nuint ol
 86}