ITranscodeManager.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using MediaBrowser.Controller.Streaming;
  5. namespace MediaBrowser.Controller.MediaEncoding;
  6. /// <summary>
  7. /// A service for managing media transcoding.
  8. /// </summary>
  9. public interface ITranscodeManager
  10. {
  11. /// <summary>
  12. /// Get transcoding job.
  13. /// </summary>
  14. /// <param name="playSessionId">Playback session id.</param>
  15. /// <returns>The transcoding job.</returns>
  16. public TranscodingJob? GetTranscodingJob(string playSessionId);
  17. /// <summary>
  18. /// Get transcoding job.
  19. /// </summary>
  20. /// <param name="path">Path to the transcoding file.</param>
  21. /// <param name="type">The <see cref="TranscodingJobType"/>.</param>
  22. /// <returns>The transcoding job.</returns>
  23. public TranscodingJob? GetTranscodingJob(string path, TranscodingJobType type);
  24. /// <summary>
  25. /// Ping transcoding job.
  26. /// </summary>
  27. /// <param name="playSessionId">Play session id.</param>
  28. /// <param name="isUserPaused">Is user paused.</param>
  29. /// <exception cref="ArgumentNullException">Play session id is null.</exception>
  30. public void PingTranscodingJob(string playSessionId, bool? isUserPaused);
  31. /// <summary>
  32. /// Kills the single transcoding job.
  33. /// </summary>
  34. /// <param name="deviceId">The device id.</param>
  35. /// <param name="playSessionId">The play session identifier.</param>
  36. /// <param name="deleteFiles">The delete files.</param>
  37. /// <returns>Task.</returns>
  38. public Task KillTranscodingJobs(string deviceId, string? playSessionId, Func<string, bool> deleteFiles);
  39. /// <summary>
  40. /// Report the transcoding progress to the session manager.
  41. /// </summary>
  42. /// <param name="job">The <see cref="TranscodingJob"/> of which the progress will be reported.</param>
  43. /// <param name="state">The <see cref="StreamState"/> of the current transcoding job.</param>
  44. /// <param name="transcodingPosition">The current transcoding position.</param>
  45. /// <param name="framerate">The framerate of the transcoding job.</param>
  46. /// <param name="percentComplete">The completion percentage of the transcode.</param>
  47. /// <param name="bytesTranscoded">The number of bytes transcoded.</param>
  48. /// <param name="bitRate">The bitrate of the transcoding job.</param>
  49. public void ReportTranscodingProgress(
  50. TranscodingJob job,
  51. StreamState state,
  52. TimeSpan? transcodingPosition,
  53. float? framerate,
  54. double? percentComplete,
  55. long? bytesTranscoded,
  56. int? bitRate);
  57. /// <summary>
  58. /// Starts FFMpeg.
  59. /// </summary>
  60. /// <param name="state">The state.</param>
  61. /// <param name="outputPath">The output path.</param>
  62. /// <param name="commandLineArguments">The command line arguments for FFmpeg.</param>
  63. /// <param name="userId">The user id.</param>
  64. /// <param name="transcodingJobType">The <see cref="TranscodingJobType"/>.</param>
  65. /// <param name="cancellationTokenSource">The cancellation token source.</param>
  66. /// <param name="workingDirectory">The working directory.</param>
  67. /// <returns>Task.</returns>
  68. public Task<TranscodingJob> StartFfMpeg(
  69. StreamState state,
  70. string outputPath,
  71. string commandLineArguments,
  72. Guid userId,
  73. TranscodingJobType transcodingJobType,
  74. CancellationTokenSource cancellationTokenSource,
  75. string? workingDirectory = null);
  76. /// <summary>
  77. /// Called when [transcode begin request].
  78. /// </summary>
  79. /// <param name="path">The path.</param>
  80. /// <param name="type">The type.</param>
  81. /// <returns>The <see cref="TranscodingJob"/>.</returns>
  82. public TranscodingJob? OnTranscodeBeginRequest(string path, TranscodingJobType type);
  83. /// <summary>
  84. /// Called when [transcode end].
  85. /// </summary>
  86. /// <param name="job">The transcode job.</param>
  87. public void OnTranscodeEndRequest(TranscodingJob job);
  88. /// <summary>
  89. /// Transcoding lock.
  90. /// </summary>
  91. /// <param name="outputPath">The output path of the transcoded file.</param>
  92. /// <param name="cancellationToken">The cancellation token.</param>
  93. /// <returns>An <see cref="IDisposable"/>.</returns>
  94. ValueTask<IDisposable> LockAsync(string outputPath, CancellationToken cancellationToken);
  95. }