public IVideoSource Open(IVideoSourceConfig config, IVideoSourceType type, IntPtr hWnd) { if (config != null && config.Enabled) { IVideoSource vs = GetVideoSource(config.Name); if (vs == null) { IVideoSourceFactory vsFactory = GetVideoSourceFactory(type); if (vsFactory != null) { vs = vsFactory.CreateVideoSource(config, hWnd); if (vs != null) { lock (mVideoSources.SyncRoot) { if (vs.Open(null)) { vs.OnPlayStatusChanged += new PLAYSTATUS_CHANGED(DoPlayStausChanged); vs.OnRecordProgress += new RECORD_PROGRESS(DoRecordProgress); (vs as IKernelVideoSource).OnKernelStatus += new KERNELSTATUS_CHANGED(DoKernelStatus); mVideoSources.Add(vs.Name, vs); vs.RefreshState(); } else { return(null); } } } } } else { if (hWnd != IntPtr.Zero) { vs.HWnd = hWnd; } if (!vs.IsOpen) { vs.Open(null); } } return(vs); } return(null); }
public void Start() { var stopwatch = new Stopwatch(); stopwatch.Start(); Loggers.Current.Log(LogLevel.Info, $"Starting TwometerVR v{Version}"); Loggers.Current.Log(LogLevel.Debug, "Opening video stream"); var videoConfig = configProvider.VideoSourceConfig; videoSource = VideoSourceFactory.Create(videoConfig.VideoSourceType, videoConfig.VideoSourceIndex); videoSource.Width = videoConfig.FrameWidth; videoSource.Height = videoConfig.FrameHeight; videoSource.Framerate = videoConfig.Framerate; videoSource.Open(); Loggers.Current.Log(LogLevel.Debug, "Initializing tracking engine"); trackingEngine = new TrackingEngine(trackerManager, configProvider, videoSource); Loggers.Current.Log(LogLevel.Debug, "Setting up network"); discoveryClient = new DiscoveryClient(); driverClient = new DriverClient(trackerManager); trackerClient = new TrackerClient(trackerManager); watchdog = new TrackerWatchdog(trackerManager, configProvider); Loggers.Current.Log(LogLevel.Debug, "Initializing update timer"); updateTimer = new Timer(Update, null, 0, 1 / configProvider.UserConfig.Input.RefreshRate); Loggers.Current.Log(LogLevel.Debug, "Starting video procecssing thread"); videoThread = new Thread(VideoLoop); videoThread.Start(); stopwatch.Stop(); Loggers.Current.Log(LogLevel.Info, $"Done after {stopwatch.Elapsed}"); }
private void StartVideoSource() { if (_videoSource == null || _videoSource.State == VideoSourceState.Running) { return; } _videoSource.AttachMatrix(_matrix); _videoSource.MatrixUpdated += OnMatrixUpdated; try { if (_videoSource.State == VideoSourceState.Closed) { _videoSource.Open(); } _videoSource.Start(); } catch (Exception exc) { Log.Error("Не удалось открыть видеоисточник.", exc); } }
public VideoFrameStreamer(IVideoSource videoSource, IClock clock) : base(nameof(VideoFrameStreamer), clock) { VideoSource = videoSource; Started += (sender, e) => videoSource.Open(); Stopped += (sender, e) => videoSource.Shutdown(); }