diff --git a/conf/config.ini b/conf/config.ini index 899e57b8..cc141882 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -201,6 +201,8 @@ sslport=19350 audioMtuSize=600 #视频mtu大小,该参数限制rtp最大字节数,推荐不要超过1400 videoMtuSize=1400 +#rtp包最大长度限制,可以降低内存分配,单位k +rtpMaxSize=10 [rtp_proxy] #导出调试数据(包括rtp/ps/h264)至该目录,置空则关闭数据导出 diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 42630146..72760a8b 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -192,10 +192,13 @@ namespace Rtp { //RTP打包最大MTU,公网情况下更小 const string kVideoMtuSize = RTP_FIELD"videoMtuSize"; const string kAudioMtuSize = RTP_FIELD"audioMtuSize"; +//rtp包最大长度限制,单位是k +const string kRtpMaxSize = RTP_FIELD"rtpMaxSize"; onceToken token([](){ mINI::Instance()[kVideoMtuSize] = 1400; mINI::Instance()[kAudioMtuSize] = 600; + mINI::Instance()[kRtpMaxSize] = 10; },nullptr); } //namespace Rtsp diff --git a/src/Common/config.h b/src/Common/config.h index 1a22cf81..f3bf2d18 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -228,6 +228,8 @@ namespace Rtp { extern const string kVideoMtuSize; //RTP打包最大MTU,公网情况下更小 extern const string kAudioMtuSize; +//rtp包最大长度限制, 单位k +extern const string kRtpMaxSize; } //namespace Rtsp ////////////组播配置/////////// diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index c685114c..57a511e4 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -83,7 +83,8 @@ void RtpSession::onRtpPacket(const char *data, size_t len) { } return; } - if (len > 1024 * 10) { + GET_CONFIG(uint32_t, rtpMaxSize, Rtp::kRtpMaxSize); + if (len > 1024 * rtpMaxSize) { _search_rtp = true; WarnL << "rtp包长度异常(" << len << "),发送端可能缓存溢出并覆盖,开始搜索ssrc以便恢复上下文"; return; diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index 64639b8d..643cbd9a 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -11,8 +11,6 @@ #include "Common/config.h" #include "RtpReceiver.h" -#define RTP_MAX_SIZE (10 * 1024) - namespace mediakit { RtpTrack::RtpTrack() { @@ -36,8 +34,9 @@ RtpPacket::Ptr RtpTrack::inputRtp(TrackType type, int sample_rate, uint8_t *ptr, WarnL << "rtp包太小:" << len; return nullptr; } - if (len > RTP_MAX_SIZE) { - WarnL << "超大的rtp包:" << len << " > " << RTP_MAX_SIZE; + GET_CONFIG(uint32_t, rtpMaxSize, Rtp::kRtpMaxSize); + if (len > 1024 * rtpMaxSize) { + WarnL << "超大的rtp包:" << len << " > " << 1024 * rtpMaxSize; return nullptr; } if (!sample_rate) { diff --git a/tests/test_rtp.cpp b/tests/test_rtp.cpp index 2312d835..c14dabf0 100644 --- a/tests/test_rtp.cpp +++ b/tests/test_rtp.cpp @@ -36,7 +36,7 @@ static bool loadFile(const char *path){ uint32_t timeStamp_last = 0; uint16_t len; - char rtp[2 * 1024]; + char rtp[50 * 1024]; struct sockaddr addr = {0}; auto sock = Socket::createSocket(); size_t total_size = 0;