Remove EOF counter

This commit is contained in:
cvium 2020-09-26 19:03:23 +02:00
parent 6ca313abc1
commit 146cad6150

View file

@ -79,13 +79,10 @@ namespace Jellyfin.Api.Helpers
/// <inheritdoc /> /// <inheritdoc />
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{ {
var eofCount = 0;
const int EmptyReadLimit = 20;
int totalBytesRead = 0; int totalBytesRead = 0;
int remainingBytesToRead = count; int remainingBytesToRead = count;
while (eofCount < EmptyReadLimit && remainingBytesToRead > 0) while (remainingBytesToRead > 0)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
int bytesRead; int bytesRead;
@ -109,20 +106,15 @@ namespace Jellyfin.Api.Helpers
_job.BytesDownloaded = Math.Max(_job.BytesDownloaded ?? _bytesWritten, _bytesWritten); _job.BytesDownloaded = Math.Max(_job.BytesDownloaded ?? _bytesWritten, _bytesWritten);
} }
} }
else
if (bytesRead == 0)
{ {
if (_job == null || _job.HasExited) if (_job == null || _job.HasExited)
{ {
eofCount++; break;
} }
await Task.Delay(100, cancellationToken).ConfigureAwait(false); await Task.Delay(100, cancellationToken).ConfigureAwait(false);
} }
else
{
eofCount = 0;
}
} }
return totalBytesRead; return totalBytesRead;
@ -148,17 +140,23 @@ namespace Jellyfin.Api.Helpers
return; return;
} }
if (disposing) try
{ {
_fileStream.Dispose(); if (disposing)
if (_job != null)
{ {
_transcodingJobHelper.OnTranscodeEndRequest(_job); _fileStream.Dispose();
if (_job != null)
{
_transcodingJobHelper.OnTranscodeEndRequest(_job);
}
} }
} }
finally
_disposed = true; {
_disposed = true;
base.Dispose(disposing);
}
} }
} }
} }