EncodingJobInfo.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 false;
  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 + recordings
  84. if (string.Equals(InputContainer, "mpegts", StringComparison.OrdinalIgnoreCase) ||
  85. string.Equals(InputContainer, "ts", StringComparison.OrdinalIgnoreCase))
  86. {
  87. return "cfr";
  88. }
  89. return "-1";
  90. }
  91. }
  92. public string AlbumCoverPath { get; set; }
  93. public string InputAudioSync { get; set; }
  94. public string InputVideoSync { get; set; }
  95. public TransportStreamTimestamp InputTimestamp { get; set; }
  96. public MediaStream AudioStream { get; set; }
  97. public List<string> SupportedAudioCodecs { get; set; }
  98. public List<string> SupportedVideoCodecs { get; set; }
  99. public string InputContainer { get; set; }
  100. public IsoType? IsoType { get; set; }
  101. public bool EnableMpegtsM2TsMode { get; set; }
  102. public BaseEncodingJobOptions BaseRequest { get; set; }
  103. public long? StartTimeTicks
  104. {
  105. get { return BaseRequest.StartTimeTicks; }
  106. }
  107. public bool CopyTimestamps
  108. {
  109. get { return BaseRequest.CopyTimestamps; }
  110. }
  111. public int? OutputAudioBitrate;
  112. public int? OutputAudioChannels;
  113. public int? OutputAudioSampleRate;
  114. public bool DeInterlace { get; set; }
  115. public bool IsVideoRequest { get; set; }
  116. public TranscodingJobType TranscodingType { get; set; }
  117. public EncodingJobInfo(ILogger logger, TranscodingJobType jobType)
  118. {
  119. _logger = logger;
  120. TranscodingType = jobType;
  121. RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  122. PlayableStreamFileNames = new List<string>();
  123. SupportedAudioCodecs = new List<string>();
  124. SupportedVideoCodecs = new List<string>();
  125. SupportedSubtitleCodecs = new List<string>();
  126. }
  127. public bool IsSegmentedLiveStream
  128. {
  129. get
  130. {
  131. return TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
  132. }
  133. }
  134. public bool EnableBreakOnNonKeyFrames(string videoCodec)
  135. {
  136. if (TranscodingType != TranscodingJobType.Progressive)
  137. {
  138. if (IsSegmentedLiveStream)
  139. {
  140. return false;
  141. }
  142. return BaseRequest.BreakOnNonKeyFrames && string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase);
  143. }
  144. return false;
  145. }
  146. /// <summary>
  147. /// Predicts the audio sample rate that will be in the output stream
  148. /// </summary>
  149. public double? TargetVideoLevel
  150. {
  151. get
  152. {
  153. var stream = VideoStream;
  154. var request = BaseRequest;
  155. return !string.IsNullOrEmpty(request.Level) && !request.Static
  156. ? double.Parse(request.Level, CultureInfo.InvariantCulture)
  157. : stream == null ? null : stream.Level;
  158. }
  159. }
  160. protected void DisposeIsoMount()
  161. {
  162. if (IsoMount != null)
  163. {
  164. try
  165. {
  166. IsoMount.Dispose();
  167. }
  168. catch (Exception ex)
  169. {
  170. _logger.ErrorException("Error disposing iso mount", ex);
  171. }
  172. IsoMount = null;
  173. }
  174. }
  175. public abstract void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate);
  176. }
  177. /// <summary>
  178. /// Enum TranscodingJobType
  179. /// </summary>
  180. public enum TranscodingJobType
  181. {
  182. /// <summary>
  183. /// The progressive
  184. /// </summary>
  185. Progressive,
  186. /// <summary>
  187. /// The HLS
  188. /// </summary>
  189. Hls,
  190. /// <summary>
  191. /// The dash
  192. /// </summary>
  193. Dash
  194. }
  195. }