Example #1
0
        public async Task <IProducer <PictureFrame> > Start(CancellationToken cts)
        {
            var jpegConverter = new OiUdpStreamToJpegBlock();
            await jpegConverter.TryStart();

            var converterTask = Task.Run(async() =>
            {
                try
                {
                    while (await this.receiver.Reader.WaitToReadAsync() && !cts.IsCancellationRequested)
                    {
                        if (this.receiver.Reader.TryRead(out var frame) && frame != null)
                        {
                            await jpegConverter.Continue(frame);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }, cts);

            return(jpegConverter);
        }
Example #2
0
        public async Task Continue(byte[] t = null)
        {
            if (t != null)
            {
                lock (this.SortedSet)
                {
                    var fn = OiUdpStreamToJpegBlock.FrameNumer(t);
                    this.SortedSet.Add(fn, t);
                    if (this.SortedSet.Count > this.Treshold)
                    {
                        this.SortedSet = new Dictionary <short, Byte[]>(this.SortedSet.TakeLast(this.Treshold));
                        var minKey = this.SortedSet.Keys.Min();
                        var f      = this.SortedSet[minKey];

                        if (f != null)
                        {
                            this.SortedSet.Remove(minKey);
                            this.Writer.TryWrite(f);
                        }
                    }
                }
            }
        }