zoneminder/src/zm_analysis_thread.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.6 KiB
C++
Raw Normal View History

2017-09-05 03:29:40 +08:00
#include "zm_analysis_thread.h"
#include "zm_signal.h"
AnalysisThread::AnalysisThread(std::shared_ptr<Monitor> monitor) :
monitor_(std::move(monitor)), terminate_(false) {
thread_ = std::thread(&AnalysisThread::Run, this);
}
2017-09-05 03:29:40 +08:00
AnalysisThread::~AnalysisThread() {
terminate_ = true;
if (thread_.joinable())
thread_.join();
2017-09-05 03:29:40 +08:00
}
AnalysisThread::AnalysisThread(AnalysisThread &&rhs) noexcept
: monitor_(std::move(rhs.monitor_)), terminate_(rhs.terminate_.load()), thread_(std::move(rhs.thread_)) {}
2017-09-05 03:29:40 +08:00
void AnalysisThread::Run() {
Debug(2, "AnalysisThread::Run()");
2017-09-05 03:29:40 +08:00
useconds_t analysis_rate = monitor_->GetAnalysisRate();
unsigned int analysis_update_delay = monitor_->GetAnalysisUpdateDelay();
time_t last_analysis_update_time, cur_time;
monitor_->UpdateAdaptiveSkip();
last_analysis_update_time = time(nullptr);
2017-09-05 03:29:40 +08:00
while (!(terminate_ or zm_terminate)) {
2017-09-05 03:29:40 +08:00
// Some periodic updates are required for variable capturing framerate
if (analysis_update_delay) {
cur_time = time(nullptr);
if ((unsigned int) (cur_time - last_analysis_update_time) > analysis_update_delay) {
analysis_rate = monitor_->GetAnalysisRate();
monitor_->UpdateAdaptiveSkip();
2017-09-05 03:29:40 +08:00
last_analysis_update_time = cur_time;
}
}
2020-09-26 04:19:31 +08:00
Debug(2, "Analyzing");
if (!monitor_->Analyse()) {
Debug(2, "uSleeping for %d", (monitor_->Active() ? ZM_SAMPLE_RATE : ZM_SUSPENDED_RATE));
usleep(monitor_->Active() ? ZM_SAMPLE_RATE : ZM_SUSPENDED_RATE);
} else if (analysis_rate) {
Debug(2, "uSleeping for %d", analysis_rate);
usleep(analysis_rate);
2017-11-28 21:29:03 +08:00
} else {
Debug(2, "Not Sleeping");
2017-09-05 03:29:40 +08:00
}
}
}