Move helpers to parse base rtp packet fields to rtp_rtcp module

rtp_rtcp_format is lighter build target than rtc_media_base and
a more natural place to keep rtp parsing functions.

Bug: None
Change-Id: Ibcb5661cc65edbdc89a63f3e411d7ad1218353cc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226330
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34504}
This commit is contained in:
Danil Chapovalov
2021-07-19 13:20:46 +00:00
committed by WebRTC LUCI CQ
parent 4261a73b56
commit 99a71f49c0
14 changed files with 167 additions and 273 deletions

View File

@ -13,7 +13,8 @@
#include <iomanip>
#include "absl/base/attributes.h"
#include "media/base/rtp_utils.h"
#include "api/array_view.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "pc/external_hmac.h"
#include "rtc_base/logging.h"
#include "rtc_base/ssl_stream_adapter.h"
@ -26,6 +27,8 @@
namespace cricket {
using ::webrtc::ParseRtpSequenceNumber;
// One more than the maximum libsrtp error code. Required by
// RTC_HISTOGRAM_ENUMERATION. Keep this in sync with srtp_error_status_t defined
// in srtp.h.
@ -96,8 +99,8 @@ bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) {
*out_len = in_len;
int err = srtp_protect(session_, p, out_len);
int seq_num;
GetRtpSeqNum(p, in_len, &seq_num);
int seq_num = ParseRtpSequenceNumber(
rtc::MakeArrayView(reinterpret_cast<const uint8_t*>(p), in_len));
if (err != srtp_err_status_ok) {
RTC_LOG(LS_WARNING) << "Failed to protect SRTP packet, seqnum=" << seq_num
<< ", err=" << err

View File

@ -18,6 +18,7 @@
#include "absl/strings/match.h"
#include "media/base/rtp_utils.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "pc/rtp_transport.h"
#include "pc/srtp_session.h"
#include "rtc_base/async_packet_socket.h"
@ -160,10 +161,8 @@ bool SrtpTransport::SendRtpPacket(rtc::CopyOnWriteBuffer* packet,
}
#endif
if (!res) {
int seq_num = -1;
uint32_t ssrc = 0;
cricket::GetRtpSeqNum(data, len, &seq_num);
cricket::GetRtpSsrc(data, len, &ssrc);
uint16_t seq_num = ParseRtpSequenceNumber(*packet);
uint32_t ssrc = ParseRtpSsrc(*packet);
RTC_LOG(LS_ERROR) << "Failed to protect RTP packet: size=" << len
<< ", seqnum=" << seq_num << ", SSRC=" << ssrc;
return false;
@ -210,17 +209,13 @@ void SrtpTransport::OnRtpPacketReceived(rtc::CopyOnWriteBuffer packet,
char* data = packet.MutableData<char>();
int len = rtc::checked_cast<int>(packet.size());
if (!UnprotectRtp(data, len, &len)) {
int seq_num = -1;
uint32_t ssrc = 0;
cricket::GetRtpSeqNum(data, len, &seq_num);
cricket::GetRtpSsrc(data, len, &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
<< ", seqnum=" << ParseRtpSequenceNumber(packet)
<< ", SSRC=" << ParseRtpSsrc(packet)
<< ", previous failure count: "
<< decryption_failure_count_;
}