update stream management

This commit is contained in:
Luke Pulverenti 2016-07-28 02:29:14 -04:00
parent 2fb082cbf3
commit 9b98d8b2e1
4 changed files with 32 additions and 7 deletions

View file

@ -126,9 +126,10 @@ namespace MediaBrowser.Api
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool dispose) protected virtual void Dispose(bool dispose)
{ {
var jobCount = _activeTranscodingJobs.Count; var list = _activeTranscodingJobs.ToList();
var jobCount = list.Count;
Parallel.ForEach(_activeTranscodingJobs.ToList(), j => KillTranscodingJob(j, false, path => true)); Parallel.ForEach(list, j => KillTranscodingJob(j, false, path => true));
// Try to allow for some time to kill the ffmpeg processes and delete the partial stream files // Try to allow for some time to kill the ffmpeg processes and delete the partial stream files
if (jobCount > 0) if (jobCount > 0)

View file

@ -175,7 +175,9 @@ namespace MediaBrowser.Api.Playback.Progressive
ResponseHeaders = responseHeaders, ResponseHeaders = responseHeaders,
ContentType = contentType, ContentType = contentType,
IsHeadRequest = isHeadRequest, IsHeadRequest = isHeadRequest,
Path = outputPath Path = outputPath,
FileShare = FileShare.ReadWrite
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
finally finally
@ -187,8 +189,7 @@ namespace MediaBrowser.Api.Playback.Progressive
// Need to start ffmpeg // Need to start ffmpeg
try try
{ {
return await GetStreamResult(state, responseHeaders, isHeadRequest, cancellationTokenSource) return await GetStreamResult(state, responseHeaders, isHeadRequest, cancellationTokenSource).ConfigureAwait(false);
.ConfigureAwait(false);
} }
catch catch
{ {

View file

@ -208,7 +208,7 @@ namespace MediaBrowser.Api.Playback
private async void DisposeLiveStream() private async void DisposeLiveStream()
{ {
if (MediaSource.RequiresClosing && string.IsNullOrWhiteSpace(Request.LiveStreamId)) if (MediaSource.RequiresClosing && string.IsNullOrWhiteSpace(Request.LiveStreamId) && !string.IsNullOrWhiteSpace(MediaSource.LiveStreamId))
{ {
try try
{ {

View file

@ -446,8 +446,31 @@ namespace MediaBrowser.Server.Implementations.Library
} }
} }
private async Task CloseLiveStreamWithProvider(IMediaSourceProvider provider, string streamId, CancellationToken cancellationToken)
{
_logger.Info("Closing live stream {0} with provider {1}", streamId, provider.GetType().Name);
try
{
await provider.CloseMediaSource(streamId, cancellationToken).ConfigureAwait(false);
}
catch (NotImplementedException)
{
}
catch (Exception ex)
{
_logger.ErrorException("Error closing live stream {0}", ex, streamId);
}
}
public async Task CloseLiveStream(string id, CancellationToken cancellationToken) public async Task CloseLiveStream(string id, CancellationToken cancellationToken)
{ {
if (string.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException("id");
}
await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try try
@ -459,7 +482,7 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
var tuple = GetProvider(id); var tuple = GetProvider(id);
await tuple.Item1.CloseMediaSource(tuple.Item2, cancellationToken).ConfigureAwait(false); await CloseLiveStreamWithProvider(tuple.Item1, tuple.Item2, cancellationToken).ConfigureAwait(false);
} }
} }