< Summary - Jellyfin

Information
Class: MediaBrowser.Model.Dto.MediaSourceInfo
Assembly: MediaBrowser.Model
File(s): /srv/git/jellyfin/MediaBrowser.Model/Dto/MediaSourceInfo.cs
Line coverage
88%
Covered lines: 53
Uncovered lines: 7
Coverable lines: 60
Total lines: 261
Line coverage: 88.3%
Branch coverage
82%
Covered branches: 46
Total branches: 56
Branch coverage: 82.1%
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
.ctor()100%11100%
get_VideoStream()100%44100%
InferTotalBitrate(...)75%12.871281.81%
GetDefaultAudioStream(...)70%31.652069.23%
GetMediaStream(...)100%66100%
GetStreamCount(...)100%66100%
IsSecondaryAudio(...)87.5%8.19885.71%

File(s)

/srv/git/jellyfin/MediaBrowser.Model/Dto/MediaSourceInfo.cs

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System;
 5using System.Collections.Generic;
 6using System.ComponentModel;
 7using System.Text.Json.Serialization;
 8using Jellyfin.Data.Enums;
 9using MediaBrowser.Model.Dlna;
 10using MediaBrowser.Model.Entities;
 11using MediaBrowser.Model.MediaInfo;
 12using MediaBrowser.Model.Session;
 13
 14namespace MediaBrowser.Model.Dto
 15{
 16    public class MediaSourceInfo
 17    {
 18        public MediaSourceInfo()
 19        {
 34920            Formats = Array.Empty<string>();
 34921            MediaStreams = Array.Empty<MediaStream>();
 34922            MediaAttachments = Array.Empty<MediaAttachment>();
 34923            RequiredHttpHeaders = new Dictionary<string, string>();
 34924            SupportsTranscoding = true;
 34925            SupportsDirectStream = true;
 34926            SupportsDirectPlay = true;
 34927            SupportsProbing = true;
 34928            UseMostCompatibleTranscodingProfile = false;
 34929        }
 30
 31        public MediaProtocol Protocol { get; set; }
 32
 33        public string Id { get; set; }
 34
 35        public string Path { get; set; }
 36
 37        public string EncoderPath { get; set; }
 38
 39        public MediaProtocol? EncoderProtocol { get; set; }
 40
 41        public MediaSourceType Type { get; set; }
 42
 43        public string Container { get; set; }
 44
 45        public long? Size { get; set; }
 46
 47        public string Name { get; set; }
 48
 49        /// <summary>
 50        /// Gets or sets a value indicating whether the media is remote.
 51        /// Differentiate internet url vs local network.
 52        /// </summary>
 53        public bool IsRemote { get; set; }
 54
 55        public string ETag { get; set; }
 56
 57        public long? RunTimeTicks { get; set; }
 58
 59        public bool ReadAtNativeFramerate { get; set; }
 60
 61        public bool IgnoreDts { get; set; }
 62
 63        public bool IgnoreIndex { get; set; }
 64
 65        public bool GenPtsInput { get; set; }
 66
 67        public bool SupportsTranscoding { get; set; }
 68
 69        public bool SupportsDirectStream { get; set; }
 70
 71        public bool SupportsDirectPlay { get; set; }
 72
 73        public bool IsInfiniteStream { get; set; }
 74
 75        [DefaultValue(false)]
 76        public bool UseMostCompatibleTranscodingProfile { get; set; }
 77
 78        public bool RequiresOpening { get; set; }
 79
 80        public string OpenToken { get; set; }
 81
 82        public bool RequiresClosing { get; set; }
 83
 84        public string LiveStreamId { get; set; }
 85
 86        public int? BufferMs { get; set; }
 87
 88        public bool RequiresLooping { get; set; }
 89
 90        public bool SupportsProbing { get; set; }
 91
 92        public VideoType? VideoType { get; set; }
 93
 94        public IsoType? IsoType { get; set; }
 95
 96        public Video3DFormat? Video3DFormat { get; set; }
 97
 98        public IReadOnlyList<MediaStream> MediaStreams { get; set; }
 99
 100        public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
 101
 102        public string[] Formats { get; set; }
 103
 104        public int? Bitrate { get; set; }
 105
 106        public int? FallbackMaxStreamingBitrate { get; set; }
 107
 108        public TransportStreamTimestamp? Timestamp { get; set; }
 109
 110        public Dictionary<string, string> RequiredHttpHeaders { get; set; }
 111
 112        public string TranscodingUrl { get; set; }
 113
 114        public MediaStreamProtocol TranscodingSubProtocol { get; set; }
 115
 116        public string TranscodingContainer { get; set; }
 117
 118        public int? AnalyzeDurationMs { get; set; }
 119
 120        [JsonIgnore]
 121        public TranscodeReason TranscodeReasons { get; set; }
 122
 123        public int? DefaultAudioStreamIndex { get; set; }
 124
 125        public int? DefaultSubtitleStreamIndex { get; set; }
 126
 127        public bool HasSegments { get; set; }
 128
 129        [JsonIgnore]
 130        public MediaStream VideoStream
 131        {
 132            get
 133            {
 4029134                foreach (var i in MediaStreams)
 135                {
 1339136                    if (i.Type == MediaStreamType.Video)
 137                    {
 1339138                        return i;
 139                    }
 140                }
 141
 6142                return null;
 1339143            }
 144        }
 145
 146        public void InferTotalBitrate(bool force = false)
 147        {
 4148            if (MediaStreams is null)
 149            {
 0150                return;
 151            }
 152
 4153            if (!force && Bitrate.HasValue)
 154            {
 0155                return;
 156            }
 157
 4158            var bitrate = 0;
 26159            foreach (var stream in MediaStreams)
 160            {
 9161                if (!stream.IsExternal)
 162                {
 9163                    bitrate += stream.BitRate ?? 0;
 164                }
 165            }
 166
 4167            if (bitrate > 0)
 168            {
 4169                Bitrate = bitrate;
 170            }
 4171        }
 172
 173        public MediaStream GetDefaultAudioStream(int? defaultIndex)
 174        {
 1180175            if (defaultIndex.HasValue && defaultIndex != -1)
 176            {
 1176177                var val = defaultIndex.Value;
 178
 6236179                foreach (var i in MediaStreams)
 180                {
 2530181                    if (i.Type == MediaStreamType.Audio && i.Index == val)
 182                    {
 1176183                        return i;
 184                    }
 185                }
 186            }
 187
 8188            foreach (var i in MediaStreams)
 189            {
 0190                if (i.Type == MediaStreamType.Audio && i.IsDefault)
 191                {
 0192                    return i;
 193                }
 194            }
 195
 8196            foreach (var i in MediaStreams)
 197            {
 0198                if (i.Type == MediaStreamType.Audio)
 199                {
 0200                    return i;
 201                }
 202            }
 203
 4204            return null;
 1176205        }
 206
 207        public MediaStream GetMediaStream(MediaStreamType type, int index)
 208        {
 2575209            foreach (var i in MediaStreams)
 210            {
 1095211                if (i.Type == type && i.Index == index)
 212                {
 357213                    return i;
 214                }
 215            }
 216
 14217            return null;
 357218        }
 219
 220        public int? GetStreamCount(MediaStreamType type)
 221        {
 1056222            int numMatches = 0;
 1056223            int numStreams = 0;
 224
 9156225            foreach (var i in MediaStreams)
 226            {
 3522227                numStreams++;
 3522228                if (i.Type == type)
 229                {
 1294230                    numMatches++;
 231                }
 232            }
 233
 1056234            if (numStreams == 0)
 235            {
 6236                return null;
 237            }
 238
 1050239            return numMatches;
 240        }
 241
 242        public bool? IsSecondaryAudio(MediaStream stream)
 243        {
 398244            if (stream.IsExternal)
 245            {
 10246                return false;
 247            }
 248
 249            // Look for the first audio track
 1940250            foreach (var currentStream in MediaStreams)
 251            {
 776252                if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
 253                {
 388254                    return currentStream.Index != stream.Index;
 255                }
 256            }
 257
 0258            return null;
 388259        }
 260    }
 261}