|
@@ -9,8 +9,8 @@ using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using Jellyfin.Api.Attributes;
|
|
|
+using Jellyfin.Api.Extensions;
|
|
|
using Jellyfin.Api.Helpers;
|
|
|
-using Jellyfin.Api.Models.PlaybackDtos;
|
|
|
using Jellyfin.Api.Models.StreamingDtos;
|
|
|
using Jellyfin.Data.Enums;
|
|
|
using Jellyfin.Extensions;
|
|
@@ -19,6 +19,7 @@ using MediaBrowser.Common.Configuration;
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
+using MediaBrowser.Controller.Streaming;
|
|
|
using MediaBrowser.MediaEncoding.Encoder;
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
using MediaBrowser.Model.Dlna;
|
|
@@ -51,7 +52,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
- private readonly TranscodingJobHelper _transcodingJobHelper;
|
|
|
+ private readonly ITranscodeManager _transcodeManager;
|
|
|
private readonly ILogger<DynamicHlsController> _logger;
|
|
|
private readonly EncodingHelper _encodingHelper;
|
|
|
private readonly IDynamicHlsPlaylistGenerator _dynamicHlsPlaylistGenerator;
|
|
@@ -67,7 +68,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
|
|
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
|
|
|
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
|
|
- /// <param name="transcodingJobHelper">Instance of the <see cref="TranscodingJobHelper"/> class.</param>
|
|
|
+ /// <param name="transcodeManager">Instance of the <see cref="ITranscodeManager"/> interface.</param>
|
|
|
/// <param name="logger">Instance of the <see cref="ILogger{DynamicHlsController}"/> interface.</param>
|
|
|
/// <param name="dynamicHlsHelper">Instance of <see cref="DynamicHlsHelper"/>.</param>
|
|
|
/// <param name="encodingHelper">Instance of <see cref="EncodingHelper"/>.</param>
|
|
@@ -79,7 +80,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
IServerConfigurationManager serverConfigurationManager,
|
|
|
IMediaEncoder mediaEncoder,
|
|
|
IFileSystem fileSystem,
|
|
|
- TranscodingJobHelper transcodingJobHelper,
|
|
|
+ ITranscodeManager transcodeManager,
|
|
|
ILogger<DynamicHlsController> logger,
|
|
|
DynamicHlsHelper dynamicHlsHelper,
|
|
|
EncodingHelper encodingHelper,
|
|
@@ -91,7 +92,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
_serverConfigurationManager = serverConfigurationManager;
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
_fileSystem = fileSystem;
|
|
|
- _transcodingJobHelper = transcodingJobHelper;
|
|
|
+ _transcodeManager = transcodeManager;
|
|
|
_logger = logger;
|
|
|
_dynamicHlsHelper = dynamicHlsHelper;
|
|
|
_encodingHelper = encodingHelper;
|
|
@@ -283,17 +284,17 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
_serverConfigurationManager,
|
|
|
_mediaEncoder,
|
|
|
_encodingHelper,
|
|
|
- _transcodingJobHelper,
|
|
|
+ _transcodeManager,
|
|
|
TranscodingJobType,
|
|
|
cancellationToken)
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
- TranscodingJobDto? job = null;
|
|
|
+ TranscodingJob? job = null;
|
|
|
var playlistPath = Path.ChangeExtension(state.OutputFilePath, ".m3u8");
|
|
|
|
|
|
if (!System.IO.File.Exists(playlistPath))
|
|
|
{
|
|
|
- var transcodingLock = _transcodingJobHelper.GetTranscodingLock(playlistPath);
|
|
|
+ var transcodingLock = _transcodeManager.GetTranscodingLock(playlistPath);
|
|
|
await transcodingLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
try
|
|
|
{
|
|
@@ -302,11 +303,11 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
// If the playlist doesn't already exist, startup ffmpeg
|
|
|
try
|
|
|
{
|
|
|
- job = await _transcodingJobHelper.StartFfMpeg(
|
|
|
+ job = await _transcodeManager.StartFfMpeg(
|
|
|
state,
|
|
|
playlistPath,
|
|
|
GetCommandLineArguments(playlistPath, state, true, 0),
|
|
|
- Request,
|
|
|
+ Request.HttpContext.User.GetUserId(),
|
|
|
TranscodingJobType,
|
|
|
cancellationTokenSource)
|
|
|
.ConfigureAwait(false);
|
|
@@ -331,11 +332,11 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- job ??= _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
+ job ??= _transcodeManager.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
|
|
|
if (job is not null)
|
|
|
{
|
|
|
- _transcodingJobHelper.OnTranscodeEndRequest(job);
|
|
|
+ _transcodeManager.OnTranscodeEndRequest(job);
|
|
|
}
|
|
|
|
|
|
var playlistText = HlsHelpers.GetLivePlaylistText(playlistPath, state);
|
|
@@ -1383,7 +1384,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
_serverConfigurationManager,
|
|
|
_mediaEncoder,
|
|
|
_encodingHelper,
|
|
|
- _transcodingJobHelper,
|
|
|
+ _transcodeManager,
|
|
|
TranscodingJobType,
|
|
|
cancellationTokenSource.Token)
|
|
|
.ConfigureAwait(false);
|
|
@@ -1421,7 +1422,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
_serverConfigurationManager,
|
|
|
_mediaEncoder,
|
|
|
_encodingHelper,
|
|
|
- _transcodingJobHelper,
|
|
|
+ _transcodeManager,
|
|
|
TranscodingJobType,
|
|
|
cancellationToken)
|
|
|
.ConfigureAwait(false);
|
|
@@ -1432,16 +1433,16 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
|
|
|
var segmentExtension = EncodingHelper.GetSegmentFileExtension(state.Request.SegmentContainer);
|
|
|
|
|
|
- TranscodingJobDto? job;
|
|
|
+ TranscodingJob? job;
|
|
|
|
|
|
if (System.IO.File.Exists(segmentPath))
|
|
|
{
|
|
|
- job = _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
+ job = _transcodeManager.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
_logger.LogDebug("returning {0} [it exists, try 1]", segmentPath);
|
|
|
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, segmentId, job, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
|
|
|
- var transcodingLock = _transcodingJobHelper.GetTranscodingLock(playlistPath);
|
|
|
+ var transcodingLock = _transcodeManager.GetTranscodingLock(playlistPath);
|
|
|
await transcodingLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
var released = false;
|
|
|
var startTranscoding = false;
|
|
@@ -1450,7 +1451,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
{
|
|
|
if (System.IO.File.Exists(segmentPath))
|
|
|
{
|
|
|
- job = _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
+ job = _transcodeManager.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
transcodingLock.Release();
|
|
|
released = true;
|
|
|
_logger.LogDebug("returning {0} [it exists, try 2]", segmentPath);
|
|
@@ -1488,7 +1489,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
// If the playlist doesn't already exist, startup ffmpeg
|
|
|
try
|
|
|
{
|
|
|
- await _transcodingJobHelper.KillTranscodingJobs(streamingRequest.DeviceId, streamingRequest.PlaySessionId, p => false)
|
|
|
+ await _transcodeManager.KillTranscodingJobs(streamingRequest.DeviceId, streamingRequest.PlaySessionId, p => false)
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
if (currentTranscodingIndex.HasValue)
|
|
@@ -1499,11 +1500,11 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
streamingRequest.StartTimeTicks = streamingRequest.CurrentRuntimeTicks;
|
|
|
|
|
|
state.WaitForPath = segmentPath;
|
|
|
- job = await _transcodingJobHelper.StartFfMpeg(
|
|
|
+ job = await _transcodeManager.StartFfMpeg(
|
|
|
state,
|
|
|
playlistPath,
|
|
|
GetCommandLineArguments(playlistPath, state, false, segmentId),
|
|
|
- Request,
|
|
|
+ Request.HttpContext.User.GetUserId(),
|
|
|
TranscodingJobType,
|
|
|
cancellationTokenSource).ConfigureAwait(false);
|
|
|
}
|
|
@@ -1517,7 +1518,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- job = _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
+ job = _transcodeManager.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
if (job?.TranscodingThrottler is not null)
|
|
|
{
|
|
|
await job.TranscodingThrottler.UnpauseTranscoding().ConfigureAwait(false);
|
|
@@ -1534,7 +1535,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
}
|
|
|
|
|
|
_logger.LogDebug("returning {0} [general case]", segmentPath);
|
|
|
- job ??= _transcodingJobHelper.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
+ job ??= _transcodeManager.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
|
|
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, segmentId, job, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
|
|
@@ -1922,7 +1923,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
string segmentPath,
|
|
|
string segmentExtension,
|
|
|
int segmentIndex,
|
|
|
- TranscodingJobDto? transcodingJob,
|
|
|
+ TranscodingJob? transcodingJob,
|
|
|
CancellationToken cancellationToken)
|
|
|
{
|
|
|
var segmentExists = System.IO.File.Exists(segmentPath);
|
|
@@ -1991,7 +1992,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
return GetSegmentResult(state, segmentPath, transcodingJob);
|
|
|
}
|
|
|
|
|
|
- private ActionResult GetSegmentResult(StreamState state, string segmentPath, TranscodingJobDto? transcodingJob)
|
|
|
+ private ActionResult GetSegmentResult(StreamState state, string segmentPath, TranscodingJob? transcodingJob)
|
|
|
{
|
|
|
var segmentEndingPositionTicks = state.Request.CurrentRuntimeTicks + state.Request.ActualSegmentLengthTicks;
|
|
|
|
|
@@ -2001,7 +2002,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
if (transcodingJob is not null)
|
|
|
{
|
|
|
transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks);
|
|
|
- _transcodingJobHelper.OnTranscodeEndRequest(transcodingJob);
|
|
|
+ _transcodeManager.OnTranscodeEndRequest(transcodingJob);
|
|
|
}
|
|
|
|
|
|
return Task.CompletedTask;
|
|
@@ -2012,7 +2013,7 @@ public class DynamicHlsController : BaseJellyfinApiController
|
|
|
|
|
|
private int? GetCurrentTranscodingIndex(string playlist, string segmentExtension)
|
|
|
{
|
|
|
- var job = _transcodingJobHelper.GetTranscodingJob(playlist, TranscodingJobType);
|
|
|
+ var job = _transcodeManager.GetTranscodingJob(playlist, TranscodingJobType);
|
|
|
|
|
|
if (job is null || job.HasExited)
|
|
|
{
|