From 01a57222d3cecc53751bf2405617242bc74fab19 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Mon, 12 Nov 2018 12:43:20 -0500 Subject: [PATCH 1/2] keep track if we have written alarmed frame incase savejpeg is off --- src/zm_event.cpp | 8 ++++++++ src/zm_event.h | 1 + web/views/image.php | 36 ++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 8d3108b31..20f7902f3 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -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"); diff --git a/src/zm_event.h b/src/zm_event.h index 1e55ae593..95595f689 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -82,6 +82,7 @@ class Event { bool videoEvent; int frames; int alarm_frames; + static bool alarm_frame_written; unsigned int tot_score; unsigned int max_score; char path[PATH_MAX]; diff --git a/web/views/image.php b/web/views/image.php index 2c04f18e6..16c88f908 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -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 { From e06f5b0f902a5d8cbaa18e52fce73edc7ea280a5 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Mon, 12 Nov 2018 13:34:29 -0500 Subject: [PATCH 2/2] removed static --- src/zm_event.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_event.h b/src/zm_event.h index 95595f689..7c38764bc 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -82,7 +82,7 @@ class Event { bool videoEvent; int frames; int alarm_frames; - static bool alarm_frame_written; + bool alarm_frame_written; unsigned int tot_score; unsigned int max_score; char path[PATH_MAX];