EncodingJobInfo.cs 5.7 KB

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