openRtpServer接口不允许添加重复的stream_id

This commit is contained in:
xiongziliang 2020-07-09 10:57:17 +08:00
parent 363673dd00
commit d6d861c401

View File

@ -762,19 +762,23 @@ void installWebApi() {
CHECK_ARGS("port", "enable_tcp", "stream_id");
auto stream_id = allArgs["stream_id"];
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
if(s_rtpServerMap.find(stream_id) != s_rtpServerMap.end()) {
//为了防止RtpProcess所有权限混乱的问题不允许重复添加相同的stream_id
throw InvalidArgsException("该stream_id已存在");
}
RtpServer::Ptr server = std::make_shared<RtpServer>();
server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as<bool>());
server->setOnDetach([stream_id]() {
//设置rtp超时移除事件
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.erase(stream_id);
});
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
//保存对象,强制覆盖
s_rtpServerMap[stream_id] = server;
//保存对象
s_rtpServerMap.emplace(stream_id, server);
//回复json
val["port"] = server->getPort();
});