From f9df7f521701c1f44c5217db748afc77faa24c65 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 29 Apr 2020 11:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4ultraLowDelay=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 6 ++---- src/Common/MediaSource.cpp | 3 +-- src/Common/config.cpp | 4 +--- src/Common/config.h | 4 +--- src/Http/HttpSession.cpp | 4 ++-- src/Rtmp/RtmpPusher.cpp | 4 ++-- src/Rtmp/RtmpSession.cpp | 4 ++-- src/Rtsp/RtspPusher.cpp | 4 ++-- src/Rtsp/RtspSession.cpp | 4 ++-- 9 files changed, 15 insertions(+), 22 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index accde647..44aca9e6 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -29,8 +29,6 @@ maxStreamWaitMS=15000 #某个流无人观看时,触发hook.on_stream_none_reader事件的最大等待时间,单位毫秒 #在配合hook.on_stream_none_reader事件时,可以做到无人观看自动停止拉流或停止接收推流 streamNoneReaderDelayMS=20000 -#是否开启低延时模式,该模式下禁用MSG_MORE,启用TCP_NODEALY,延时将降低,但数据发送性能将降低 -ultraLowDelay=1 #拉流代理是否添加静音音频(直接拉流模式本协议无效) addMuteAudio=1 #拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始, @@ -43,8 +41,8 @@ publishToHls=1 #是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置 publishToMP4=0 #合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时 -#在开启低延时模式后,该参数不起作用 -mergeWriteMS=300 +#开启后会同时关闭TCP_NODELAY并开启MSG_MORE +mergeWriteMS=0 [hls] #hls写文件的buf大小,调整参数可以提高文件io性能 diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 3c41c0ec..fafb13dd 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -516,9 +516,8 @@ static bool isFlushAble_merge(bool is_audio, uint32_t last_stamp, uint32_t new_s bool FlushPolicy::isFlushAble(uint32_t new_stamp, int cache_size) { bool ret = false; - GET_CONFIG(bool, ultraLowDelay, General::kUltraLowDelay); GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); - if (ultraLowDelay || mergeWriteMS <= 0) { + if (mergeWriteMS <= 0) { //关闭了合并写或者合并写阈值小于等于0 ret = isFlushAble_default(_is_audio, _last_stamp, new_stamp, cache_size); } else { diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 819901fb..8a22bea1 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -61,7 +61,6 @@ const string kFlowThreshold = GENERAL_FIELD"flowThreshold"; const string kStreamNoneReaderDelayMS = GENERAL_FIELD"streamNoneReaderDelayMS"; const string kMaxStreamWaitTimeMS = GENERAL_FIELD"maxStreamWaitMS"; 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"; @@ -74,13 +73,12 @@ onceToken token([](){ mINI::Instance()[kStreamNoneReaderDelayMS] = 20 * 1000; mINI::Instance()[kMaxStreamWaitTimeMS] = 15 * 1000; mINI::Instance()[kEnableVhost] = 0; - mINI::Instance()[kUltraLowDelay] = 1; mINI::Instance()[kAddMuteAudio] = 1; mINI::Instance()[kResetWhenRePlay] = 1; mINI::Instance()[kPublishToRtxp] = 1; mINI::Instance()[kPublishToHls] = 1; mINI::Instance()[kPublishToMP4] = 0; - mINI::Instance()[kMergeWriteMS] = 300; + mINI::Instance()[kMergeWriteMS] = 0; },nullptr); }//namespace General diff --git a/src/Common/config.h b/src/Common/config.h index aa42acaa..3948879f 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -160,8 +160,6 @@ extern const string kStreamNoneReaderDelayMS; extern const string kMaxStreamWaitTimeMS; //是否启动虚拟主机 extern const string kEnableVhost; -//超低延时模式,默认打开,打开后会降低延时但是转发性能会稍差 -extern const string kUltraLowDelay; //拉流代理时是否添加静音音频 extern const string kAddMuteAudio; //拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始, @@ -174,7 +172,7 @@ extern const string kPublishToHls ; //是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置 extern const string kPublishToMP4 ; //合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时 -//在开启低延时模式后,该参数不起作用 +//开启后会同时关闭TCP_NODELAY并开启MSG_MORE extern const string kMergeWriteMS ; }//namespace General diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 26056ed0..65ed9b3a 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -606,8 +606,8 @@ void HttpSession::sendNotFound(bool bClose) { } void HttpSession::setSocketFlags(){ - GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay); - if(!ultraLowDelay) { + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if(mergeWriteMS > 0) { //推流模式下,关闭TCP_NODELAY会增加推流端的延时,但是服务器性能将提高 SockUtil::setNoDelay(_sock->rawFD(), false); //播放模式下,开启MSG_MORE会增加延时,但是能提高发送性能 diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index 3722e23d..725868b5 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -228,8 +228,8 @@ inline void RtmpPusher::send_metaData(){ } void RtmpPusher::setSocketFlags(){ - GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay); - if(!ultraLowDelay) { + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if(mergeWriteMS > 0) { //提高发送性能 setSendFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE); SockUtil::setNoDelay(_sock->rawFD(), false); diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index d606f118..a062c5d6 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -529,8 +529,8 @@ int RtmpSession::totalReaderCount(MediaSource &sender) { } void RtmpSession::setSocketFlags(){ - GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay); - if(!ultraLowDelay) { + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if(mergeWriteMS > 0) { //推流模式下,关闭TCP_NODELAY会增加推流端的延时,但是服务器性能将提高 SockUtil::setNoDelay(_sock->rawFD(), false); //播放模式下,开启MSG_MORE会增加延时,但是能提高发送性能 diff --git a/src/Rtsp/RtspPusher.cpp b/src/Rtsp/RtspPusher.cpp index 5243be4c..f259a0d6 100644 --- a/src/Rtsp/RtspPusher.cpp +++ b/src/Rtsp/RtspPusher.cpp @@ -392,8 +392,8 @@ void RtspPusher::sendRecord() { } void RtspPusher::setSocketFlags(){ - GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay); - if(!ultraLowDelay) { + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if(mergeWriteMS > 0) { //提高发送性能 setSendFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE); SockUtil::setNoDelay(_sock->rawFD(), false); diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index f8591e6c..a9cbcffb 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -1236,8 +1236,8 @@ void RtspSession::sendSenderReport(bool overTcp,int iTrackIndex) { } void RtspSession::setSocketFlags(){ - GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay); - if(!ultraLowDelay) { + GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); + if(mergeWriteMS > 0) { //推流模式下,关闭TCP_NODELAY会增加推流端的延时,但是服务器性能将提高 SockUtil::setNoDelay(_sock->rawFD(), false); //播放模式下,开启MSG_MORE会增加延时,但是能提高发送性能