Merge branch 'storageareas' into zma_to_thread
This commit is contained in:
commit
b9c57028c8
121
src/zmc.cpp
121
src/zmc.cpp
|
@ -73,25 +73,25 @@ possible, this should run at more or less constant speed.
|
|||
#include "zm_analysis_thread.h"
|
||||
|
||||
void Usage() {
|
||||
fprintf( stderr, "zmc -d <device_path> or -r <proto> -H <host> -P <port> -p <path> or -f <file_path> or -m <monitor_id>\n" );
|
||||
fprintf(stderr, "zmc -d <device_path> or -r <proto> -H <host> -P <port> -p <path> or -f <file_path> or -m <monitor_id>\n");
|
||||
|
||||
fprintf( stderr, "Options:\n" );
|
||||
fprintf(stderr, "Options:\n");
|
||||
#if defined(BSD)
|
||||
fprintf( stderr, " -d, --device <device_path> : For local cameras, device to access. E.g /dev/bktr0 etc\n" );
|
||||
fprintf(stderr, " -d, --device <device_path> : For local cameras, device to access. E.g /dev/bktr0 etc\n");
|
||||
#else
|
||||
fprintf( stderr, " -d, --device <device_path> : For local cameras, device to access. E.g /dev/video0 etc\n" );
|
||||
fprintf(stderr, " -d, --device <device_path> : For local cameras, device to access. E.g /dev/video0 etc\n");
|
||||
#endif
|
||||
fprintf( stderr, " -f, --file <file_path> : For local images, jpg file to access.\n" );
|
||||
fprintf( stderr, " -m, --monitor <monitor_id> : For sources associated with a single monitor\n" );
|
||||
fprintf( stderr, " -h, --help : This screen\n" );
|
||||
fprintf( stderr, " -v, --version : Report the installed version of ZoneMinder\n" );
|
||||
exit( 0 );
|
||||
fprintf(stderr, " -f, --file <file_path> : For local images, jpg file to access.\n");
|
||||
fprintf(stderr, " -m, --monitor <monitor_id> : For sources associated with a single monitor\n");
|
||||
fprintf(stderr, " -h, --help : This screen\n");
|
||||
fprintf(stderr, " -v, --version : Report the installed version of ZoneMinder\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
int main(int argc, char *argv[]) {
|
||||
self = argv[0];
|
||||
|
||||
srand( getpid() * time( 0 ) );
|
||||
srand(getpid() * time(0));
|
||||
|
||||
const char *device = "";
|
||||
const char *protocol = "";
|
||||
|
@ -117,13 +117,12 @@ int main( int argc, char *argv[] ) {
|
|||
while (1) {
|
||||
int option_index = 0;
|
||||
|
||||
int c = getopt_long (argc, argv, "d:H:P:p:f:m:h:v", long_options, &option_index);
|
||||
if (c == -1) {
|
||||
int c = getopt_long(argc, argv, "d:H:P:p:f:m:h:v", long_options, &option_index);
|
||||
if ( c == -1 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'd':
|
||||
device = optarg;
|
||||
break;
|
||||
|
@ -155,61 +154,61 @@ int main( int argc, char *argv[] ) {
|
|||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
fprintf( stderr, "Extraneous options, " );
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
if ( optind < argc ) {
|
||||
fprintf(stderr, "Extraneous options, ");
|
||||
while ( optind < argc )
|
||||
printf("%s ", argv[optind++]);
|
||||
printf("\n");
|
||||
Usage();
|
||||
}
|
||||
|
||||
int modes = ( device[0]?1:0 + host[0]?1:0 + file[0]?1:0 + (monitor_id>0?1:0) );
|
||||
int modes = (device[0]?1:0 + host[0]?1:0 + file[0]?1:0 + (monitor_id > 0 ? 1 : 0));
|
||||
if ( modes > 1 ) {
|
||||
fprintf( stderr, "Only one of device, host/port/path, file or monitor id allowed\n" );
|
||||
fprintf(stderr, "Only one of device, host/port/path, file or monitor id allowed\n");
|
||||
Usage();
|
||||
exit( 0 );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ( modes < 1 ) {
|
||||
fprintf( stderr, "One of device, host/port/path, file or monitor id must be specified\n" );
|
||||
fprintf(stderr, "One of device, host/port/path, file or monitor id must be specified\n");
|
||||
Usage();
|
||||
exit( 0 );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
char log_id_string[32] = "";
|
||||
if ( device[0] ) {
|
||||
const char *slash_ptr = strrchr( device, '/' );
|
||||
snprintf( log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device );
|
||||
const char *slash_ptr = strrchr(device, '/');
|
||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device);
|
||||
} else if ( host[0] ) {
|
||||
snprintf( log_id_string, sizeof(log_id_string), "zmc_h%s", host );
|
||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_h%s", host);
|
||||
} else if ( file[0] ) {
|
||||
const char *slash_ptr = strrchr( file, '/' );
|
||||
snprintf( log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file );
|
||||
const char *slash_ptr = strrchr(file, '/');
|
||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file);
|
||||
} else {
|
||||
snprintf( log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id );
|
||||
snprintf(log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id);
|
||||
}
|
||||
|
||||
zmLoadConfig();
|
||||
|
||||
logInit( log_id_string );
|
||||
|
||||
logInit(log_id_string);
|
||||
|
||||
hwcaps_detect();
|
||||
|
||||
Monitor **monitors = 0;
|
||||
int n_monitors = 0;
|
||||
#if ZM_HAS_V4L
|
||||
if ( device[0] ) {
|
||||
n_monitors = Monitor::LoadLocalMonitors( device, monitors, Monitor::CAPTURE );
|
||||
n_monitors = Monitor::LoadLocalMonitors(device, monitors, Monitor::CAPTURE);
|
||||
} else
|
||||
#endif // ZM_HAS_V4L
|
||||
if ( host[0] ) {
|
||||
if ( !port )
|
||||
port = "80";
|
||||
n_monitors = Monitor::LoadRemoteMonitors( protocol, host, port, path, monitors, Monitor::CAPTURE );
|
||||
n_monitors = Monitor::LoadRemoteMonitors(protocol, host, port, path, monitors, Monitor::CAPTURE);
|
||||
} else if ( file[0] ) {
|
||||
n_monitors = Monitor::LoadFileMonitors( file, monitors, Monitor::CAPTURE );
|
||||
n_monitors = Monitor::LoadFileMonitors(file, monitors, Monitor::CAPTURE);
|
||||
} else {
|
||||
Monitor *monitor = Monitor::Load( monitor_id, true, Monitor::CAPTURE );
|
||||
Monitor *monitor = Monitor::Load(monitor_id, true, Monitor::CAPTURE);
|
||||
if ( monitor ) {
|
||||
monitors = new Monitor *[1];
|
||||
monitors[0] = monitor;
|
||||
|
@ -218,25 +217,25 @@ int main( int argc, char *argv[] ) {
|
|||
}
|
||||
|
||||
if ( !n_monitors ) {
|
||||
Error( "No monitors found" );
|
||||
exit ( -1 );
|
||||
Error("No monitors found");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
Info( "Starting Capture version %s", ZM_VERSION );
|
||||
Info("Starting Capture version %s", ZM_VERSION);
|
||||
|
||||
zmSetDefaultTermHandler();
|
||||
zmSetDefaultDieHandler();
|
||||
|
||||
sigset_t block_set;
|
||||
sigemptyset( &block_set );
|
||||
sigemptyset(&block_set);
|
||||
|
||||
sigaddset( &block_set, SIGUSR1 );
|
||||
sigaddset( &block_set, SIGUSR2 );
|
||||
sigaddset(&block_set, SIGUSR1);
|
||||
sigaddset(&block_set, SIGUSR2);
|
||||
|
||||
monitors[0]->setStartupTime( (time_t)time(NULL) );
|
||||
monitors[0]->setStartupTime((time_t)time(NULL));
|
||||
if ( monitors[0]->PrimeCapture() < 0 ) {
|
||||
Error( "Failed to prime capture of initial monitor" );
|
||||
exit( -1 );
|
||||
Error("Failed to prime capture of initial monitor");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
AnalysisThread **analysis_threads = new AnalysisThread *[n_monitors];
|
||||
|
@ -262,15 +261,15 @@ int main( int argc, char *argv[] ) {
|
|||
int result = 0;
|
||||
struct timeval now;
|
||||
struct DeltaTimeval delta_time;
|
||||
while( !zm_terminate ) {
|
||||
sigprocmask( SIG_BLOCK, &block_set, 0 );
|
||||
while ( !zm_terminate ) {
|
||||
sigprocmask(SIG_BLOCK, &block_set, 0);
|
||||
for ( int i = 0; i < n_monitors; i++ ) {
|
||||
long min_delay = MAXINT;
|
||||
|
||||
gettimeofday( &now, NULL );
|
||||
gettimeofday(&now, NULL);
|
||||
for ( int j = 0; j < n_monitors; j++ ) {
|
||||
if ( last_capture_times[j].tv_sec ) {
|
||||
DELTA_TIMEVAL( delta_time, now, last_capture_times[j], DT_PREC_3 );
|
||||
DELTA_TIMEVAL(delta_time, now, last_capture_times[j], DT_PREC_3);
|
||||
if ( monitors[i]->GetState() == Monitor::ALARM )
|
||||
next_delays[j] = alarm_capture_delays[j]-delta_time.delta;
|
||||
else
|
||||
|
@ -287,38 +286,38 @@ int main( int argc, char *argv[] ) {
|
|||
|
||||
if ( next_delays[i] <= min_delay || next_delays[i] <= 0 ) {
|
||||
if ( monitors[i]->PreCapture() < 0 ) {
|
||||
Error( "Failed to pre-capture monitor %d %d (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
|
||||
Error("Failed to pre-capture monitor %d %d (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors);
|
||||
zm_terminate = true;
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if ( monitors[i]->Capture() < 0 ) {
|
||||
Error( "Failed to capture image from monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
|
||||
Error("Failed to capture image from monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors);
|
||||
zm_terminate = true;
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if ( monitors[i]->PostCapture() < 0 ) {
|
||||
Error( "Failed to post-capture monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors );
|
||||
Error("Failed to post-capture monitor %d %s (%d/%d)", monitors[i]->Id(), monitors[i]->Name(), i+1, n_monitors);
|
||||
zm_terminate = true;
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( next_delays[i] > 0 ) {
|
||||
gettimeofday( &now, NULL );
|
||||
DELTA_TIMEVAL( delta_time, now, last_capture_times[i], DT_PREC_3 );
|
||||
gettimeofday(&now, NULL);
|
||||
DELTA_TIMEVAL(delta_time, now, last_capture_times[i], DT_PREC_3);
|
||||
long sleep_time = next_delays[i]-delta_time.delta;
|
||||
if ( sleep_time > 0 ) {
|
||||
usleep( sleep_time*(DT_MAXGRAN/DT_PREC_3) );
|
||||
usleep(sleep_time*(DT_MAXGRAN/DT_PREC_3));
|
||||
}
|
||||
}
|
||||
gettimeofday( &(last_capture_times[i]), NULL );
|
||||
} // end if next_delay <= min_delay || next_delays[i] <= 0 )
|
||||
gettimeofday(&(last_capture_times[i]), NULL);
|
||||
} // end if next_delay <= min_delay || next_delays[i] <= 0 )
|
||||
|
||||
} // end foreach n_monitors
|
||||
sigprocmask( SIG_UNBLOCK, &block_set, 0 );
|
||||
} // end while ! zm_terminate
|
||||
} // end foreach n_monitors
|
||||
sigprocmask(SIG_UNBLOCK, &block_set, 0);
|
||||
} // end while ! zm_terminate
|
||||
for ( int i = 0; i < n_monitors; i++ ) {
|
||||
if ( analysis_threads[i] ) {
|
||||
analysis_threads[i]->stop();
|
||||
|
|
Loading…
Reference in New Issue