Merge pull request #2305 from pliablepixels/save-first-alarm

Save first alarm
This commit is contained in:
Andrew Bauer 2018-12-11 09:35:40 -06:00 committed by GitHub
commit 22460f580b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 16 deletions

View File

@ -117,6 +117,7 @@ Event::Event(
alarm_frames = 0;
tot_score = 0;
max_score = 0;
alarm_frame_written = false;
char id_file[PATH_MAX];
@ -527,6 +528,13 @@ void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *a
snprintf(snapshot_file, sizeof(snapshot_file), "%s/snapshot.jpg", path);
WriteFrameImage(image, timestamp, snapshot_file);
}
// The first frame with a score will be the frame that alarmed the event
if (!alarm_frame_written && score > 0) {
alarm_frame_written = true;
char alarm_file[PATH_MAX];
snprintf(alarm_file, sizeof(alarm_file), "%s/alarm.jpg", path);
WriteFrameImage(image, timestamp, alarm_file);
}
}
if ( videowriter != NULL ) {
Debug(3, "Writing video");

View File

@ -82,6 +82,7 @@ class Event {
bool videoEvent;
int frames;
int alarm_frames;
bool alarm_frame_written;
unsigned int tot_score;
unsigned int max_score;
char path[PATH_MAX];

View File

@ -69,7 +69,7 @@ if ( empty($_REQUEST['path']) ) {
}
if ( !empty($_REQUEST['eid']) ) {
Logger::Debug("Loading by eid");
Logger::Debug("Loading by eid");
$Event = Event::find_one(array('Id'=>$_REQUEST['eid']));
if ( !$Event ) {
header('HTTP/1.0 404 Not Found');
@ -77,24 +77,28 @@ Logger::Debug("Loading by eid");
return;
}
# if alarm, get the fid of the first alarmed frame if available and let the
# fid= code continue processing it. Sort it to get the first alarmed frame
if ( $_REQUEST['fid'] == 'alarm' ) {
# look for first alarmed frame
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Type'=>'Alarm'),
array('order'=>'FrameId ASC'));
if ( !$Frame ) # no alarms
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'])); # first frame
if ( !$Frame ) {
Warning("No frame found for event " + $_REQUEST['eid']);
$Frame = new Frame();
$Frame->Delta(1);
$Frame->FrameId('snapshot');
if ( !$Frame ) { # no alarms, get first one I find
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid']));
if ( !$Frame ) {
Warning("No frame found for event " + $_REQUEST['eid']);
$Frame = new Frame();
$Frame->Delta(1);
$Frame->FrameId(1);
}
}
$Monitor = $Event->Monitor();
if ( $Monitor->SaveJPEGs() & 1 ) {
# If we store Frames as jpgs, then we don't store an alarmed snapshot
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
} else {
$path = $Event->Path().'/alarm.jpg';
}
$_REQUEST['fid']=$Frame->FrameId();
}
if ( $_REQUEST['fid'] == 'snapshot' ) {
else if ( $_REQUEST['fid'] == 'snapshot' ) {
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore()));
if ( !$Frame )
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid']));
@ -130,14 +134,14 @@ Logger::Debug("Loading by eid");
$percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']);
$Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100);
Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage );
Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage );
} else {
Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')');
}
}
// Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
Logger::Debug("Path: $path");
Logger::Debug("Path: $path");
}
} else {