diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs index e650086d3..d4fcd7780 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs @@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { public class MulticastStream { - private readonly ConcurrentDictionary _outputStreams = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _outputStreams = new ConcurrentDictionary(); private const int BufferSize = 81920; private readonly ILogger _logger; @@ -31,9 +31,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts throw new ArgumentNullException("source"); } - while (!cancellationToken.IsCancellationRequested) + while (true) { - var bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + + var bytesRead = source.Read(buffer, 0, buffer.Length); if (bytesRead > 0) { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs index 543d2e373..19c711172 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs @@ -14,7 +14,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { private readonly Stream _outputStream; private readonly ConcurrentQueue> _queue = new ConcurrentQueue>(); - private CancellationToken _cancellationToken; public TaskCompletionSource TaskCompletion { get; private set; } public Action OnFinished { get; set; } @@ -35,8 +34,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public void Start(CancellationToken cancellationToken) { - _cancellationToken = cancellationToken; - Task.Run(() => StartInternal()); + Task.Run(() => StartInternal(cancellationToken)); } private Tuple Dequeue() @@ -59,10 +57,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - public async Task WriteAsync(byte[] bytes, int offset, int count) + public async Task WriteAsync(byte[] bytes, int offset, int count, CancellationToken cancellationToken) { //return _outputStream.WriteAsync(bytes, offset, count, cancellationToken); - var cancellationToken = _cancellationToken; try { @@ -82,18 +79,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - private async Task StartInternal() + private async Task StartInternal(CancellationToken cancellationToken) { - var cancellationToken = _cancellationToken; - try { while (true) { + cancellationToken.ThrowIfCancellationRequested(); + var result = Dequeue(); if (result != null) { - await _outputStream.WriteAsync(result.Item1, result.Item2, result.Item3, cancellationToken).ConfigureAwait(false); + _outputStream.Write(result.Item1, result.Item2, result.Item3); } else {