From aa39680c695827b52e4bfbd524531d43c71912d2 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Thu, 17 Jun 2021 10:41:26 +0800 Subject: [PATCH] =?UTF-8?q?addStreamPusherProxy=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9key=E5=94=AF=E4=B8=80=E6=80=A7=E8=A7=84=E5=88=99,?= =?UTF-8?q?=E6=96=B0=E5=A2=9Ertsp=E6=8E=A8=E6=B5=81=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E3=80=81=E8=B6=85=E6=97=B6=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 328f1e05..3f30332e 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -249,10 +249,15 @@ static unordered_map s_rtpServerMap; static recursive_mutex s_rtpServerMapMtx; #endif -static inline string getProxyKey(const string &vhost,const string &app,const string &stream){ +static inline string getProxyKey(const string &vhost, const string &app, const string &stream) { return vhost + "/" + app + "/" + stream; } +static inline string getPusherKey(const string &schema, const string &vhost, const string &app, const string &stream, + const string &dst_url) { + return schema + "/" + vhost + "/" + app + "/" + stream + "/" + MD5(dst_url).hexdigest(); +} + Value makeMediaSourceJson(MediaSource &media){ Value item; item["schema"] = media.getSchema(); @@ -606,9 +611,11 @@ void installWebApi() { const string &app, const string &stream, const string &url, - int retryCount, + int retry_count, + int rtp_type, + float timeout_sec, const function &cb) { - auto key = getProxyKey(vhost, app, stream); + auto key = getPusherKey(schema, vhost, app, stream, url); lock_guard lck(s_proxyPusherMapMtx); if (s_proxyPusherMap.find(key) != s_proxyPusherMap.end()) { //已经在推流了 @@ -616,14 +623,18 @@ void installWebApi() { return; } - auto poller = EventPollerPool::Instance().getPoller(); - int retry_count = 3; - if (retryCount != 0) retry_count = retryCount; - //添加推流代理 - PusherProxy::Ptr pusher(new PusherProxy(schema, vhost, app, stream, retry_count, poller)); + PusherProxy::Ptr pusher(new PusherProxy(schema, vhost, app, stream, retry_count ? retry_count : -1)); s_proxyPusherMap[key] = pusher; + //指定RTP over TCP(播放rtsp时有效) + (*pusher)[kRtpType] = rtp_type; + + if (timeout_sec > 0.1) { + //推流握手超时时间 + (*pusher)[kTimeoutMS] = timeout_sec * 1000; + } + //开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试 pusher->setPushCallbackOnce([cb, key, url](const SockException &ex) { if (ex) { @@ -671,6 +682,8 @@ void installWebApi() { allArgs["stream"], allArgs["dst_url"], allArgs["retry_count"], + allArgs["rtp_type"], + allArgs["timeout_sec"], [invoker, val, headerOut, dst_url](const SockException &ex, const string &key) mutable { if (ex) { val["code"] = API::OtherFailed;