From 3202db1b3339fc8a7c778273e71ae5c3744c6be2 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 27 Mar 2021 15:08:40 -0400 Subject: [PATCH] Move waiting for decoding down into motion detection part, which is what needs it. Not sure why it was up so high. This should allow more ram freeing for people with analysis fps set to something. --- src/zm_monitor.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 14602f017..6c0bd9a39 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1800,8 +1800,6 @@ void Monitor::UpdateAnalysisFPS() { // If there is an event, the we should do our best to empty the queue. // If there isn't then we keep pre-event + alarm frames. = pre_event_count bool Monitor::Analyse() { - - // if have event, send frames until we find a video packet, at which point do analysis. Adaptive skip should only affect which frames we do analysis on. // get_analysis_packet will lock the packet and may wait if analysis_it is at the end @@ -1923,18 +1921,6 @@ bool Monitor::Analyse() { noteSetMap[LINKED_CAUSE] = noteSet; } // end if linked_monitors - if ( decoding_enabled ) { - while (!snap->image and !snap->decoded and !zm_terminate) { - // Need to wait for the decoder thread. - Debug(1, "Waiting for decode"); - packet_lock->wait(); - if (!snap->image and snap->decoded) { - Debug(1, "No image but was decoded, giving up"); - delete packet_lock; - return false; - } - } // end while ! decoded - } struct timeval *timestamp = snap->timestamp; @@ -1952,16 +1938,25 @@ bool Monitor::Analyse() { } if (!(analysis_image_count % (motion_frame_skip+1))) { - if (snap->image) { - // Get new score. - motion_score = DetectMotion(*(snap->image), zoneSet); - - Debug(3, "After motion detection, score:%d last_motion_score(%d), new motion score(%d)", - score, last_motion_score, motion_score); - motion_frame_count += 1; - } else { - Debug(1, "No image in snap, codec likely not ready"); + if (decoding_enabled) { + while (!snap->image and !snap->decoded and !zm_terminate) { + // Need to wait for the decoder thread. + Debug(1, "Waiting for decode"); + packet_lock->wait(); + if (!snap->image and snap->decoded) { + Debug(1, "No image but was decoded, giving up"); + delete packet_lock; + return false; + } + } // end while ! decoded } + + // Get new score. + motion_score = DetectMotion(*(snap->image), zoneSet); + + Debug(3, "After motion detection, score:%d last_motion_score(%d), new motion score(%d)", + score, last_motion_score, motion_score); + motion_frame_count += 1; // Why are we updating the last_motion_score too? last_motion_score = motion_score; } else {