From bc0a39bc5265547867ede538184ee1871a479f5b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 20 May 2019 18:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=A2=9E=E5=88=A0=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=9B=B4=E6=94=B9=E5=94=AF=E4=B8=80key=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 4b2fb819..c7f5839b 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -196,8 +196,11 @@ bool checkArgs(Args &&args,First &&first,KeyTypes && ...keys){ } -static unordered_map s_proxyMap; +static unordered_map s_proxyMap; static recursive_mutex s_proxyMapMtx; +static inline string getProxyKey(const string &vhost,const string &app,const string &stream){ + return vhost + "/" + app + "/" + stream; +} //安装api接口 void installWebApi() { @@ -366,6 +369,7 @@ void installWebApi() { API_REGIST_INVOKER(api,addStreamProxy,{ CHECK_SECRET(); CHECK_ARGS("vhost","app","stream","url","secret"); + auto key = getProxyKey(allArgs["vhost"],allArgs["app"],allArgs["stream"]); //添加拉流代理 PlayerProxy::Ptr player(new PlayerProxy( allArgs["vhost"], @@ -377,14 +381,14 @@ void installWebApi() { //指定RTP over TCP(播放rtsp时有效) (*player)[kRtpType] = allArgs["rtp_type"].as(); //开始播放,如果播放失败或者播放中止,将会自动重试若干次,默认一直重试 - player->setPlayCallbackOnce([invoker,val,headerOut,player](const SockException &ex){ + player->setPlayCallbackOnce([invoker,val,headerOut,player,key](const SockException &ex){ if(ex){ const_cast(val)["code"] = API::OtherFailed; const_cast(val)["msg"] = ex.what(); }else{ - const_cast(val)["data"]["id"] = (uint64_t)player.get(); + const_cast(val)["data"]["key"] = key; lock_guard lck(s_proxyMapMtx); - s_proxyMap[(uint64_t)player.get()] = player; + s_proxyMap[key] = player; } const_cast(player).reset(); invoker("200 OK", headerOut, val.toStyledString()); @@ -394,9 +398,9 @@ void installWebApi() { API_REGIST(api,delStreamProxy,{ CHECK_SECRET(); - CHECK_ARGS("id"); + CHECK_ARGS("key"); lock_guard lck(s_proxyMapMtx); - val["data"]["flag"] = s_proxyMap.erase(allArgs["id"].as()) == 1; + val["data"]["flag"] = s_proxyMap.erase(allArgs["key"]) == 1; });