From 71fc5b0bc248c8645039299e7f80df163e8b8294 Mon Sep 17 00:00:00 2001 From: Zii Date: Tue, 13 Jun 2023 20:58:45 -0400 Subject: [PATCH] v3.0.t18 -ffmpeg still stalls even with tcp timeout parameters in place. added self end -t option to match the heart beat of RecLoop. doing this auto re-fresh ffmpeg every 30mins and should prevent stall. for some reason ffmpeg just can't run long term without stalling. --- src/camera.cpp | 59 ++++++++++++++++---------------------------------- src/camera.h | 3 +-- src/common.h | 2 +- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index e6995d1..2399cd2 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -107,8 +107,9 @@ bool Loop::exec() RecLoop::RecLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop(sharedRes, thr, parent) { - recProc = 0; - imgProc = 0; + recProc = 0; + imgProc = 0; + heartBeat = 1800; } void RecLoop::init() @@ -117,8 +118,8 @@ void RecLoop::init() imgProc = new QProcess(this); connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &RecLoop::term); - - updateCmd(); + connect(recProc, &QProcess::readyReadStandardError, this, &RecLoop::rdProcErr); + connect(imgProc, &QProcess::readyReadStandardError, this, &RecLoop::rdProcErr); Loop::init(); } @@ -141,6 +142,7 @@ void RecLoop::updateCmd() recArgs << "-hls_flags" << "append_list"; recArgs << "-rtsp_transport" << "tcp"; recArgs << "-stimeout" << "3000"; + recArgs << "-t" << QString::number(heartBeat); recArgs << "stream.m3u8"; imgArgs << "-hide_banner"; @@ -150,6 +152,7 @@ void RecLoop::updateCmd() imgArgs << "-vf" << "fps=1,scale=320:240"; imgArgs << "-rtsp_transport" << "tcp"; imgArgs << "-stimeout" << "3000"; + imgArgs << "-t" << QString::number(heartBeat); imgArgs << "img/" + QString(STRFTIME_FMT) + ".bmp"; recProc->setProgram("ffmpeg"); @@ -160,8 +163,12 @@ void RecLoop::updateCmd() recLog("rec_args: " + recArgs.join(" "), shared); recLog("img_args: " + imgArgs.join(" "), shared); +} - curUrl = shared->recordUrl; +void RecLoop::rdProcErr() +{ + procError("img", imgProc); + procError("rec", recProc); } void RecLoop::term() @@ -173,17 +180,9 @@ void RecLoop::term() imgProc->waitForFinished(); } -void RecLoop::reset() -{ - recLog("--rec_and_img_cmds_resetting--", shared); - - term(); - updateCmd(); -} - void RecLoop::procError(const QString &desc, QProcess *proc) { - if (proc->isOpen() && proc->state() == QProcess::NotRunning) + if (proc->isOpen() && (proc->state() != QProcess::Running)) { auto errBlob = QString(proc->readAllStandardError()); auto errLines = errBlob.split('\n'); @@ -198,37 +197,17 @@ void RecLoop::procError(const QString &desc, QProcess *proc) } } -void RecLoop::startProc(const QString &desc, QProcess *proc) -{ - if (proc->state() == QProcess::NotRunning) - { - proc->start(); - - if (proc->waitForStarted()) - { - recLog(desc + "_cmd_start: ok", shared); - } - else - { - recLog(desc + "_cmd_start: fail", shared); - procError(desc, proc); - } - } -} - bool RecLoop::exec() { - procError("img", imgProc); - procError("rec", recProc); - - if (curUrl != shared->recordUrl) + if ((imgProc->state() == QProcess::Running) || (recProc->state() == QProcess::Running)) { - recLog("a change in the recording URL was detected.", shared); - reset(); + term(); } - startProc("img", imgProc); - startProc("rec", recProc); + updateCmd(); + + imgProc->start(); + recProc->start(); return Loop::exec(); } diff --git a/src/camera.h b/src/camera.h index fdef187..18f66bf 100644 --- a/src/camera.h +++ b/src/camera.h @@ -68,14 +68,13 @@ private: QString curUrl; void updateCmd(); - void reset(); - void startProc(const QString &desc, QProcess *proc); void procError(const QString &desc, QProcess *proc); private slots: void init(); void term(); + void rdProcErr(); public: diff --git a/src/common.h b/src/common.h index c828b72..888a94d 100644 --- a/src/common.h +++ b/src/common.h @@ -29,7 +29,7 @@ using namespace std; -#define APP_VER "3.0.t17" +#define APP_VER "3.0.t18" #define APP_NAME "Motion Watch" #define APP_BIN "mow" #define REC_LOG_NAME "rec_log_lines.html"