mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-21 13:10:45 +02:00
rework hls timer
This commit is contained in:
parent
5d7f6b0744
commit
967751d2a5
|
@ -292,6 +292,42 @@ namespace MediaBrowser.Api
|
||||||
job.ActiveRequestCount--;
|
job.ActiveRequestCount--;
|
||||||
|
|
||||||
if (job.ActiveRequestCount == 0)
|
if (job.ActiveRequestCount == 0)
|
||||||
|
{
|
||||||
|
PingTimer(job, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal void PingTranscodingJob(string deviceId, string playSessionId)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(deviceId))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("deviceId");
|
||||||
|
}
|
||||||
|
|
||||||
|
var jobs = new List<TranscodingJob>();
|
||||||
|
|
||||||
|
lock (_activeTranscodingJobs)
|
||||||
|
{
|
||||||
|
// This is really only needed for HLS.
|
||||||
|
// Progressive streams can stop on their own reliably
|
||||||
|
jobs = jobs.Where(j =>
|
||||||
|
{
|
||||||
|
if (string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var job in jobs)
|
||||||
|
{
|
||||||
|
PingTimer(job, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PingTimer(TranscodingJob job, bool startTimerIfNeeded)
|
||||||
{
|
{
|
||||||
// TODO: Lower this hls timeout
|
// TODO: Lower this hls timeout
|
||||||
var timerDuration = job.Type == TranscodingJobType.Progressive ?
|
var timerDuration = job.Type == TranscodingJobType.Progressive ?
|
||||||
|
@ -299,15 +335,17 @@ namespace MediaBrowser.Api
|
||||||
1800000;
|
1800000;
|
||||||
|
|
||||||
if (job.KillTimer == null)
|
if (job.KillTimer == null)
|
||||||
|
{
|
||||||
|
if (startTimerIfNeeded)
|
||||||
{
|
{
|
||||||
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
|
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
job.KillTimer.Change(timerDuration, Timeout.Infinite);
|
job.KillTimer.Change(timerDuration, Timeout.Infinite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when [transcode kill timer stopped].
|
/// Called when [transcode kill timer stopped].
|
||||||
|
|
|
@ -294,6 +294,11 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
public void Post(ReportPlaybackProgress request)
|
public void Post(ReportPlaybackProgress request)
|
||||||
{
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.PlaySessionId))
|
||||||
|
{
|
||||||
|
ApiEntryPoint.Instance.PingTranscodingJob(AuthorizationContext.GetAuthorizationInfo(Request).DeviceId, request.PlaySessionId);
|
||||||
|
}
|
||||||
|
|
||||||
request.SessionId = GetSession().Result.Id;
|
request.SessionId = GetSession().Result.Id;
|
||||||
|
|
||||||
var task = _sessionManager.OnPlaybackProgress(request);
|
var task = _sessionManager.OnPlaybackProgress(request);
|
||||||
|
@ -317,6 +322,11 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
public void Post(ReportPlaybackStopped request)
|
public void Post(ReportPlaybackStopped request)
|
||||||
{
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(request.PlaySessionId))
|
||||||
|
{
|
||||||
|
ApiEntryPoint.Instance.KillTranscodingJobs(AuthorizationContext.GetAuthorizationInfo(Request).DeviceId, request.PlaySessionId, s => true);
|
||||||
|
}
|
||||||
|
|
||||||
request.SessionId = GetSession().Result.Id;
|
request.SessionId = GetSession().Result.Id;
|
||||||
|
|
||||||
var task = _sessionManager.OnPlaybackStopped(request);
|
var task = _sessionManager.OnPlaybackStopped(request);
|
||||||
|
|
Loading…
Reference in a new issue