diff --git a/README.md b/README.md index 7e90f17..f8bfb56 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ web_root = /var/www/html # warning: this will overwrite any existing index.html files so be sure # to choose a directory that doesn't have an existing website. # +buffer_path = /tmp +# this is the work directory the app will use to store live footage and +# image frames. it's recommended to use a ram disk for this since there +# will be large amounts of io occuring here. +# cam_name = cam-1 # this is the optional camera name parameter to identify the camera. this # name will also be used to as the base directory in web_root. if not diff --git a/install.sh b/install.sh index f83e5aa..f7eb291 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,9 @@ #!/bin/sh -apt install apache2 if [ ! -d "/opt/mow" ]; then mkdir /opt/mow fi cp ./.build-mow/mow /opt/mow/bin printf "#!/bin/sh\n" > /opt/mow/run -printf "export OPENCV_LOG_LEVEL=DEBUG\n" >> /opt/mow/run -printf "export OPENCV_VIDEOIO_DEBUG=1\n" >> /opt/mow/run printf "/opt/mow/bin \$1 \$2 \$3\n" >> /opt/mow/run chmod +x /opt/mow/run chmod +x /opt/mow/bin diff --git a/src/camera.cpp b/src/camera.cpp index 173e141..b555fa8 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -25,6 +25,7 @@ Camera::Camera(QObject *parent) : QObject(parent) shared.skipCmd = false; shared.postSecs = 60; shared.evMaxSecs = 30; + shared.buffPath = QDir::tempPath(); shared.webRoot = "/var/www/html"; shared.webBg = "#485564"; shared.webTxt = "#dee5ee"; @@ -37,14 +38,6 @@ int Camera::start(const QStringList &args) if (rdConf(&shared)) { - QDir("live").removeRecursively(); - QDir("img").removeRecursively(); - - QDir().mkdir("live"); - QDir().mkdir("events"); - QDir().mkdir("logs"); - QDir().mkdir("img"); - auto thr1 = new QThread(nullptr); auto thr2 = new QThread(nullptr); auto thr3 = new QThread(nullptr); @@ -215,11 +208,6 @@ Upkeep::Upkeep(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop(shared bool Upkeep::exec() { - QDir().mkdir("live"); - QDir().mkdir("events"); - QDir().mkdir("logs"); - QDir().mkdir("img"); - enforceMaxLogSize(QString("logs/") + REC_LOG_NAME, shared); enforceMaxLogSize(QString("logs/") + DET_LOG_NAME, shared); diff --git a/src/common.cpp b/src/common.cpp index c57b72f..b4aaa1b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -167,6 +167,21 @@ void rdLine(const QString ¶m, const QString &line, int *value) } } +void touch(const QString &path) +{ + if (!QFile::exists(path)) + { + QFile file(path); + + if (file.open(QFile::WriteOnly)) + { + file.write(""); + } + + file.close(); + } +} + bool rdConf(const QString &filePath, shared_t *share) { QFile varFile(filePath); @@ -189,6 +204,7 @@ bool rdConf(const QString &filePath, shared_t *share) { rdLine("cam_name = ", line, &share->camName); rdLine("recording_stream = ", line, &share->recordUrl); + rdLine("buffer_path = ", line, &share->buffPath); rdLine("web_root = ", line, &share->webRoot); rdLine("web_text = ", line, &share->webTxt); rdLine("web_bg = ", line, &share->webBg); @@ -217,10 +233,29 @@ bool rdConf(shared_t *share) } share->outDir = QDir().cleanPath(share->webRoot) + "/" + share->camName; + share->tmpDir = share->buffPath + "/" + APP_BIN + "/" + share->camName; QDir().mkpath(share->outDir); + QDir().mkpath(share->tmpDir); - if (!QDir::setCurrent(share->outDir)) + QDir().mkpath(share->outDir + "/events"); + QDir().mkpath(share->tmpDir + "/live"); + QDir().mkpath(share->tmpDir + "/logs"); + QDir().mkpath(share->tmpDir + "/img"); + + touch(share->tmpDir + "/index.html"); + touch(share->tmpDir + "/stream.html"); + touch(share->tmpDir + "/stream.m3u8"); + + QFile::link(share->tmpDir + "/live", share->outDir + "/live"); + QFile::link(share->tmpDir + "/logs", share->outDir + "/logs"); + QFile::link(share->tmpDir + "/img", share->outDir + "/img"); + QFile::link(share->tmpDir + "/index.html", share->outDir + "/index.html"); + QFile::link(share->tmpDir + "/stream.html", share->outDir + "/stream.html"); + QFile::link(share->tmpDir + "/stream.m3u8", share->outDir + "/stream.m3u8"); + QFile::link(share->outDir + "/events", share->tmpDir + "/events"); + + if (!QDir::setCurrent(share->tmpDir)) { QTextStream(stderr) << "err: failed to change/create the current working directory to camera folder: '" << share->outDir << "' does it exists?" << Qt::endl; diff --git a/src/common.h b/src/common.h index 1e4f78d..da44e3f 100644 --- a/src/common.h +++ b/src/common.h @@ -29,7 +29,7 @@ using namespace std; -#define APP_VER "3.1.t1" +#define APP_VER "3.1.t2" #define APP_NAME "Motion Watch" #define APP_BIN "mow" #define REC_LOG_NAME "rec_log_lines.html" @@ -58,6 +58,8 @@ struct shared_t QString detLog; QString recordUrl; QString outDir; + QString tmpDir; + QString buffPath; QString postCmd; QString camName; QString webBg; @@ -81,6 +83,7 @@ QStringList backwardFacingFiles(const QString &path, const QString &ext, const Q QStringList forwardFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs); bool rdConf(const QString &filePath, shared_t *share); bool rdConf(shared_t *share); +void touch(const QString &path); void rdLine(const QString ¶m, const QString &line, QString *value); void rdLine(const QString ¶m, const QString &line, int *value); void enforceMaxEvents(shared_t *share);