private void EnableCapture() { _hyperionTasks.Clear(); if (!SettingsManager.HyperionTaskConfigurations.Exists(config => config.Enabled)) { LOG.Info("Cannot start capture: No hyperion task configuration is enabled"); _notificationUtils.Error("Cannot start capture: No capture task enabled"); ExecuteToggleCaptureCommand(CaptureCommand.OFF); return; } LOG.Info($"Enabling {SettingsManager.HyperionTaskConfigurations.Count} screen capture(s)"); foreach (HyperionTaskConfiguration configuration in SettingsManager.HyperionTaskConfigurations) { if (configuration.Enabled) { HyperionTask hyperionTask = new HyperionTask(configuration, _notificationUtils); hyperionTask.EnableCapture(); _hyperionTasks.Add(hyperionTask); } else { LOG.Info($"Capture task with ID {configuration.Id} is disabled. Skipping."); } } CaptureEnabled = true; new Thread(DisableCaptureOnFailure) { IsBackground = true }.Start(); LOG.Info($"Enabled {_hyperionTasks.Count} screen capture(s)"); }
public static void TryClearPriority(int priority) { try { LOG.Info("Clearing Hyperion priority"); ClearPriority(priority); Thread.Sleep(50); ClearPriority(priority); LOG.Info("Hyperion priority cleared"); } catch (Exception ex) { LOG.Error("Failed to clear Hyperion priority", ex); NotificationUtils.Error($"Failed to clear Hyperion priority. {ex.Message}"); } }
private static void StartCapture() { int captureAttempt = 1; while (_captureEnabled) { try // This block will help retry capture before giving up { InitScreenCapture(); InitProtoClient(); TransmitNextFrame(); _screenCapture.DelayNextCapture(); // Reset attempt count captureAttempt = 1; } catch (Exception ex) { LOG.Error($"Exception in screen capture attempt: {captureAttempt}", ex); if (captureAttempt > AppConstants.REINIT_CAPTURE_AFTER_ATTEMPTS) { // After a few attempt, try disposing screen capture object as well _screenCapture?.Dispose(); LOG.Info("Will re-initialize screen capture on retry"); } if (++captureAttempt == AppConstants.MAX_CAPTURE_ATTEMPTS) { LOG.Error("Max screen capture attempts reached. Giving up."); NotificationUtils.Error(ex.Message); return; } else { LOG.Info("Waiting before next screen capture attempt"); Thread.Sleep(AppConstants.CAPTURE_FAILED_COOLDOWN_MILLIS); } } } }