2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Analysis Daemon, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2018-03-30 00:24:21 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
2018-03-30 00:24:21 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2018-03-30 00:24:21 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2018-03-30 00:24:21 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
|
2015-06-21 06:11:20 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
zma - The ZoneMinder Analysis daemon
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
zma -m <monitor_id>
|
|
|
|
zma --monitor <monitor_id>
|
|
|
|
zma -h
|
|
|
|
zma --help
|
|
|
|
zma -v
|
|
|
|
zma --version
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This is the component that goes through the captured frames and checks them
|
|
|
|
for motion which might generate an alarm or event. It generally keeps up with
|
|
|
|
the Capture daemon but if very busy may skip some frames to prevent it falling
|
|
|
|
behind.
|
|
|
|
|
|
|
|
=head1 OPTIONS
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
-m, --monitor_id - ID of the monitor to analyse
|
|
|
|
-h, --help - Display usage information
|
|
|
|
-v, --version - Print the installed version of ZoneMinder
|
2015-06-21 06:11:20 +08:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2002-12-24 20:01:28 +08:00
|
|
|
#include <getopt.h>
|
2003-03-26 20:00:16 +08:00
|
|
|
#include <signal.h>
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_db.h"
|
2006-04-05 20:22:27 +08:00
|
|
|
#include "zm_signal.h"
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm_monitor.h"
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
void Usage() {
|
2018-03-30 00:24:21 +08:00
|
|
|
fprintf(stderr, "zma -m <monitor_id>\n");
|
|
|
|
fprintf(stderr, "Options:\n");
|
|
|
|
fprintf(stderr, " -m, --monitor <monitor_id> : Specify which monitor to use\n");
|
|
|
|
fprintf(stderr, " -h, --help : This screen\n");
|
|
|
|
fprintf(stderr, " -v, --version : Report the installed version of ZoneMinder\n");
|
|
|
|
exit(0);
|
2002-12-24 20:01:28 +08:00
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
int main( int argc, char *argv[] ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
self = argv[0];
|
|
|
|
|
2018-03-30 00:24:21 +08:00
|
|
|
srand(getpid() * time(0));
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
int id = -1;
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"monitor", 1, 0, 'm'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"version", 0, 0, 'v'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
while (1) {
|
2016-04-04 22:11:48 +08:00
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
int c = getopt_long (argc, argv, "m:h:v", long_options, &option_index);
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( c == -1 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
switch (c) {
|
2016-04-04 22:11:48 +08:00
|
|
|
case 'm':
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
Usage();
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
std::cout << ZM_VERSION << "\n";
|
|
|
|
exit(0);
|
|
|
|
default:
|
|
|
|
//fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
if (optind < argc) {
|
2018-03-30 00:24:21 +08:00
|
|
|
fprintf(stderr, "Extraneous options, ");
|
2016-04-04 22:11:48 +08:00
|
|
|
while (optind < argc)
|
2018-03-30 00:24:21 +08:00
|
|
|
printf("%s ", argv[optind++]);
|
|
|
|
printf("\n");
|
2016-04-04 22:11:48 +08:00
|
|
|
Usage();
|
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( id < 0 ) {
|
2018-03-30 00:24:21 +08:00
|
|
|
fprintf(stderr, "Bogus monitor %d\n", id);
|
2016-04-04 22:11:48 +08:00
|
|
|
Usage();
|
2018-03-30 00:24:21 +08:00
|
|
|
exit(0);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char log_id_string[16];
|
2018-03-30 00:24:21 +08:00
|
|
|
snprintf(log_id_string, sizeof(log_id_string), "zma_m%d", id);
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
zmLoadConfig();
|
|
|
|
|
2018-03-30 00:24:21 +08:00
|
|
|
logInit(log_id_string);
|
|
|
|
|
2017-03-19 08:05:01 +08:00
|
|
|
hwcaps_detect();
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2018-03-30 00:24:21 +08:00
|
|
|
Monitor *monitor = Monitor::Load(id, true, Monitor::ANALYSIS);
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( monitor ) {
|
2018-03-30 00:24:21 +08:00
|
|
|
Info("In mode %d/%d, warming up", monitor->GetFunction(), monitor->Enabled());
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
zmSetDefaultHupHandler();
|
|
|
|
zmSetDefaultTermHandler();
|
|
|
|
zmSetDefaultDieHandler();
|
|
|
|
|
|
|
|
sigset_t block_set;
|
2018-03-30 00:24:21 +08:00
|
|
|
sigemptyset(&block_set);
|
2016-04-04 22:11:48 +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 );
|
|
|
|
|
2018-04-24 04:24:44 +08:00
|
|
|
while( (!zm_terminate) && monitor->ShmValid() ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
// Process the next image
|
2018-03-30 00:24:21 +08:00
|
|
|
sigprocmask(SIG_BLOCK, &block_set, 0);
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
// Some periodic updates are required for variable capturing framerate
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( analysis_update_delay ) {
|
2018-03-30 00:24:21 +08:00
|
|
|
cur_time = time(0);
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( (unsigned int)( cur_time - last_analysis_update_time ) > analysis_update_delay ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
analysis_rate = monitor->GetAnalysisRate();
|
|
|
|
monitor->UpdateAdaptiveSkip();
|
|
|
|
last_analysis_update_time = cur_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( !monitor->Analyse() ) {
|
2018-03-30 00:24:21 +08:00
|
|
|
usleep(monitor->Active()?ZM_SAMPLE_RATE:ZM_SUSPENDED_RATE);
|
2017-10-19 01:23:40 +08:00
|
|
|
} else if ( analysis_rate ) {
|
2018-03-30 00:24:21 +08:00
|
|
|
usleep(analysis_rate);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
|
2017-10-19 01:23:40 +08:00
|
|
|
if ( zm_reload ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
monitor->Reload();
|
2018-01-11 01:58:22 +08:00
|
|
|
logTerm();
|
2018-03-30 00:24:21 +08:00
|
|
|
logInit(log_id_string);
|
2016-04-04 22:11:48 +08:00
|
|
|
zm_reload = false;
|
|
|
|
}
|
2018-03-30 00:24:21 +08:00
|
|
|
sigprocmask(SIG_UNBLOCK, &block_set, 0);
|
2018-03-22 22:26:05 +08:00
|
|
|
} // end while ! zm_terminate
|
2016-04-04 22:11:48 +08:00
|
|
|
delete monitor;
|
2017-10-19 01:23:40 +08:00
|
|
|
} else {
|
2018-03-30 00:24:21 +08:00
|
|
|
fprintf(stderr, "Can't find monitor with id of %d\n", id);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2016-10-07 23:35:14 +08:00
|
|
|
Image::Deinitialise();
|
2016-04-04 22:11:48 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|