加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ChannelNet.cpp 5.48 KB
一键复制 编辑 原始数据 按行查看 历史
#include "ChannelNet.h"
#include <QFile>
#include <unistd.h>
ChannelNet::ChannelNet(QObject *parent) :
Channel(parent)
{
video=Link::create("DecodeV");
net=Link::create("InputNet");
audio=Link::create("Resample");
decA=Link::create("DecodeA");
ev=Link::create("EncodeV");
encV2=Link::create("EncodeV");
ea=Link::create("EncodeA");
queue=Link::create("Queue");
encV=net;
encA=net;
}
void ChannelNet::init(QVariantMap)
{
video->linkV(ev);
video->linkV(encV2);
gain->linkA(ea);
decA->start();
audio->start();
queue->linkV(video);
queue->linkA(decA);
net->linkV(video);
net->linkA(decA)->linkA(audio);
Channel::init();
}
void ChannelNet::updateConfig(QVariantMap cfg)
{
if(cfg["net"].toMap()["decodeV"].toBool())
{
video->start();
if(encV==net)
{
ev->invoke("reset");
encV2->invoke("reset");
snap->invoke("reset");
}
encV=ev;
foreach(QString key,muxMap.keys())
{
net->unLinkV(muxMap[key]);
muxMap[key]->stop();
encV->linkV(muxMap[key]);
if(muxMap_sub.contains(key))
{
net->unLinkV(muxMap_sub[key]);
muxMap_sub[key]->stop();
encV2->linkV(muxMap_sub[key]);
}
}
}
else
{
video->stop();
encV=net;
foreach(QString key,muxMap.keys())
{
ev->unLinkV(muxMap[key]);
muxMap[key]->stop();
encV->linkV(muxMap[key]);
if(muxMap_sub.contains(key))
{
encV2->unLinkV(muxMap_sub[key]);
muxMap_sub[key]->stop();
encV->linkV(muxMap_sub[key]);
}
}
}
if(cfg["net"].toMap()["decodeA"].toBool())
{
decA->start();
encA=ea;
if(cfg["enca"].toMap()["codec"].toString()=="close")
encA->stop();
else
encA->start(cfg["enca"].toMap());
foreach(QString key,muxMap.keys())
{
net->unLinkA(muxMap[key]);
muxMap[key]->stop();
encA->linkA(muxMap[key]);
if(muxMap_sub.contains(key))
{
net->unLinkA(muxMap_sub[key]);
muxMap_sub[key]->stop();
encA->linkA(muxMap_sub[key]);
}
}
}
else
{
decA->stop();
encA=net;
if(cfg["enca"].toMap()["codec"].toString()=="close")
encA=NULL;
foreach(QString key,muxMap.keys())
{
ea->unLinkA(muxMap[key]);
muxMap[key]->stop();
if(encA!=NULL)
encA->linkA(muxMap[key]);
if(muxMap_sub.contains(key))
{
ea->unLinkA(muxMap_sub[key]);
muxMap_sub[key]->stop();
if(encA!=NULL)
encA->linkA(muxMap_sub[key]);
}
}
}
if(cfg["enable"].toBool() )
{
QVariantMap nd;
nd["path"]=cfg["net"].toMap()["path"].toString();
nd["protocol"]=cfg["net"].toMap()["protocol"].toString();
nd["minDelay"]=cfg["net"].toMap()["minDelay"].toInt();
nd["timeout"]=20;
int bm=cfg["net"].toMap()["bufferMode"].toInt();
if(bm==0)
{
nd["lowLatency"]=false;
nd["buffer"]=true;
nd["sync"]=false;
}
else if(bm==1)
{
nd["lowLatency"]=true;
nd["buffer"]=false;
nd["sync"]=false;
}
else if(bm==2)
{
nd["lowLatency"]=true;
nd["buffer"]=false;
nd["sync"]=false;
}
if(bm==2 && cfg["net"].toMap()["decodeV"].toBool())
{
QVariantMap data;
data["delay"]=cfg["net"].toMap()["minDelay"].toInt();
queue->start(data);
net->unLinkV(video);
net->unLinkA(decA);
data.clear();
data["noThread"]=true;
video->setData(data);
net->linkV(queue);
net->linkA(queue);
}
else
{
queue->stop();
net->unLinkV(queue);
net->unLinkA(queue);
QVariantMap data;
data["block"]=false;
video->setData(data);
net->linkV(video);
net->linkA(decA);
}
if(encV!=net)
{
if(nd["path"].toString()!=url)
{
encV->stop();
net->stop();
video->stop();
ev->invoke("reset");
encV2->invoke("reset");
snap->invoke("reset");
}
url=nd["path"].toString();
QVariantMap frm;
frm["srcFramerate"]=cfg["net"].toMap()["framerate"].toInt();
encV->setData(frm);
encV2->setData(frm);
if(cfg["enable"].toBool() && cfg["encv"].toMap()["codec"].toString()!="close")
encV->start(cfg["encv"].toMap());
else
encV->stop();
if(cfg["enable2"].toBool() && cfg["encv2"].toMap()["codec"].toString()!="close")
encV2->start(cfg["encv2"].toMap());
else
encV2->stop();
video->start();
}
net->start(nd);
}
else
{
if(encV!=net)
encV->stop();
net->stop();
decA->stop();
}
Channel::updateConfig(cfg);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化