mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
hls seek fixes
This commit is contained in:
parent
a6cbe47941
commit
3b06092f69
@ -164,12 +164,14 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
if (FileSystem.FileExists(segmentPath))
|
if (FileSystem.FileExists(segmentPath))
|
||||||
{
|
{
|
||||||
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
||||||
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var transcodingLock = ApiEntryPoint.Instance.GetTranscodingLock(playlistPath);
|
var transcodingLock = ApiEntryPoint.Instance.GetTranscodingLock(playlistPath);
|
||||||
await transcodingLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
await transcodingLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
var released = false;
|
var released = false;
|
||||||
|
var startTranscoding = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (FileSystem.FileExists(segmentPath))
|
if (FileSystem.FileExists(segmentPath))
|
||||||
@ -177,12 +179,10 @@ 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;
|
||||||
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var startTranscoding = false;
|
|
||||||
|
|
||||||
var currentTranscodingIndex = GetCurrentTranscodingIndex(playlistPath, segmentExtension);
|
var currentTranscodingIndex = GetCurrentTranscodingIndex(playlistPath, segmentExtension);
|
||||||
var segmentGapRequiringTranscodingChange = 24 / state.SegmentLength;
|
var segmentGapRequiringTranscodingChange = 24 / state.SegmentLength;
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
|
|
||||||
Logger.Info("returning {0}", segmentPath);
|
Logger.Info("returning {0}", segmentPath);
|
||||||
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
|
||||||
return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private const int BufferSize = 81920;
|
private const int BufferSize = 81920;
|
||||||
@ -422,18 +422,33 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
return Path.Combine(folder, filename + index.ToString(UsCulture) + GetSegmentFileExtension(state.Request));
|
return Path.Combine(folder, filename + index.ToString(UsCulture) + GetSegmentFileExtension(state.Request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<object> GetSegmentResult(StreamState state, string playlistPath,
|
private async Task<object> GetSegmentResult(StreamState state,
|
||||||
|
string playlistPath,
|
||||||
string segmentPath,
|
string segmentPath,
|
||||||
|
string segmentExtension,
|
||||||
int segmentIndex,
|
int segmentIndex,
|
||||||
TranscodingJob transcodingJob,
|
TranscodingJob transcodingJob,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
var segmentFileExists = FileSystem.FileExists(segmentPath);
|
||||||
|
|
||||||
// If all transcoding has completed, just return immediately
|
// If all transcoding has completed, just return immediately
|
||||||
if (transcodingJob != null && transcodingJob.HasExited && FileSystem.FileExists(segmentPath))
|
if (transcodingJob != null && transcodingJob.HasExited && segmentFileExists)
|
||||||
{
|
{
|
||||||
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
|
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (segmentFileExists)
|
||||||
|
{
|
||||||
|
var currentTranscodingIndex = GetCurrentTranscodingIndex(playlistPath, segmentExtension);
|
||||||
|
|
||||||
|
// If requested segment is less than transcoding position, we can't transcode backwards, so assume it's ready
|
||||||
|
if (segmentIndex < currentTranscodingIndex)
|
||||||
|
{
|
||||||
|
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var segmentFilename = Path.GetFileName(segmentPath);
|
var segmentFilename = Path.GetFileName(segmentPath);
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
@ -449,7 +464,11 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
// If it appears in the playlist, it's done
|
// If it appears in the playlist, it's done
|
||||||
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
|
if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
if (FileSystem.FileExists(segmentPath))
|
if (!segmentFileExists)
|
||||||
|
{
|
||||||
|
segmentFileExists = FileSystem.FileExists(segmentPath);
|
||||||
|
}
|
||||||
|
if (segmentFileExists)
|
||||||
{
|
{
|
||||||
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
|
return await GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -536,12 +555,12 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
|
|
||||||
var subtitleGroup = subtitleStreams.Count > 0 &&
|
var subtitleGroup = subtitleStreams.Count > 0 &&
|
||||||
request is GetMasterHlsVideoPlaylist &&
|
request is GetMasterHlsVideoPlaylist &&
|
||||||
(state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Hls || state.VideoRequest.EnableSubtitlesInManifest) ?
|
(state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Hls || state.VideoRequest.EnableSubtitlesInManifest) ?
|
||||||
"subs" :
|
"subs" :
|
||||||
null;
|
null;
|
||||||
|
|
||||||
// If we're burning in subtitles then don't add additional subs to the manifest
|
// If we're burning in subtitles then don't add additional subs to the manifest
|
||||||
if (state.SubtitleStream != null && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode)
|
if (state.SubtitleStream != null && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
|
||||||
{
|
{
|
||||||
subtitleGroup = null;
|
subtitleGroup = null;
|
||||||
}
|
}
|
||||||
@ -583,7 +602,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
|
|
||||||
private void AddSubtitles(StreamState state, IEnumerable<MediaStream> subtitles, StringBuilder builder)
|
private void AddSubtitles(StreamState state, IEnumerable<MediaStream> subtitles, StringBuilder builder)
|
||||||
{
|
{
|
||||||
var selectedIndex = state.SubtitleStream == null || state.VideoRequest.SubtitleMethod != SubtitleDeliveryMethod.Hls ? (int?)null : state.SubtitleStream.Index;
|
var selectedIndex = state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Hls ? (int?)null : state.SubtitleStream.Index;
|
||||||
|
|
||||||
foreach (var stream in subtitles)
|
foreach (var stream in subtitles)
|
||||||
{
|
{
|
||||||
@ -843,7 +862,7 @@ namespace MediaBrowser.Api.Playback.Hls
|
|||||||
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
|
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
|
||||||
state.SegmentLength.ToString(UsCulture));
|
state.SegmentLength.ToString(UsCulture));
|
||||||
|
|
||||||
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.VideoRequest.SubtitleMethod == SubtitleDeliveryMethod.Encode;
|
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
|
||||||
|
|
||||||
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user