improve stopping of progressive streams

This commit is contained in:
Luke Pulverenti 2016-08-06 10:08:38 -04:00
parent 7d5a4c078d
commit 24003580e7
3 changed files with 45 additions and 21 deletions

View File

@ -349,7 +349,7 @@ namespace MediaBrowser.Api
return;
}
var timerDuration = 1000;
var timerDuration = 10000;
if (job.Type != TranscodingJobType.Progressive)
{

View File

@ -142,7 +142,8 @@ namespace MediaBrowser.Api.Playback.Progressive
var outputPath = state.OutputFilePath;
var outputPathExists = FileSystem.FileExists(outputPath);
var isTranscodeCached = outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive);
var transcodingJob = ApiEntryPoint.Instance.GetTranscodingJob(outputPath, TranscodingJobType.Progressive);
var isTranscodeCached = outputPathExists && transcodingJob != null;
AddDlnaHeaders(state, responseHeaders, request.Static || isTranscodeCached);
@ -159,6 +160,7 @@ namespace MediaBrowser.Api.Playback.Progressive
ContentType = contentType,
IsHeadRequest = isHeadRequest,
Path = state.MediaPath
}).ConfigureAwait(false);
}
}
@ -170,13 +172,25 @@ namespace MediaBrowser.Api.Playback.Progressive
try
{
if (transcodingJob != null)
{
ApiEntryPoint.Instance.OnTranscodeBeginRequest(transcodingJob);
}
return await ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
{
ResponseHeaders = responseHeaders,
ContentType = contentType,
IsHeadRequest = isHeadRequest,
Path = outputPath,
FileShare = FileShare.ReadWrite
FileShare = FileShare.ReadWrite,
OnComplete = () =>
{
if (transcodingJob != null)
{
ApiEntryPoint.Instance.OnTranscodeEndRequest(transcodingJob);
}
}
}).ConfigureAwait(false);
}

View File

@ -26,6 +26,8 @@ namespace MediaBrowser.Api.Playback.Progressive
}
public async Task StreamFile(string path, Stream outputStream, CancellationToken cancellationToken)
{
try
{
var eofCount = 0;
@ -53,6 +55,14 @@ namespace MediaBrowser.Api.Playback.Progressive
}
}
}
finally
{
if (_job != null)
{
ApiEntryPoint.Instance.OnTranscodeEndRequest(_job);
}
}
}
private async Task<int> CopyToAsyncInternal(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
{