Commit 4b39fd48 by xiongziliang

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

parent a164b286
...@@ -257,7 +257,7 @@ static recursive_mutex s_ffmpegMapMtx; ...@@ -257,7 +257,7 @@ static recursive_mutex s_ffmpegMapMtx;
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
//rtp服务器列表 //rtp服务器列表
static unordered_map<uint16_t, RtpServer::Ptr> s_rtpServerMap; static unordered_map<string, RtpServer::Ptr> s_rtpServerMap;
static recursive_mutex s_rtpServerMapMtx; static recursive_mutex s_rtpServerMapMtx;
#endif #endif
...@@ -759,38 +759,41 @@ void installWebApi() { ...@@ -759,38 +759,41 @@ void installWebApi() {
CHECK_SECRET(); CHECK_SECRET();
CHECK_ARGS("port", "enable_tcp", "stream_id"); CHECK_ARGS("port", "enable_tcp", "stream_id");
auto stream_id = allArgs["stream_id"];
RtpServer::Ptr server = std::make_shared<RtpServer>(); 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([stream_id]() {
server->setOnDetach([port]() {
//设置rtp超时移除事件 //设置rtp超时移除事件
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.erase(port); s_rtpServerMap.erase(stream_id);
}); });
//保存对象
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.emplace(port, server); //保存对象,强制覆盖
s_rtpServerMap[stream_id] = server;
//回复json //回复json
val["port"] = port; val["port"] = server->getPort();
}); });
api_regist1("/index/api/closeRtpServer",[](API_ARGS1){ api_regist1("/index/api/closeRtpServer",[](API_ARGS1){
CHECK_SECRET(); CHECK_SECRET();
CHECK_ARGS("port"); CHECK_ARGS("stream_id");
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); 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){ api_regist1("/index/api/listRtpServer",[](API_ARGS1){
CHECK_SECRET(); CHECK_SECRET();
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
for(auto &pr : s_rtpServerMap){ for (auto &pr : s_rtpServerMap) {
val["data"].append(pr.first); Value obj;
obj["stream_id"] = pr.first;
obj["port"] = pr.second->getPort();
val["data"].append(obj);
} }
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论