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"
|
2024-05-07 15:06:36 +08:00
|
|
|
|
#include "SerialPortTool.h"
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include "TcpServer.h"
|
2024-05-07 15:06:36 +08:00
|
|
|
|
#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>
|
2024-05-11 15:40:07 +08:00
|
|
|
|
#include <stdlib.h>
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// Tcp服务器
|
2024-01-18 15:41:43 +08:00
|
|
|
|
TcpServer* server;
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 串口工具
|
|
|
|
|
SerialPortTool* serialPortTool;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// 数据库管理
|
|
|
|
|
DatabaseManager* db;
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 视频输出通道
|
2024-01-18 15:41:43 +08:00
|
|
|
|
LinkObject* vo;
|
|
|
|
|
LinkObject* vo1;
|
2024-01-25 09:57:08 +08:00
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 通道列表
|
|
|
|
|
QList<Channel*> channelList;
|
|
|
|
|
// 录制模式
|
|
|
|
|
Constant::RecordMode recordMode;
|
|
|
|
|
// 回放模式
|
|
|
|
|
Constant::PlaybackMode playbackMode;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
QString mainChannelProtocol;
|
|
|
|
|
QString secondaryChannelProtocol;
|
2024-03-04 16:22:40 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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-05-11 15:40:07 +08:00
|
|
|
|
// 初始化通道
|
2024-03-04 16:22:40 +08:00
|
|
|
|
for (int i = 0; i < list.count(); i++) {
|
|
|
|
|
Channel* chn = new Channel();
|
|
|
|
|
QVariantMap cfg = list.at(i).toMap();
|
|
|
|
|
chn->channelName = cfg["name"].toString();
|
2024-08-12 11:26:42 +08:00
|
|
|
|
if (chn->channelName == Constant::MainChannel) {
|
|
|
|
|
mainChannelProtocol = cfg["protocol"].toString();
|
|
|
|
|
} else if (chn->channelName == Constant::SecondaryChannel) {
|
|
|
|
|
secondaryChannelProtocol = cfg["protocol"].toString();
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
chn->init();
|
|
|
|
|
channelList.push_back(chn);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 开始录制
|
|
|
|
|
*/
|
|
|
|
|
void startRecord()
|
|
|
|
|
{
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 判断是否挂载了磁盘
|
|
|
|
|
QString info = Tool::writeCom(QString("df %1").arg(Constant::MountedPath));
|
|
|
|
|
if (!info.contains(Constant::MountedPath)) {
|
|
|
|
|
Log::error("there is no disk mounted");
|
2024-05-11 15:40:07 +08:00
|
|
|
|
serialPortTool->onLoopOn();
|
|
|
|
|
QThread::msleep(100);
|
2024-05-07 15:06:36 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-12 11:26:42 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 一路录制,只录制主通道
|
2024-03-04 16:22:40 +08:00
|
|
|
|
if (recordMode == Constant::OneChannelRecord) {
|
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
|
if (chn->channelName == Constant::MainChannel) {
|
|
|
|
|
chn->startRecord();
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// QThread::msleep(100);
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool->onRecordStart();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
QThread::msleep(100);
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// serialPortTool->onLoopOff();
|
2024-03-04 16:22:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 两路录制
|
|
|
|
|
else if (recordMode == Constant::TwoChannelRecord) {
|
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
|
chn->startRecord();
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool->onRecordStart();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
QThread::msleep(100);
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// serialPortTool->onLoopOff();
|
|
|
|
|
// QThread::msleep(100);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 无录制
|
|
|
|
|
else {
|
|
|
|
|
// 打开环路灯
|
|
|
|
|
serialPortTool->onLoopOn();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
QThread::msleep(100);
|
2024-05-07 15:06:36 +08:00
|
|
|
|
}
|
2024-03-04 16:22:40 +08:00
|
|
|
|
}
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-08-12 11:26:42 +08:00
|
|
|
|
void setChannelProtocol()
|
|
|
|
|
{
|
|
|
|
|
if (mainChannelProtocol == "HDMI") {
|
|
|
|
|
serialPortTool->onMainChannelHDMI();
|
|
|
|
|
} else if (mainChannelProtocol == "VGA") {
|
|
|
|
|
serialPortTool->onMainChannelVGA();
|
|
|
|
|
}
|
|
|
|
|
QThread::msleep(100);
|
|
|
|
|
if (secondaryChannelProtocol == "HDMI") {
|
|
|
|
|
serialPortTool->onSecondaryChannelHDMI();
|
|
|
|
|
} else if (secondaryChannelProtocol == "VGA") {
|
|
|
|
|
serialPortTool->onSecondaryChannelVGA();
|
|
|
|
|
}
|
|
|
|
|
QThread::msleep(100);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 15:41:43 +08:00
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 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之前初始化视频输出和linuxfb
|
|
|
|
|
// 否则不能显示qt的ui
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// HDMI-OUT0视频输出,只将ui输出在0口
|
2024-01-18 15:41:43 +08:00
|
|
|
|
vo = Link::create("OutputVo");
|
|
|
|
|
QVariantMap dataVo;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
dataVo["ui"] = true;
|
2024-01-18 15:41:43 +08:00
|
|
|
|
dataVo["type"] = "hdmi";
|
|
|
|
|
vo->start(dataVo);
|
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// HDMI-OUT1视频输出
|
2024-01-18 15:41:43 +08:00
|
|
|
|
vo1 = Link::create("OutputVo");
|
|
|
|
|
QVariantMap dataVo1;
|
|
|
|
|
dataVo1["ui"] = false;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
dataVo1["type"] = "bt1120";
|
2024-01-18 15:41:43 +08:00
|
|
|
|
vo1->start(dataVo1);
|
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* 后续可能需要进行修改**************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// HDMI-OUT1口特殊设置
|
2024-01-18 15:41:43 +08:00
|
|
|
|
static int lastNorm = 0;
|
|
|
|
|
int norm = 0;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
int ddr = 0;
|
|
|
|
|
// 获取到设置的输出分辨率
|
2024-01-18 15:41:43 +08:00
|
|
|
|
QString str = "1080P60";
|
|
|
|
|
if (str == "1080P60")
|
|
|
|
|
norm = 9;
|
|
|
|
|
else if (str == "1080P50")
|
|
|
|
|
norm = 10;
|
|
|
|
|
else if (str == "1080P30")
|
|
|
|
|
norm = 12;
|
|
|
|
|
else if (str == "720P60")
|
|
|
|
|
norm = 5;
|
|
|
|
|
else if (str == "720P50")
|
|
|
|
|
norm = 6;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
else if (str == "3840x2160_30") {
|
2024-01-18 15:41:43 +08:00
|
|
|
|
norm = 14;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
ddr = 1;
|
|
|
|
|
}
|
2024-01-18 15:41:43 +08:00
|
|
|
|
if (norm != lastNorm) {
|
|
|
|
|
lastNorm = norm;
|
|
|
|
|
QString cmd = "rmmod hi_lt8618sx_lp.ko";
|
|
|
|
|
system(cmd.toLatin1().data());
|
2024-08-12 11:26:42 +08:00
|
|
|
|
cmd = cmd.sprintf("insmod /ko/extdrv/hi_lt8618sx_lp.ko norm=%d USE_DDRCLK=%d", norm, ddr);
|
2024-01-18 15:41:43 +08:00
|
|
|
|
system(cmd.toLatin1().data());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
|
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
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 打开串口
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool = new SerialPortTool();
|
|
|
|
|
serialPortTool->open();
|
2024-03-04 16:22:40 +08:00
|
|
|
|
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// setChannelProtocol();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
serialPortTool->onPowerOn(); // 打开电源灯
|
|
|
|
|
QThread::msleep(100);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
|
|
|
|
|
// 开启Tcp服务
|
2024-01-25 09:57:08 +08:00
|
|
|
|
server = new TcpServer();
|
2024-05-07 15:06:36 +08:00
|
|
|
|
server->listen();
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// qt界面
|
|
|
|
|
Widget w;
|
|
|
|
|
w.show();
|
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 硬盘检测线程,检测硬盘容量
|
|
|
|
|
CheckStorageThread* thread = new CheckStorageThread();
|
2024-03-05 13:47:32 +08:00
|
|
|
|
thread->start();
|
2024-05-07 15:06:36 +08:00
|
|
|
|
QObject::connect(thread, SIGNAL(diskWillFull()), serialPortTool, SLOT(onDiskWillFull()));
|
|
|
|
|
QObject::connect(thread, SIGNAL(diskNotFull()), serialPortTool, SLOT(onDiskNotFull()));
|
2024-03-05 13:47:32 +08:00
|
|
|
|
Log::info("start storage check thread...");
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 开始录制
|
|
|
|
|
startRecord();
|
2024-01-18 15:41:43 +08:00
|
|
|
|
return a.exec();
|
|
|
|
|
}
|