动态创建rtp端口采用stream_id为索引

This commit is contained in:
xiongziliang 2020-07-09 10:38:57 +08:00
parent a164b28608
commit 4b39fd487d

View File

@ -257,7 +257,7 @@ static recursive_mutex s_ffmpegMapMtx;
#if defined(ENABLE_RTPPROXY)
//rtp服务器列表
static unordered_map<uint16_t, RtpServer::Ptr> s_rtpServerMap;
static unordered_map<string, RtpServer::Ptr> s_rtpServerMap;
static recursive_mutex s_rtpServerMapMtx;
#endif
@ -759,38 +759,41 @@ void installWebApi() {
CHECK_SECRET();
CHECK_ARGS("port", "enable_tcp", "stream_id");
auto stream_id = allArgs["stream_id"];
RtpServer::Ptr server = std::make_shared<RtpServer>();
server->start(allArgs["port"], allArgs["stream_id"], allArgs["enable_tcp"].as<bool>());
server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as<bool>());
auto port = server->getPort();
server->setOnDetach([port]() {
server->setOnDetach([stream_id]() {
//设置rtp超时移除事件
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.erase(port);
s_rtpServerMap.erase(stream_id);
});
//保存对象
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.emplace(port, server);
//保存对象,强制覆盖
s_rtpServerMap[stream_id] = server;
//回复json
val["port"] = port;
val["port"] = server->getPort();
});
api_regist1("/index/api/closeRtpServer",[](API_ARGS1){
CHECK_SECRET();
CHECK_ARGS("port");
CHECK_ARGS("stream_id");
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
val["hit"] = (int)s_rtpServerMap.erase(allArgs["port"].as<uint16_t>());
val["hit"] = (int) s_rtpServerMap.erase(allArgs["stream_id"]);
});
api_regist1("/index/api/listRtpServer",[](API_ARGS1){
CHECK_SECRET();
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
for(auto &pr : s_rtpServerMap){
val["data"].append(pr.first);
for (auto &pr : s_rtpServerMap) {
Value obj;
obj["stream_id"] = pr.first;
obj["port"] = pr.second->getPort();
val["data"].append(obj);
}
});