Cleanup RtcpReceiver tests

update MOCK_METHODs to use new syntax recommended in go/totw/164
Replace fixture with struct of mocks.
Use main method under test (IncomingPacket) directly rather than through fixture helpers

minor cleanup of the RtcReceiver itself:
make IncomingPacket function more friendly to containers,
mark class as final to verify ability to inherit from it is not used and
thus destructor doesn't need to be virtual.

Bug: None
Change-Id: I346e7dc513b1fbe663ebe5858dec7df0520416a7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170226
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30765}
This commit is contained in:
Danil Chapovalov
2020-03-11 12:24:40 +01:00
committed by Commit Bot
parent 3bc8123247
commit 443f26695f
3 changed files with 666 additions and 444 deletions

View File

@ -172,14 +172,14 @@ RTCPReceiver::RTCPReceiver(const RtpRtcp::Configuration& config,
RTCPReceiver::~RTCPReceiver() {}
void RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) {
if (packet_size == 0) {
void RTCPReceiver::IncomingPacket(rtc::ArrayView<const uint8_t> packet) {
if (packet.empty()) {
RTC_LOG(LS_WARNING) << "Incoming empty RTCP packet";
return;
}
PacketInformation packet_information;
if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information))
if (!ParseCompoundPacket(packet, &packet_information))
return;
TriggerCallbacksFromRtcpPacket(packet_information);
}
@ -325,18 +325,17 @@ std::vector<ReportBlockData> RTCPReceiver::GetLatestReportBlockData() const {
return result;
}
bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin,
const uint8_t* packet_end,
bool RTCPReceiver::ParseCompoundPacket(rtc::ArrayView<const uint8_t> packet,
PacketInformation* packet_information) {
rtc::CritScope lock(&rtcp_receiver_lock_);
CommonHeader rtcp_block;
for (const uint8_t* next_block = packet_begin; next_block != packet_end;
for (const uint8_t* next_block = packet.begin(); next_block != packet.end();
next_block = rtcp_block.NextPacket()) {
ptrdiff_t remaining_blocks_size = packet_end - next_block;
ptrdiff_t remaining_blocks_size = packet.end() - next_block;
RTC_DCHECK_GT(remaining_blocks_size, 0);
if (!rtcp_block.Parse(next_block, remaining_blocks_size)) {
if (next_block == packet_begin) {
if (next_block == packet.begin()) {
// Failed to parse 1st header, nothing was extracted from this packet.
RTC_LOG(LS_WARNING) << "Incoming invalid RTCP packet";
return false;