60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
|
#include "Config.h"
|
||
|
#include "Channel.h"
|
||
|
#include "Json.h"
|
||
|
#include <QDebug>
|
||
|
#include <QFileInfo>
|
||
|
#include <QList>
|
||
|
|
||
|
QList<Channel*> channelList;
|
||
|
|
||
|
Config::Config()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void Config::loadConfig(QString path)
|
||
|
{
|
||
|
QFileInfo fileInfo(path);
|
||
|
if (!fileInfo.exists()) {
|
||
|
qDebug() << "config.json does not exist, exit";
|
||
|
exit(0);
|
||
|
}
|
||
|
// read the configuration
|
||
|
QVariantMap config = Json::loadFile(path).toMap();
|
||
|
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->startRecord();
|
||
|
}
|
||
|
channelList.push_back(chn);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @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;
|
||
|
}
|