2017-09-05 03:29:40 +08:00
|
|
|
#include "zm_analysis_thread.h"
|
|
|
|
|
2017-09-05 04:36:34 +08:00
|
|
|
AnalysisThread::AnalysisThread(Monitor *p_monitor) {
|
2017-09-05 03:29:40 +08:00
|
|
|
monitor = p_monitor;
|
|
|
|
terminate = false;
|
2017-09-05 04:36:34 +08:00
|
|
|
sigemptyset(&block_set);
|
2017-09-05 03:29:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AnalysisThread::~AnalysisThread() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int AnalysisThread::run() {
|
|
|
|
|
|
|
|
useconds_t analysis_rate = monitor->GetAnalysisRate();
|
|
|
|
unsigned int analysis_update_delay = monitor->GetAnalysisUpdateDelay();
|
|
|
|
time_t last_analysis_update_time, cur_time;
|
|
|
|
monitor->UpdateAdaptiveSkip();
|
2017-09-05 04:36:34 +08:00
|
|
|
last_analysis_update_time = time(0);
|
2017-09-05 03:29:40 +08:00
|
|
|
|
|
|
|
while( !terminate ) {
|
|
|
|
// Process the next image
|
2017-09-05 04:36:34 +08:00
|
|
|
sigprocmask(SIG_BLOCK, &block_set, 0);
|
2017-09-05 03:29:40 +08:00
|
|
|
|
|
|
|
// Some periodic updates are required for variable capturing framerate
|
|
|
|
if ( analysis_update_delay ) {
|
|
|
|
cur_time = time( 0 );
|
|
|
|
if ( (unsigned int)( cur_time - last_analysis_update_time ) > analysis_update_delay ) {
|
|
|
|
analysis_rate = monitor->GetAnalysisRate();
|
|
|
|
monitor->UpdateAdaptiveSkip();
|
|
|
|
last_analysis_update_time = cur_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !monitor->Analyse() ) {
|
2017-09-05 04:36:34 +08:00
|
|
|
usleep(monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
|
2017-09-05 03:29:40 +08:00
|
|
|
} else if ( analysis_rate ) {
|
2017-09-05 04:36:34 +08:00
|
|
|
usleep(analysis_rate);
|
2017-09-05 03:29:40 +08:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:36:34 +08:00
|
|
|
sigprocmask(SIG_UNBLOCK, &block_set, 0);
|
2017-09-05 03:29:40 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} // end in AnalysisThread::run()
|