From 271937f005e3dc84662a5668d7b946972d285cd3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 4 Apr 2019 12:28:08 -0400 Subject: [PATCH] store the snapshot_file and alarm_file strings in the boject during construction so that we don't have to do it everytime we write out an image --- src/zm_event.cpp | 9 +++------ src/zm_event.h | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 876a031d4..c44f8ee93 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -193,6 +193,9 @@ Event::Event( video_name[0] = 0; + snprintf(snapshot_file, sizeof(snapshot_file), "%s/snapshot.jpg", path); + snprintf(alarm_file, sizeof(alarm_file), "%s/alarm.jpg", path); + /* Save as video */ if ( monitor->GetOptVideoWriter() != 0 ) { @@ -464,8 +467,6 @@ void Event::AddFramesInternal( int n_frames, int start_frame, Image **images, st // neccessarily be of the motion. But some events are less than 10 frames, // so I am changing this to 1, but we should overwrite it later with a better snapshot. if ( frames == 1 ) { - char snapshot_file[PATH_MAX]; - snprintf(snapshot_file, sizeof(snapshot_file), "%s/snapshot.jpg", path); WriteFrameImage(images[i], *(timestamps[i]), snapshot_file); } } @@ -549,15 +550,11 @@ 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 ) { - char snapshot_file[PATH_MAX]; - 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); } } diff --git a/src/zm_event.h b/src/zm_event.h index 1d31addcc..2035b6af6 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -90,6 +90,8 @@ class Event { unsigned int tot_score; unsigned int max_score; char path[PATH_MAX]; + char snapshot_file[PATH_MAX]; + char alarm_file[PATH_MAX]; VideoWriter* videowriter; FILE* timecodes_fd; char video_name[PATH_MAX];