diff --git a/server/WebApi.cpp b/server/WebApi.cpp index bbfc803d..1aef1402 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -257,7 +257,7 @@ static recursive_mutex s_ffmpegMapMtx; #if defined(ENABLE_RTPPROXY) //rtp服务器列表 -static unordered_map s_rtpServerMap; +static unordered_map 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(); - server->start(allArgs["port"], allArgs["stream_id"], allArgs["enable_tcp"].as()); + server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as()); - auto port = server->getPort(); - server->setOnDetach([port]() { + server->setOnDetach([stream_id]() { //设置rtp超时移除事件 lock_guard lck(s_rtpServerMapMtx); - s_rtpServerMap.erase(port); + s_rtpServerMap.erase(stream_id); }); - //保存对象 lock_guard 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 lck(s_rtpServerMapMtx); - val["hit"] = (int)s_rtpServerMap.erase(allArgs["port"].as()); + val["hit"] = (int) s_rtpServerMap.erase(allArgs["stream_id"]); }); api_regist1("/index/api/listRtpServer",[](API_ARGS1){ CHECK_SECRET(); lock_guard 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); } });