rtsp and rtp h264 lowlatency mode config

This commit is contained in:
xiongguangjie 2022-10-19 14:20:53 +08:00
parent 4a51d6b488
commit 0d2e035215
5 changed files with 33 additions and 5 deletions

View File

@ -264,6 +264,8 @@ audioMtuSize=600
videoMtuSize=1400 videoMtuSize=1400
#rtp包最大长度限制单位KB,主要用于识别TCP上下文破坏时获取到错误的rtp #rtp包最大长度限制单位KB,主要用于识别TCP上下文破坏时获取到错误的rtp
rtpMaxSize=10 rtpMaxSize=10
# rtp 打包时低延迟开关默认关闭为0h264存在一帧多个sliceNAL的情况在这种情况下如果开启可能会导致画面花屏
lowLatency=0
[rtp_proxy] [rtp_proxy]
#导出调试数据(包括rtp/ps/h264)至该目录,置空则关闭数据导出 #导出调试数据(包括rtp/ps/h264)至该目录,置空则关闭数据导出
@ -352,7 +354,8 @@ keepAliveSecond=15
port=554 port=554
#rtsps服务器监听地址 #rtsps服务器监听地址
sslport=0 sslport=0
#rtsp 转发是否使用低延迟模式当开启时不会缓存rtp包来提高并发可以降低一帧的延迟
lowLatency=0
[shell] [shell]
#调试telnet服务器接受最大bufffer大小 #调试telnet服务器接受最大bufffer大小
maxReqSize=1024 maxReqSize=1024

View File

@ -398,6 +398,12 @@ private:
//但是却对性能提升很大,这样做还是比较划算的 //但是却对性能提升很大,这样做还是比较划算的
GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS); GET_CONFIG(int, mergeWriteMS, General::kMergeWriteMS);
GET_CONFIG(int, rtspLowLatency, Rtsp::KLowLatency);
if(std::is_same<packet, RtpPacket>::value && rtspLowLatency){
return true;
}
return std::is_same<packet, RtpPacket>::value ? false : (mergeWriteMS <= 0); return std::is_same<packet, RtpPacket>::value ? false : (mergeWriteMS <= 0);
} }

View File

@ -173,6 +173,7 @@ const string kAuthBasic = RTSP_FIELD "authBasic";
const string kHandshakeSecond = RTSP_FIELD "handshakeSecond"; const string kHandshakeSecond = RTSP_FIELD "handshakeSecond";
const string kKeepAliveSecond = RTSP_FIELD "keepAliveSecond"; const string kKeepAliveSecond = RTSP_FIELD "keepAliveSecond";
const string kDirectProxy = RTSP_FIELD "directProxy"; const string kDirectProxy = RTSP_FIELD "directProxy";
const string KLowLatency = RTSP_FIELD"lowLatency";
static onceToken token([]() { static onceToken token([]() {
// 默认Md5方式认证 // 默认Md5方式认证
@ -180,6 +181,7 @@ static onceToken token([]() {
mINI::Instance()[kHandshakeSecond] = 15; mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15; mINI::Instance()[kKeepAliveSecond] = 15;
mINI::Instance()[kDirectProxy] = 1; mINI::Instance()[kDirectProxy] = 1;
mINI::Instance()[KLowLatency] = 0;
}); });
} // namespace Rtsp } // namespace Rtsp
@ -206,10 +208,14 @@ const string kAudioMtuSize = RTP_FIELD "audioMtuSize";
// rtp包最大长度限制单位是KB // rtp包最大长度限制单位是KB
const string kRtpMaxSize = RTP_FIELD "rtpMaxSize"; const string kRtpMaxSize = RTP_FIELD "rtpMaxSize";
const string KLowLatency = RTP_FIELD "lowLatency";
static onceToken token([]() { static onceToken token([]() {
mINI::Instance()[kVideoMtuSize] = 1400; mINI::Instance()[kVideoMtuSize] = 1400;
mINI::Instance()[kAudioMtuSize] = 600; mINI::Instance()[kAudioMtuSize] = 600;
mINI::Instance()[kRtpMaxSize] = 10; mINI::Instance()[kRtpMaxSize] = 10;
mINI::Instance()[KLowLatency] = 0;
}); });
} // namespace Rtp } // namespace Rtp

View File

@ -251,6 +251,9 @@ extern const std::string kKeepAliveSecond;
// 假定您的拉流源地址不是264或265或AAC那么你可以使用直接代理的方式来支持rtsp代理 // 假定您的拉流源地址不是264或265或AAC那么你可以使用直接代理的方式来支持rtsp代理
// 默认开启rtsp直接代理rtmp由于没有这些问题是强制开启直接代理的 // 默认开启rtsp直接代理rtmp由于没有这些问题是强制开启直接代理的
extern const std::string kDirectProxy; extern const std::string kDirectProxy;
// rtsp 转发是否使用低延迟模式当开启时不会缓存rtp包来提高并发可以降低一帧的延迟
extern const std::string KLowLatency;
} // namespace Rtsp } // namespace Rtsp
////////////RTMP服务器配置/////////// ////////////RTMP服务器配置///////////
@ -271,6 +274,8 @@ extern const std::string kVideoMtuSize;
extern const std::string kAudioMtuSize; extern const std::string kAudioMtuSize;
// rtp包最大长度限制, 单位KB // rtp包最大长度限制, 单位KB
extern const std::string kRtpMaxSize; extern const std::string kRtpMaxSize;
// rtp 打包时低延迟开关默认关闭为0h264存在一帧多个sliceNAL的情况在这种情况下如果开启可能会导致画面花屏
extern const std::string KLowLatency;
} // namespace Rtp } // namespace Rtp
////////////组播配置/////////// ////////////组播配置///////////

View File

@ -283,11 +283,19 @@ bool H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
default: break; default: break;
} }
if (_last_frame) { GET_CONFIG(int,lowLatency,Rtp::KLowLatency);
//如果时间戳发生了变化那么markbit才置true if (lowLatency) { // 低延迟模式
inputFrame_l(_last_frame, _last_frame->pts() != frame->pts()); if (_last_frame) {
flush();
}
inputFrame_l(frame, true);
} else {
if (_last_frame) {
//如果时间戳发生了变化那么markbit才置true
inputFrame_l(_last_frame, _last_frame->pts() != frame->pts());
}
_last_frame = Frame::getCacheAbleFrame(frame);
} }
_last_frame = Frame::getCacheAbleFrame(frame);
return true; return true;
} }