2024-01-18 15:41:43 +08:00
|
|
|
#include "Config.h"
|
|
|
|
#include "Channel.h"
|
|
|
|
#include "Json.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QList>
|
|
|
|
|
2024-01-25 09:57:08 +08:00
|
|
|
// input channels list
|
2024-01-18 15:41:43 +08:00
|
|
|
QList<Channel*> channelList;
|
|
|
|
|
|
|
|
Config::Config()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-25 09:57:08 +08:00
|
|
|
/**
|
|
|
|
* @brief load config when initialize
|
|
|
|
* @param path
|
|
|
|
*/
|
|
|
|
void Config::loadConfig(QString configPath)
|
2024-01-18 15:41:43 +08:00
|
|
|
{
|
2024-01-25 09:57:08 +08:00
|
|
|
QFileInfo fileInfo(configPath);
|
2024-01-18 15:41:43 +08:00
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
qDebug() << "config.json does not exist, exit";
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
// read the configuration
|
2024-01-25 09:57:08 +08:00
|
|
|
QVariantMap config = Json::loadFile(configPath).toMap();
|
2024-01-18 15:41:43 +08:00
|
|
|
QVariantList list = config["interface"].toList();
|
|
|
|
for (int i = 0; i < list.count(); i++) {
|
|
|
|
Channel* chn = new Channel();
|
|
|
|
QVariantMap cfg = list.at(i).toMap();
|
|
|
|
chn->channelName = cfg["name"].toString();
|
|
|
|
|
|
|
|
QVariantMap encV = cfg["encV"].toMap();
|
|
|
|
chn->videoEncoderParams = encV;
|
|
|
|
|
|
|
|
QVariantMap encA = cfg["encA"].toMap();
|
|
|
|
chn->audioEncoderParams = encA;
|
|
|
|
|
|
|
|
chn->pushCode = cfg["pushCode"].toString();
|
|
|
|
chn->init();
|
|
|
|
|
|
|
|
bool autoRecord = cfg["autoRecord"].toBool();
|
|
|
|
if (autoRecord) {
|
2024-01-25 09:57:08 +08:00
|
|
|
chn->autoRecord = autoRecord;
|
2024-01-18 15:41:43 +08:00
|
|
|
}
|
|
|
|
channelList.push_back(chn);
|
|
|
|
}
|
2024-01-25 09:57:08 +08:00
|
|
|
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
if (chn->autoRecord) {
|
|
|
|
chn->startRecord();
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 15:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief find the channel from channel list by channel name
|
|
|
|
* @param name
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
Channel* Config::findChannelByName(QString name)
|
|
|
|
{
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
if (chn->channelName == name) {
|
|
|
|
return chn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|