Commit e628cba1 by 夏楚 Committed by GitHub

新增配置项过滤on_stream_changed hook协议类型 (#2759)

配置项hook.stream_changed_schemas可指定监听感兴趣的协议
parent f69204b3
...@@ -166,6 +166,8 @@ on_rtsp_realm=https://127.0.0.1/index/hook/on_rtsp_realm ...@@ -166,6 +166,8 @@ on_rtsp_realm=https://127.0.0.1/index/hook/on_rtsp_realm
on_shell_login=https://127.0.0.1/index/hook/on_shell_login on_shell_login=https://127.0.0.1/index/hook/on_shell_login
#直播流注册或注销事件 #直播流注册或注销事件
on_stream_changed=https://127.0.0.1/index/hook/on_stream_changed on_stream_changed=https://127.0.0.1/index/hook/on_stream_changed
#过滤on_stream_changed hook的协议类型,可以选择只监听某些感兴趣的协议;置空则不过滤协议
stream_changed_schemas=rtsp/rtmp/fmp4/ts/hls/hls.fmp4
#无人观看流事件,通过该事件,可以选择是否关闭无人观看的流。配合general.streamNoneReaderDelayMS选项一起使用 #无人观看流事件,通过该事件,可以选择是否关闭无人观看的流。配合general.streamNoneReaderDelayMS选项一起使用
on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader
#播放时,未找到流事件,通过配合hook.on_stream_none_reader事件可以完成按需拉流 #播放时,未找到流事件,通过配合hook.on_stream_none_reader事件可以完成按需拉流
......
...@@ -37,6 +37,7 @@ const string kOnFlowReport = HOOK_FIELD "on_flow_report"; ...@@ -37,6 +37,7 @@ const string kOnFlowReport = HOOK_FIELD "on_flow_report";
const string kOnRtspRealm = HOOK_FIELD "on_rtsp_realm"; const string kOnRtspRealm = HOOK_FIELD "on_rtsp_realm";
const string kOnRtspAuth = HOOK_FIELD "on_rtsp_auth"; const string kOnRtspAuth = HOOK_FIELD "on_rtsp_auth";
const string kOnStreamChanged = HOOK_FIELD "on_stream_changed"; const string kOnStreamChanged = HOOK_FIELD "on_stream_changed";
const string kStreamChangedSchemas = HOOK_FIELD "stream_changed_schemas";
const string kOnStreamNotFound = HOOK_FIELD "on_stream_not_found"; const string kOnStreamNotFound = HOOK_FIELD "on_stream_not_found";
const string kOnRecordMp4 = HOOK_FIELD "on_record_mp4"; const string kOnRecordMp4 = HOOK_FIELD "on_record_mp4";
const string kOnRecordTs = HOOK_FIELD "on_record_ts"; const string kOnRecordTs = HOOK_FIELD "on_record_ts";
...@@ -76,6 +77,7 @@ static onceToken token([]() { ...@@ -76,6 +77,7 @@ static 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;
mINI::Instance()[kStreamChangedSchemas] = "rtsp/rtmp/fmp4/ts/hls/hls.fmp4";
}); });
} // namespace Hook } // namespace Hook
...@@ -442,10 +444,26 @@ void installWebHook() { ...@@ -442,10 +444,26 @@ 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_changed, Hook::kOnStreamChanged);
if (!hook_enable || hook_stream_chaned.empty()) { if (!hook_enable || hook_stream_changed.empty()) {
return; return;
} }
GET_CONFIG_FUNC(std::set<std::string>, stream_changed_set, Hook::kStreamChangedSchemas, [](const std::string &str) {
std::set<std::string> ret;
auto vec = split(str, "/");
for (auto &schema : vec) {
trim(schema);
if (!schema.empty()) {
ret.emplace(schema);
}
}
return ret;
});
if (!stream_changed_set.empty() && stream_changed_set.find(sender.getSchema()) == stream_changed_set.end()) {
// 该协议注册注销事件被忽略
return;
}
ArgsType body; ArgsType body;
if (bRegist) { if (bRegist) {
body = makeMediaSourceJson(sender); body = makeMediaSourceJson(sender);
...@@ -456,7 +474,7 @@ void installWebHook() { ...@@ -456,7 +474,7 @@ void installWebHook() {
body["regist"] = bRegist; body["regist"] = bRegist;
} }
// 执行hook // 执行hook
do_http_hook(hook_stream_chaned, body, nullptr); do_http_hook(hook_stream_changed, body, nullptr);
}); });
GET_CONFIG_FUNC(vector<string>, origin_urls, Cluster::kOriginUrl, [](const string &str) { GET_CONFIG_FUNC(vector<string>, origin_urls, Cluster::kOriginUrl, [](const string &str) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论