Merge pull request #2305 from pliablepixels/save-first-alarm
Save first alarm
This commit is contained in:
commit
22460f580b
|
@ -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");
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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 ) { # 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('snapshot');
|
||||
$Frame->FrameId(1);
|
||||
}
|
||||
$_REQUEST['fid']=$Frame->FrameId();
|
||||
}
|
||||
|
||||
|
||||
if ( $_REQUEST['fid'] == 'snapshot' ) {
|
||||
$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';
|
||||
}
|
||||
}
|
||||
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']));
|
||||
|
|
Loading…
Reference in New Issue