diff options
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs')
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs | 59 |
1 files changed, 2 insertions, 57 deletions
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs index 02ebbcf16..e650086d3 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs @@ -15,7 +15,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { private readonly ConcurrentDictionary<Guid,QueueStream> _outputStreams = new ConcurrentDictionary<Guid, QueueStream>(); private const int BufferSize = 81920; - private CancellationToken _cancellationToken; private readonly ILogger _logger; public MulticastStream(ILogger logger) @@ -25,8 +24,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public async Task CopyUntilCancelled(Stream source, Action onStarted, CancellationToken cancellationToken) { - _cancellationToken = cancellationToken; - byte[] buffer = new byte[BufferSize]; if (source == null) @@ -72,59 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - private static int RtpHeaderBytes = 12; - public async Task CopyUntilCancelled(ISocket udpClient, Action onStarted, CancellationToken cancellationToken) - { - _cancellationToken = cancellationToken; - - while (!cancellationToken.IsCancellationRequested) - { - var receiveToken = cancellationToken; - - // On the first connection attempt, put a timeout to avoid being stuck indefinitely in the event of failure - if (onStarted != null) - { - receiveToken = CancellationTokenSource.CreateLinkedTokenSource(new CancellationTokenSource(5000).Token, cancellationToken).Token; - } - - var data = await udpClient.ReceiveAsync(receiveToken).ConfigureAwait(false); - var bytesRead = data.ReceivedBytes - RtpHeaderBytes; - - if (bytesRead > 0) - { - var allStreams = _outputStreams.ToList(); - - if (allStreams.Count == 1) - { - await allStreams[0].Value.WriteAsync(data.Buffer, 0, bytesRead).ConfigureAwait(false); - } - else - { - byte[] copy = new byte[bytesRead]; - Buffer.BlockCopy(data.Buffer, RtpHeaderBytes, copy, 0, bytesRead); - - foreach (var stream in allStreams) - { - stream.Value.Queue(copy, 0, copy.Length); - } - } - - if (onStarted != null) - { - var onStartedCopy = onStarted; - onStarted = null; - Task.Run(onStartedCopy); - } - } - - else - { - await Task.Delay(100).ConfigureAwait(false); - } - } - } - - public Task CopyToAsync(Stream stream) + public Task CopyToAsync(Stream stream, CancellationToken cancellationToken) { var result = new QueueStream(stream, _logger) { @@ -133,7 +78,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts _outputStreams.TryAdd(result.Id, result); - result.Start(_cancellationToken); + result.Start(cancellationToken); return result.TaskCompletion.Task; } |
