| | | 1 | | #nullable disable |
| | | 2 | | #pragma warning disable CS1591 |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using System.Text.Json.Serialization; |
| | | 7 | | using Jellyfin.Data.Enums; |
| | | 8 | | using MediaBrowser.Model.Entities; |
| | | 9 | | using MediaBrowser.Model.MediaInfo; |
| | | 10 | | using MediaBrowser.Model.Session; |
| | | 11 | | |
| | | 12 | | namespace MediaBrowser.Model.Dto |
| | | 13 | | { |
| | | 14 | | public class MediaSourceInfo |
| | | 15 | | { |
| | | 16 | | public MediaSourceInfo() |
| | | 17 | | { |
| | 364 | 18 | | Formats = []; |
| | 364 | 19 | | MediaStreams = []; |
| | 364 | 20 | | MediaAttachments = []; |
| | 364 | 21 | | RequiredHttpHeaders = []; |
| | 364 | 22 | | SupportsTranscoding = true; |
| | 364 | 23 | | SupportsDirectStream = true; |
| | 364 | 24 | | SupportsDirectPlay = true; |
| | 364 | 25 | | SupportsProbing = true; |
| | 364 | 26 | | UseMostCompatibleTranscodingProfile = false; |
| | 364 | 27 | | DefaultAudioIndexSource = AudioIndexSource.None; |
| | 364 | 28 | | } |
| | | 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 | | { |
| | 4245 | 136 | | foreach (var i in MediaStreams) |
| | | 137 | | { |
| | 1411 | 138 | | if (i.Type == MediaStreamType.Video) |
| | | 139 | | { |
| | 1411 | 140 | | return i; |
| | | 141 | | } |
| | | 142 | | } |
| | | 143 | | |
| | 6 | 144 | | return null; |
| | 1411 | 145 | | } |
| | | 146 | | } |
| | | 147 | | |
| | | 148 | | public void InferTotalBitrate(bool force = false) |
| | | 149 | | { |
| | 5 | 150 | | if (MediaStreams is null) |
| | | 151 | | { |
| | 0 | 152 | | return; |
| | | 153 | | } |
| | | 154 | | |
| | 5 | 155 | | if (!force && Bitrate.HasValue) |
| | | 156 | | { |
| | 0 | 157 | | return; |
| | | 158 | | } |
| | | 159 | | |
| | 5 | 160 | | var bitrate = 0; |
| | 34 | 161 | | foreach (var stream in MediaStreams) |
| | | 162 | | { |
| | 12 | 163 | | if (!stream.IsExternal) |
| | | 164 | | { |
| | 12 | 165 | | bitrate += stream.BitRate ?? 0; |
| | | 166 | | } |
| | | 167 | | } |
| | | 168 | | |
| | 5 | 169 | | if (bitrate > 0) |
| | | 170 | | { |
| | 5 | 171 | | Bitrate = bitrate; |
| | | 172 | | } |
| | 5 | 173 | | } |
| | | 174 | | |
| | | 175 | | public MediaStream GetDefaultAudioStream(int? defaultIndex) |
| | | 176 | | { |
| | 1248 | 177 | | if (defaultIndex.HasValue && defaultIndex != -1) |
| | | 178 | | { |
| | 1244 | 179 | | var val = defaultIndex.Value; |
| | | 180 | | |
| | 6576 | 181 | | foreach (var i in MediaStreams) |
| | | 182 | | { |
| | 2666 | 183 | | if (i.Type == MediaStreamType.Audio && i.Index == val) |
| | | 184 | | { |
| | 1244 | 185 | | return i; |
| | | 186 | | } |
| | | 187 | | } |
| | | 188 | | } |
| | | 189 | | |
| | 8 | 190 | | foreach (var i in MediaStreams) |
| | | 191 | | { |
| | 0 | 192 | | if (i.Type == MediaStreamType.Audio && i.IsDefault) |
| | | 193 | | { |
| | 0 | 194 | | return i; |
| | | 195 | | } |
| | | 196 | | } |
| | | 197 | | |
| | 8 | 198 | | foreach (var i in MediaStreams) |
| | | 199 | | { |
| | 0 | 200 | | if (i.Type == MediaStreamType.Audio) |
| | | 201 | | { |
| | 0 | 202 | | return i; |
| | | 203 | | } |
| | | 204 | | } |
| | | 205 | | |
| | 4 | 206 | | return null; |
| | 1244 | 207 | | } |
| | | 208 | | |
| | | 209 | | public MediaStream GetMediaStream(MediaStreamType type, int index) |
| | | 210 | | { |
| | 2681 | 211 | | foreach (var i in MediaStreams) |
| | | 212 | | { |
| | 1137 | 213 | | if (i.Type == type && i.Index == index) |
| | | 214 | | { |
| | 371 | 215 | | return i; |
| | | 216 | | } |
| | | 217 | | } |
| | | 218 | | |
| | 18 | 219 | | return null; |
| | 371 | 220 | | } |
| | | 221 | | |
| | | 222 | | public int? GetStreamCount(MediaStreamType type) |
| | | 223 | | { |
| | 1750 | 224 | | int numMatches = 0; |
| | 1750 | 225 | | int numStreams = 0; |
| | | 226 | | |
| | 18224 | 227 | | foreach (var i in MediaStreams) |
| | | 228 | | { |
| | 7362 | 229 | | numStreams++; |
| | 7362 | 230 | | if (i.Type == type) |
| | | 231 | | { |
| | 2129 | 232 | | numMatches++; |
| | | 233 | | } |
| | | 234 | | } |
| | | 235 | | |
| | 1750 | 236 | | if (numStreams == 0) |
| | | 237 | | { |
| | 2 | 238 | | return null; |
| | | 239 | | } |
| | | 240 | | |
| | 1748 | 241 | | return numMatches; |
| | | 242 | | } |
| | | 243 | | |
| | | 244 | | public bool? IsSecondaryAudio(MediaStream stream) |
| | | 245 | | { |
| | 418 | 246 | | if (stream.IsExternal) |
| | | 247 | | { |
| | 10 | 248 | | return false; |
| | | 249 | | } |
| | | 250 | | |
| | | 251 | | // Look for the first audio track |
| | 2040 | 252 | | foreach (var currentStream in MediaStreams) |
| | | 253 | | { |
| | 816 | 254 | | if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal) |
| | | 255 | | { |
| | 408 | 256 | | return currentStream.Index != stream.Index; |
| | | 257 | | } |
| | | 258 | | } |
| | | 259 | | |
| | 0 | 260 | | return null; |
| | 408 | 261 | | } |
| | | 262 | | } |
| | | 263 | | } |