summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-07 11:49:12 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-07 11:54:41 +0200
commitcdbe9e8ea3283dde4667098e8b35f09b94cbcfc4 (patch)
treeacf31cbfcf7f237e07e47fdc97a7994255a5cfca /opentrack
parent511e095fa3b944b2016560e6bb21e3f0413aa1a4 (diff)
camera dialog: don't crash due to race condition
We have no idea when the capture can be closed, so wait for three seconds instead.
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/opencv-camera-dialog.hpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp
index 3b700a70..6218f125 100644
--- a/opentrack/opencv-camera-dialog.hpp
+++ b/opentrack/opencv-camera-dialog.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <QTimer>
#include <QMutex>
#include <QMutexLocker>
#include <opencv2/videoio.hpp>
@@ -9,6 +10,14 @@ template<typename tracker>
class camera_dialog
{
cv::VideoCapture fake_capture;
+ QTimer t;
+
+private:
+ void delete_capture()
+ {
+ fake_capture.open("");
+ }
+
public:
void open_camera_settings(cv::VideoCapture* cap, const QString& camera_name, QMutex* camera_mtx)
{
@@ -23,10 +32,20 @@ public:
}
}
+ if (t.isActive())
+ return;
+
+ // don't hog the camera capture
+ if (!t.isSingleShot())
+ QObject::connect(&t, &QTimer::timeout, [&]() -> void { delete_capture(); });
+
+ t.setSingleShot(true);
+ t.setInterval(3000);
+
fake_capture = cv::VideoCapture(camera_name_to_index(camera_name));
fake_capture.set(cv::CAP_PROP_SETTINGS, 1);
- // don't hog the camera capture
- fake_capture.open("");
+ // HACK: we're not notified when it's safe to close the capture
+ t.start();
}
};