From 57fcb2e4298fffd197ce4fc2662995dac5cbd947 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 1 Dec 2023 11:33:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84http=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 10 +++++++++- server/WebApi.h | 2 +- server/WebHook.cpp | 2 +- src/Http/HttpClient.cpp | 15 ++++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 8bd2f416..58bf5627 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -540,7 +540,7 @@ void getStatisticJson(const function &cb) { } void addStreamProxy(const string &vhost, const string &app, const string &stream, const string &url, int retry_count, - const ProtocolOption &option, int rtp_type, float timeout_sec, + const ProtocolOption &option, int rtp_type, float timeout_sec, const mINI &args, const function &cb) { auto key = getProxyKey(vhost, app, stream); lock_guard lck(s_proxyMapMtx); @@ -575,6 +575,7 @@ void addStreamProxy(const string &vhost, const string &app, const string &stream lock_guard lck(s_proxyMapMtx); s_proxyMap.erase(key); }); + player->mINI::operator=(args); player->play(url); }; @@ -1058,6 +1059,11 @@ void installWebApi() { CHECK_SECRET(); CHECK_ARGS("vhost","app","stream","url"); + mINI args; + for (auto &pr : allArgs.getArgs()) { + args.emplace(pr.first, pr.second); + } + ProtocolOption option(allArgs); auto retry_count = allArgs["retry_count"].empty()? -1: allArgs["retry_count"].as(); addStreamProxy(allArgs["vhost"], @@ -1068,6 +1074,7 @@ void installWebApi() { option, allArgs["rtp_type"], allArgs["timeout_sec"], + args, [invoker,val,headerOut](const SockException &ex,const string &key) mutable{ if (ex) { val["code"] = API::OtherFailed; @@ -1891,6 +1898,7 @@ void installWebApi() { option, 0,//rtp over tcp方式拉流 10,//10秒超时 + mINI{}, [invoker,val,headerOut](const SockException &ex,const string &key) mutable{ if(ex){ val["code"] = API::OtherFailed; diff --git a/server/WebApi.h b/server/WebApi.h index f7ec0cb3..ea6caa81 100755 --- a/server/WebApi.h +++ b/server/WebApi.h @@ -247,6 +247,6 @@ bool closeRtpServer(const std::string &stream_id); Json::Value makeMediaSourceJson(mediakit::MediaSource &media); void getStatisticJson(const std::function &cb); void addStreamProxy(const std::string &vhost, const std::string &app, const std::string &stream, const std::string &url, int retry_count, - const mediakit::ProtocolOption &option, int rtp_type, float timeout_sec, + const mediakit::ProtocolOption &option, int rtp_type, float timeout_sec, const toolkit::mINI &args, const std::function &cb); #endif //ZLMEDIAKIT_WEBAPI_H diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 409d11f4..f0e68972 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -301,7 +301,7 @@ static void pullStreamFromOrigin(const vector &urls, size_t index, size_ option.enable_hls = option.enable_hls || (args.schema == HLS_SCHEMA); option.enable_mp4 = false; - addStreamProxy(args.vhost, args.app, args.stream, url, retry_count, option, Rtsp::RTP_TCP, timeout_sec, [=](const SockException &ex, const string &key) mutable { + addStreamProxy(args.vhost, args.app, args.stream, url, retry_count, option, Rtsp::RTP_TCP, timeout_sec, mINI{}, [=](const SockException &ex, const string &key) mutable { if (!ex) { return; } diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 793e9ca1..068727a5 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -78,15 +78,16 @@ void HttpClient::sendRequest(const string &url) { printer.pop_back(); _header.emplace("Cookie", printer); } - if (isUsedProxy()) { - startConnect(_proxy_host, _proxy_port, _wait_header_ms / 1000.0f); - } else { - if (!alive() || host_changed) { - startConnect(host, port, _wait_header_ms / 1000.0f); + if (!alive() || host_changed) { + if (isUsedProxy()) { + _proxy_connected = false; + startConnect(_proxy_host, _proxy_port, _wait_header_ms / 1000.0f); } else { - SockException ex; - onConnect_l(ex); + startConnect(host, port, _wait_header_ms / 1000.0f); } + } else { + SockException ex; + onConnect_l(ex); } }