diff --git a/pc/srtpsession.cc b/pc/srtpsession.cc index a5fda8897f..aadd4711a5 100644 --- a/pc/srtpsession.cc +++ b/pc/srtpsession.cc @@ -138,7 +138,15 @@ bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) { *out_len = in_len; int err = srtp_unprotect(session_, p, out_len); if (err != srtp_err_status_ok) { - RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err; + // Limit the error logging to avoid excessive logs when there are lots of + // bad packets. + const int kFailureLogThrottleCount = 100; + if (decryption_failure_count_ % kFailureLogThrottleCount == 0) { + RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err + << ", previous failure count: " + << decryption_failure_count_; + } + ++decryption_failure_count_; RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.SrtpUnprotectError", static_cast(err), kSrtpErrorCodeBoundary); return false; diff --git a/pc/srtpsession.h b/pc/srtpsession.h index c3a01bd139..ce05ce6d72 100644 --- a/pc/srtpsession.h +++ b/pc/srtpsession.h @@ -122,6 +122,7 @@ class SrtpSession { int last_send_seq_num_ = -1; bool external_auth_active_ = false; bool external_auth_enabled_ = false; + int decryption_failure_count_ = 0; RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); }; diff --git a/pc/srtptransport.cc b/pc/srtptransport.cc index 6fd8be37c2..8f9de67146 100644 --- a/pc/srtptransport.cc +++ b/pc/srtptransport.cc @@ -207,8 +207,17 @@ void SrtpTransport::OnRtpPacketReceived(rtc::CopyOnWriteBuffer* packet, uint32_t ssrc = 0; cricket::GetRtpSeqNum(data, len, &seq_num); cricket::GetRtpSsrc(data, len, &ssrc); - RTC_LOG(LS_ERROR) << "Failed to unprotect RTP packet: size=" << len - << ", seqnum=" << seq_num << ", SSRC=" << ssrc; + + // Limit the error logging to avoid excessive logs when there are lots of + // bad packets. + const int kFailureLogThrottleCount = 100; + if (decryption_failure_count_ % kFailureLogThrottleCount == 0) { + RTC_LOG(LS_ERROR) << "Failed to unprotect RTP packet: size=" << len + << ", seqnum=" << seq_num << ", SSRC=" << ssrc + << ", previous failure count: " + << decryption_failure_count_; + } + ++decryption_failure_count_; return; } packet->SetSize(len); diff --git a/pc/srtptransport.h b/pc/srtptransport.h index 198024f5a5..70829d45e0 100644 --- a/pc/srtptransport.h +++ b/pc/srtptransport.h @@ -160,6 +160,8 @@ class SrtpTransport : public RtpTransport { bool external_auth_enabled_ = false; int rtp_abs_sendtime_extn_id_ = -1; + + int decryption_failure_count_ = 0; }; } // namespace webrtc