From 5f9c4be6b237a067ca828cc961410d87e9144fb0 Mon Sep 17 00:00:00 2001 From: Zii Date: Tue, 20 Jun 2023 17:49:52 -0400 Subject: [PATCH] v3.1.t1 -added event age to evt_t as a way to track the age of the event in EventLoop so now only events approching and exceeding evMaxSecs will have the video range added for writing. --- src/camera.cpp | 61 +++++++++++++++++++++++++++++++------------------- src/common.h | 3 ++- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index a06c5e4..4230da8 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -253,7 +253,7 @@ EventLoop::EventLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop( bool EventLoop::exec() { - if (cycles * 2 >= shared->evMaxSecs) + if (!vidList.isEmpty()) { vidList.removeDuplicates(); @@ -282,32 +282,46 @@ bool EventLoop::exec() vidList.clear(); } - else + + shared->recMutex.lock(); + + QList rmIndx; + + for (auto i = 0; i < shared->recList.size(); ++i) { - cycles += 1; + auto event = &shared->recList[i]; - shared->recMutex.lock(); - - for (auto &&event : shared->recList) + if (highScore < event->score) { - auto maxFiles = shared->evMaxSecs / 2; - // there's 2 secs in each hls segment - - if (highScore < event.score) - { - name = event.timeStamp.toString(DATETIME_FMT); - imgPath = event.imgPath; - highScore = event.score; - } - - vidList.append(backwardFacingFiles("live", ".ts", event.timeStamp, maxFiles / 2)); - vidList.append(forwardFacingFiles("live", ".ts", event.timeStamp, maxFiles / 2)); + name = event->timeStamp.toString(DATETIME_FMT); + imgPath = event->imgPath; + highScore = event->score; } - shared->recList.clear(); - shared->recMutex.unlock(); + if (event->queAge >= (shared->evMaxSecs / heartBeat)) + { + auto maxSecs = shared->evMaxSecs / 2; + // half the maxsecs value to get front-back half secs + + auto backFiles = backwardFacingFiles("live", ".ts", event->timeStamp, maxSecs); + auto frontFiles = forwardFacingFiles("live", ".ts", event->timeStamp, maxSecs); + + vidList.append(backFiles + frontFiles); + rmIndx.append(i); + } + else + { + event->queAge += heartBeat; + } } + for (auto i : rmIndx) + { + shared->recList.remove(i); + } + + shared->recMutex.unlock(); + return Loop::exec(); } @@ -377,9 +391,9 @@ DetectLoop::DetectLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loo { pcTimer = 0; heartBeat = 2; - delayCycles = 8; // this will be used to delay the - // actual start of DetectLoop by - // 16secs. + delayCycles = 12; // this will be used to delay the + // actual start of DetectLoop by + // 24secs. } void DetectLoop::init() @@ -473,6 +487,7 @@ bool DetectLoop::exec() event.timeStamp = curDT; event.score = score; event.imgPath = images[pos]; + event.queAge = 0; shared->recMutex.lock(); shared->recList.append(event); mod = true; diff --git a/src/common.h b/src/common.h index 0047d74..1e4f78d 100644 --- a/src/common.h +++ b/src/common.h @@ -29,7 +29,7 @@ using namespace std; -#define APP_VER "3.0.0" +#define APP_VER "3.1.t1" #define APP_NAME "Motion Watch" #define APP_BIN "mow" #define REC_LOG_NAME "rec_log_lines.html" @@ -45,6 +45,7 @@ struct evt_t QDateTime timeStamp; QString imgPath; float score; + uint queAge; }; struct shared_t