From 4b39fd487da7f1f69874f1aa1a3d8d5036cf6b8b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 9 Jul 2020 10:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=88=9B=E5=BB=BArtp?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E9=87=87=E7=94=A8stream=5Fid=E4=B8=BA?= =?UTF-8?q?=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) 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); } });