예제 #1
0
        public Task StartCapture(DreamClient dreamClient, CancellationToken cancellationToken)
        {
            LogUtil.Write("Beginning capture process...");
            SetCapVars();
            return(Task.Run(() => {
                var autoEvent = new AutoResetEvent(false);
                saveTimer = new Timer(SaveFrame, autoEvent, 5000, 5000);
                LogUtil.WriteInc($"Starting capture task, setting sw and h to {_scaleWidth} and {_scaleHeight}");
                _splitter = new Splitter(_ledData, _scaleWidth, _scaleHeight);
                var wlArray = DataUtil.GetCollection <WLedData>("Dev_Wled");
                foreach (var wl in wlArray)
                {
                    _splitter.AddWled(wl);
                }
                LogUtil.Write("All wled devices added, executing main capture loop...");

                while (!cancellationToken.IsCancellationRequested)
                {
                    var frame = _vc.Frame;
                    if (frame == null)
                    {
                        SourceActive = false;
                        LogUtil.Write("Frame is null, dude.", "WARN");
                        continue;
                    }

                    if (frame.Cols == 0)
                    {
                        SourceActive = false;
                        LogUtil.Write("Frame has no columns, dude.", "WARN");
                        continue;
                    }
                    var warped = ProcessFrame(frame);
                    if (warped == null)
                    {
                        SourceActive = false;
                        LogUtil.Write("Unable to process frame, Dude.", "WARN");
                        continue;
                    }
                    _splitter.Update(warped);
                    SourceActive = !_splitter.NoImage;

                    var colors = _splitter.GetColors();
                    var sectors = _splitter.GetSectors();
                    var sectors3 = _splitter.GetSectorsV2();
                    var sectorsWled = _splitter.GetWledSectors();
                    if (_sendColors)
                    {
                        dreamClient.SendColors(colors, sectors, sectors3, sectorsWled);
                    }
                }

                saveTimer.Dispose();
                LogUtil.Write("Capture task completed!", "WARN");
                return Task.CompletedTask;
            }, cancellationToken));
        }