Deactivate the CameraServer by default.

Add `monitoring_feeds` property to `CameraServer`.
This saves resources for games that don't use a physical camera.
This commit is contained in:
Lukas Tenbrink
2025-03-16 13:03:06 +01:00
parent b377562b52
commit 54685c3037
7 changed files with 63 additions and 10 deletions

View File

@@ -162,11 +162,25 @@ bool CameraLinux::_can_query_format(int p_file_descriptor, int p_type) {
return ioctl(p_file_descriptor, VIDIOC_G_FMT, &format) != -1;
}
CameraLinux::CameraLinux() {
camera_thread.start(CameraLinux::camera_thread_func, this);
inline void CameraLinux::set_monitoring_feeds(bool p_monitoring_feeds) {
if (p_monitoring_feeds == monitoring_feeds) {
return;
}
CameraServer::set_monitoring_feeds(p_monitoring_feeds);
if (p_monitoring_feeds) {
camera_thread.start(CameraLinux::camera_thread_func, this);
} else {
exit_flag.set();
if (camera_thread.is_started()) {
camera_thread.wait_to_finish();
}
}
}
CameraLinux::~CameraLinux() {
exit_flag.set();
camera_thread.wait_to_finish();
if (camera_thread.is_started()) {
camera_thread.wait_to_finish();
}
}

View File

@@ -52,6 +52,8 @@ private:
bool _can_query_format(int p_file_descriptor, int p_type);
public:
CameraLinux();
CameraLinux() = default;
~CameraLinux();
void set_monitoring_feeds(bool p_monitoring_feeds) override;
};

View File

@@ -37,7 +37,8 @@
class CameraMacOS : public CameraServer {
public:
CameraMacOS();
CameraMacOS() = default;
void update_feeds();
void set_monitoring_feeds(bool p_monitoring_feeds) override;
};

View File

@@ -359,10 +359,20 @@ void CameraMacOS::update_feeds() {
};
}
CameraMacOS::CameraMacOS() {
// Find available cameras we have at this time
update_feeds();
void CameraMacOS::set_monitoring_feeds(bool p_monitoring_feeds) {
if (p_monitoring_feeds == monitoring_feeds) {
return;
}
// should only have one of these....
device_notifications = [[MyDeviceNotifications alloc] initForServer:this];
CameraServer::set_monitoring_feeds(p_monitoring_feeds);
if (p_monitoring_feeds) {
// Find available cameras we have at this time.
update_feeds();
// Get notified on feed changes.
device_notifications = [[MyDeviceNotifications alloc] initForServer:this];
} else {
// Stop monitoring feed changes.
device_notifications = nil;
}
}