Merge pull request #2082 from connortechnology/fix_signalcheck

Fix signalcheck
This commit is contained in:
Andrew Bauer 2018-04-19 13:26:54 -05:00 committed by GitHub
commit e7be406eb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 34 deletions

View File

@ -499,6 +499,7 @@ CREATE TABLE `Monitors` (
`DefaultView` enum('Events','Control') NOT NULL default 'Events',
`DefaultRate` smallint(5) unsigned NOT NULL default '100',
`DefaultScale` smallint(5) unsigned NOT NULL default '100',
`SignalCheckPoints` INT UNSIGNED NOT NULL default '0',
`SignalCheckColour` varchar(32) NOT NULL default '#0000BE',
`WebColour` varchar(32) NOT NULL default 'red',
`Exif` tinyint(1) unsigned NOT NULL default '0',

12
db/zm_update-1.31.42.sql Normal file
View File

@ -0,0 +1,12 @@
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Monitors'
AND column_name = 'SignalCheckPoints'
) > 0,
"SELECT 'Column SignalCheckPoints already exists in Storage'",
"ALTER TABLE `Monitors` ADD `SignalCheckPoints` INT UNSIGNED NOT NULL default '0' AFTER `DefaultScale`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

View File

@ -1723,26 +1723,6 @@ our @options = (
type => $types{abs_path},
category => 'config',
},
{
name => 'ZM_SIGNAL_CHECK_POINTS',
default => '10',
description => 'How many points in a captured image to check for signal loss',
help => q`
For locally attached video cameras ZoneMinder can check for
signal loss by looking at a number of random points on each
captured image. If all of these points are set to the same
fixed colour then the camera is assumed to have lost signal.
When this happens any open events are closed and a short one
frame signal loss event is generated, as is another when the
signal returns. This option defines how many points on each
image to check. Note that this is a maximum, any points found
to not have the check colour will abort any further checks so
in most cases on a couple of points will actually be checked.
Network and file based cameras are never checked.
`,
type => $types{integer},
category => 'config',
},
{
name => 'ZM_V4L_MULTI_BUFFER',
default => 'yes',

View File

@ -77,7 +77,7 @@ std::string load_monitor_sql =
"EventPrefix, LabelFormat, LabelX, LabelY, LabelSize,"
"ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, "
"SectionLength, FrameSkip, MotionFrameSkip, "
"FPSReportInterval, RefBlendPerc, AlarmRefBlendPerc, TrackMotion, Exif, SignalCheckColour FROM Monitors";
"FPSReportInterval, RefBlendPerc, AlarmRefBlendPerc, TrackMotion, Exif, SignalCheckPoints, SignalCheckColour FROM Monitors";
std::string CameraType_Strings[] = {
"Local",
@ -304,6 +304,7 @@ Monitor::Monitor(
int p_ref_blend_perc,
int p_alarm_ref_blend_perc,
bool p_track_motion,
int p_signal_check_points,
Rgb p_signal_check_colour,
bool p_embed_exif,
Purpose p_purpose,
@ -341,6 +342,7 @@ Monitor::Monitor(
ref_blend_perc( p_ref_blend_perc ),
alarm_ref_blend_perc( p_alarm_ref_blend_perc ),
track_motion( p_track_motion ),
signal_check_points(p_signal_check_points),
signal_check_colour( p_signal_check_colour ),
embed_exif( p_embed_exif ),
delta_image( width, height, ZM_COLOUR_GRAY8, ZM_SUBPIX_ORDER_NONE ),
@ -1164,7 +1166,7 @@ bool Monitor::CheckSignal( const Image *image ) {
static Rgb colour_val; /* RGB32 color */
static int usedsubpixorder;
if ( config.signal_check_points > 0 ) {
if ( signal_check_points > 0 ) {
if ( static_undef ) {
static_undef = false;
usedsubpixorder = camera->SubpixelOrder();
@ -1182,8 +1184,9 @@ bool Monitor::CheckSignal( const Image *image ) {
int colours = image->Colours();
int index = 0;
for ( int i = 0; i < config.signal_check_points; i++ ) {
for ( int i = 0; i < signal_check_points; i++ ) {
while( true ) {
// Why the casting to long long? also note that on a 64bit cpu, long long is 128bits
index = (int)(((long long)rand()*(long long)(pixels-1))/RAND_MAX);
if ( !config.timestamp_on_capture || !label_format[0] )
break;
@ -1219,6 +1222,7 @@ bool Monitor::CheckSignal( const Image *image ) {
}
}
} // end for < signal_check_points
Debug(1,"SignalCheck: %d points, colour_val(%d)", signal_check_points, colour_val);
return false;
} // end if signal_check_points
return true;
@ -1801,6 +1805,7 @@ void Monitor::Reload() {
alarm_ref_blend_perc = atoi(dbrow[index++]);
track_motion = atoi(dbrow[index++]);
signal_check_points = dbrow[index]?atoi(dbrow[index]):0;index++;
if ( dbrow[index][0] == '#' )
signal_check_colour = strtol(dbrow[index]+1,0,16);
@ -2088,7 +2093,7 @@ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) {
int ref_blend_perc = atoi(dbrow[col]); col++;
int alarm_ref_blend_perc = atoi(dbrow[col]); col++;
int track_motion = atoi(dbrow[col]); col++;
int signal_check_points = dbrow[col] ? atoi(dbrow[col]) : 0;col++;
int signal_check_color = strtol(dbrow[col][0] == '#' ? dbrow[col]+1 : dbrow[col], 0, 16); col++;
bool embed_exif = (*dbrow[col] != '0'); col++;
@ -2288,6 +2293,7 @@ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) {
ref_blend_perc,
alarm_ref_blend_perc,
track_motion,
signal_check_points,
signal_check_color,
embed_exif,
purpose,
@ -2435,7 +2441,7 @@ int Monitor::Capture() {
TimestampImage( capture_image, image_buffer[index].timestamp );
}
// Maybe we don't need to do this on all camera types
shared_data->signal = CheckSignal(capture_image);
shared_data->signal = signal_check_points ? CheckSignal(capture_image) : true;
shared_data->last_write_index = index;
shared_data->last_write_time = image_buffer[index].timestamp->tv_sec;

View File

@ -284,6 +284,7 @@ protected:
int ref_blend_perc; // Percentage of new image going into reference image.
int alarm_ref_blend_perc; // Percentage of new image going into reference image during alarm.
bool track_motion; // Whether this monitor tries to track detected motion
int signal_check_points; // Number of points in the image to check for signal
Rgb signal_check_colour; // The colour that the camera will emit when no video signal detected
bool embed_exif; // Whether to embed Exif data into each image frame or not
@ -384,6 +385,7 @@ public:
int p_ref_blend_perc,
int p_alarm_ref_blend_perc,
bool p_track_motion,
int p_signal_check_points,
Rgb p_signal_check_colour,
bool p_embed_exif,
Purpose p_purpose,

View File

@ -1 +1 @@
1.31.41
1.31.42

View File

@ -133,6 +133,7 @@ if ( ! $monitor ) {
'DefaultView' => 'Events',
'DefaultRate' => '100',
'DefaultScale' => '100',
'SignalCheckPoints' => '10',
'SignalCheckColour' => '#0000c0',
'WebColour' => 'red',
'Exif' => '0',
@ -659,8 +660,9 @@ if ( $tab != 'misc' ) {
<input type="hidden" name="newMonitor[Exif]" value="<?php echo validHtmlStr($monitor->Exif()) ?>"/>
<?php
}
if ( ZM_HAS_V4L && ($tab != 'misc' || $monitor->Type()!= 'Local') ) {
if ( $tab != 'misc' ) {
?>
<input type="hidden" name="newMonitor[SignalCheckPoints]" value="<?php echo validHtmlStr($monitor->SignalCheckPoints()) ?>"/>
<input type="hidden" name="newMonitor[SignalCheckColour]" value="<?php echo validHtmlStr($monitor->SignalCheckColour()) ?>"/>
<?php
}
@ -980,19 +982,19 @@ if ( $monitor->Type() == 'Local' ) {
</select></td></tr>
<tr><td><?php echo translate('DefaultRate') ?></td><td><?php echo htmlSelect( "newMonitor[DefaultRate]", $rates, $monitor->DefaultRate() ); ?></td></tr>
<tr><td><?php echo translate('DefaultScale') ?></td><td><?php echo htmlSelect( "newMonitor[DefaultScale]", $scales, $monitor->DefaultScale() ); ?></td></tr>
<?php
if ( ZM_HAS_V4L && $monitor->Type() == 'Local' ) {
?>
<tr>
<td><?php echo translate('SignalCheckPoints') ?></td>
<td>
<input type="number" name="newMonitor[SignalCheckPoints]" value="<?php echo validInt($monitor->SignalCheckPoints()) ?>"/>
</td>
</tr>
<tr>
<td><?php echo translate('SignalCheckColour') ?></td>
<td>
<input type="text" name="newMonitor[SignalCheckColour]" value="<?php echo validHtmlStr($monitor->SignalCheckColour()) ?>" size="10" onchange="$('SignalCheckSwatch').setStyle( 'backgroundColor', this.value )"/>
<input type="text" name="newMonitor[SignalCheckColour]" value="<?php echo validHtmlStr($monitor->SignalCheckColour()) ?>" size="10" onchange="$('SignalCheckSwatch').setStyle('backgroundColor', this.value)"/>
<span id="SignalCheckSwatch" class="swatch" style="background-color: <?php echo $monitor->SignalCheckColour()?>;">&nbsp;&nbsp;&nbsp;&nbsp;</span>
</td>
</tr>
<?php
}
?>
<tr>
<td><?php echo translate('WebColour') ?></td>
<td>