MediaSourceInfo.cs 6.5 KB

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