EncodingJobInfo.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Model.Dlna;
  6. using MediaBrowser.Model.Dto;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.IO;
  9. using MediaBrowser.Model.Logging;
  10. using MediaBrowser.Model.MediaInfo;
  11. namespace MediaBrowser.Controller.MediaEncoding
  12. {
  13. // For now, a common base class until the API and MediaEncoding classes are unified
  14. public abstract class EncodingJobInfo
  15. {
  16. private readonly ILogger _logger;
  17. public MediaStream VideoStream { get; set; }
  18. public VideoType VideoType { get; set; }
  19. public Dictionary<string, string> RemoteHttpHeaders { get; set; }
  20. public string OutputVideoCodec { get; set; }
  21. public MediaProtocol InputProtocol { get; set; }
  22. public string MediaPath { get; set; }
  23. public bool IsInputVideo { get; set; }
  24. public IIsoMount IsoMount { get; set; }
  25. public List<string> PlayableStreamFileNames { get; set; }
  26. public string OutputAudioCodec { get; set; }
  27. public int? OutputVideoBitrate { get; set; }
  28. public MediaStream SubtitleStream { get; set; }
  29. public SubtitleDeliveryMethod SubtitleDeliveryMethod { get; set; }
  30. public List<string> SupportedSubtitleCodecs { get; set; }
  31. public int InternalSubtitleStreamOffset { get; set; }
  32. public MediaSourceInfo MediaSource { get; set; }
  33. public User User { get; set; }
  34. public long? RunTimeTicks { get; set; }
  35. public bool ReadInputAtNativeFramerate { get; set; }
  36. public bool IgnoreInputDts
  37. {
  38. get
  39. {
  40. return MediaSource.IgnoreDts;
  41. }
  42. }
  43. public bool IgnoreInputIndex
  44. {
  45. get
  46. {
  47. return MediaSource.IgnoreIndex;
  48. }
  49. }
  50. public bool GenPtsInput
  51. {
  52. get
  53. {
  54. return MediaSource.GenPtsInput;
  55. }
  56. }
  57. public bool DiscardCorruptFramesInput
  58. {
  59. get
  60. {
  61. return false;
  62. }
  63. }
  64. public bool EnableFastSeekInput
  65. {
  66. get
  67. {
  68. return false;
  69. }
  70. }
  71. public bool GenPtsOutput
  72. {
  73. get
  74. {
  75. return false;
  76. }
  77. }
  78. public string OutputContainer { get; set; }
  79. public string OutputVideoSync
  80. {
  81. get
  82. {
  83. // For live tv + in progress recordings
  84. if (string.Equals(InputContainer, "mpegts", StringComparison.OrdinalIgnoreCase) || string.Equals(InputContainer, "ts", StringComparison.OrdinalIgnoreCase))
  85. {
  86. if (!MediaSource.RunTimeTicks.HasValue)
  87. {
  88. return "cfr";
  89. }
  90. }
  91. return "-1";
  92. }
  93. }
  94. public string AlbumCoverPath { get; set; }
  95. public string InputAudioSync { get; set; }
  96. public string InputVideoSync { get; set; }
  97. public TransportStreamTimestamp InputTimestamp { get; set; }
  98. public MediaStream AudioStream { get; set; }
  99. public List<string> SupportedAudioCodecs { get; set; }
  100. public List<string> SupportedVideoCodecs { get; set; }
  101. public string InputContainer { get; set; }
  102. public IsoType? IsoType { get; set; }
  103. public bool EnableMpegtsM2TsMode { get; set; }
  104. public BaseEncodingJobOptions BaseRequest { get; set; }
  105. public long? StartTimeTicks
  106. {
  107. get { return BaseRequest.StartTimeTicks; }
  108. }
  109. public bool CopyTimestamps
  110. {
  111. get { return BaseRequest.CopyTimestamps; }
  112. }
  113. public int? OutputAudioBitrate;
  114. public int? OutputAudioChannels;
  115. public int? OutputAudioSampleRate;
  116. public bool DeInterlace { get; set; }
  117. public bool IsVideoRequest { get; set; }
  118. public TranscodingJobType TranscodingType { get; set; }
  119. public EncodingJobInfo(ILogger logger, TranscodingJobType jobType)
  120. {
  121. _logger = logger;
  122. TranscodingType = jobType;
  123. RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  124. PlayableStreamFileNames = new List<string>();
  125. SupportedAudioCodecs = new List<string>();
  126. SupportedVideoCodecs = new List<string>();
  127. SupportedSubtitleCodecs = new List<string>();
  128. }
  129. public bool IsSegmentedLiveStream
  130. {
  131. get
  132. {
  133. return TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
  134. }
  135. }
  136. public bool EnableBreakOnNonKeyFrames(string videoCodec)
  137. {
  138. if (TranscodingType != TranscodingJobType.Progressive)
  139. {
  140. if (IsSegmentedLiveStream)
  141. {
  142. return false;
  143. }
  144. return BaseRequest.BreakOnNonKeyFrames && string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase);
  145. }
  146. return false;
  147. }
  148. /// <summary>
  149. /// Predicts the audio sample rate that will be in the output stream
  150. /// </summary>
  151. public double? TargetVideoLevel
  152. {
  153. get
  154. {
  155. var stream = VideoStream;
  156. var request = BaseRequest;
  157. return !string.IsNullOrEmpty(request.Level) && !request.Static
  158. ? double.Parse(request.Level, CultureInfo.InvariantCulture)
  159. : stream == null ? null : stream.Level;
  160. }
  161. }
  162. protected void DisposeIsoMount()
  163. {
  164. if (IsoMount != null)
  165. {
  166. try
  167. {
  168. IsoMount.Dispose();
  169. }
  170. catch (Exception ex)
  171. {
  172. _logger.ErrorException("Error disposing iso mount", ex);
  173. }
  174. IsoMount = null;
  175. }
  176. }
  177. public abstract void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate);
  178. }
  179. /// <summary>
  180. /// Enum TranscodingJobType
  181. /// </summary>
  182. public enum TranscodingJobType
  183. {
  184. /// <summary>
  185. /// The progressive
  186. /// </summary>
  187. Progressive,
  188. /// <summary>
  189. /// The HLS
  190. /// </summary>
  191. Hls,
  192. /// <summary>
  193. /// The dash
  194. /// </summary>
  195. Dash
  196. }
  197. }