aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
diff options
context:
space:
mode:
authorcvium <clausvium@gmail.com>2021-09-10 11:40:28 +0200
committercvium <clausvium@gmail.com>2021-09-10 11:40:28 +0200
commit8496d7638ab7823169c220b615289c401cefa9a0 (patch)
tree66134cb10250319dc4be0dc8abf6b2a6573e4cbf /Jellyfin.Api/Helpers/ProgressiveFileStream.cs
parentfb7587dd84784afb7c64aadf1fc2d0bab5251814 (diff)
parentb96dbbf553820861eab9d1a453adcc8ce8a9ef05 (diff)
Merge branch 'master' into NetworkAccessPolicy
Diffstat (limited to 'Jellyfin.Api/Helpers/ProgressiveFileStream.cs')
-rw-r--r--Jellyfin.Api/Helpers/ProgressiveFileStream.cs14
1 files changed, 9 insertions, 5 deletions
diff --git a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
index 824870c7e..d4cc0172d 100644
--- a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
+++ b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
@@ -1,6 +1,6 @@
using System;
+using System.Diagnostics;
using System.IO;
-using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Api.Models.PlaybackDtos;
@@ -16,6 +16,7 @@ namespace Jellyfin.Api.Helpers
private readonly FileStream _fileStream;
private readonly TranscodingJobDto? _job;
private readonly TranscodingJobHelper _transcodingJobHelper;
+ private readonly int _timeoutMs;
private readonly bool _allowAsyncFileRead;
private int _bytesWritten;
private bool _disposed;
@@ -26,17 +27,19 @@ namespace Jellyfin.Api.Helpers
/// <param name="filePath">The path to the transcoded file.</param>
/// <param name="job">The transcoding job information.</param>
/// <param name="transcodingJobHelper">The transcoding job helper.</param>
- public ProgressiveFileStream(string filePath, TranscodingJobDto? job, TranscodingJobHelper transcodingJobHelper)
+ /// <param name="timeoutMs">The timeout duration in milliseconds.</param>
+ public ProgressiveFileStream(string filePath, TranscodingJobDto? job, TranscodingJobHelper transcodingJobHelper, int timeoutMs = 30000)
{
_job = job;
_transcodingJobHelper = transcodingJobHelper;
+ _timeoutMs = timeoutMs;
_bytesWritten = 0;
var fileOptions = FileOptions.SequentialScan;
_allowAsyncFileRead = false;
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if (AsyncFile.UseAsyncIO)
{
fileOptions |= FileOptions.Asynchronous;
_allowAsyncFileRead = true;
@@ -81,6 +84,7 @@ namespace Jellyfin.Api.Helpers
{
int totalBytesRead = 0;
int remainingBytesToRead = count;
+ var stopwatch = Stopwatch.StartNew();
int newOffset = offset;
while (remainingBytesToRead > 0)
@@ -111,8 +115,8 @@ namespace Jellyfin.Api.Helpers
}
else
{
- // If the job is null it's a live stream and will require user action to close
- if (_job?.HasExited ?? false)
+ // If the job is null it's a live stream and will require user action to close, but don't keep it open indefinitely
+ if (_job?.HasExited ?? stopwatch.ElapsedMilliseconds > _timeoutMs)
{
break;
}