From 651ec960833ba4995063a6cfb76d9e1b58184004 Mon Sep 17 00:00:00 2001 From: Maurice ONeal Date: Sun, 11 Dec 2022 21:00:53 -0500 Subject: [PATCH] v1.5.t7 Moved logging out of it's own loop, hopefully this fixes the issue with it not outputting all log lines. recLoop() and detectLoop() will now update logs synchronously. The setup.sh script will now include gstreamer and pkg-config. This should help fix opencv video-io format support. --- setup.sh | 3 ++- src/common.h | 2 +- src/logger.cpp | 34 ++++++++++++++-------------------- src/logger.h | 2 +- src/main.cpp | 10 ++++++---- src/mo_detect.cpp | 4 +--- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/setup.sh b/setup.sh index 66b042c..19e23af 100644 --- a/setup.sh +++ b/setup.sh @@ -1,7 +1,8 @@ #!/bin/sh apt update -y -apt install -y cmake g++ wget unzip git ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev +apt install -y pkg-config +apt install -y cmake g++ wget unzip git ffmpeg gstreamer1.0* libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev add-apt-repository -y ppa:ubuntu-toolchain-r/test apt update -y apt install -y gcc-10 gcc-10-base gcc-10-doc g++-10 diff --git a/src/common.h b/src/common.h index 17c297c..219c717 100644 --- a/src/common.h +++ b/src/common.h @@ -35,7 +35,7 @@ using namespace cv; using namespace std; using namespace std::filesystem; -#define APP_VER "1.5.t6" +#define APP_VER "1.5.t7" #define APP_NAME "Motion Watch" struct shared_t diff --git a/src/logger.cpp b/src/logger.cpp index 00a556b..1cab08b 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -39,9 +39,14 @@ string combine(const vector &log) return ret; } -void logLoop(shared_t *share) +void wrOutLogs(shared_t *share) { - string htmlText = "\n"; + auto recLogFilePath = cleanDir(share->outDir) + "/recording_log.html"; + auto detLogFilePath = cleanDir(share->outDir) + "/detection_log.html"; + string htmlText = "\n"; + + ofstream recFile(recLogFilePath.c_str()); + ofstream detFile(detLogFilePath.c_str()); htmlText += "\n"; htmlText += "\n"; @@ -50,23 +55,12 @@ void logLoop(shared_t *share) htmlText += "\n"; htmlText += "

\n"; - while (share->logRun && (share->retCode == 0)) - { - sleep(10); + recFile << htmlText << combine(share->recLogLines) << "

\n\n\n"; + detFile << htmlText << combine(share->detLogLines) << "

\n\n\n"; + + recFile.close(); + detFile.close(); - enforceMaxLogLines(share->recLogLines, share); - enforceMaxLogLines(share->detLogLines, share); - - auto recLogFilePath = cleanDir(share->outDir) + "/recording_log.html"; - auto detLogFilePath = cleanDir(share->outDir) + "/detection_log.html"; - - ofstream recFile(recLogFilePath.c_str()); - ofstream detFile(detLogFilePath.c_str()); - - recFile << htmlText << combine(share->recLogLines) << "

\n\n"; - detFile << htmlText << combine(share->detLogLines) << "

\n\n"; - - recFile.close(); - detFile.close(); - } + enforceMaxLogLines(share->recLogLines, share); + enforceMaxLogLines(share->detLogLines, share); } diff --git a/src/logger.h b/src/logger.h index d4be579..e70b937 100644 --- a/src/logger.h +++ b/src/logger.h @@ -17,7 +17,7 @@ void recLog(const string &line, shared_t *share); void detLog(const string &line, shared_t *share); -void logLoop(shared_t *share); +void wrOutLogs(shared_t *share); void enforceMaxLogLines(vector &log, shared_t *share); string combine(const vector &log); diff --git a/src/main.cpp b/src/main.cpp index 6c67a10..fb8bf75 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ void detectLoop(shared_t *share) { detLog("detectLoop() -- start", share); + wrOutLogs(share); vector bufFiles; @@ -55,6 +56,7 @@ void detectLoop(shared_t *share) while (!bufFiles.empty() && !share->recLoopWait); detLog("detectLoop() -- finished", share); + wrOutLogs(share); } void recLoop(shared_t *share) @@ -62,6 +64,7 @@ void recLoop(shared_t *share) while (rdConf(share)) { recLog("recLoop() -- start", share); + wrOutLogs(share); if (!fileExists("/tmp/mow-lock")) { @@ -96,6 +99,8 @@ void recLoop(shared_t *share) th2.join(); + wrOutLogs(share); + if (!share->skipCmd) { recLog("motion not detected by detect loop.", share); @@ -108,6 +113,7 @@ void recLoop(shared_t *share) } recLog("recLoop() -- finished", share); + wrOutLogs(share); } share->logRun = false; @@ -143,12 +149,8 @@ int main(int argc, char** argv) sharedRes.init = true; sharedRes.logRun = true; - thread th3(logLoop, &sharedRes); - recLoop(&sharedRes); - th3.join(); - return sharedRes.retCode; } diff --git a/src/mo_detect.cpp b/src/mo_detect.cpp index bbfe851..37df853 100644 --- a/src/mo_detect.cpp +++ b/src/mo_detect.cpp @@ -116,9 +116,7 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share) } else { - detLog("failed to open buff file: " + buffFile + " for reading.", share); - detLog("check formatting/permissions.", share); - detLog("also check if opencv was compiled with FFMPEG encoding enabled.", share); + detLog("failed to open buff file: " + buffFile + " for reading. check permissions and/or opencv's video-io support (gstreamer/ffmpeg).", share); } return mod;