MediaSourceInfo.cs 6.6 KB

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