zoneminder/src/zm_analysis_thread.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

2017-09-05 03:29:40 +08:00
#include "zm_analysis_thread.h"
AnalysisThread::AnalysisThread(Monitor *p_monitor) {
2017-09-05 03:29:40 +08:00
monitor = p_monitor;
terminate = false;
2017-11-10 03:50:20 +08:00
//sigemptyset(&block_set);
2017-09-05 03:29:40 +08:00
}
AnalysisThread::~AnalysisThread() {
2017-11-10 03:50:20 +08:00
Debug(2, "THREAD: deleteing");
2017-09-05 03:29:40 +08:00
}
int AnalysisThread::run() {
2017-12-01 05:10:30 +08:00
Debug(2, "In run");
2017-09-05 03:29:40 +08:00
useconds_t analysis_rate = monitor->GetAnalysisRate();
2017-12-01 05:10:30 +08:00
Debug(2, "after getanalysisrate");
2017-09-05 03:29:40 +08:00
unsigned int analysis_update_delay = monitor->GetAnalysisUpdateDelay();
2017-12-01 05:10:30 +08:00
Debug(2, "after getanalysisUpdateDelay");
2017-09-05 03:29:40 +08:00
time_t last_analysis_update_time, cur_time;
monitor->UpdateAdaptiveSkip();
2017-12-01 05:10:30 +08:00
Debug(2, "after UpdateAdaptiveSkip");
last_analysis_update_time = time(0);
2017-09-05 03:29:40 +08:00
2017-11-10 03:50:20 +08:00
Debug(2, "THREAD: Getting ref image");
monitor->get_ref_image();
2017-09-05 03:29:40 +08:00
while( !terminate ) {
// Process the next image
2017-11-10 03:50:20 +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-11-28 03:57:24 +08:00
Debug(2, "Sleeping for %d", monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
2017-11-28 21:29:03 +08:00
usleep(100*(monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE));
2017-09-05 03:29:40 +08:00
} else if ( analysis_rate ) {
2017-11-28 03:57:24 +08:00
Debug(2, "Sleeping 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-10 03:50:20 +08:00
//sigprocmask(SIG_UNBLOCK, &block_set, 0);
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()