+ if (is_mode_scanning[card_index]) {
+ if (video_format.has_signal) {
+ // Found a stable signal, so stop scanning.
+ is_mode_scanning[card_index] = false;
+ } else {
+ static constexpr double switch_time_s = 0.5; // Should be enough time for the signal to stabilize.
+ timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ double sec_since_last_switch = (now.tv_sec - last_mode_scan_change[card_index].tv_sec) +
+ 1e-9 * (now.tv_nsec - last_mode_scan_change[card_index].tv_nsec);
+ if (sec_since_last_switch > switch_time_s) {
+ // It isn't this mode; try the next one.
+ mode_scanlist_index[card_index]++;
+ mode_scanlist_index[card_index] %= mode_scanlist[card_index].size();
+ cards[card_index].capture->set_video_mode(mode_scanlist[card_index][mode_scanlist_index[card_index]]);
+ last_mode_scan_change[card_index] = now;
+ }
+ }
+ }
+