diff options
Diffstat (limited to 'MediaBrowser.Api/ApiEntryPoint.cs')
| -rw-r--r-- | MediaBrowser.Api/ApiEntryPoint.cs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 3e9a0926b..154966240 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -42,6 +42,7 @@ namespace MediaBrowser.Api /// </summary> /// <param name="logger">The logger.</param> /// <param name="appPaths">The application paths.</param> + /// <param name="sessionManager">The session manager.</param> public ApiEntryPoint(ILogger logger, IServerApplicationPaths appPaths, ISessionManager sessionManager) { Logger = logger; @@ -99,7 +100,7 @@ namespace MediaBrowser.Api { var jobCount = _activeTranscodingJobs.Count; - Parallel.ForEach(_activeTranscodingJobs.ToList(), j => KillTranscodingJob(j, true)); + Parallel.ForEach(_activeTranscodingJobs.ToList(), j => KillTranscodingJob(j, FileDeleteMode.All)); // Try to allow for some time to kill the ffmpeg processes and delete the partial stream files if (jobCount > 0) @@ -119,14 +120,12 @@ namespace MediaBrowser.Api /// <param name="path">The path.</param> /// <param name="type">The type.</param> /// <param name="process">The process.</param> - /// <param name="startTimeTicks">The start time ticks.</param> /// <param name="deviceId">The device id.</param> /// <param name="state">The state.</param> /// <param name="cancellationTokenSource">The cancellation token source.</param> public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, - long? startTimeTicks, string deviceId, StreamState state, CancellationTokenSource cancellationTokenSource) @@ -139,7 +138,6 @@ namespace MediaBrowser.Api Path = path, Process = process, ActiveRequestCount = 1, - StartTimeTicks = startTimeTicks, DeviceId = deviceId, CancellationTokenSource = cancellationTokenSource }); @@ -215,9 +213,14 @@ namespace MediaBrowser.Api /// <returns><c>true</c> if [has active transcoding job] [the specified path]; otherwise, <c>false</c>.</returns> public bool HasActiveTranscodingJob(string path, TranscodingJobType type) { + return GetTranscodingJob(path, type) != null; + } + + public TranscodingJob GetTranscodingJob(string path, TranscodingJobType type) + { lock (_activeTranscodingJobs) { - return _activeTranscodingJobs.Any(j => j.Type == type && j.Path.Equals(path, StringComparison.OrdinalIgnoreCase)); + return _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && j.Path.Equals(path, StringComparison.OrdinalIgnoreCase)); } } @@ -290,16 +293,16 @@ namespace MediaBrowser.Api { var job = (TranscodingJob)state; - KillTranscodingJob(job, true); + KillTranscodingJob(job, FileDeleteMode.All); } /// <summary> /// Kills the single transcoding job. /// </summary> /// <param name="deviceId">The device id.</param> - /// <param name="deleteFiles">if set to <c>true</c> [delete files].</param> + /// <param name="deleteMode">The delete mode.</param> /// <exception cref="System.ArgumentNullException">sourcePath</exception> - internal void KillTranscodingJobs(string deviceId, bool deleteFiles) + internal void KillTranscodingJobs(string deviceId, FileDeleteMode deleteMode) { if (string.IsNullOrEmpty(deviceId)) { @@ -317,7 +320,7 @@ namespace MediaBrowser.Api foreach (var job in jobs) { - KillTranscodingJob(job, deleteFiles); + KillTranscodingJob(job, deleteMode); } } @@ -325,8 +328,8 @@ namespace MediaBrowser.Api /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> - /// <param name="deleteFiles">if set to <c>true</c> [delete files].</param> - private void KillTranscodingJob(TranscodingJob job, bool deleteFiles) + /// <param name="deleteMode">The delete mode.</param> + private void KillTranscodingJob(TranscodingJob job, FileDeleteMode deleteMode) { lock (_activeTranscodingJobs) { @@ -378,7 +381,7 @@ namespace MediaBrowser.Api } } - if (deleteFiles) + if (deleteMode == FileDeleteMode.All) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } @@ -486,12 +489,13 @@ namespace MediaBrowser.Api /// <value>The kill timer.</value> public Timer KillTimer { get; set; } - public long? StartTimeTicks { get; set; } public string DeviceId { get; set; } public CancellationTokenSource CancellationTokenSource { get; set; } public object ProcessLock = new object(); + + public bool HasExited { get; set; } } /// <summary> @@ -508,4 +512,10 @@ namespace MediaBrowser.Api /// </summary> Hls } + + public enum FileDeleteMode + { + None, + All + } } |
