mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
格式化代码
This commit is contained in:
parent
f949c6de2a
commit
9443d68d6c
@ -14,10 +14,10 @@
|
|||||||
#include "Util/NoticeCenter.h"
|
#include "Util/NoticeCenter.h"
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
|
#include "Http/HttpSession.h"
|
||||||
#include "Http/HttpRequester.h"
|
#include "Http/HttpRequester.h"
|
||||||
#include "Network/Session.h"
|
#include "Network/Session.h"
|
||||||
#include "Rtsp/RtspSession.h"
|
#include "Rtsp/RtspSession.h"
|
||||||
#include "Http/HttpSession.h"
|
|
||||||
#include "WebHook.h"
|
#include "WebHook.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ const string kAliveInterval = HOOK_FIELD"alive_interval";
|
|||||||
const string kRetry = HOOK_FIELD "retry";
|
const string kRetry = HOOK_FIELD "retry";
|
||||||
const string kRetryDelay = HOOK_FIELD "retry_delay";
|
const string kRetryDelay = HOOK_FIELD "retry_delay";
|
||||||
|
|
||||||
onceToken token([](){
|
static onceToken token([]() {
|
||||||
mINI::Instance()[kEnable] = false;
|
mINI::Instance()[kEnable] = false;
|
||||||
mINI::Instance()[kTimeoutSec] = 10;
|
mINI::Instance()[kTimeoutSec] = 10;
|
||||||
// 默认hook地址设置为空,采用默认行为(例如不鉴权)
|
// 默认hook地址设置为空,采用默认行为(例如不鉴权)
|
||||||
@ -76,7 +76,7 @@ onceToken token([](){
|
|||||||
mINI::Instance()[kAliveInterval] = 30.0;
|
mINI::Instance()[kAliveInterval] = 30.0;
|
||||||
mINI::Instance()[kRetry] = 1;
|
mINI::Instance()[kRetry] = 1;
|
||||||
mINI::Instance()[kRetryDelay] = 3.0;
|
mINI::Instance()[kRetryDelay] = 3.0;
|
||||||
},nullptr);
|
});
|
||||||
} // namespace Hook
|
} // namespace Hook
|
||||||
|
|
||||||
namespace Cluster {
|
namespace Cluster {
|
||||||
@ -93,8 +93,7 @@ static onceToken token([]() {
|
|||||||
|
|
||||||
} // namespace Cluster
|
} // namespace Cluster
|
||||||
|
|
||||||
static void parse_http_response(const SockException &ex, const Parser &res,
|
static void parse_http_response(const SockException &ex, const Parser &res, const function<void(const Value &, const string &, bool)> &fun) {
|
||||||
const function<void(const Value &,const string &,const bool &)> &fun){
|
|
||||||
bool should_retry = true;
|
bool should_retry = true;
|
||||||
if (ex) {
|
if (ex) {
|
||||||
auto errStr = StrPrinter << "[network err]:" << ex.what() << endl;
|
auto errStr = StrPrinter << "[network err]:" << ex.what() << endl;
|
||||||
@ -183,7 +182,7 @@ void do_http_hook(const string &url, const ArgsType &body, const function<void(c
|
|||||||
Ticker ticker;
|
Ticker ticker;
|
||||||
requester->startRequester(url, [url, func, bodyStr, body, requester, ticker, retry](const SockException &ex, const Parser &res) mutable {
|
requester->startRequester(url, [url, func, bodyStr, body, requester, ticker, retry](const SockException &ex, const Parser &res) mutable {
|
||||||
onceToken token(nullptr, [&]() mutable { requester.reset(); });
|
onceToken token(nullptr, [&]() mutable { requester.reset(); });
|
||||||
parse_http_response(ex, res, [&](const Value &obj, const string &err,const bool &should_retry) {
|
parse_http_response(ex, res, [&](const Value &obj, const string &err, bool should_retry) {
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
// hook失败
|
// hook失败
|
||||||
WarnL << "hook " << url << " " << ticker.elapsedTime() << "ms,failed" << err << ":" << bodyStr;
|
WarnL << "hook " << url << " " << ticker.elapsedTime() << "ms,failed" << err << ":" << bodyStr;
|
||||||
@ -272,9 +271,7 @@ static string getPullUrl(const string &origin_fmt, const MediaInfo &info) {
|
|||||||
return string(url) + '?' + kEdgeServerParam + '&' + VHOST_KEY + '=' + info._vhost + '&' + info._param_strs;
|
return string(url) + '?' + kEdgeServerParam + '&' + VHOST_KEY + '=' + info._vhost + '&' + info._param_strs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pullStreamFromOrigin(const vector<string>& urls, size_t index, size_t failed_cnt, const MediaInfo &args,
|
static void pullStreamFromOrigin(const vector<string> &urls, size_t index, size_t failed_cnt, const MediaInfo &args, const function<void()> &closePlayer) {
|
||||||
const function<void()> &closePlayer) {
|
|
||||||
|
|
||||||
GET_CONFIG(float, cluster_timeout_sec, Cluster::kTimeoutSec);
|
GET_CONFIG(float, cluster_timeout_sec, Cluster::kTimeoutSec);
|
||||||
GET_CONFIG(int, retry_count, Cluster::kRetryCount);
|
GET_CONFIG(int, retry_count, Cluster::kRetryCount);
|
||||||
|
|
||||||
@ -286,8 +283,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._streamid, url, retry_count, option, Rtsp::RTP_TCP, timeout_sec,
|
addStreamProxy(args._vhost, args._app, args._streamid, url, retry_count, option, Rtsp::RTP_TCP, timeout_sec, [=](const SockException &ex, const string &key) mutable {
|
||||||
[=](const SockException &ex, const string &key) mutable {
|
|
||||||
if (!ex) {
|
if (!ex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -359,9 +355,7 @@ void installWebHook(){
|
|||||||
body["port"] = sender.get_peer_port();
|
body["port"] = sender.get_peer_port();
|
||||||
body["id"] = sender.getIdentifier();
|
body["id"] = sender.getIdentifier();
|
||||||
// 执行hook
|
// 执行hook
|
||||||
do_http_hook(hook_play,body,[invoker](const Value &obj,const string &err){
|
do_http_hook(hook_play, body, [invoker](const Value &obj, const string &err) { invoker(err); });
|
||||||
invoker(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastFlowReport, [](BroadcastFlowReportArgs) {
|
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastFlowReport, [](BroadcastFlowReportArgs) {
|
||||||
@ -380,7 +374,6 @@ void installWebHook(){
|
|||||||
do_http_hook(hook_flowreport, body, nullptr);
|
do_http_hook(hook_flowreport, body, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
static const string unAuthedRealm = "unAuthedRealm";
|
static const string unAuthedRealm = "unAuthedRealm";
|
||||||
|
|
||||||
// 监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
// 监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
||||||
@ -432,7 +425,6 @@ void installWebHook(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 监听rtsp、rtmp源注册或注销事件
|
// 监听rtsp、rtmp源注册或注销事件
|
||||||
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastMediaChanged, [](BroadcastMediaChangedArgs) {
|
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastMediaChanged, [](BroadcastMediaChangedArgs) {
|
||||||
GET_CONFIG(string, hook_stream_chaned, Hook::kOnStreamChanged);
|
GET_CONFIG(string, hook_stream_chaned, Hook::kOnStreamChanged);
|
||||||
@ -552,9 +544,7 @@ void installWebHook(){
|
|||||||
body["passwd"] = passwd;
|
body["passwd"] = passwd;
|
||||||
|
|
||||||
// 执行hook
|
// 执行hook
|
||||||
do_http_hook(hook_shell_login,body, [invoker](const Value &,const string &err){
|
do_http_hook(hook_shell_login, body, [invoker](const Value &, const string &err) { invoker(err); });
|
||||||
invoker(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastStreamNoneReader, [](BroadcastStreamNoneReaderArgs) {
|
||||||
|
Loading…
Reference in New Issue
Block a user