Cleanup RtcpReceiver::TMMBRReceived function
BUG=webrtc:951 Review-Url: https://codereview.webrtc.org/2250633002 Cr-Commit-Position: refs/heads/master@{#13786}
This commit is contained in:
@ -1234,17 +1234,11 @@ void RTCPReceiver::HandleTransportFeedback(
|
||||
|
||||
rtcp_parser->Iterate();
|
||||
}
|
||||
|
||||
int32_t RTCPReceiver::UpdateTMMBR() {
|
||||
int32_t size = TMMBRReceived(0, 0, NULL);
|
||||
TMMBRSet candidates;
|
||||
if (size > 0) {
|
||||
candidates.reserve(size);
|
||||
// Get candidate set from receiver.
|
||||
TMMBRReceived(size, 0, &candidates);
|
||||
}
|
||||
// Find bounding set
|
||||
std::vector<rtcp::TmmbItem> bounding =
|
||||
TMMBRHelp::FindBoundingSet(std::move(candidates));
|
||||
TMMBRHelp::FindBoundingSet(TMMBRReceived());
|
||||
// Set bounding set
|
||||
// Inform remote clients about the new bandwidth
|
||||
// inform the remote client
|
||||
@ -1399,44 +1393,18 @@ int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// no callbacks allowed inside this function
|
||||
int32_t RTCPReceiver::TMMBRReceived(uint32_t size,
|
||||
uint32_t accNumCandidates,
|
||||
TMMBRSet* candidateSet) const {
|
||||
std::vector<rtcp::TmmbItem> RTCPReceiver::TMMBRReceived() const {
|
||||
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
||||
std::vector<rtcp::TmmbItem> candidates;
|
||||
|
||||
std::map<uint32_t, RTCPReceiveInformation*>::const_iterator
|
||||
receiveInfoIt = _receivedInfoMap.begin();
|
||||
if (receiveInfoIt == _receivedInfoMap.end()) {
|
||||
return -1;
|
||||
int64_t now_ms = _clock->TimeInMilliseconds();
|
||||
|
||||
for (const auto& kv : _receivedInfoMap) {
|
||||
RTCPReceiveInformation* receive_info = kv.second;
|
||||
RTC_DCHECK(receive_info);
|
||||
receive_info->GetTMMBRSet(now_ms, &candidates);
|
||||
}
|
||||
uint32_t num = accNumCandidates;
|
||||
if (candidateSet) {
|
||||
while( num < size && receiveInfoIt != _receivedInfoMap.end()) {
|
||||
RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
|
||||
if (receiveInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
for (uint32_t i = 0;
|
||||
(num < size) && (i < receiveInfo->TmmbrSet.lengthOfSet()); i++) {
|
||||
if (receiveInfo->GetTMMBRSet(i, num, candidateSet,
|
||||
_clock->TimeInMilliseconds()) == 0) {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
receiveInfoIt++;
|
||||
}
|
||||
} else {
|
||||
while (receiveInfoIt != _receivedInfoMap.end()) {
|
||||
RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
|
||||
if(receiveInfo == NULL) {
|
||||
return -1;
|
||||
}
|
||||
num += receiveInfo->TmmbrSet.lengthOfSet();
|
||||
receiveInfoIt++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
return candidates;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -92,9 +92,7 @@ public:
|
||||
bool RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms);
|
||||
|
||||
// Get TMMBR
|
||||
int32_t TMMBRReceived(uint32_t size,
|
||||
uint32_t accNumCandidates,
|
||||
TMMBRSet* candidateSet) const;
|
||||
std::vector<rtcp::TmmbItem> TMMBRReceived() const;
|
||||
|
||||
bool UpdateRTCPReceiveInformationTimers();
|
||||
|
||||
|
||||
@ -159,30 +159,23 @@ void RTCPReceiveInformation::InsertTMMBRItem(
|
||||
_tmmbrSetTimeouts.push_back(currentTimeMS);
|
||||
}
|
||||
|
||||
int32_t RTCPReceiveInformation::GetTMMBRSet(
|
||||
const uint32_t sourceIdx,
|
||||
const uint32_t targetIdx,
|
||||
TMMBRSet* candidateSet,
|
||||
const int64_t currentTimeMS) {
|
||||
if (sourceIdx >= TmmbrSet.lengthOfSet()) {
|
||||
return -1;
|
||||
}
|
||||
if (targetIdx >= candidateSet->sizeOfSet()) {
|
||||
return -1;
|
||||
}
|
||||
// use audio define since we don't know what interval the remote peer is using
|
||||
if (currentTimeMS - _tmmbrSetTimeouts[sourceIdx] >
|
||||
void RTCPReceiveInformation::GetTMMBRSet(
|
||||
int64_t current_time_ms,
|
||||
std::vector<rtcp::TmmbItem>* candidates) {
|
||||
// Erase timeout entries.
|
||||
for (size_t source_idx = 0; source_idx < TmmbrSet.size();) {
|
||||
// Use audio define since we don't know what interval the remote peer is
|
||||
// using.
|
||||
if (current_time_ms - _tmmbrSetTimeouts[source_idx] >
|
||||
5 * RTCP_INTERVAL_AUDIO_MS) {
|
||||
// value timed out
|
||||
TmmbrSet.RemoveEntry(sourceIdx);
|
||||
_tmmbrSetTimeouts.erase(_tmmbrSetTimeouts.begin() + sourceIdx);
|
||||
return -1;
|
||||
// Value timed out.
|
||||
TmmbrSet.erase(TmmbrSet.begin() + source_idx);
|
||||
_tmmbrSetTimeouts.erase(_tmmbrSetTimeouts.begin() + source_idx);
|
||||
continue;
|
||||
}
|
||||
candidates->push_back(TmmbrSet[source_idx]);
|
||||
++source_idx;
|
||||
}
|
||||
candidateSet->SetEntry(targetIdx,
|
||||
TmmbrSet.Tmmbr(sourceIdx),
|
||||
TmmbrSet.PacketOH(sourceIdx),
|
||||
TmmbrSet.Ssrc(sourceIdx));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RTCPReceiveInformation::VerifyAndAllocateBoundingSet(
|
||||
|
||||
@ -109,10 +109,8 @@ public:
|
||||
const int64_t currentTimeMS);
|
||||
|
||||
// get
|
||||
int32_t GetTMMBRSet(const uint32_t sourceIdx,
|
||||
const uint32_t targetIdx,
|
||||
TMMBRSet* candidateSet,
|
||||
const int64_t currentTimeMS);
|
||||
void GetTMMBRSet(int64_t current_time_ms,
|
||||
std::vector<rtcp::TmmbItem>* candidates);
|
||||
|
||||
int64_t lastTimeReceived;
|
||||
|
||||
|
||||
@ -1033,7 +1033,7 @@ TEST_F(RtcpReceiverTest, ReceiveReportTimeout) {
|
||||
|
||||
TEST_F(RtcpReceiverTest, TmmbrReceivedWithNoIncomingPacket) {
|
||||
// This call is expected to fail because no data has arrived.
|
||||
EXPECT_EQ(-1, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
EXPECT_EQ(0u, rtcp_receiver_->TMMBRReceived().size());
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, TmmbrPacketAccepted) {
|
||||
@ -1055,12 +1055,10 @@ TEST_F(RtcpReceiverTest, TmmbrPacketAccepted) {
|
||||
rtc::Buffer packet = compound.Build();
|
||||
EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
|
||||
|
||||
EXPECT_EQ(1, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
TMMBRSet candidate_set;
|
||||
candidate_set.VerifyAndAllocateSet(1);
|
||||
EXPECT_EQ(1, rtcp_receiver_->TMMBRReceived(1, 0, &candidate_set));
|
||||
EXPECT_LT(0U, candidate_set.Tmmbr(0));
|
||||
EXPECT_EQ(kSenderSsrc, candidate_set.Ssrc(0));
|
||||
std::vector<rtcp::TmmbItem> candidate_set = rtcp_receiver_->TMMBRReceived();
|
||||
EXPECT_EQ(1u, candidate_set.size());
|
||||
EXPECT_LT(0U, candidate_set[0].bitrate_bps());
|
||||
EXPECT_EQ(kSenderSsrc, candidate_set[0].ssrc());
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, TmmbrPacketNotForUsIgnored) {
|
||||
@ -1083,7 +1081,7 @@ TEST_F(RtcpReceiverTest, TmmbrPacketNotForUsIgnored) {
|
||||
ssrcs.insert(kMediaFlowSsrc);
|
||||
rtcp_receiver_->SetSsrcs(kMediaFlowSsrc, ssrcs);
|
||||
EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
|
||||
EXPECT_EQ(0, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
EXPECT_EQ(0u, rtcp_receiver_->TMMBRReceived().size());
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, TmmbrPacketZeroRateIgnored) {
|
||||
@ -1105,7 +1103,7 @@ TEST_F(RtcpReceiverTest, TmmbrPacketZeroRateIgnored) {
|
||||
rtc::Buffer packet = compound.Build();
|
||||
|
||||
EXPECT_EQ(0, InjectRtcpPacket(packet.data(), packet.size()));
|
||||
EXPECT_EQ(0, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
EXPECT_EQ(0u, rtcp_receiver_->TMMBRReceived().size());
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, TmmbrThreeConstraintsTimeOut) {
|
||||
@ -1133,18 +1131,15 @@ TEST_F(RtcpReceiverTest, TmmbrThreeConstraintsTimeOut) {
|
||||
system_clock_.AdvanceTimeMilliseconds(5000);
|
||||
}
|
||||
// It is now starttime + 15.
|
||||
EXPECT_EQ(3, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
TMMBRSet candidate_set;
|
||||
candidate_set.VerifyAndAllocateSet(3);
|
||||
EXPECT_EQ(3, rtcp_receiver_->TMMBRReceived(3, 0, &candidate_set));
|
||||
EXPECT_LT(0U, candidate_set.Tmmbr(0));
|
||||
std::vector<rtcp::TmmbItem> candidate_set = rtcp_receiver_->TMMBRReceived();
|
||||
EXPECT_EQ(3u, candidate_set.size());
|
||||
EXPECT_LT(0U, candidate_set[0].bitrate_bps());
|
||||
// We expect the timeout to be 25 seconds. Advance the clock by 12
|
||||
// seconds, timing out the first packet.
|
||||
system_clock_.AdvanceTimeMilliseconds(12000);
|
||||
// Odd behaviour: Just counting them does not trigger the timeout.
|
||||
EXPECT_EQ(3, rtcp_receiver_->TMMBRReceived(0, 0, nullptr));
|
||||
EXPECT_EQ(2, rtcp_receiver_->TMMBRReceived(3, 0, &candidate_set));
|
||||
EXPECT_EQ(kSenderSsrc + 1, candidate_set.Ssrc(0));
|
||||
candidate_set = rtcp_receiver_->TMMBRReceived();
|
||||
EXPECT_EQ(2u, candidate_set.size());
|
||||
EXPECT_EQ(kSenderSsrc + 1, candidate_set[0].ssrc());
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, Callbacks) {
|
||||
|
||||
Reference in New Issue
Block a user