mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-17 06:23:03 +03:00
rework live stream handling
This commit is contained in:
@@ -8,6 +8,7 @@ using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Session;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -44,7 +45,13 @@ namespace MediaBrowser.Api
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IMediaSourceManager _mediaSourceManager;
|
||||
|
||||
public readonly SemaphoreSlim TranscodingStartLock = new SemaphoreSlim(1, 1);
|
||||
/// <summary>
|
||||
/// The active transcoding jobs
|
||||
/// </summary>
|
||||
private readonly List<TranscodingJob> _activeTranscodingJobs = new List<TranscodingJob>();
|
||||
|
||||
private readonly Dictionary<string, SemaphoreSlim> _transcodingLocks =
|
||||
new Dictionary<string, SemaphoreSlim>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiEntryPoint" /> class.
|
||||
@@ -67,6 +74,21 @@ namespace MediaBrowser.Api
|
||||
_sessionManager.PlaybackStart += _sessionManager_PlaybackStart;
|
||||
}
|
||||
|
||||
public SemaphoreSlim GetTranscodingLock(string outputPath)
|
||||
{
|
||||
lock (_transcodingLocks)
|
||||
{
|
||||
SemaphoreSlim result;
|
||||
if (!_transcodingLocks.TryGetValue(outputPath, out result))
|
||||
{
|
||||
result = new SemaphoreSlim(1, 1);
|
||||
_transcodingLocks[outputPath] = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
|
||||
@@ -148,11 +170,6 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The active transcoding jobs
|
||||
/// </summary>
|
||||
private readonly List<TranscodingJob> _activeTranscodingJobs = new List<TranscodingJob>();
|
||||
|
||||
/// <summary>
|
||||
/// Called when [transcode beginning].
|
||||
/// </summary>
|
||||
@@ -258,6 +275,11 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
}
|
||||
|
||||
lock (_transcodingLocks)
|
||||
{
|
||||
_transcodingLocks.Remove(path);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(state.Request.DeviceId))
|
||||
{
|
||||
_sessionManager.ClearTranscodingInfo(state.Request.DeviceId);
|
||||
@@ -497,6 +519,11 @@ namespace MediaBrowser.Api
|
||||
}
|
||||
}
|
||||
|
||||
lock (_transcodingLocks)
|
||||
{
|
||||
_transcodingLocks.Remove(job.Path);
|
||||
}
|
||||
|
||||
lock (job.ProcessLock)
|
||||
{
|
||||
if (job.TranscodingThrottler != null)
|
||||
|
||||
Reference in New Issue
Block a user