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;
|
alarm_frames = 0;
|
||||||
tot_score = 0;
|
tot_score = 0;
|
||||||
max_score = 0;
|
max_score = 0;
|
||||||
|
alarm_frame_written = false;
|
||||||
|
|
||||||
char id_file[PATH_MAX];
|
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);
|
snprintf(snapshot_file, sizeof(snapshot_file), "%s/snapshot.jpg", path);
|
||||||
WriteFrameImage(image, timestamp, snapshot_file);
|
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 ) {
|
if ( videowriter != NULL ) {
|
||||||
Debug(3, "Writing video");
|
Debug(3, "Writing video");
|
||||||
|
|
|
@ -82,6 +82,7 @@ class Event {
|
||||||
bool videoEvent;
|
bool videoEvent;
|
||||||
int frames;
|
int frames;
|
||||||
int alarm_frames;
|
int alarm_frames;
|
||||||
|
bool alarm_frame_written;
|
||||||
unsigned int tot_score;
|
unsigned int tot_score;
|
||||||
unsigned int max_score;
|
unsigned int max_score;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
|
@ -69,7 +69,7 @@ if ( empty($_REQUEST['path']) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($_REQUEST['eid']) ) {
|
if ( !empty($_REQUEST['eid']) ) {
|
||||||
Logger::Debug("Loading by eid");
|
Logger::Debug("Loading by eid");
|
||||||
$Event = Event::find_one(array('Id'=>$_REQUEST['eid']));
|
$Event = Event::find_one(array('Id'=>$_REQUEST['eid']));
|
||||||
if ( !$Event ) {
|
if ( !$Event ) {
|
||||||
header('HTTP/1.0 404 Not Found');
|
header('HTTP/1.0 404 Not Found');
|
||||||
|
@ -77,24 +77,28 @@ Logger::Debug("Loading by eid");
|
||||||
return;
|
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' ) {
|
if ( $_REQUEST['fid'] == 'alarm' ) {
|
||||||
|
# look for first alarmed frame
|
||||||
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Type'=>'Alarm'),
|
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Type'=>'Alarm'),
|
||||||
array('order'=>'FrameId ASC'));
|
array('order'=>'FrameId ASC'));
|
||||||
if ( !$Frame ) # no alarms
|
if ( !$Frame ) { # no alarms, get first one I find
|
||||||
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'])); # first frame
|
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid']));
|
||||||
if ( !$Frame ) {
|
if ( !$Frame ) {
|
||||||
Warning("No frame found for event " + $_REQUEST['eid']);
|
Warning("No frame found for event " + $_REQUEST['eid']);
|
||||||
$Frame = new Frame();
|
$Frame = new Frame();
|
||||||
$Frame->Delta(1);
|
$Frame->Delta(1);
|
||||||
$Frame->FrameId('snapshot');
|
$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();
|
|
||||||
}
|
}
|
||||||
|
else if ( $_REQUEST['fid'] == 'snapshot' ) {
|
||||||
|
|
||||||
if ( $_REQUEST['fid'] == 'snapshot' ) {
|
|
||||||
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore()));
|
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore()));
|
||||||
if ( !$Frame )
|
if ( !$Frame )
|
||||||
$Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid']));
|
$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']);
|
$percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']);
|
||||||
|
|
||||||
$Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100);
|
$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 {
|
} else {
|
||||||
Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')');
|
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
|
// 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';
|
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
|
||||||
Logger::Debug("Path: $path");
|
Logger::Debug("Path: $path");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue