完善http proxy
This commit is contained in:
parent
b3441f800a
commit
57fcb2e429
|
|
@ -540,7 +540,7 @@ void getStatisticJson(const function<void(Value &val)> &cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void addStreamProxy(const string &vhost, const string &app, const string &stream, const string &url, int retry_count,
|
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<void(const SockException &ex, const string &key)> &cb) {
|
const function<void(const SockException &ex, const string &key)> &cb) {
|
||||||
auto key = getProxyKey(vhost, app, stream);
|
auto key = getProxyKey(vhost, app, stream);
|
||||||
lock_guard<recursive_mutex> lck(s_proxyMapMtx);
|
lock_guard<recursive_mutex> lck(s_proxyMapMtx);
|
||||||
|
|
@ -575,6 +575,7 @@ void addStreamProxy(const string &vhost, const string &app, const string &stream
|
||||||
lock_guard<recursive_mutex> lck(s_proxyMapMtx);
|
lock_guard<recursive_mutex> lck(s_proxyMapMtx);
|
||||||
s_proxyMap.erase(key);
|
s_proxyMap.erase(key);
|
||||||
});
|
});
|
||||||
|
player->mINI::operator=(args);
|
||||||
player->play(url);
|
player->play(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1058,6 +1059,11 @@ void installWebApi() {
|
||||||
CHECK_SECRET();
|
CHECK_SECRET();
|
||||||
CHECK_ARGS("vhost","app","stream","url");
|
CHECK_ARGS("vhost","app","stream","url");
|
||||||
|
|
||||||
|
mINI args;
|
||||||
|
for (auto &pr : allArgs.getArgs()) {
|
||||||
|
args.emplace(pr.first, pr.second);
|
||||||
|
}
|
||||||
|
|
||||||
ProtocolOption option(allArgs);
|
ProtocolOption option(allArgs);
|
||||||
auto retry_count = allArgs["retry_count"].empty()? -1: allArgs["retry_count"].as<int>();
|
auto retry_count = allArgs["retry_count"].empty()? -1: allArgs["retry_count"].as<int>();
|
||||||
addStreamProxy(allArgs["vhost"],
|
addStreamProxy(allArgs["vhost"],
|
||||||
|
|
@ -1068,6 +1074,7 @@ void installWebApi() {
|
||||||
option,
|
option,
|
||||||
allArgs["rtp_type"],
|
allArgs["rtp_type"],
|
||||||
allArgs["timeout_sec"],
|
allArgs["timeout_sec"],
|
||||||
|
args,
|
||||||
[invoker,val,headerOut](const SockException &ex,const string &key) mutable{
|
[invoker,val,headerOut](const SockException &ex,const string &key) mutable{
|
||||||
if (ex) {
|
if (ex) {
|
||||||
val["code"] = API::OtherFailed;
|
val["code"] = API::OtherFailed;
|
||||||
|
|
@ -1891,6 +1898,7 @@ void installWebApi() {
|
||||||
option,
|
option,
|
||||||
0,//rtp over tcp方式拉流
|
0,//rtp over tcp方式拉流
|
||||||
10,//10秒超时
|
10,//10秒超时
|
||||||
|
mINI{},
|
||||||
[invoker,val,headerOut](const SockException &ex,const string &key) mutable{
|
[invoker,val,headerOut](const SockException &ex,const string &key) mutable{
|
||||||
if(ex){
|
if(ex){
|
||||||
val["code"] = API::OtherFailed;
|
val["code"] = API::OtherFailed;
|
||||||
|
|
|
||||||
|
|
@ -247,6 +247,6 @@ bool closeRtpServer(const std::string &stream_id);
|
||||||
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
Json::Value makeMediaSourceJson(mediakit::MediaSource &media);
|
||||||
void getStatisticJson(const std::function<void(Json::Value &val)> &cb);
|
void getStatisticJson(const std::function<void(Json::Value &val)> &cb);
|
||||||
void addStreamProxy(const std::string &vhost, const std::string &app, const std::string &stream, const std::string &url, int retry_count,
|
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<void(const toolkit::SockException &ex, const std::string &key)> &cb);
|
const std::function<void(const toolkit::SockException &ex, const std::string &key)> &cb);
|
||||||
#endif //ZLMEDIAKIT_WEBAPI_H
|
#endif //ZLMEDIAKIT_WEBAPI_H
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ static void pullStreamFromOrigin(const vector<string> &urls, size_t index, size_
|
||||||
option.enable_hls = option.enable_hls || (args.schema == HLS_SCHEMA);
|
option.enable_hls = option.enable_hls || (args.schema == HLS_SCHEMA);
|
||||||
option.enable_mp4 = false;
|
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) {
|
if (!ex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,17 +78,18 @@ void HttpClient::sendRequest(const string &url) {
|
||||||
printer.pop_back();
|
printer.pop_back();
|
||||||
_header.emplace("Cookie", printer);
|
_header.emplace("Cookie", printer);
|
||||||
}
|
}
|
||||||
|
if (!alive() || host_changed) {
|
||||||
if (isUsedProxy()) {
|
if (isUsedProxy()) {
|
||||||
|
_proxy_connected = false;
|
||||||
startConnect(_proxy_host, _proxy_port, _wait_header_ms / 1000.0f);
|
startConnect(_proxy_host, _proxy_port, _wait_header_ms / 1000.0f);
|
||||||
} else {
|
} else {
|
||||||
if (!alive() || host_changed) {
|
|
||||||
startConnect(host, port, _wait_header_ms / 1000.0f);
|
startConnect(host, port, _wait_header_ms / 1000.0f);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SockException ex;
|
SockException ex;
|
||||||
onConnect_l(ex);
|
onConnect_l(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void HttpClient::clear() {
|
void HttpClient::clear() {
|
||||||
_url.clear();
|
_url.clear();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue