Merge pull request #7994 from nyanmisaka/fix-throttler

This commit is contained in:
Joshua M. Boniface 2022-06-26 20:53:03 -04:00 committed by GitHub
commit a7d45b5d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 26 deletions

View File

@ -285,7 +285,7 @@ namespace Jellyfin.Api.Controllers
// Due to CTS.Token calling ThrowIfDisposed (https://github.com/dotnet/runtime/issues/29970) we have to "cache" the token // Due to CTS.Token calling ThrowIfDisposed (https://github.com/dotnet/runtime/issues/29970) we have to "cache" the token
// since it gets disposed when ffmpeg exits // since it gets disposed when ffmpeg exits
var cancellationToken = cancellationTokenSource.Token; var cancellationToken = cancellationTokenSource.Token;
using var state = await StreamingHelpers.GetStreamingState( var state = await StreamingHelpers.GetStreamingState(
streamingRequest, streamingRequest,
Request, Request,
_authContext, _authContext,
@ -1432,7 +1432,7 @@ namespace Jellyfin.Api.Controllers
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token; var cancellationToken = cancellationTokenSource.Token;
using var state = await StreamingHelpers.GetStreamingState( var state = await StreamingHelpers.GetStreamingState(
streamingRequest, streamingRequest,
Request, Request,
_authContext, _authContext,

View File

@ -427,7 +427,7 @@ namespace Jellyfin.Api.Controllers
StreamOptions = streamOptions StreamOptions = streamOptions
}; };
using var state = await StreamingHelpers.GetStreamingState( var state = await StreamingHelpers.GetStreamingState(
streamingRequest, streamingRequest,
Request, Request,
_authContext, _authContext,

View File

@ -654,8 +654,8 @@ namespace Jellyfin.Api.Helpers
{ {
if (EnableThrottling(state)) if (EnableThrottling(state))
{ {
transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, new Logger<TranscodingThrottler>(new LoggerFactory()), _serverConfigurationManager, _fileSystem); transcodingJob.TranscodingThrottler = new TranscodingThrottler(transcodingJob, new Logger<TranscodingThrottler>(new LoggerFactory()), _serverConfigurationManager, _fileSystem);
state.TranscodingThrottler.Start(); transcodingJob.TranscodingThrottler.Start();
} }
} }
@ -663,18 +663,11 @@ namespace Jellyfin.Api.Helpers
{ {
var encodingOptions = _serverConfigurationManager.GetEncodingOptions(); var encodingOptions = _serverConfigurationManager.GetEncodingOptions();
// enable throttling when NOT using hardware acceleration return state.InputProtocol == MediaProtocol.File &&
if (string.IsNullOrEmpty(encodingOptions.HardwareAccelerationType)) state.RunTimeTicks.HasValue &&
{ state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks &&
return state.InputProtocol == MediaProtocol.File && state.IsInputVideo &&
state.RunTimeTicks.HasValue && state.VideoType == VideoType.VideoFile;
state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks &&
state.IsInputVideo &&
state.VideoType == VideoType.VideoFile &&
!EncodingHelper.IsCopyCodec(state.OutputVideoCodec);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -47,11 +47,6 @@ namespace Jellyfin.Api.Models.StreamingDtos
} }
} }
/// <summary>
/// Gets or sets the transcoding throttler.
/// </summary>
public TranscodingThrottler? TranscodingThrottler { get; set; }
/// <summary> /// <summary>
/// Gets the video request. /// Gets the video request.
/// </summary> /// </summary>
@ -191,11 +186,8 @@ namespace Jellyfin.Api.Models.StreamingDtos
{ {
_mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult(); _mediaSourceManager.CloseLiveStream(MediaSource.LiveStreamId).GetAwaiter().GetResult();
} }
TranscodingThrottler?.Dispose();
} }
TranscodingThrottler = null;
TranscodingJob = null; TranscodingJob = null;
_disposed = true; _disposed = true;

View File

@ -111,7 +111,7 @@ namespace MediaBrowser.Controller.MediaEncoding
percent = 100.0 * currentMs / totalMs; percent = 100.0 * currentMs / totalMs;
transcodingPosition = val; transcodingPosition = TimeSpan.FromMilliseconds(currentMs);
} }
} }
else if (part.StartsWith("size=", StringComparison.OrdinalIgnoreCase)) else if (part.StartsWith("size=", StringComparison.OrdinalIgnoreCase))