Stop waiting for a segment to become ready if there's no alive transcode

Remove extra quotes in logging

Fix typo in comment
pull/1904/head
Vasily 5 years ago
parent c1f9107b8b
commit 7aea9266d0

@ -297,12 +297,12 @@ namespace MediaBrowser.Api.Playback
// Wait for the file to exist before proceeeding // Wait for the file to exist before proceeeding
var waitFor = state.WaitForPath ?? outputPath; var waitFor = state.WaitForPath ?? outputPath;
Logger.LogDebug("Waiting for the creation of '{0}'", waitFor); Logger.LogDebug("Waiting for the creation of {0}", waitFor);
while (!File.Exists(waitFor) && !transcodingJob.HasExited) while (!File.Exists(waitFor) && !transcodingJob.HasExited)
{ {
await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false); await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);
} }
Logger.LogDebug("File '{0}' created or transcoding has finished", waitFor); Logger.LogDebug("File {0} created or transcoding has finished", waitFor);
if (state.IsInputVideo && transcodingJob.Type == TranscodingJobType.Progressive && !transcodingJob.HasExited) if (state.IsInputVideo && transcodingJob.Type == TranscodingJobType.Progressive && !transcodingJob.HasExited)
{ {

@ -192,6 +192,7 @@ namespace MediaBrowser.Api.Playback.Hls
if (File.Exists(segmentPath)) if (File.Exists(segmentPath))
{ {
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
Logger.LogDebug("returning {0} [it exists, try 1]", segmentPath);
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false); return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
} }
@ -207,6 +208,7 @@ namespace MediaBrowser.Api.Playback.Hls
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
transcodingLock.Release(); transcodingLock.Release();
released = true; released = true;
Logger.LogDebug("returning {0} [it exists, try 2]", segmentPath);
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false); return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
} }
else else
@ -278,7 +280,7 @@ namespace MediaBrowser.Api.Playback.Hls
// await Task.Delay(50, cancellationToken).ConfigureAwait(false); // await Task.Delay(50, cancellationToken).ConfigureAwait(false);
//} //}
Logger.LogInformation("returning {0}", segmentPath); Logger.LogDebug("returning {0} [general case]", segmentPath);
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false); return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
} }
@ -465,6 +467,7 @@ namespace MediaBrowser.Api.Playback.Hls
if (transcodingJob != null && transcodingJob.HasExited) if (transcodingJob != null && transcodingJob.HasExited)
{ {
// Transcoding job is over, so assume all existing files are ready // Transcoding job is over, so assume all existing files are ready
Logger.LogDebug("serving up {0} as transcode is over", segmentPath);
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false); return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
} }
@ -473,19 +476,21 @@ namespace MediaBrowser.Api.Playback.Hls
// If requested segment is less than transcoding position, we can't transcode backwards, so assume it's ready // If requested segment is less than transcoding position, we can't transcode backwards, so assume it's ready
if (segmentIndex < currentTranscodingIndex) if (segmentIndex < currentTranscodingIndex)
{ {
Logger.LogDebug("serving up {0} as transcode index {1} is past requested point {2}", segmentPath, segmentIndex, currentTranscodingIndex);
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false); return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
} }
} }
var nextSegmentPath = GetSegmentPath(state, playlistPath, segmentIndex + 1); var nextSegmentPath = GetSegmentPath(state, playlistPath, segmentIndex + 1);
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested && transcodingJob != null && !transcodingJob.HasExited)
{ {
// To be considered ready, the segment file has to exist AND // To be considered ready, the segment file has to exist AND
// either the transcoding job should be done or next segment should also exit // either the transcoding job should be done or next segment should also exist
if (segmentExists) if (segmentExists)
{ {
if ((transcodingJob != null && transcodingJob.HasExited) || File.Exists(nextSegmentPath)) if (transcodingJob.HasExited || File.Exists(nextSegmentPath))
{ {
Logger.LogDebug("serving up {0} as it deemed ready", segmentPath);
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false); return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
} }
} }
@ -501,6 +506,14 @@ namespace MediaBrowser.Api.Playback.Hls
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (!File.Exists(segmentPath))
{
Logger.LogWarning("cannot serve {0} as transcoding quit before we got there", segmentPath);
}
else
{
Logger.LogDebug("serving {0} as it's on disk and transcoding stopped", segmentPath);
}
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false); return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
} }
@ -514,6 +527,7 @@ namespace MediaBrowser.Api.Playback.Hls
FileShare = FileShareMode.ReadWrite, FileShare = FileShareMode.ReadWrite,
OnComplete = () => OnComplete = () =>
{ {
Logger.LogDebug("finished serving {0}", segmentPath);
if (transcodingJob != null) if (transcodingJob != null)
{ {
transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks); transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks);

Loading…
Cancel
Save