#include "Config.h" #include "Channel.h" #include "Json.h" #include #include #include // input channels list QList channelList; Config::Config() { } /** * @brief load config when initialize * @param path */ void Config::loadConfig(QString configPath) { QFileInfo fileInfo(configPath); if (!fileInfo.exists()) { qDebug() << "config.json does not exist, exit"; exit(0); } // read the configuration QVariantMap config = Json::loadFile(configPath).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->autoRecord = autoRecord; } channelList.push_back(chn); } for (Channel* chn : channelList) { if (chn->autoRecord) { chn->startRecord(); } } } /** * @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; }