From a8a4f267f78a2c277ab3e113ef976aadbc259225 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 8 Nov 2019 15:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=EF=BC=8C=E6=8E=A7=E5=88=B6=E5=9C=A8=E5=85=B3=E9=97=ADhook?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=8E=A8=E6=B5=81=E6=98=AF=E5=90=A6=E8=BD=AC?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E6=88=96=E5=BD=95=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 6 ++++++ server/WebHook.cpp | 5 ++++- src/Common/config.cpp | 6 ++++++ src/Common/config.h | 6 ++++++ src/Rtmp/RtmpSession.cpp | 5 ++++- src/Rtsp/RtspSession.cpp | 7 +++++-- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 048971f2..937ff6d2 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -36,6 +36,12 @@ addMuteAudio=1 #拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始, #如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写) resetWhenRePlay=1 +#是否默认推流时转换成rtsp或rtmp,hook接口(on_publish中可以覆盖该设置) +publishToRtxp=1 +#是否默认推流时转换成hls,hook接口(on_publish中可以覆盖该设置) +publishToHls=1 +#是否默认推流时mp4录像,hook接口(on_publish中可以覆盖该设置) +publishToMP4=0 [hls] #hls写文件的buf大小,调整参数可以提高文件io性能 diff --git a/server/WebHook.cpp b/server/WebHook.cpp index e4c8945e..1391d10a 100644 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -195,7 +195,10 @@ void installWebHook(){ NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPublish,[](BroadcastMediaPublishArgs){ if(!hook_enable || args._param_strs == hook_adminparams || hook_publish.empty() || sender.get_peer_ip() == "127.0.0.1"){ - invoker("",true, true,false); + GET_CONFIG(bool,toRtxp,General::kPublishToRtxp); + GET_CONFIG(bool,toHls,General::kPublishToHls); + GET_CONFIG(bool,toMP4,General::kPublishToMP4); + invoker("",toRtxp,toHls,toMP4); return; } //异步执行该hook api,防止阻塞NoticeCenter diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 8991d768..39336e69 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -79,6 +79,9 @@ const string kEnableVhost = GENERAL_FIELD"enableVhost"; const string kUltraLowDelay = GENERAL_FIELD"ultraLowDelay"; const string kAddMuteAudio = GENERAL_FIELD"addMuteAudio"; const string kResetWhenRePlay = GENERAL_FIELD"resetWhenRePlay"; +const string kPublishToRtxp = GENERAL_FIELD"publishToRtxp"; +const string kPublishToHls = GENERAL_FIELD"publishToHls"; +const string kPublishToMP4 = GENERAL_FIELD"publishToMP4"; onceToken token([](){ mINI::Instance()[kFlowThreshold] = 1024; @@ -88,6 +91,9 @@ onceToken token([](){ mINI::Instance()[kUltraLowDelay] = 1; mINI::Instance()[kAddMuteAudio] = 1; mINI::Instance()[kResetWhenRePlay] = 1; + mINI::Instance()[kPublishToRtxp] = 1; + mINI::Instance()[kPublishToHls] = 1; + mINI::Instance()[kPublishToMP4] = 0; },nullptr); }//namespace General diff --git a/src/Common/config.h b/src/Common/config.h index 5658bd53..13abe95c 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -182,6 +182,12 @@ extern const string kAddMuteAudio; //拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始, //如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写) extern const string kResetWhenRePlay; +//是否默认推流时转换成rtsp或rtmp,hook接口(on_publish中可以覆盖该设置) +extern const string kPublishToRtxp ; +//是否默认推流时转换成hls,hook接口(on_publish中可以覆盖该设置) +extern const string kPublishToHls ; +//是否默认推流时mp4录像,hook接口(on_publish中可以覆盖该设置) +extern const string kPublishToMP4 ; }//namespace General diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 62787b1d..e946d275 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -198,7 +198,10 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { *this); if(!flag){ //该事件无人监听,默认鉴权成功 - onRes("",true,true,false); + GET_CONFIG(bool,toRtxp,General::kPublishToRtxp); + GET_CONFIG(bool,toHls,General::kPublishToHls); + GET_CONFIG(bool,toMP4,General::kPublishToMP4); + onRes("",toRtxp,toHls,toMP4); } } diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 3985ebec..14e2b89a 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -324,8 +324,11 @@ void RtspSession::handleReq_RECORD(const Parser &parser){ auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish,_mediaInfo,invoker,*this); if(!flag){ //该事件无人监听,默认不鉴权 - onRes("",true,true,false); - } + GET_CONFIG(bool,toRtxp,General::kPublishToRtxp); + GET_CONFIG(bool,toHls,General::kPublishToHls); + GET_CONFIG(bool,toMP4,General::kPublishToMP4); + onRes("",toRtxp,toHls,toMP4); + } } void RtspSession::handleReq_Describe(const Parser &parser) {