mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-03-16 04:51:42 -04:00
add analysis_thread
This commit is contained in:
44
src/zm_analysis_thread.cpp
Normal file
44
src/zm_analysis_thread.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "zm_analysis_thread.h"
|
||||
|
||||
|
||||
AnalysisThread::AnalysisThread( Monitor *p_monitor ) {
|
||||
monitor = p_monitor;
|
||||
terminate = false;
|
||||
sigemptyset( &block_set );
|
||||
}
|
||||
|
||||
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();
|
||||
last_analysis_update_time = time( 0 );
|
||||
|
||||
while( !terminate ) {
|
||||
// Process the next image
|
||||
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
||||
|
||||
// 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() ) {
|
||||
usleep( monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE );
|
||||
} else if ( analysis_rate ) {
|
||||
usleep( analysis_rate );
|
||||
}
|
||||
|
||||
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
||||
}
|
||||
return 0;
|
||||
} // end in AnalysisThread::run()
|
||||
Reference in New Issue
Block a user