Merge BitrateControllerImpl::RtcpBandwidthObserverImpl into BitrateControllerImpl
This allows to protect ssrc_to_last_received_extended_high_seq_num_ member and make calls to OnReceivedRtcpReceiverReport thread-safe without introducing new critical section. Bug: webrtc:7735 Change-Id: Iee23bb780d07b0f906f1f8eeddde2b74cc0a2b89 Reviewed-on: https://chromium-review.googlesource.com/518130 Reviewed-by: Stefan Holmer <stefan@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18540}
This commit is contained in:
committed by
Commit Bot
parent
42742a56ef
commit
38018ba67d
@ -12,7 +12,6 @@
|
||||
#include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
@ -28,64 +27,20 @@ class BitrateControllerImpl::RtcpBandwidthObserverImpl
|
||||
explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner)
|
||||
: owner_(owner) {
|
||||
}
|
||||
virtual ~RtcpBandwidthObserverImpl() {
|
||||
}
|
||||
~RtcpBandwidthObserverImpl() override = default;
|
||||
// Received RTCP REMB or TMMBR.
|
||||
void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
|
||||
owner_->OnReceiverEstimatedBitrate(bitrate);
|
||||
owner_->OnReceivedEstimatedBitrate(bitrate);
|
||||
}
|
||||
// Received RTCP receiver block.
|
||||
void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
|
||||
int64_t rtt,
|
||||
int64_t now_ms) override {
|
||||
if (report_blocks.empty())
|
||||
return;
|
||||
|
||||
int fraction_lost_aggregate = 0;
|
||||
int total_number_of_packets = 0;
|
||||
|
||||
// Compute the a weighted average of the fraction loss from all report
|
||||
// blocks.
|
||||
for (const RTCPReportBlock& report_block : report_blocks) {
|
||||
std::map<uint32_t, uint32_t>::iterator seq_num_it =
|
||||
ssrc_to_last_received_extended_high_seq_num_.find(
|
||||
report_block.sourceSSRC);
|
||||
|
||||
int number_of_packets = 0;
|
||||
if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) {
|
||||
number_of_packets =
|
||||
report_block.extendedHighSeqNum - seq_num_it->second;
|
||||
}
|
||||
|
||||
fraction_lost_aggregate += number_of_packets * report_block.fractionLost;
|
||||
total_number_of_packets += number_of_packets;
|
||||
|
||||
// Update last received for this SSRC.
|
||||
ssrc_to_last_received_extended_high_seq_num_[report_block.sourceSSRC] =
|
||||
report_block.extendedHighSeqNum;
|
||||
}
|
||||
if (total_number_of_packets < 0) {
|
||||
LOG(LS_WARNING) << "Received report block where extended high sequence "
|
||||
"number goes backwards, ignoring.";
|
||||
return;
|
||||
}
|
||||
if (total_number_of_packets == 0)
|
||||
fraction_lost_aggregate = 0;
|
||||
else
|
||||
fraction_lost_aggregate = (fraction_lost_aggregate +
|
||||
total_number_of_packets / 2) / total_number_of_packets;
|
||||
if (fraction_lost_aggregate > 255)
|
||||
return;
|
||||
|
||||
RTC_DCHECK_GE(total_number_of_packets, 0);
|
||||
|
||||
owner_->OnReceivedRtcpReceiverReport(fraction_lost_aggregate, rtt,
|
||||
total_number_of_packets, now_ms);
|
||||
owner_->OnReceivedRtcpReceiverReport(report_blocks, rtt, now_ms);
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_;
|
||||
BitrateControllerImpl* owner_;
|
||||
BitrateControllerImpl* const owner_;
|
||||
};
|
||||
|
||||
BitrateController* BitrateController::CreateBitrateController(
|
||||
@ -175,7 +130,7 @@ void BitrateControllerImpl::SetReservedBitrate(uint32_t reserved_bitrate_bps) {
|
||||
}
|
||||
|
||||
// This is called upon reception of REMB or TMMBR.
|
||||
void BitrateControllerImpl::OnReceiverEstimatedBitrate(uint32_t bitrate) {
|
||||
void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) {
|
||||
{
|
||||
rtc::CritScope cs(&critsect_);
|
||||
bandwidth_estimation_.UpdateReceiverEstimate(clock_->TimeInMilliseconds(),
|
||||
@ -220,14 +175,55 @@ void BitrateControllerImpl::Process() {
|
||||
}
|
||||
|
||||
void BitrateControllerImpl::OnReceivedRtcpReceiverReport(
|
||||
uint8_t fraction_loss,
|
||||
const ReportBlockList& report_blocks,
|
||||
int64_t rtt,
|
||||
int number_of_packets,
|
||||
int64_t now_ms) {
|
||||
if (report_blocks.empty())
|
||||
return;
|
||||
|
||||
{
|
||||
rtc::CritScope cs(&critsect_);
|
||||
bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt,
|
||||
number_of_packets, now_ms);
|
||||
int fraction_lost_aggregate = 0;
|
||||
int total_number_of_packets = 0;
|
||||
|
||||
// Compute the a weighted average of the fraction loss from all report
|
||||
// blocks.
|
||||
for (const RTCPReportBlock& report_block : report_blocks) {
|
||||
std::map<uint32_t, uint32_t>::iterator seq_num_it =
|
||||
ssrc_to_last_received_extended_high_seq_num_.find(
|
||||
report_block.sourceSSRC);
|
||||
|
||||
int number_of_packets = 0;
|
||||
if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) {
|
||||
number_of_packets =
|
||||
report_block.extendedHighSeqNum - seq_num_it->second;
|
||||
}
|
||||
|
||||
fraction_lost_aggregate += number_of_packets * report_block.fractionLost;
|
||||
total_number_of_packets += number_of_packets;
|
||||
|
||||
// Update last received for this SSRC.
|
||||
ssrc_to_last_received_extended_high_seq_num_[report_block.sourceSSRC] =
|
||||
report_block.extendedHighSeqNum;
|
||||
}
|
||||
if (total_number_of_packets < 0) {
|
||||
LOG(LS_WARNING) << "Received report block where extended high sequence "
|
||||
"number goes backwards, ignoring.";
|
||||
return;
|
||||
}
|
||||
if (total_number_of_packets == 0)
|
||||
fraction_lost_aggregate = 0;
|
||||
else
|
||||
fraction_lost_aggregate =
|
||||
(fraction_lost_aggregate + total_number_of_packets / 2) /
|
||||
total_number_of_packets;
|
||||
if (fraction_lost_aggregate > 255)
|
||||
return;
|
||||
|
||||
RTC_DCHECK_GE(total_number_of_packets, 0);
|
||||
|
||||
bandwidth_estimation_.UpdateReceiverBlock(fraction_lost_aggregate, rtt,
|
||||
total_number_of_packets, now_ms);
|
||||
}
|
||||
MaybeTriggerOnNetworkChanged();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user