summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_PT
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-06-11 20:05:36 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-06-11 20:05:36 +0200
commit64dea656becd8c914a3c8dc3f3b4f0d71bd3f2d0 (patch)
tree17aecacbb6d6c7c663ccd465ab92703dc52d51cf /FTNoIR_Tracker_PT
parent2f85648fe4b6ec33adb2fa90be16da49acd1ad71 (diff)
Defer PT apply to avoid deadlock
Diffstat (limited to 'FTNoIR_Tracker_PT')
-rw-r--r--FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp22
-rw-r--r--FTNoIR_Tracker_PT/ftnoir_tracker_pt.h6
2 files changed, 22 insertions, 6 deletions
diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp
index cbc1f1dc..787a5128 100644
--- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp
+++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp
@@ -26,7 +26,9 @@ Tracker::Tracker()
: commands(0),
video_widget(NULL),
video_frame(NULL),
- tracking_valid(false)
+ tracking_valid(false),
+ need_apply(false),
+ new_settings(nullptr)
{
qDebug()<<"Tracker::Tracker";
}
@@ -73,7 +75,7 @@ void Tracker::run()
if (commands & ABORT) break;
if (commands & PAUSE) continue;
commands = 0;
-
+ apply_inner();
dt = time.start() / 1000.0;
new_frame = camera.get_frame(dt, &frame);
@@ -111,11 +113,23 @@ void Tracker::run()
qDebug()<<"Tracker:: Thread stopping";
}
-
void Tracker::apply(settings& s)
{
- qDebug()<<"Tracker:: Applying settings";
QMutexLocker lock(&mutex);
+ need_apply = true;
+ // caller guarantees object lifetime
+ new_settings = &s;
+}
+
+void Tracker::apply_inner()
+{
+ QMutexLocker lock(&mutex);
+ if (!need_apply)
+ return;
+ qDebug()<<"Tracker:: Applying settings";
+ auto& s = *new_settings;
+ new_settings = nullptr;
+ need_apply = false;
camera.set_device_index(s.cam_index);
camera.set_res(s.cam_res_x, s.cam_res_y);
camera.set_fps(s.cam_fps);
diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h
index 80abbc6a..47a9987b 100644
--- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h
+++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h
@@ -44,6 +44,7 @@ public:
virtual void refreshVideo();
void apply(settings& s);
+ void apply_inner();
void center();
void reset(); // reset the trackers internal state variables
void run();
@@ -81,9 +82,10 @@ protected:
PTVideoWidget* video_widget;
QFrame* video_frame;
- bool tracking_valid;
-
+ bool tracking_valid, need_apply;
+
settings s;
+ settings* new_settings;
Timer time;
};