zoneminder/src/zm_analysis_thread.cpp

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

47 lines
1.4 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) {}
2017-09-05 03:29:40 +08:00
AnalysisThread::~AnalysisThread() {
Debug(2, "THREAD: deleteing analysis thread");
2017-09-05 03:29:40 +08:00
}
int 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(0);
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 ) {
2020-12-31 10:21:41 +08:00
cur_time = time(0);
2017-09-05 03:29:40 +08:00
if ( (unsigned int)( cur_time - last_analysis_update_time ) > analysis_update_delay ) {
analysis_rate = monitor->GetAnalysisRate();
monitor->UpdateAdaptiveSkip();
last_analysis_update_time = cur_time;
}
}
2020-09-26 04:19:31 +08:00
Debug(2, "Analyzing");
2017-09-05 03:29:40 +08:00
if ( !monitor->Analyse() ) {
Debug(2, "uSleeping for %d", (monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE));
2020-12-31 10:21:41 +08:00
usleep(monitor->Active() ? ZM_SAMPLE_RATE : ZM_SUSPENDED_RATE);
2017-09-05 03:29:40 +08:00
} 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
}
2017-11-13 00:50:07 +08:00
} // end while ! terminate
2017-09-05 03:29:40 +08:00
return 0;
} // end in AnalysisThread::run()