Move RTCPHelp::RTCPReportBlockInformation into RTCPReceiver

removing RTCPHelp namespace and rtcp_receiver_help files,
cleaning style of the ReportBlockInformation usage.

BUG=webrtc:5565

Review-Url: https://codereview.webrtc.org/2390643002
Cr-Commit-Position: refs/heads/master@{#14527}
This commit is contained in:
danilchap 2016-10-05 06:59:44 -07:00 committed by Commit bot
parent 62b1c35d30
commit 28b03eb449
7 changed files with 90 additions and 233 deletions

View File

@ -98,8 +98,6 @@ rtc_static_library("rtp_rtcp") {
"source/rtcp_packet/voip_metric.h",
"source/rtcp_receiver.cc",
"source/rtcp_receiver.h",
"source/rtcp_receiver_help.cc",
"source/rtcp_receiver_help.h",
"source/rtcp_sender.cc",
"source/rtcp_sender.h",
"source/rtcp_utility.cc",

View File

@ -92,8 +92,6 @@
'source/rtcp_packet/voip_metric.h',
'source/rtcp_receiver.cc',
'source/rtcp_receiver.h',
'source/rtcp_receiver_help.cc',
'source/rtcp_receiver_help.h',
'source/rtcp_sender.cc',
'source/rtcp_sender.h',
'source/rtcp_utility.cc',

View File

@ -49,7 +49,6 @@ namespace {
using rtcp::CommonHeader;
using rtcp::ReportBlock;
using RTCPHelp::RTCPReportBlockInformation;
// The number of RTCP time intervals needed to trigger a timeout.
const int kRrTimeoutIntervals = 3;
@ -88,6 +87,16 @@ struct RTCPReceiver::ReceiveInformation {
std::map<uint32_t, TimedTmmbrItem> tmmbr;
};
struct RTCPReceiver::ReportBlockWithRtt {
RTCPReportBlock report_block;
int64_t last_rtt_ms = 0;
int64_t min_rtt_ms = 0;
int64_t max_rtt_ms = 0;
int64_t sum_rtt_ms = 0;
size_t num_rtts = 0;
};
RTCPReceiver::RTCPReceiver(
Clock* clock,
bool receiver_only,
@ -120,17 +129,7 @@ RTCPReceiver::RTCPReceiver(
memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
}
RTCPReceiver::~RTCPReceiver() {
ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
for (; it != _receivedReportBlockMap.end(); ++it) {
ReportBlockInfoMap* info_map = &(it->second);
while (!info_map->empty()) {
ReportBlockInfoMap::iterator it_info = info_map->begin();
delete it_info->second;
info_map->erase(it_info);
}
}
}
RTCPReceiver::~RTCPReceiver() {}
bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) {
if (packet_size == 0) {
@ -186,31 +185,38 @@ void RTCPReceiver::SetSsrcs(uint32_t main_ssrc,
}
}
int32_t RTCPReceiver::RTT(uint32_t remoteSSRC,
int64_t* RTT,
int64_t* avgRTT,
int64_t* minRTT,
int64_t* maxRTT) const {
int32_t RTCPReceiver::RTT(uint32_t remote_ssrc,
int64_t* last_rtt_ms,
int64_t* avg_rtt_ms,
int64_t* min_rtt_ms,
int64_t* max_rtt_ms) const {
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
RTCPReportBlockInformation* reportBlock =
GetReportBlockInformation(remoteSSRC, main_ssrc_);
if (reportBlock == NULL) {
auto it = received_report_blocks_.find(main_ssrc_);
if (it == received_report_blocks_.end())
return -1;
}
if (RTT) {
*RTT = reportBlock->RTT;
}
if (avgRTT) {
*avgRTT = reportBlock->avgRTT;
}
if (minRTT) {
*minRTT = reportBlock->minRTT;
}
if (maxRTT) {
*maxRTT = reportBlock->maxRTT;
}
auto it_info = it->second.find(remote_ssrc);
if (it_info == it->second.end())
return -1;
const ReportBlockWithRtt* report_block = &it_info->second;
if (report_block->num_rtts == 0)
return -1;
if (last_rtt_ms)
*last_rtt_ms = report_block->last_rtt_ms;
if (avg_rtt_ms)
*avg_rtt_ms = report_block->sum_rtt_ms / report_block->num_rtts;
if (min_rtt_ms)
*min_rtt_ms = report_block->min_rtt_ms;
if (max_rtt_ms)
*max_rtt_ms = report_block->max_rtt_ms;
return 0;
}
@ -292,20 +298,14 @@ int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const {
return 0;
}
// statistics
// we can get multiple receive reports when we receive the report from a CE
// We can get multiple receive reports when we receive the report from a CE.
int32_t RTCPReceiver::StatisticsReceived(
std::vector<RTCPReportBlock>* receiveBlocks) const {
assert(receiveBlocks);
std::vector<RTCPReportBlock>* receive_blocks) const {
RTC_DCHECK(receive_blocks);
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin();
for (; it != _receivedReportBlockMap.end(); ++it) {
const ReportBlockInfoMap* info_map = &(it->second);
ReportBlockInfoMap::const_iterator it_info = info_map->begin();
for (; it_info != info_map->end(); ++it_info) {
receiveBlocks->push_back(it_info->second->remoteReceiveBlock);
}
}
for (const auto& reports_per_receiver : received_report_blocks_)
for (const auto& report : reports_per_receiver.second)
receive_blocks->push_back(report.second.report_block);
return 0;
}
@ -481,51 +481,43 @@ void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block,
void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
PacketInformation* packet_information,
uint32_t remoteSSRC) {
uint32_t remote_ssrc) {
// This will be called once per report block in the RTCP packet.
// We filter out all report blocks that are not for us.
// Each packet has max 31 RR blocks.
//
// We can calc RTT if we send a send report and get a report block back.
// |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to
// |report_block.source_ssrc()| is the SSRC identifier of the source to
// which the information in this reception report block pertains.
// Filter out all report blocks that are not for us.
if (registered_ssrcs_.count(report_block.source_ssrc()) == 0)
return;
RTCPReportBlockInformation* reportBlock =
CreateOrGetReportBlockInformation(remoteSSRC, report_block.source_ssrc());
if (reportBlock == NULL) {
LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" << remoteSSRC
<< ")";
return;
}
ReportBlockWithRtt* report_block_info =
&received_report_blocks_[report_block.source_ssrc()][remote_ssrc];
_lastReceivedRrMs = _clock->TimeInMilliseconds();
reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC;
reportBlock->remoteReceiveBlock.sourceSSRC = report_block.source_ssrc();
reportBlock->remoteReceiveBlock.fractionLost = report_block.fraction_lost();
reportBlock->remoteReceiveBlock.cumulativeLost =
report_block_info->report_block.remoteSSRC = remote_ssrc;
report_block_info->report_block.sourceSSRC = report_block.source_ssrc();
report_block_info->report_block.fractionLost = report_block.fraction_lost();
report_block_info->report_block.cumulativeLost =
report_block.cumulative_lost();
if (report_block.extended_high_seq_num() >
reportBlock->remoteReceiveBlock.extendedHighSeqNum) {
report_block_info->report_block.extendedHighSeqNum) {
// We have successfully delivered new RTP packets to the remote side after
// the last RR was sent from the remote side.
_lastIncreasedSequenceNumberMs = _lastReceivedRrMs;
}
reportBlock->remoteReceiveBlock.extendedHighSeqNum =
report_block_info->report_block.extendedHighSeqNum =
report_block.extended_high_seq_num();
reportBlock->remoteReceiveBlock.jitter = report_block.jitter();
reportBlock->remoteReceiveBlock.delaySinceLastSR =
report_block_info->report_block.jitter = report_block.jitter();
report_block_info->report_block.delaySinceLastSR =
report_block.delay_since_last_sr();
reportBlock->remoteReceiveBlock.lastSR = report_block.last_sr();
report_block_info->report_block.lastSR = report_block.last_sr();
if (report_block.jitter() > reportBlock->remoteMaxJitter)
reportBlock->remoteMaxJitter = report_block.jitter();
int64_t rtt = 0;
int64_t rtt_ms = 0;
uint32_t send_time = report_block.last_sr();
// RFC3550, section 6.4.1, LSR field discription states:
// If no SR has been received yet, the field is set to zero.
@ -539,66 +531,24 @@ void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
// RTT in 1/(2^16) seconds.
uint32_t rtt_ntp = receive_time - delay - send_time;
// Convert to 1/1000 seconds (milliseconds).
rtt = CompactNtpRttToMs(rtt_ntp);
if (rtt > reportBlock->maxRTT) {
// Store max RTT.
reportBlock->maxRTT = rtt;
}
if (reportBlock->minRTT == 0) {
// First RTT.
reportBlock->minRTT = rtt;
} else if (rtt < reportBlock->minRTT) {
// Store min RTT.
reportBlock->minRTT = rtt;
}
// Store last RTT.
reportBlock->RTT = rtt;
rtt_ms = CompactNtpRttToMs(rtt_ntp);
if (rtt_ms > report_block_info->max_rtt_ms)
report_block_info->max_rtt_ms = rtt_ms;
// store average RTT
if (reportBlock->numAverageCalcs != 0) {
float ac = static_cast<float>(reportBlock->numAverageCalcs);
float newAverage =
((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt);
reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f);
} else {
// First RTT.
reportBlock->avgRTT = rtt;
}
reportBlock->numAverageCalcs++;
if (report_block_info->num_rtts == 0 ||
rtt_ms < report_block_info->min_rtt_ms)
report_block_info->min_rtt_ms = rtt_ms;
report_block_info->last_rtt_ms = rtt_ms;
report_block_info->sum_rtt_ms += rtt_ms;
++report_block_info->num_rtts;
}
TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT",
report_block.source_ssrc(), rtt);
report_block.source_ssrc(), rtt_ms);
packet_information->rtt_ms = rtt;
packet_information->report_blocks.push_back(reportBlock->remoteReceiveBlock);
}
RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation(
uint32_t remote_ssrc,
uint32_t source_ssrc) {
RTCPReportBlockInformation* info =
GetReportBlockInformation(remote_ssrc, source_ssrc);
if (info == NULL) {
info = new RTCPReportBlockInformation;
_receivedReportBlockMap[source_ssrc][remote_ssrc] = info;
}
return info;
}
RTCPReportBlockInformation* RTCPReceiver::GetReportBlockInformation(
uint32_t remote_ssrc,
uint32_t source_ssrc) const {
ReportBlockMap::const_iterator it = _receivedReportBlockMap.find(source_ssrc);
if (it == _receivedReportBlockMap.end()) {
return NULL;
}
const ReportBlockInfoMap* info_map = &(it->second);
ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc);
if (it_info == info_map->end()) {
return NULL;
}
return it_info->second;
packet_information->rtt_ms = rtt_ms;
packet_information->report_blocks.push_back(report_block_info->report_block);
}
void RTCPReceiver::CreateReceiveInformation(uint32_t remote_ssrc) {
@ -737,15 +687,8 @@ void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) {
}
// clear our lists
ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
for (; it != _receivedReportBlockMap.end(); ++it) {
ReportBlockInfoMap* info_map = &(it->second);
ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc());
if (it_info != info_map->end()) {
delete it_info->second;
info_map->erase(it_info);
}
}
for (auto& reports_per_receiver : received_report_blocks_)
reports_per_receiver.second.erase(bye.sender_ssrc());
// We can't delete it due to TMMBR.
ReceiveInformation* receive_info = GetReceiveInformation(bye.sender_ssrc());

View File

@ -20,7 +20,6 @@
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/typedefs.h"
@ -76,12 +75,12 @@ class RTCPReceiver {
bool LastReceivedXrReferenceTimeInfo(rtcp::ReceiveTimeInfo* info) const;
// get rtt
int32_t RTT(uint32_t remoteSSRC,
int64_t* RTT,
int64_t* avgRTT,
int64_t* minRTT,
int64_t* maxRTT) const;
// Get rtt.
int32_t RTT(uint32_t remote_ssrc,
int64_t* last_rtt_ms,
int64_t* avg_rtt_ms,
int64_t* min_rtt_ms,
int64_t* max_rtt_ms) const;
int32_t SenderInfoReceived(RTCPSenderInfo* senderInfo) const;
@ -115,12 +114,12 @@ class RTCPReceiver {
private:
struct PacketInformation;
struct ReceiveInformation;
struct ReportBlockWithRtt;
// Mapped by remote ssrc.
using ReceivedInfoMap = std::map<uint32_t, ReceiveInformation>;
// RTCP report block information mapped by remote SSRC.
using ReportBlockInfoMap =
std::map<uint32_t, RTCPHelp::RTCPReportBlockInformation*>;
// RTCP report block information map mapped by source SSRC.
// RTCP report blocks mapped by remote SSRC.
using ReportBlockInfoMap = std::map<uint32_t, ReportBlockWithRtt>;
// RTCP report blocks map mapped by source SSRC.
using ReportBlockMap = std::map<uint32_t, ReportBlockInfoMap>;
bool ParseCompoundPacket(const uint8_t* packet_begin,
@ -206,15 +205,6 @@ class RTCPReceiver {
PacketInformation* packet_information)
EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
RTCPHelp::RTCPReportBlockInformation* CreateOrGetReportBlockInformation(
uint32_t remote_ssrc,
uint32_t source_ssrc)
EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
RTCPHelp::RTCPReportBlockInformation* GetReportBlockInformation(
uint32_t remote_ssrc,
uint32_t source_ssrc) const
EXCLUSIVE_LOCKS_REQUIRED(_criticalSectionRTCPReceiver);
Clock* const _clock;
const bool receiver_only_;
ModuleRtpRtcp& _rtpRtcp;
@ -245,7 +235,7 @@ class RTCPReceiver {
int64_t xr_rr_rtt_ms_;
// Received report blocks.
ReportBlockMap _receivedReportBlockMap
ReportBlockMap received_report_blocks_
GUARDED_BY(_criticalSectionRTCPReceiver);
ReceivedInfoMap received_infos_ GUARDED_BY(_criticalSectionRTCPReceiver);
std::map<uint32_t, std::string> received_cnames_

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver_help.h"
#include <assert.h> // assert
#include <string.h> // memset
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
namespace webrtc {
namespace RTCPHelp {
RTCPReportBlockInformation::RTCPReportBlockInformation()
: remoteReceiveBlock(),
remoteMaxJitter(0),
RTT(0),
minRTT(0),
maxRTT(0),
avgRTT(0),
numAverageCalcs(0) {
memset(&remoteReceiveBlock, 0, sizeof(remoteReceiveBlock));
}
RTCPReportBlockInformation::~RTCPReportBlockInformation() {}
} // namespace RTCPHelp
} // namespace webrtc

View File

@ -1,40 +0,0 @@
/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_HELP_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_HELP_H_
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace RTCPHelp {
class RTCPReportBlockInformation {
public:
RTCPReportBlockInformation();
~RTCPReportBlockInformation();
// Statistics
RTCPReportBlock remoteReceiveBlock;
uint32_t remoteMaxJitter;
// RTT
int64_t RTT;
int64_t minRTT;
int64_t maxRTT;
int64_t avgRTT;
uint32_t numAverageCalcs;
};
} // end namespace RTCPHelp
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_HELP_H_

View File

@ -514,12 +514,16 @@ TEST_F(RtcpReceiverTest, InjectRrPacketsFromTwoRemoteSsrcs) {
}
TEST_F(RtcpReceiverTest, GetRtt) {
const uint32_t kSentCompactNtp = 0x1234;
const uint32_t kDelayCompactNtp = 0x222;
// No report block received.
EXPECT_EQ(
-1, rtcp_receiver_.RTT(kSenderSsrc, nullptr, nullptr, nullptr, nullptr));
rtcp::ReportBlock rb;
rb.SetMediaSsrc(kReceiverMainSsrc);
rb.SetLastSr(kSentCompactNtp);
rb.SetDelayLastSr(kDelayCompactNtp);
rtcp::ReceiverReport rr;
rr.SetSenderSsrc(kSenderSsrc);