159 lines
4.3 KiB
C++
Executable File
159 lines
4.3 KiB
C++
Executable File
#include "Channel.h"
|
||
#include "CheckStorageThread.h"
|
||
#include "Constant.h"
|
||
#include "DatabaseManager.h"
|
||
#include "Json.h"
|
||
#include "Link.h"
|
||
#include "Log.h"
|
||
#include "SerialPortTool.h"
|
||
#include "TcpServer.h"
|
||
#include "Tool.h"
|
||
#include "Widget.h"
|
||
#include <QApplication>
|
||
#include <cstring>
|
||
#include <stdlib.h>
|
||
#include <unistd.h>
|
||
|
||
// Tcp服务器
|
||
TcpServer* server;
|
||
// 串口工具
|
||
SerialPortTool* serialPortTool;
|
||
// 数据库管理
|
||
DatabaseManager* db;
|
||
// 硬盘检测线程
|
||
CheckStorageThread* thread;
|
||
|
||
// 通道列表
|
||
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();
|
||
// 初始化通道
|
||
for (int i = 0; i < list.count(); i++) {
|
||
QVariantMap cfg = list.at(i).toMap();
|
||
QString channelName = cfg["name"].toString();
|
||
if (channelName.isEmpty()) {
|
||
return false;
|
||
}
|
||
QVariantMap output = cfg["output"].toMap();
|
||
Channel* chn = new Channel(channelName, output);
|
||
|
||
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;
|
||
}
|
||
|
||
// 一路录制,只录制主通道
|
||
if (recordMode == Constant::OneChannelRecord) {
|
||
for (Channel* chn : channelList) {
|
||
if (chn->channelName == Constant::MainChannel) {
|
||
chn->startRecord();
|
||
serialPortTool->onRecordStart();
|
||
QThread::msleep(100);
|
||
}
|
||
}
|
||
}
|
||
// 两路录制
|
||
else if (recordMode == Constant::TwoChannelRecord) {
|
||
for (Channel* chn : channelList) {
|
||
chn->startRecord();
|
||
serialPortTool->onRecordStart();
|
||
QThread::msleep(100);
|
||
}
|
||
}
|
||
}
|
||
|
||
int main(int argc, char* argv[])
|
||
{
|
||
// qDebug() << (R"(
|
||
// ____ _ _____
|
||
// / ___|| |__ __ _ _ __ | ___|__ _ __ __ _
|
||
// \___ \| '_ \ / _` | '_ \| |_ / _ \ '_ \ / _` |
|
||
// ___) | | | | (_| | | | | _| __/ | | | (_| |
|
||
// |____/|_| |_|\__,_|_| |_|_| \___|_| |_|\__, |
|
||
// |___/ )");
|
||
// std::atexit(resetLight);
|
||
// 初始化日志
|
||
Log::init();
|
||
|
||
// 初始化Link编码系统
|
||
if (!Link::init()) {
|
||
Log::error("Link init failed, exit");
|
||
return 0;
|
||
}
|
||
// 初始化配置文件, 需要在QApplication之后
|
||
if (!loadConfiguration(Constant::ConfigurationPath)) {
|
||
Log::error("load configuration failed, exit...");
|
||
return 0;
|
||
}
|
||
|
||
QApplication a(argc, argv);
|
||
|
||
// 初始化通道配置,需要在QApplication之后进行
|
||
for (const auto& chn : channelList) {
|
||
chn->init();
|
||
}
|
||
|
||
// 打开串口
|
||
serialPortTool = new SerialPortTool();
|
||
serialPortTool->open();
|
||
|
||
// 开启Tcp服务
|
||
// server = new TcpServer();
|
||
// server->listen();
|
||
|
||
// qt界面
|
||
Widget w;
|
||
w.show();
|
||
|
||
// 硬盘检测线程,检测硬盘容量
|
||
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...");
|
||
|
||
// 开始录制
|
||
startRecord();
|
||
return a.exec();
|
||
}
|