From f719dd9acc4b042be9b56999be179fabbe166b83 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 7 Apr 2019 10:29:02 -0400 Subject: [PATCH] always commit buffered db_frames when we have a new max score image or alarm cause image --- src/zm_event.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 7b8b446d4..330f421eb 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -538,6 +538,7 @@ void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *a } frames++; + bool write_to_db = false; if ( monitor->GetOptSaveJPEGs() & 1 ) { static char event_file[PATH_MAX]; @@ -549,10 +550,12 @@ void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *a } else { //If this is the first frame, we should add a thumbnail to the event directory if ( (frames == 1) || (score > (int)max_score) ) { + write_to_db = true; // web ui might show this as thumbnail, so db needs to know about it. 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) ) { + write_to_db = true; // OD processing will need it, so the db needs to know about it alarm_frame_written = true; WriteFrameImage(image, timestamp, alarm_file); } @@ -574,7 +577,7 @@ void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *a static char sql[ZM_SQL_MED_BUFSIZ]; frame_data.push(new Frame(id, frames, frame_type, timestamp, delta_time, score)); - if ( frame_data.size() > 20 ) { + if ( write_to_db || ( frame_data.size() > 20 ) ) { WriteDbFrames(); Debug(1, "Adding 20 frames to DB"); last_db_frame = frames;