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

View File

@ -17,6 +17,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/array_view.h"
#include "modules/rtp_rtcp/include/report_block_data.h" #include "modules/rtp_rtcp/include/report_block_data.h"
#include "modules/rtp_rtcp/include/rtcp_statistics.h" #include "modules/rtp_rtcp/include/rtcp_statistics.h"
#include "modules/rtp_rtcp/include/rtp_rtcp.h" #include "modules/rtp_rtcp/include/rtp_rtcp.h"
@ -37,7 +38,7 @@ class TargetBitrate;
class TmmbItem; class TmmbItem;
} // namespace rtcp } // namespace rtcp
class RTCPReceiver { class RTCPReceiver final {
public: public:
class ModuleRtpRtcp { class ModuleRtpRtcp {
public: public:
@ -53,9 +54,12 @@ class RTCPReceiver {
}; };
RTCPReceiver(const RtpRtcp::Configuration& config, ModuleRtpRtcp* owner); RTCPReceiver(const RtpRtcp::Configuration& config, ModuleRtpRtcp* owner);
virtual ~RTCPReceiver(); ~RTCPReceiver();
void IncomingPacket(const uint8_t* packet, size_t packet_size); void IncomingPacket(const uint8_t* packet, size_t packet_size) {
IncomingPacket(rtc::MakeArrayView(packet, packet_size));
}
void IncomingPacket(rtc::ArrayView<const uint8_t> packet);
int64_t LastReceivedReportBlockMs() const; int64_t LastReceivedReportBlockMs() const;
@ -124,8 +128,7 @@ class RTCPReceiver {
// RTCP report blocks map mapped by source SSRC. // RTCP report blocks map mapped by source SSRC.
using ReportBlockMap = std::map<uint32_t, ReportBlockDataMap>; using ReportBlockMap = std::map<uint32_t, ReportBlockDataMap>;
bool ParseCompoundPacket(const uint8_t* packet_begin, bool ParseCompoundPacket(rtc::ArrayView<const uint8_t> packet,
const uint8_t* packet_end,
PacketInformation* packet_information); PacketInformation* packet_information);
void TriggerCallbacksFromRtcpPacket( void TriggerCallbacksFromRtcpPacket(

File diff suppressed because it is too large Load Diff