mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-18 06:53:07 +03:00
Kill ProgressiveFileCopier and seek to end for ongoing livetv
This commit is contained in:
@@ -13,9 +13,9 @@ namespace Jellyfin.Api.Helpers
|
||||
/// </summary>
|
||||
public class ProgressiveFileStream : Stream
|
||||
{
|
||||
private readonly FileStream _fileStream;
|
||||
private readonly Stream _stream;
|
||||
private readonly TranscodingJobDto? _job;
|
||||
private readonly TranscodingJobHelper _transcodingJobHelper;
|
||||
private readonly TranscodingJobHelper? _transcodingJobHelper;
|
||||
private readonly int _timeoutMs;
|
||||
private readonly bool _allowAsyncFileRead;
|
||||
private int _bytesWritten;
|
||||
@@ -33,7 +33,6 @@ namespace Jellyfin.Api.Helpers
|
||||
_job = job;
|
||||
_transcodingJobHelper = transcodingJobHelper;
|
||||
_timeoutMs = timeoutMs;
|
||||
_bytesWritten = 0;
|
||||
|
||||
var fileOptions = FileOptions.SequentialScan;
|
||||
_allowAsyncFileRead = false;
|
||||
@@ -45,11 +44,27 @@ namespace Jellyfin.Api.Helpers
|
||||
_allowAsyncFileRead = true;
|
||||
}
|
||||
|
||||
_fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, IODefaults.FileStreamBufferSize, fileOptions);
|
||||
_stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, IODefaults.FileStreamBufferSize, fileOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProgressiveFileStream"/> class.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to progressively copy.</param>
|
||||
/// <param name="job">The transcoding job information.</param>
|
||||
/// <param name="transcodingJobHelper">The transcoding job helper.</param>
|
||||
/// <param name="timeoutMs">The timeout duration in milliseconds.</param>
|
||||
public ProgressiveFileStream(Stream stream, TranscodingJobDto? job, TranscodingJobHelper? transcodingJobHelper, int timeoutMs = 30000)
|
||||
{
|
||||
_job = job;
|
||||
_transcodingJobHelper = transcodingJobHelper;
|
||||
_timeoutMs = timeoutMs;
|
||||
_allowAsyncFileRead = AsyncFile.UseAsyncIO;
|
||||
_stream = stream;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanRead => _fileStream.CanRead;
|
||||
public override bool CanRead => _stream.CanRead;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanSeek => false;
|
||||
@@ -70,13 +85,13 @@ namespace Jellyfin.Api.Helpers
|
||||
/// <inheritdoc />
|
||||
public override void Flush()
|
||||
{
|
||||
_fileStream.Flush();
|
||||
_stream.Flush();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
return _fileStream.Read(buffer, offset, count);
|
||||
return _stream.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -93,11 +108,11 @@ namespace Jellyfin.Api.Helpers
|
||||
int bytesRead;
|
||||
if (_allowAsyncFileRead)
|
||||
{
|
||||
bytesRead = await _fileStream.ReadAsync(buffer, newOffset, remainingBytesToRead, cancellationToken).ConfigureAwait(false);
|
||||
bytesRead = await _stream.ReadAsync(buffer, newOffset, remainingBytesToRead, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesRead = _fileStream.Read(buffer, newOffset, remainingBytesToRead);
|
||||
bytesRead = _stream.Read(buffer, newOffset, remainingBytesToRead);
|
||||
}
|
||||
|
||||
remainingBytesToRead -= bytesRead;
|
||||
@@ -152,11 +167,11 @@ namespace Jellyfin.Api.Helpers
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_fileStream.Dispose();
|
||||
_stream.Dispose();
|
||||
|
||||
if (_job != null)
|
||||
{
|
||||
_transcodingJobHelper.OnTranscodeEndRequest(_job);
|
||||
_transcodingJobHelper?.OnTranscodeEndRequest(_job);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user