2022-09-22 20:57:46 -04:00
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
|
|
|
// This file is part of Motion Watch.
|
|
|
|
|
|
|
|
// Motion Watch 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.
|
|
|
|
|
|
|
|
// Motion Watch 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.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2023-03-05 16:07:07 -05:00
|
|
|
#include <chrono>
|
2022-09-22 20:57:46 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <vector>
|
2023-02-18 21:20:24 -05:00
|
|
|
#include <thread>
|
2022-09-22 20:57:46 -04:00
|
|
|
#include <filesystem>
|
2022-09-29 11:37:10 -04:00
|
|
|
#include <mutex>
|
2022-10-02 09:01:38 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2023-03-12 13:22:10 -04:00
|
|
|
#include <map>
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
#include <opencv4/opencv2/opencv.hpp>
|
|
|
|
#include <opencv4/opencv2/videoio.hpp>
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
using namespace std::filesystem;
|
2023-03-05 16:07:07 -05:00
|
|
|
using namespace std::chrono;
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-03-12 13:22:10 -04:00
|
|
|
#define APP_VER "2.0.t8"
|
2023-03-10 19:05:54 -05:00
|
|
|
#define APP_NAME "Motion Watch"
|
|
|
|
#define REC_LOG_NAME "rec_log_lines.html"
|
|
|
|
#define DET_LOG_NAME "det_log_lines.html"
|
|
|
|
#define UPK_LOG_NAME "upk_log_lines.html"
|
2022-09-22 20:57:46 -04:00
|
|
|
|
2023-03-05 16:07:07 -05:00
|
|
|
struct pls_t
|
|
|
|
{
|
2023-03-12 13:22:10 -04:00
|
|
|
string evName;
|
|
|
|
string dstPath;
|
|
|
|
vector<string> srcPaths;
|
|
|
|
vector<string> dstPaths;
|
|
|
|
vector<string> extINFs;
|
|
|
|
uint64_t createTime;
|
|
|
|
Mat thumbnail;
|
2023-03-05 16:07:07 -05:00
|
|
|
};
|
|
|
|
|
2022-09-22 20:57:46 -04:00
|
|
|
struct shared_t
|
|
|
|
{
|
2023-03-12 13:22:10 -04:00
|
|
|
map<string, pls_t> recList;
|
|
|
|
string conf;
|
|
|
|
string recLog;
|
|
|
|
string detLog;
|
|
|
|
string upkLog;
|
|
|
|
string recordUrl;
|
|
|
|
string outDir;
|
|
|
|
string postCmd;
|
|
|
|
string camName;
|
|
|
|
string webBg;
|
|
|
|
string webTxt;
|
|
|
|
string webFont;
|
|
|
|
string webRoot;
|
|
|
|
bool skipCmd;
|
|
|
|
bool postCmdRunning;
|
|
|
|
int schSec;
|
|
|
|
int frameGap;
|
|
|
|
int pixThresh;
|
|
|
|
int imgThresh;
|
|
|
|
int maxDays;
|
|
|
|
int maxEvents;
|
|
|
|
int maxLogSize;
|
|
|
|
int retCode;
|
2023-02-07 23:19:41 -05:00
|
|
|
};
|
|
|
|
|
2023-03-05 16:07:07 -05:00
|
|
|
string genVidNameFromLive(const string &tsPath);
|
|
|
|
string genEventPath(const string &tsPath);
|
2022-09-22 20:57:46 -04:00
|
|
|
string genDstFile(const string &dirOut, const char *fmt, const string &ext);
|
|
|
|
string genTimeStr(const char *fmt);
|
|
|
|
string cleanDir(const string &path);
|
2023-02-12 15:04:32 -05:00
|
|
|
string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs);
|
2022-09-22 20:57:46 -04:00
|
|
|
string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
|
|
|
|
bool createDir(const string &dir);
|
|
|
|
bool createDirTree(const string &full_path);
|
|
|
|
void rdLine(const string ¶m, const string &line, string *value);
|
|
|
|
void rdLine(const string ¶m, const string &line, int *value);
|
2023-03-05 16:07:07 -05:00
|
|
|
void cleanupEmptyDirs(const string &path);
|
|
|
|
void cleanupStream(const string &plsPath);
|
|
|
|
void enforceMaxEvents(shared_t *share);
|
2022-09-22 20:57:46 -04:00
|
|
|
bool rdConf(shared_t *share);
|
2022-12-04 15:13:39 -05:00
|
|
|
vector<string> lsFilesInDir(const string &path, const string &ext = string());
|
|
|
|
vector<string> lsDirsInDir(const string &path);
|
2023-03-05 16:07:07 -05:00
|
|
|
uint64_t genEpoch();
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
#endif // COMMON_H
|