EncodingJobInfo.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 IgnoreDts
  37. {
  38. get { return MediaSource.IgnoreDts; }
  39. }
  40. public bool IgnoreIndex
  41. {
  42. get { return MediaSource.IgnoreIndex; }
  43. }
  44. public string OutputContainer { get; set; }
  45. public string OutputVideoSync
  46. {
  47. get
  48. {
  49. // For live tv + recordings
  50. if (string.Equals(InputContainer, "mpegts", StringComparison.OrdinalIgnoreCase) ||
  51. string.Equals(InputContainer, "ts", StringComparison.OrdinalIgnoreCase))
  52. {
  53. return "cfr";
  54. }
  55. return "-1";
  56. }
  57. }
  58. public string AlbumCoverPath { get; set; }
  59. public string InputAudioSync { get; set; }
  60. public string InputVideoSync { get; set; }
  61. public TransportStreamTimestamp InputTimestamp { get; set; }
  62. public MediaStream AudioStream { get; set; }
  63. public List<string> SupportedAudioCodecs { get; set; }
  64. public List<string> SupportedVideoCodecs { get; set; }
  65. public string InputContainer { get; set; }
  66. public IsoType? IsoType { get; set; }
  67. public bool EnableMpegtsM2TsMode { get; set; }
  68. public BaseEncodingJobOptions BaseRequest { get; set; }
  69. public long? StartTimeTicks
  70. {
  71. get { return BaseRequest.StartTimeTicks; }
  72. }
  73. public bool CopyTimestamps
  74. {
  75. get { return BaseRequest.CopyTimestamps; }
  76. }
  77. public int? OutputAudioBitrate;
  78. public int? OutputAudioChannels;
  79. public int? OutputAudioSampleRate;
  80. public bool DeInterlace { get; set; }
  81. public bool IsVideoRequest { get; set; }
  82. public TranscodingJobType TranscodingType { get; set; }
  83. public EncodingJobInfo(ILogger logger, TranscodingJobType jobType)
  84. {
  85. _logger = logger;
  86. TranscodingType = jobType;
  87. RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  88. PlayableStreamFileNames = new List<string>();
  89. SupportedAudioCodecs = new List<string>();
  90. SupportedVideoCodecs = new List<string>();
  91. SupportedSubtitleCodecs = new List<string>();
  92. }
  93. public bool IsSegmentedLiveStream
  94. {
  95. get
  96. {
  97. return TranscodingType != TranscodingJobType.Progressive && !RunTimeTicks.HasValue;
  98. }
  99. }
  100. public bool EnableBreakOnNonKeyFrames(string videoCodec)
  101. {
  102. if (TranscodingType != TranscodingJobType.Progressive)
  103. {
  104. if (IsSegmentedLiveStream)
  105. {
  106. return false;
  107. }
  108. return BaseRequest.BreakOnNonKeyFrames && string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase);
  109. }
  110. return false;
  111. }
  112. /// <summary>
  113. /// Predicts the audio sample rate that will be in the output stream
  114. /// </summary>
  115. public double? TargetVideoLevel
  116. {
  117. get
  118. {
  119. var stream = VideoStream;
  120. var request = BaseRequest;
  121. return !string.IsNullOrEmpty(request.Level) && !request.Static
  122. ? double.Parse(request.Level, CultureInfo.InvariantCulture)
  123. : stream == null ? null : stream.Level;
  124. }
  125. }
  126. protected void DisposeIsoMount()
  127. {
  128. if (IsoMount != null)
  129. {
  130. try
  131. {
  132. IsoMount.Dispose();
  133. }
  134. catch (Exception ex)
  135. {
  136. _logger.ErrorException("Error disposing iso mount", ex);
  137. }
  138. IsoMount = null;
  139. }
  140. }
  141. public abstract void ReportTranscodingProgress(TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate);
  142. }
  143. /// <summary>
  144. /// Enum TranscodingJobType
  145. /// </summary>
  146. public enum TranscodingJobType
  147. {
  148. /// <summary>
  149. /// The progressive
  150. /// </summary>
  151. Progressive,
  152. /// <summary>
  153. /// The HLS
  154. /// </summary>
  155. Hls,
  156. /// <summary>
  157. /// The dash
  158. /// </summary>
  159. Dash
  160. }
  161. }