MediaSourceInfo.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Text.Json.Serialization;
  6. using Jellyfin.Data.Enums;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.MediaInfo;
  9. using MediaBrowser.Model.Session;
  10. namespace MediaBrowser.Model.Dto
  11. {
  12. public class MediaSourceInfo
  13. {
  14. public MediaSourceInfo()
  15. {
  16. Formats = [];
  17. MediaStreams = [];
  18. MediaAttachments = [];
  19. RequiredHttpHeaders = [];
  20. SupportsTranscoding = true;
  21. SupportsDirectStream = true;
  22. SupportsDirectPlay = true;
  23. SupportsProbing = true;
  24. UseMostCompatibleTranscodingProfile = false;
  25. DefaultAudioIndexSource = AudioIndexSource.None;
  26. }
  27. public MediaProtocol Protocol { get; set; }
  28. public string Id { get; set; }
  29. public string Path { get; set; }
  30. public string EncoderPath { get; set; }
  31. public MediaProtocol? EncoderProtocol { get; set; }
  32. public MediaSourceType Type { get; set; }
  33. public string Container { get; set; }
  34. public long? Size { get; set; }
  35. public string Name { get; set; }
  36. /// <summary>
  37. /// Gets or sets a value indicating whether the media is remote.
  38. /// Differentiate internet url vs local network.
  39. /// </summary>
  40. public bool IsRemote { get; set; }
  41. public string ETag { get; set; }
  42. public long? RunTimeTicks { get; set; }
  43. public bool ReadAtNativeFramerate { get; set; }
  44. public bool IgnoreDts { get; set; }
  45. public bool IgnoreIndex { get; set; }
  46. public bool GenPtsInput { get; set; }
  47. public bool SupportsTranscoding { get; set; }
  48. public bool SupportsDirectStream { get; set; }
  49. public bool SupportsDirectPlay { get; set; }
  50. public bool IsInfiniteStream { get; set; }
  51. [DefaultValue(false)]
  52. public bool UseMostCompatibleTranscodingProfile { get; set; }
  53. public bool RequiresOpening { get; set; }
  54. public string OpenToken { get; set; }
  55. public bool RequiresClosing { get; set; }
  56. public string LiveStreamId { get; set; }
  57. public int? BufferMs { get; set; }
  58. public bool RequiresLooping { get; set; }
  59. public bool SupportsProbing { get; set; }
  60. public VideoType? VideoType { get; set; }
  61. public IsoType? IsoType { get; set; }
  62. public Video3DFormat? Video3DFormat { get; set; }
  63. public IReadOnlyList<MediaStream> MediaStreams { get; set; }
  64. public IReadOnlyList<MediaAttachment> MediaAttachments { get; set; }
  65. public string[] Formats { get; set; }
  66. public int? Bitrate { get; set; }
  67. public int? FallbackMaxStreamingBitrate { get; set; }
  68. public TransportStreamTimestamp? Timestamp { get; set; }
  69. public Dictionary<string, string> RequiredHttpHeaders { get; set; }
  70. public string TranscodingUrl { get; set; }
  71. public MediaStreamProtocol TranscodingSubProtocol { get; set; }
  72. public string TranscodingContainer { get; set; }
  73. public int? AnalyzeDurationMs { get; set; }
  74. [JsonIgnore]
  75. public TranscodeReason TranscodeReasons { get; set; }
  76. [JsonIgnore]
  77. public AudioIndexSource DefaultAudioIndexSource { get; set; }
  78. public int? DefaultAudioStreamIndex { get; set; }
  79. public int? DefaultSubtitleStreamIndex { get; set; }
  80. public bool HasSegments { get; set; }
  81. [JsonIgnore]
  82. public MediaStream VideoStream
  83. {
  84. get
  85. {
  86. foreach (var i in MediaStreams)
  87. {
  88. if (i.Type == MediaStreamType.Video)
  89. {
  90. return i;
  91. }
  92. }
  93. return null;
  94. }
  95. }
  96. public void InferTotalBitrate(bool force = false)
  97. {
  98. if (MediaStreams is null)
  99. {
  100. return;
  101. }
  102. if (!force && Bitrate.HasValue)
  103. {
  104. return;
  105. }
  106. var bitrate = 0;
  107. foreach (var stream in MediaStreams)
  108. {
  109. if (!stream.IsExternal)
  110. {
  111. bitrate += stream.BitRate ?? 0;
  112. }
  113. }
  114. if (bitrate > 0)
  115. {
  116. Bitrate = bitrate;
  117. }
  118. }
  119. public MediaStream GetDefaultAudioStream(int? defaultIndex)
  120. {
  121. if (defaultIndex.HasValue && defaultIndex != -1)
  122. {
  123. var val = defaultIndex.Value;
  124. foreach (var i in MediaStreams)
  125. {
  126. if (i.Type == MediaStreamType.Audio && i.Index == val)
  127. {
  128. return i;
  129. }
  130. }
  131. }
  132. foreach (var i in MediaStreams)
  133. {
  134. if (i.Type == MediaStreamType.Audio && i.IsDefault)
  135. {
  136. return i;
  137. }
  138. }
  139. foreach (var i in MediaStreams)
  140. {
  141. if (i.Type == MediaStreamType.Audio)
  142. {
  143. return i;
  144. }
  145. }
  146. return null;
  147. }
  148. public MediaStream GetMediaStream(MediaStreamType type, int index)
  149. {
  150. foreach (var i in MediaStreams)
  151. {
  152. if (i.Type == type && i.Index == index)
  153. {
  154. return i;
  155. }
  156. }
  157. return null;
  158. }
  159. public int? GetStreamCount(MediaStreamType type)
  160. {
  161. int numMatches = 0;
  162. int numStreams = 0;
  163. foreach (var i in MediaStreams)
  164. {
  165. numStreams++;
  166. if (i.Type == type)
  167. {
  168. numMatches++;
  169. }
  170. }
  171. if (numStreams == 0)
  172. {
  173. return null;
  174. }
  175. return numMatches;
  176. }
  177. public bool? IsSecondaryAudio(MediaStream stream)
  178. {
  179. if (stream.IsExternal)
  180. {
  181. return false;
  182. }
  183. // Look for the first audio track
  184. foreach (var currentStream in MediaStreams)
  185. {
  186. if (currentStream.Type == MediaStreamType.Audio && !currentStream.IsExternal)
  187. {
  188. return currentStream.Index != stream.Index;
  189. }
  190. }
  191. return null;
  192. }
  193. }
  194. }