diff --git a/webrtc/Nack.cpp b/webrtc/Nack.cpp index d2447f7a..a5269996 100644 --- a/webrtc/Nack.cpp +++ b/webrtc/Nack.cpp @@ -192,7 +192,7 @@ uint64_t NackContext::reSendNack() { it = _nack_send_status.erase(it); continue; } - if (now - it->second.update_stamp < 2 * _rtt) { + if (now - it->second.update_stamp < kNackIntervalRatio * _rtt) { //距离上次nack不足2倍的rtt,不用再发送nack ++it; continue; diff --git a/webrtc/Nack.h b/webrtc/Nack.h index e6d01093..6d987bfd 100644 --- a/webrtc/Nack.h +++ b/webrtc/Nack.h @@ -39,11 +39,13 @@ public: using Ptr = std::shared_ptr; using onNack = function; //最大保留的rtp丢包状态个数 - static constexpr auto kNackMaxSize = 100; + static constexpr auto kNackMaxSize = 1024; //rtp丢包状态最长保留时间 static constexpr auto kNackMaxMS = 3 * 1000; //nack最多请求重传10次 static constexpr auto kNackMaxCount = 10; + //nack重传频率,rtt的倍数 + static constexpr auto kNackIntervalRatio = 2.0f; NackContext() = default; ~NackContext() = default; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 7d40cbeb..8ba3a252 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -97,12 +97,7 @@ void WebRtcTransport::OnDtlsTransportConnected( std::string &remoteCert) { InfoL; _srtp_session_send = std::make_shared(RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen); - - string srtpRemoteKey_str((char *) srtpRemoteKey, srtpRemoteKeyLen); - _srtp_session_recv_alloc = [srtpCryptoSuite, srtpRemoteKey_str]() { - return std::make_shared(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, - (uint8_t *) srtpRemoteKey_str.data(), srtpRemoteKey_str.size()); - }; + _srtp_session_recv = std::make_shared(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, srtpRemoteKey, srtpRemoteKeyLen); onStartWebRTC(); } @@ -255,19 +250,14 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple * _dtls_transport->ProcessDtlsData((uint8_t *) buf, len); return; } - RtpHeader *rtp = (RtpHeader *) buf; - auto it = _srtp_session_recv.find(rtp->pt); - if (it == _srtp_session_recv.end()) { - it = _srtp_session_recv.emplace((uint8_t) rtp->pt, _srtp_session_recv_alloc()).first; - } if (is_rtp(buf)) { - if (it->second->DecryptSrtp((uint8_t *) buf, &len)) { + if (_srtp_session_recv->DecryptSrtp((uint8_t *) buf, &len)) { onRtp(buf, len); } return; } if (is_rtcp(buf)) { - if (it->second->DecryptSrtcp((uint8_t *) buf, &len)) { + if (_srtp_session_recv->DecryptSrtcp((uint8_t *) buf, &len)) { onRtcp(buf, len); } return; diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index ba87729b..30ba2f95 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -122,10 +122,9 @@ private: std::shared_ptr _ice_server; std::shared_ptr _dtls_transport; std::shared_ptr _srtp_session_send; + std::shared_ptr _srtp_session_recv; RtcSession::Ptr _offer_sdp; RtcSession::Ptr _answer_sdp; - function() > _srtp_session_recv_alloc; - std::unordered_map > _srtp_session_recv; }; class RtpChannel;