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