-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.
This commit is contained in:
Zii 2023-06-13 20:58:45 -04:00
parent a493c7da5d
commit 71fc5b0bc2
3 changed files with 21 additions and 43 deletions

View File

@ -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();
}

View File

@ -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:

View File

@ -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"