diff --git a/conf/config.ini b/conf/config.ini index df110b2b..0bd86b0b 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -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_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选项一起使用 on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader #播放时,未找到流事件,通过配合hook.on_stream_none_reader事件可以完成按需拉流 diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 72ddb7fb..d05c4f60 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -37,6 +37,7 @@ const string kOnFlowReport = HOOK_FIELD "on_flow_report"; const string kOnRtspRealm = HOOK_FIELD "on_rtsp_realm"; const string kOnRtspAuth = HOOK_FIELD "on_rtsp_auth"; 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 kOnRecordMp4 = HOOK_FIELD "on_record_mp4"; const string kOnRecordTs = HOOK_FIELD "on_record_ts"; @@ -76,6 +77,7 @@ static onceToken token([]() { mINI::Instance()[kAliveInterval] = 30.0; mINI::Instance()[kRetry] = 1; mINI::Instance()[kRetryDelay] = 3.0; + mINI::Instance()[kStreamChangedSchemas] = "rtsp/rtmp/fmp4/ts/hls/hls.fmp4"; }); } // namespace Hook @@ -442,10 +444,26 @@ void installWebHook() { // 监听rtsp、rtmp源注册或注销事件 NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastMediaChanged, [](BroadcastMediaChangedArgs) { - GET_CONFIG(string, hook_stream_chaned, Hook::kOnStreamChanged); - if (!hook_enable || hook_stream_chaned.empty()) { + GET_CONFIG(string, hook_stream_changed, Hook::kOnStreamChanged); + if (!hook_enable || hook_stream_changed.empty()) { return; } + GET_CONFIG_FUNC(std::set, stream_changed_set, Hook::kStreamChangedSchemas, [](const std::string &str) { + std::set 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; if (bRegist) { body = makeMediaSourceJson(sender); @@ -456,7 +474,7 @@ void installWebHook() { body["regist"] = bRegist; } // 执行hook - do_http_hook(hook_stream_chaned, body, nullptr); + do_http_hook(hook_stream_changed, body, nullptr); }); GET_CONFIG_FUNC(vector, origin_urls, Cluster::kOriginUrl, [](const string &str) {