RecordControlApplication/Config.cpp

71 lines
1.6 KiB
C++
Raw Normal View History

2024-01-18 15:41:43 +08:00
#include "Config.h"
#include "Channel.h"
#include "Json.h"
#include <QDebug>
#include <QFileInfo>
#include <QList>
// input channels list
2024-01-18 15:41:43 +08:00
QList<Channel*> channelList;
Config::Config()
{
}
/**
* @brief load config when initialize
* @param path
*/
void Config::loadConfig(QString configPath)
2024-01-18 15:41:43 +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
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) {
chn->autoRecord = autoRecord;
2024-01-18 15:41:43 +08:00
}
channelList.push_back(chn);
}
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;
}