jellyfin/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2016-10-07 15:08:13 +00:00
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
2016-11-03 23:35:19 +00:00
namespace Emby.Server.Implementations.LiveTv.TunerHosts
2016-10-07 15:08:13 +00:00
{
public class QueueStream
{
private readonly Stream _outputStream;
2017-08-19 19:43:35 +00:00
private readonly BlockingCollection<Tuple<byte[], int, int>> _queue = new BlockingCollection<Tuple<byte[], int, int>>();
2016-10-07 15:08:13 +00:00
private readonly ILogger _logger;
2017-02-01 20:55:56 +00:00
public Guid Id = Guid.NewGuid();
2016-10-07 15:08:13 +00:00
public QueueStream(Stream outputStream, ILogger logger)
{
_outputStream = outputStream;
_logger = logger;
}
2017-03-26 16:26:52 +00:00
public void Queue(byte[] bytes, int offset, int count)
2016-10-07 15:08:13 +00:00
{
2017-08-19 19:43:35 +00:00
_queue.Add(new Tuple<byte[], int, int>(bytes, offset, count));
2016-10-07 15:08:13 +00:00
}
public void Start(CancellationToken cancellationToken)
{
2017-08-19 22:37:15 +00:00
while (true)
2016-10-07 15:08:13 +00:00
{
2017-08-19 22:37:15 +00:00
foreach (var result in _queue.GetConsumingEnumerable())
2016-10-07 15:08:13 +00:00
{
2017-06-01 05:42:49 +00:00
cancellationToken.ThrowIfCancellationRequested();
2017-08-19 22:37:15 +00:00
_outputStream.Write(result.Item1, result.Item2, result.Item3);
2016-10-07 15:08:13 +00:00
}
}
}
}
}