< 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: 54
Uncovered lines: 7
Coverable lines: 61
Total lines: 263
Line coverage: 88.5%
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%131281.81%
GetDefaultAudioStream(...)70%322069.23%
GetMediaStream(...)100%66100%
GetStreamCount(...)100%66100%
IsSecondaryAudio(...)87.5%8885.71%

File(s)

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

#LineLine coverage
 1#nullable disable
 2#pragma warning disable CS1591
 3
 4using System.Collections.Generic;
 5using System.ComponentModel;
 6using System.Text.Json.Serialization;
 7using Jellyfin.Data.Enums;
 8using MediaBrowser.Model.Entities;
 9using MediaBrowser.Model.MediaInfo;
 10using MediaBrowser.Model.Session;
 11
 12namespace MediaBrowser.Model.Dto
 13{
 14    public class MediaSourceInfo
 15    {
 16        public MediaSourceInfo()
 17        {
 36418            Formats = [];
 36419            MediaStreams = [];
 36420            MediaAttachments = [];
 36421            RequiredHttpHeaders = [];
 36422            SupportsTranscoding = true;
 36423            SupportsDirectStream = true;
 36424            SupportsDirectPlay = true;
 36425            SupportsProbing = true;
 36426            UseMostCompatibleTranscodingProfile = false;
 36427            DefaultAudioIndexSource = AudioIndexSource.None;
 36428        }
 29
 30        public MediaProtocol Protocol { get; set; }
 31
 32        public string Id { get; set; }
 33
 34        public string Path { get; set; }
 35
 36        public string EncoderPath { get; set; }
 37
 38        public MediaProtocol? EncoderProtocol { get; set; }
 39
 40        public MediaSourceType Type { get; set; }
 41
 42        public string Container { get; set; }
 43
 44        public long? Size { get; set; }
 45
 46        public string Name { get; set; }
 47
 48        /// <summary>
 49        /// Gets or sets a value indicating whether the media is remote.
 50        /// Differentiate internet url vs local network.
 51        /// </summary>
 52        public bool IsRemote { get; set; }
 53
 54        public string ETag { get; set; }
 55
 56        public long? RunTimeTicks { get; set; }
 57
 58        public bool ReadAtNativeFramerate { get; set; }
 59
 60        public bool IgnoreDts { get; set; }
 61
 62        public bool IgnoreIndex { get; set; }
 63
 64        public bool GenPtsInput { get; set; }
 65
 66        public bool SupportsTranscoding { get; set; }
 67
 68        public bool SupportsDirectStream { get; set; }
 69
 70        public bool SupportsDirectPlay { get; set; }
 71
 72        public bool IsInfiniteStream { get; set; }
 73
 74        [DefaultValue(false)]
 75        public bool UseMostCompatibleTranscodingProfile { get; set; }
 76
 77        public bool RequiresOpening { get; set; }
 78
 79        public string OpenToken { get; set; }
 80
 81        public bool RequiresClosing { get; set; }
 82
 83        public string LiveStreamId { get; set; }
 84
 85        public int? BufferMs { get; set; }
 86
 87        public bool RequiresLooping { get; set; }
 88
 89        public bool SupportsProbing { get; set; }
 90
 91        public VideoType? VideoType { get; set; }
 92
 93        public IsoType? IsoType { get; set; }
 94
 95        public Video3DFormat? Video3DFormat { get; set; }
 96
 97        public IReadOnlyList<MediaStream> MediaStreams { get; set; }
 98
 99        public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
 100
 101        public string[] Formats { get; set; }
 102
 103        public int? Bitrate { get; set; }
 104
 105        public int? FallbackMaxStreamingBitrate { get; set; }
 106
 107        public TransportStreamTimestamp? Timestamp { get; set; }
 108
 109        public Dictionary<string, string> RequiredHttpHeaders { get; set; }
 110
 111        public string TranscodingUrl { get; set; }
 112
 113        public MediaStreamProtocol TranscodingSubProtocol { get; set; }
 114
 115        public string TranscodingContainer { get; set; }
 116
 117        public int? AnalyzeDurationMs { get; set; }
 118
 119        [JsonIgnore]
 120        public TranscodeReason TranscodeReasons { get; set; }
 121
 122        [JsonIgnore]
 123        public AudioIndexSource DefaultAudioIndexSource { get; set; }
 124
 125        public int? DefaultAudioStreamIndex { get; set; }
 126
 127        public int? DefaultSubtitleStreamIndex { get; set; }
 128
 129        public bool HasSegments { get; set; }
 130
 131        [JsonIgnore]
 132        public MediaStream VideoStream
 133        {
 134            get
 135            {
 4245136                foreach (var i in MediaStreams)
 137                {
 1411138                    if (i.Type == MediaStreamType.Video)
 139                    {
 1411140                        return i;
 141                    }
 142                }
 143
 6144                return null;
 1411145            }
 146        }
 147
 148        public void InferTotalBitrate(bool force = false)
 149        {
 5150            if (MediaStreams is null)
 151            {
 0152                return;
 153            }
 154
 5155            if (!force && Bitrate.HasValue)
 156            {
 0157                return;
 158            }
 159
 5160            var bitrate = 0;
 34161            foreach (var stream in MediaStreams)
 162            {
 12163                if (!stream.IsExternal)
 164                {
 12165                    bitrate += stream.BitRate ?? 0;
 166                }
 167            }
 168
 5169            if (bitrate > 0)
 170            {
 5171                Bitrate = bitrate;
 172            }
 5173        }
 174
 175        public MediaStream GetDefaultAudioStream(int? defaultIndex)
 176        {
 1248177            if (defaultIndex.HasValue && defaultIndex != -1)
 178            {
 1244179                var val = defaultIndex.Value;
 180
 6576181                foreach (var i in MediaStreams)
 182                {
 2666183                    if (i.Type == MediaStreamType.Audio && i.Index == val)
 184                    {
 1244185                        return i;
 186                    }
 187                }
 188            }
 189
 8190            foreach (var i in MediaStreams)
 191            {
 0192                if (i.Type == MediaStreamType.Audio && i.IsDefault)
 193                {
 0194                    return i;
 195                }
 196            }
 197
 8198            foreach (var i in MediaStreams)
 199            {
 0200                if (i.Type == MediaStreamType.Audio)
 201                {
 0202                    return i;
 203                }
 204            }
 205
 4206            return null;
 1244207        }
 208
 209        public MediaStream GetMediaStream(MediaStreamType type, int index)
 210        {
 2681211            foreach (var i in MediaStreams)
 212            {
 1137213                if (i.Type == type && i.Index == index)
 214                {
 371215                    return i;
 216                }
 217            }
 218
 18219            return null;
 371220        }
 221
 222        public int? GetStreamCount(MediaStreamType type)
 223        {
 1750224            int numMatches = 0;
 1750225            int numStreams = 0;
 226
 18224227            foreach (var i in MediaStreams)
 228            {
 7362229                numStreams++;
 7362230                if (i.Type == type)
 231                {
 2129232                    numMatches++;
 233                }
 234            }
 235
 1750236            if (numStreams == 0)
 237            {
 2238                return null;
 239            }
 240
 1748241            return numMatches;
 242        }
 243
 244        public bool? IsSecondaryAudio(MediaStream stream)
 245        {
 418246            if (stream.IsExternal)
 247            {
 10248                return false;
 249            }
 250
 251            // Look for the first audio track
 2040252            foreach (var currentStream in MediaStreams)
 253            {
 816254                if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
 255                {
 408256                    return currentStream.Index != stream.Index;
 257                }
 258            }
 259
 0260            return null;
 408261        }
 262    }
 263}