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