private void Update() { if (IsInitialized) { if (_device.TryGetCapture(out var capture)) { using (capture) { CaptureReady?.Invoke(this, new CaptureEventArgs(capture)); } } } }
protected override void BackgroundLoop() { try { var forward = true; var sw = Stopwatch.StartNew(); var frameCounter = 0L; while (!playback.IsDisposed) { while (doNotPlayFasterThanOriginalFps && !playback.IsDisposed) { var expectedTime = Microseconds64.FromSeconds((double)frameCounter / frameRateHz); var elapsedTime = (Microseconds64)sw.Elapsed; if (elapsedTime >= expectedTime) { break; } var sleepInterval = new Microseconds64((expectedTime.ValueUsec - elapsedTime.ValueUsec) / 2); Thread.Sleep(sleepInterval); } var res = forward ? playback.TryGetNextCapture(out var capture) : playback.TryGetPreviousCapture(out capture); if (!res) { forward = !forward; continue; } frameCounter++; using (capture) { CaptureReady?.Invoke(this, new CaptureReadyEventArgs(capture)); } } } catch (ObjectDisposedException) { } catch (Exception exc) { Failed?.Invoke(this, new FailedEventArgs(exc)); } }
protected override void BackgroundLoop() { try { device.StartCameras(new DeviceConfiguration { CameraFps = FrameRate, ColorFormat = ImageFormat.ColorBgra32, ColorResolution = ColorResolution, DepthMode = DepthMode, WiredSyncMode = WiredSyncMode.Standalone, }); while (isRunning) { var res = device.TryGetCapture(out var capture); if (res) { using (capture) { CaptureReady?.Invoke(this, new CaptureReadyEventArgs(capture)); } } else { if (!device.IsConnected) { throw new DeviceConnectionLostException(device.DeviceIndex); } Thread.Sleep(1); } } } catch (Exception exc) { Failed?.Invoke(this, new FailedEventArgs(exc)); } }