JustMotion/src/common.h

137 lines
3.7 KiB
C
Raw Normal View History

#ifndef COMMON_H
#define COMMON_H
// This file is part of JustMotion.
// JustMotion is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// JustMotion is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
#define FUSE_USE_VERSION 31
#include <QCoreApplication>
#include <QProcess>
#include <QTextStream>
#include <QObject>
#include <QDir>
#include <QFile>
#include <QDateTime>
#include <QThread>
#include <QTimer>
#include <QStringList>
#include <QMutex>
#include <QRegularExpression>
#include <QFileSystemWatcher>
#include <QDebug>
#include <QElapsedTimer>
#include <QMutex>
#include <iostream>
#include <fuse3/fuse.h>
#include <fuse3/fuse_lowlevel.h>
#include <fuse3/fuse_common.h>
#include <errno.h>
#include <cstring>
#include <unistd.h>
using namespace std;
#define APP_VERSION "3.6.t10"
#define APP_NAME "JustMotion"
#define APP_TARGET "jmotion"
#define DATETIME_FMT "yyyyMMddhhmmss"
#define STRFTIME_FMT "%Y%m%d%H%M%S"
#define PREV_IMG "&prev&"
#define NEXT_IMG "&next&"
#define BLK_SIZE 262144
enum CmdExeType
{
MAIN_LOOP,
VID_LOOP
};
class ProcControl;
class Camera;
struct evt_t
v2.0.t1 Completely reformed the internal workings of the application code. I brought back multi-threaded functions so there is now 5 separate threads for different tasks. recLoop() - this function calls ffmpeg to begin recording footage from the defined camera and stores the footage in hls format. It is designed to keep running for as long as the application is running and if it does stop for whatever reason, it will attempt to auto re-start. upkeep() - this function does regular cleanup and enforcement of maxDays maxLogSize and maxEvents without the need to stop recording or detecting motion. detectMo() - this function reads directly from recLoop's hls output and list all footage that has motion in it. motion detection no longer has to wait for the clip to finish recording thanks to the use of .ts containers for the video clips. this makes the motion detection for less cpu intensive now that it will now operate at the camera's fps (slower). eventLoop() - this function reads the motion list from detectMo and copies the footage pointed out by the list to an events folder, also in hls format. schLoop() - this function runs an optional user defined external command every amount of seconds defined in sch_sec. this command temporary stops motion detection without actually terminating the thread. It will also not run the command at the scheduled time if motion was detected. Benefits to this reform: - far less cpu intensive operation - multi-threaded architecture for better asynchronous operation - it has support for live streaming now that hls is being used - a buff_dir is no longer necessary
2023-03-05 16:07:07 -05:00
{
QStringList vidList;
QString timeStamp;
QString imgPath;
float score;
bool inQue;
int queAge;
};
class file_t
{
public:
quint64 ino;
quint64 ctime;
quint64 mtime;
quint32 mode;
qint32 blks;
QByteArray bytes;
v2.0.t1 Completely reformed the internal workings of the application code. I brought back multi-threaded functions so there is now 5 separate threads for different tasks. recLoop() - this function calls ffmpeg to begin recording footage from the defined camera and stores the footage in hls format. It is designed to keep running for as long as the application is running and if it does stop for whatever reason, it will attempt to auto re-start. upkeep() - this function does regular cleanup and enforcement of maxDays maxLogSize and maxEvents without the need to stop recording or detecting motion. detectMo() - this function reads directly from recLoop's hls output and list all footage that has motion in it. motion detection no longer has to wait for the clip to finish recording thanks to the use of .ts containers for the video clips. this makes the motion detection for less cpu intensive now that it will now operate at the camera's fps (slower). eventLoop() - this function reads the motion list from detectMo and copies the footage pointed out by the list to an events folder, also in hls format. schLoop() - this function runs an optional user defined external command every amount of seconds defined in sch_sec. this command temporary stops motion detection without actually terminating the thread. It will also not run the command at the scheduled time if motion was detected. Benefits to this reform: - far less cpu intensive operation - multi-threaded architecture for better asynchronous operation - it has support for live streaming now that hls is being used - a buff_dir is no longer necessary
2023-03-05 16:07:07 -05:00
};
struct shared_t
{
QList<evt_t> recList;
QString rdMnt;
QString conf;
QString confPath;
QString recordUri;
QString buffPath;
QString varPath;
QString postCmd;
QString camName;
QString recPath;
QString outputType;
QString compCmd;
QString vidCodec;
QString audCodec;
QString streamExt;
QString recExt;
QString thumbExt;
QString recScale;
QString imgScale;
quint64 maxMemSize;
int liveSecs;
int recFps;
int evMaxSecs;
int postSecs;
int imgThresh;
int maxEvents;
int retCode;
};
QString buildThreadCount(int count);
QStringList lsFilesInDir(const QString &path, const QString &ext = QString());
QStringList lsDirsInDir(const QString &path);
QStringList listFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs, char dir);
QStringList backwardFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs);
QStringList forwardFacingFiles(const QString &path, const QString &ext, const QDateTime &stamp, int secs);
QStringList parseArgs(const QByteArray &data, int maxArgs, int *pos = nullptr);
bool rdConf(const QString &filePath, shared_t *share, bool reset = true);
bool mkPath(const QString &path);
void rdLine(const QString &param, const QString &line, QString *value);
void rdLine(const QString &param, const QString &line, int *value);
void rdLine(const QString &param, const QString &line, quint64 *value);
void rdLine(const QString &param, const QString &line, bool *value);
void enforceMaxEvents(shared_t *share);
void enforceMaxImages(shared_t *share);
void enforceMaxClips(shared_t *share);
void extCorrection(QString &ext);
#endif // COMMON_H