summaryrefslogtreecommitdiffstats
path: root/modules/camera/camera_feed_linux.cpp
diff options
context:
space:
mode:
authorPaweł <pkowal1982@gmail.com>2024-09-27 21:04:28 +0200
committerPaweł <pkowal1982@gmail.com>2024-09-28 17:00:29 +0200
commit0178bb88e0eac442399d915ba9392530e05e1f68 (patch)
treeb52699828e95cff31fea5becb11d1f29a7809ac4 /modules/camera/camera_feed_linux.cpp
parent76a135926aef1f02f27e4e09093787f2c670956d (diff)
downloadredot-engine-0178bb88e0eac442399d915ba9392530e05e1f68.tar.gz
Fix error message on startup when camera is busy
Diffstat (limited to 'modules/camera/camera_feed_linux.cpp')
-rw-r--r--modules/camera/camera_feed_linux.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/modules/camera/camera_feed_linux.cpp b/modules/camera/camera_feed_linux.cpp
index 9ed8eb0d0a..94bb2b6ad3 100644
--- a/modules/camera/camera_feed_linux.cpp
+++ b/modules/camera/camera_feed_linux.cpp
@@ -232,6 +232,7 @@ String CameraFeedLinux::get_device_name() const {
}
bool CameraFeedLinux::activate_feed() {
+ ERR_FAIL_COND_V_MSG(selected_format == -1, false, "CameraFeed format needs to be set before activating.");
file_descriptor = open(device_name.ascii(), O_RDWR | O_NONBLOCK, 0);
if (_request_buffers() && _start_capturing()) {
buffer_decoder = _create_buffer_decoder();
@@ -302,16 +303,14 @@ Array CameraFeedLinux::get_formats() const {
}
CameraFeed::FeedFormat CameraFeedLinux::get_format() const {
- return formats[selected_format];
+ FeedFormat feed_format = {};
+ return selected_format == -1 ? feed_format : formats[selected_format];
}
bool CameraFeedLinux::set_format(int p_index, const Dictionary &p_parameters) {
ERR_FAIL_COND_V_MSG(active, false, "Feed is active.");
ERR_FAIL_INDEX_V_MSG(p_index, formats.size(), false, "Invalid format index.");
- parameters = p_parameters.duplicate();
- selected_format = p_index;
-
FeedFormat feed_format = formats[p_index];
file_descriptor = open(device_name.ascii(), O_RDWR | O_NONBLOCK, 0);
@@ -344,6 +343,8 @@ bool CameraFeedLinux::set_format(int p_index, const Dictionary &p_parameters) {
}
close(file_descriptor);
+ parameters = p_parameters.duplicate();
+ selected_format = p_index;
emit_signal(SNAME("format_changed"));
return true;
@@ -353,7 +354,6 @@ CameraFeedLinux::CameraFeedLinux(const String &p_device_name) :
CameraFeed() {
device_name = p_device_name;
_query_device(device_name);
- set_format(0, Dictionary());
}
CameraFeedLinux::~CameraFeedLinux() {