-fixed all loop structors used throughout the app. they were
 running too fast.

-added more log lines to aid with debug.
This commit is contained in:
Maurice ONeal 2023-05-21 09:34:57 -04:00
parent 496bac7d7e
commit f850ec6a46
7 changed files with 84 additions and 87 deletions

View File

@ -1,4 +1,5 @@
#!/bin/sh
apt install apache2
if [ ! -d "/opt/mow" ]; then
mkdir /opt/mow
fi

View File

@ -1,4 +1,4 @@
#!/bin/sh
apt update -y
apt install -y pkg-config cmake make g++ wget unzip git
apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libgstreamer1.0-dev x264 libx264-dev libilmbase-dev libopencv-dev qt6-base-dev qtchooser qmake6 qt6-base-dev-tools qt6-multimedia-dev apache2
apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libgstreamer1.0-dev x264 libx264-dev libilmbase-dev libopencv-dev qt6-base-dev qtchooser qmake6 qt6-base-dev-tools qt6-multimedia-dev libxkbcommon-dev

View File

@ -36,18 +36,16 @@ Camera::Camera(QObject *parent) : QObject(parent)
int Camera::start(const QStringList &args)
{
auto ret = false;
shared.conf = getParam("-c", args);
if (rdConf(&shared))
{
QDir("live").removeRecursively();
auto thr1 = new QThread(QCoreApplication::instance());
auto thr2 = new QThread(QCoreApplication::instance());
auto thr3 = new QThread(QCoreApplication::instance());
auto thr4 = new QThread(QCoreApplication::instance());
auto thr1 = new QThread(nullptr);
auto thr2 = new QThread(nullptr);
auto thr3 = new QThread(nullptr);
auto thr4 = new QThread(nullptr);
new RecLoop(&shared, thr1, this);
new Upkeep(&shared, thr2, this);
@ -67,32 +65,29 @@ Loop::Loop(shared_t *sharedRes, QThread *thr, QObject *parent) : QObject(0)
{
shared = sharedRes;
heartBeat = 10;
loopTimer = new QTimer(nullptr);
connect(this, &Loop::loopSig, this, &Loop::loopSlot);
connect(thr, &QThread::started, this, &Loop::init);
connect(parent, &QObject::destroyed, this, &Loop::deleteLater);
connect(parent, &QObject::destroyed, thr, &QThread::terminate);
loopTimer->setSingleShot(false);
connect(thr, &QThread::started, this, &Loop::init);
connect(parent, &QObject::destroyed, this, &Loop::deleteLater);
connect(parent, &QObject::destroyed, thr, &QThread::terminate);
connect(parent, &QObject::destroyed, loopTimer, &QTimer::deleteLater);
connect(loopTimer, &QTimer::timeout, this, &Loop::loopSlot);
moveToThread(thr);
}
void Loop::init()
{
emit loopSig();
loopTimer->start(heartBeat * 1000);
}
void Loop::loopSlot()
{
auto ret = exec();
if (heartBeat != 0)
if (!exec())
{
thread()->sleep(heartBeat);
}
if (ret)
{
emit loopSig();
loopTimer->stop(); QCoreApplication::exit(shared->retCode);
}
}
@ -156,6 +151,8 @@ bool RecLoop::exec()
auto hashLogLine = "stream_hash--prev:" + QString(streamMD5.toHex()) + "--new:" + QString(md5.toHex());
streamMD5 = md5;
recLog(hashLogLine, shared);
if (proc.state() == QProcess::NotRunning)
@ -316,7 +313,7 @@ bool EventLoop::wrOutVod(const evt_t &event)
DetectLoop::DetectLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop(sharedRes, thr, parent)
{
heartBeat = 0;
heartBeat = 1;
evId = 0;
pcId = 0;
player = new QMediaPlayer(this);
@ -332,6 +329,8 @@ void DetectLoop::init()
thread()->sleep(1);
resetTimers();
Loop::init();
}
void DetectLoop::resetTimers()
@ -339,8 +338,8 @@ void DetectLoop::resetTimers()
if (evId != 0) killTimer(evId);
if (pcId != 0) killTimer(pcId);
evId = startTimer(shared->evMaxSecs);
pcId = startTimer(shared->postSecs);
evId = startTimer(shared->evMaxSecs * 1000);
pcId = startTimer(shared->postSecs * 1000);
}
void DetectLoop::timerEvent(QTimerEvent *event)
@ -389,83 +388,82 @@ void DetectLoop::timerEvent(QTimerEvent *event)
}
}
void DetectLoop::resetDetect()
{
if (player->playbackState() != QMediaPlayer::PlayingState)
{
frameAnalyzer->stop();
exec();
}
}
void DetectLoop::playError(QMediaPlayer::Error error, const QString &errorString)
{
Q_UNUSED(error)
detLog("err: media player error - " + errorString, shared);
resetDetect();
}
void DetectLoop::playStateChanged(QMediaPlayer::PlaybackState newState)
{
Q_UNUSED(newState)
resetDetect();
if (newState == QMediaPlayer::PlayingState)
{
detLog("detection playback started.", shared);
}
else if (newState == QMediaPlayer::StoppedState)
{
detLog("detection playback stopped.", shared);
}
}
bool DetectLoop::exec()
{
QFile fileIn("stream.m3u8");
QString tsPath;
if (player->playbackState() != QMediaPlayer::PlayingState)
{
QFile fileIn("stream.m3u8");
QString tsPath;
if (!fileIn.open(QFile::ReadOnly))
{
detLog("err: failed to open the stream hls file for reading. reason: " + fileIn.errorString(), shared);
}
else if (fileIn.size() < 50)
{
detLog("the stream hls list is not big enough yet. waiting for more clips.", shared);
}
else if (!fileIn.seek(fileIn.size() - 50))
{
detLog("err: failed to seek to 'near end' of stream file. reason: " + fileIn.errorString(), shared);
}
else
{
QString line;
do
if (!fileIn.open(QFile::ReadOnly))
{
line = QString::fromUtf8(fileIn.readLine());
detLog("err: failed to open the stream hls file for reading. reason: " + fileIn.errorString(), shared);
}
else if (fileIn.size() < 50)
{
detLog("the stream hls list is not big enough yet. waiting for more clips.", shared);
}
else if (!fileIn.seek(fileIn.size() - 50))
{
detLog("err: failed to seek to 'near end' of stream file. reason: " + fileIn.errorString(), shared);
}
else
{
QString line;
if (line.startsWith("live/"))
do
{
tsPath = line;
}
line = QString::fromUtf8(fileIn.readLine());
} while(!line.isEmpty());
}
if (line.startsWith("live/"))
{
tsPath = line;
}
if (tsPath.isEmpty())
{
detLog("wrn: didn't find the latest hls clip. previous failure? waiting 5secs.", shared);
} while(!line.isEmpty());
}
thread()->sleep(5);
}
else if (prevTs == tsPath)
{
detLog("wrn: the lastest hls clip is the same as the previous clip. is the recording loop running? waiting 5secs.", shared);
if (tsPath.isEmpty())
{
detLog("wrn: didn't find the latest hls clip. previous failure? waiting 5secs.", shared);
thread()->sleep(5);
}
else
{
prevTs = tsPath;
thread()->sleep(5);
}
else if (prevTs == tsPath)
{
detLog("wrn: the lastest hls clip is the same as the previous clip. is the recording loop running? waiting 5secs.", shared);
player->setSource(QUrl::fromLocalFile(tsPath));
frameAnalyzer->play(tsPath);
player->play();
thread()->sleep(5);
}
else
{
detLog("stream_clip: " + tsPath, shared);
prevTs = tsPath;
player->setSource(QUrl::fromLocalFile(tsPath));
frameAnalyzer->play(tsPath);
player->play();
}
}
return Loop::exec();

View File

@ -40,6 +40,7 @@ class Loop : public QObject
protected:
shared_t *shared;
QTimer *loopTimer;
int heartBeat;
protected slots:
@ -50,10 +51,6 @@ private slots:
void loopSlot();
signals:
void loopSig();
public:
explicit Loop(shared_t *shared, QThread *thr, QObject *parent = nullptr);

View File

@ -27,6 +27,7 @@
#include <QVideoSink>
#include <QVideoFrame>
#include <QImage>
#include <QTimer>
#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/videoio.hpp>
@ -35,7 +36,7 @@
using namespace cv;
using namespace std;
#define APP_VER "3.0.t4"
#define APP_VER "3.0.t5"
#define APP_NAME "Motion Watch"
#define APP_BIN "mow"
#define REC_LOG_NAME "rec_log_lines.html"

View File

@ -20,8 +20,6 @@ int main(int argc, char** argv)
QCoreApplication::setApplicationName(APP_NAME);
QCoreApplication::setApplicationVersion(APP_VER);
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_DEBUG);
auto args = QCoreApplication::arguments();
auto ret = 0;

View File

@ -41,9 +41,11 @@ void MoDetect::newFrame()
}
else
{
gap = 0;
auto nextImg = videoFrame().toImage();
auto nextImgGray = nextImg.convertToFormat(QImage::Format_Grayscale8);
auto score = 0;
auto score = 0;
if (diff(baseImg, nextImgGray, &score))
{