RecordControlApplication/main.cpp

159 lines
4.3 KiB
C++
Raw Permalink Normal View History

2024-03-04 16:22:40 +08:00
#include "Channel.h"
#include "CheckStorageThread.h"
#include "Constant.h"
2024-08-12 11:26:42 +08:00
#include "DatabaseManager.h"
2024-03-04 16:22:40 +08:00
#include "Json.h"
2024-01-18 15:41:43 +08:00
#include "Link.h"
2024-03-04 16:22:40 +08:00
#include "Log.h"
#include "SerialPortTool.h"
2024-01-18 15:41:43 +08:00
#include "TcpServer.h"
#include "Tool.h"
2024-01-18 15:41:43 +08:00
#include "Widget.h"
#include <QApplication>
2024-08-12 11:26:42 +08:00
#include <cstring>
#include <stdlib.h>
2024-01-18 15:41:43 +08:00
#include <unistd.h>
// Tcp服务器
TcpServer* server;
// 串口工具
SerialPortTool* serialPortTool;
2024-08-12 11:26:42 +08:00
// 数据库管理
DatabaseManager* db;
// 硬盘检测线程
CheckStorageThread* thread;
2024-03-04 16:22:40 +08:00
// 通道列表
QList<Channel*> channelList;
// 录制模式
Constant::RecordMode recordMode;
// 回放模式
Constant::PlaybackMode playbackMode;
/**
* @brief
*/
bool loadConfiguration(QString path)
{
QFileInfo fileInfo(path);
if (!fileInfo.exists()) {
Log::critical("config.json does not exist, exit");
return false;
}
QVariantMap config = Json::loadFile(path).toMap();
recordMode = Constant::RecordMode(config["recordMode"].toInt());
playbackMode = Constant::PlaybackMode(config["playbackMode"].toInt());
QVariantList list = config["interface"].toList();
// 初始化通道
2024-03-04 16:22:40 +08:00
for (int i = 0; i < list.count(); i++) {
QVariantMap cfg = list.at(i).toMap();
QString channelName = cfg["name"].toString();
if (channelName.isEmpty()) {
return false;
2024-08-12 11:26:42 +08:00
}
QVariantMap output = cfg["output"].toMap();
Channel* chn = new Channel(channelName, output);
2024-03-04 16:22:40 +08:00
QVariantMap encV = cfg["encV"].toMap();
chn->videoEncoderParams = encV;
QVariantMap encA = cfg["encA"].toMap();
chn->audioEncoderParams = encA;
chn->pushCode = cfg["pushCode"].toString();
channelList.push_back(chn);
}
return true;
}
/**
* @brief
*/
void startRecord()
{
// 判断是否挂载了磁盘
QString info = Tool::writeCom(QString("df %1").arg(Constant::MountedPath));
if (!info.contains(Constant::MountedPath)) {
Log::error("there is no disk mounted");
serialPortTool->onLoopOn();
QThread::msleep(100);
return;
}
// 一路录制,只录制主通道
2024-03-04 16:22:40 +08:00
if (recordMode == Constant::OneChannelRecord) {
for (Channel* chn : channelList) {
if (chn->channelName == Constant::MainChannel) {
chn->startRecord();
serialPortTool->onRecordStart();
QThread::msleep(100);
2024-03-04 16:22:40 +08:00
}
}
}
// 两路录制
else if (recordMode == Constant::TwoChannelRecord) {
for (Channel* chn : channelList) {
chn->startRecord();
serialPortTool->onRecordStart();
QThread::msleep(100);
2024-03-04 16:22:40 +08:00
}
}
2024-08-12 11:26:42 +08:00
}
2024-01-18 15:41:43 +08:00
int main(int argc, char* argv[])
{
// qDebug() << (R"(
// ____ _ _____
// / ___|| |__ __ _ _ __ | ___|__ _ __ __ _
// \___ \| '_ \ / _` | '_ \| |_ / _ \ '_ \ / _` |
// ___) | | | | (_| | | | | _| __/ | | | (_| |
// |____/|_| |_|\__,_|_| |_|_| \___|_| |_|\__, |
// |___/ )");
// std::atexit(resetLight);
2024-03-04 16:22:40 +08:00
// 初始化日志
Log::init();
// 初始化Link编码系统
2024-01-18 15:41:43 +08:00
if (!Link::init()) {
2024-03-04 16:22:40 +08:00
Log::error("Link init failed, exit");
2024-01-18 15:41:43 +08:00
return 0;
}
2024-03-04 16:22:40 +08:00
// 初始化配置文件, 需要在QApplication之后
if (!loadConfiguration(Constant::ConfigurationPath)) {
Log::error("load configuration failed, exit...");
return 0;
}
2024-01-18 15:41:43 +08:00
QApplication a(argc, argv);
// 初始化通道配置需要在QApplication之后进行
for (const auto& chn : channelList) {
chn->init();
}
// 打开串口
serialPortTool = new SerialPortTool();
serialPortTool->open();
2024-03-04 16:22:40 +08:00
// 开启Tcp服务
// server = new TcpServer();
// server->listen();
2024-01-18 15:41:43 +08:00
// qt界面
Widget w;
w.show();
2024-03-04 16:22:40 +08:00
// 硬盘检测线程,检测硬盘容量
thread = new CheckStorageThread();
thread->start();
QObject::connect(thread, SIGNAL(diskWillFull()), serialPortTool, SLOT(onDiskWillFull()), Qt::QueuedConnection);
QObject::connect(thread, SIGNAL(diskNotFull()), serialPortTool, SLOT(onDiskNotFull()), Qt::QueuedConnection);
Log::info("start storage check thread...");
2024-01-18 15:41:43 +08:00
// 开始录制
startRecord();
2024-01-18 15:41:43 +08:00
return a.exec();
}