| 54 | } |
| 55 | |
| 56 | void CameraLinux::_update_devices() { |
| 57 | while (!exit_flag.is_set()) { |
| 58 | { |
| 59 | MutexLock lock(camera_mutex); |
| 60 | |
| 61 | for (int i = feeds.size() - 1; i >= 0; i--) { |
| 62 | Ref<CameraFeedLinux> feed = (Ref<CameraFeedLinux>)feeds[i]; |
| 63 | if (feed.is_null()) { |
| 64 | continue; |
| 65 | } |
| 66 | String device_name = feed->get_device_name(); |
| 67 | if (!_is_active(device_name)) { |
| 68 | remove_feed(feed); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | struct dirent **devices; |
| 73 | int count = scandir("/dev", &devices, nullptr, alphasort); |
| 74 | |
| 75 | if (count != -1) { |
| 76 | for (int i = 0; i < count; i++) { |
| 77 | struct dirent *device = devices[i]; |
| 78 | if (strncmp(device->d_name, "video", 5) == 0) { |
| 79 | String device_name = String("/dev/") + String(device->d_name); |
| 80 | if (!_has_device(device_name)) { |
| 81 | _add_device(device_name); |
| 82 | } |
| 83 | } |
| 84 | free(device); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | free(devices); |
| 89 | } |
| 90 | |
| 91 | call_deferred("emit_signal", SNAME(CameraServer::feeds_updated_signal_name)); |
| 92 | usleep(1000000); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | bool CameraLinux::_has_device(const String &p_device_name) { |
| 97 | for (int i = 0; i < feeds.size(); i++) { |
no test coverage detected