Make CongestionController::remote_bitrate_estimator_ a non-pointer.
It was only assigned at construction, and this improves consistency with remote_estimator_proxy_. The declaration of the private WrappingBitrateEstimator had to be moved to the header file, and it was also converted from system_wrappers' CriticalSectionWrapper to rtc::CriticalSection. BUG=webrtc:6847 Review-Url: https://codereview.webrtc.org/2642363003 Cr-Commit-Position: refs/heads/master@{#16236}
This commit is contained in:
parent
d2b092f38a
commit
365aebdade
@ -23,7 +23,6 @@
|
||||
#include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
|
||||
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
|
||||
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
|
||||
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
@ -46,107 +45,96 @@ static void ClampBitrates(int* bitrate_bps,
|
||||
*bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps);
|
||||
}
|
||||
|
||||
class WrappingBitrateEstimator : public RemoteBitrateEstimator {
|
||||
public:
|
||||
WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock)
|
||||
: observer_(observer),
|
||||
clock_(clock),
|
||||
crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||
rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)),
|
||||
using_absolute_send_time_(false),
|
||||
packets_since_absolute_send_time_(0),
|
||||
min_bitrate_bps_(congestion_controller::GetMinBitrateBps()) {}
|
||||
} // namespace
|
||||
|
||||
virtual ~WrappingBitrateEstimator() {}
|
||||
CongestionController::WrappingBitrateEstimator::WrappingBitrateEstimator(
|
||||
RemoteBitrateObserver* observer, Clock* clock)
|
||||
: observer_(observer),
|
||||
clock_(clock),
|
||||
rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)),
|
||||
using_absolute_send_time_(false),
|
||||
packets_since_absolute_send_time_(0),
|
||||
min_bitrate_bps_(congestion_controller::GetMinBitrateBps()) {}
|
||||
|
||||
void IncomingPacket(int64_t arrival_time_ms,
|
||||
size_t payload_size,
|
||||
const RTPHeader& header) override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
PickEstimatorFromHeader(header);
|
||||
rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
|
||||
}
|
||||
void CongestionController::WrappingBitrateEstimator::IncomingPacket(
|
||||
int64_t arrival_time_ms,
|
||||
size_t payload_size,
|
||||
const RTPHeader& header) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
PickEstimatorFromHeader(header);
|
||||
rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
|
||||
}
|
||||
|
||||
void Process() override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
rbe_->Process();
|
||||
}
|
||||
void CongestionController::WrappingBitrateEstimator::Process() {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
rbe_->Process();
|
||||
}
|
||||
|
||||
int64_t TimeUntilNextProcess() override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
return rbe_->TimeUntilNextProcess();
|
||||
}
|
||||
int64_t CongestionController::WrappingBitrateEstimator::TimeUntilNextProcess() {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
return rbe_->TimeUntilNextProcess();
|
||||
}
|
||||
|
||||
void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
||||
}
|
||||
void CongestionController::WrappingBitrateEstimator::OnRttUpdate(
|
||||
int64_t avg_rtt_ms, int64_t max_rtt_ms) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
||||
}
|
||||
|
||||
void RemoveStream(unsigned int ssrc) override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
rbe_->RemoveStream(ssrc);
|
||||
}
|
||||
void CongestionController::WrappingBitrateEstimator::RemoveStream(
|
||||
unsigned int ssrc) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
rbe_->RemoveStream(ssrc);
|
||||
}
|
||||
|
||||
bool LatestEstimate(std::vector<unsigned int>* ssrcs,
|
||||
unsigned int* bitrate_bps) const override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
return rbe_->LatestEstimate(ssrcs, bitrate_bps);
|
||||
}
|
||||
bool CongestionController::WrappingBitrateEstimator::LatestEstimate(
|
||||
std::vector<unsigned int>* ssrcs,
|
||||
unsigned int* bitrate_bps) const {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
return rbe_->LatestEstimate(ssrcs, bitrate_bps);
|
||||
}
|
||||
|
||||
void SetMinBitrate(int min_bitrate_bps) override {
|
||||
CriticalSectionScoped cs(crit_sect_.get());
|
||||
rbe_->SetMinBitrate(min_bitrate_bps);
|
||||
min_bitrate_bps_ = min_bitrate_bps;
|
||||
}
|
||||
void CongestionController::WrappingBitrateEstimator::SetMinBitrate(
|
||||
int min_bitrate_bps) {
|
||||
rtc::CritScope cs(&crit_sect_);
|
||||
rbe_->SetMinBitrate(min_bitrate_bps);
|
||||
min_bitrate_bps_ = min_bitrate_bps;
|
||||
}
|
||||
|
||||
private:
|
||||
void PickEstimatorFromHeader(const RTPHeader& header)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
|
||||
if (header.extension.hasAbsoluteSendTime) {
|
||||
// If we see AST in header, switch RBE strategy immediately.
|
||||
if (!using_absolute_send_time_) {
|
||||
LOG(LS_INFO) <<
|
||||
"WrappingBitrateEstimator: Switching to absolute send time RBE.";
|
||||
using_absolute_send_time_ = true;
|
||||
void CongestionController::WrappingBitrateEstimator::PickEstimatorFromHeader(
|
||||
const RTPHeader& header) {
|
||||
if (header.extension.hasAbsoluteSendTime) {
|
||||
// If we see AST in header, switch RBE strategy immediately.
|
||||
if (!using_absolute_send_time_) {
|
||||
LOG(LS_INFO) <<
|
||||
"WrappingBitrateEstimator: Switching to absolute send time RBE.";
|
||||
using_absolute_send_time_ = true;
|
||||
PickEstimator();
|
||||
}
|
||||
packets_since_absolute_send_time_ = 0;
|
||||
} else {
|
||||
// When we don't see AST, wait for a few packets before going back to TOF.
|
||||
if (using_absolute_send_time_) {
|
||||
++packets_since_absolute_send_time_;
|
||||
if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) {
|
||||
LOG(LS_INFO) << "WrappingBitrateEstimator: Switching to transmission "
|
||||
<< "time offset RBE.";
|
||||
using_absolute_send_time_ = false;
|
||||
PickEstimator();
|
||||
}
|
||||
packets_since_absolute_send_time_ = 0;
|
||||
} else {
|
||||
// When we don't see AST, wait for a few packets before going back to TOF.
|
||||
if (using_absolute_send_time_) {
|
||||
++packets_since_absolute_send_time_;
|
||||
if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) {
|
||||
LOG(LS_INFO) << "WrappingBitrateEstimator: Switching to transmission "
|
||||
<< "time offset RBE.";
|
||||
using_absolute_send_time_ = false;
|
||||
PickEstimator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Instantiate RBE for Time Offset or Absolute Send Time extensions.
|
||||
void PickEstimator() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
|
||||
if (using_absolute_send_time_) {
|
||||
rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_, clock_));
|
||||
} else {
|
||||
rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_));
|
||||
}
|
||||
rbe_->SetMinBitrate(min_bitrate_bps_);
|
||||
// Instantiate RBE for Time Offset or Absolute Send Time extensions.
|
||||
void CongestionController::WrappingBitrateEstimator::PickEstimator() {
|
||||
if (using_absolute_send_time_) {
|
||||
rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_, clock_));
|
||||
} else {
|
||||
rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_));
|
||||
}
|
||||
|
||||
RemoteBitrateObserver* observer_;
|
||||
Clock* const clock_;
|
||||
std::unique_ptr<CriticalSectionWrapper> crit_sect_;
|
||||
std::unique_ptr<RemoteBitrateEstimator> rbe_;
|
||||
bool using_absolute_send_time_;
|
||||
uint32_t packets_since_absolute_send_time_;
|
||||
int min_bitrate_bps_;
|
||||
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
rbe_->SetMinBitrate(min_bitrate_bps_);
|
||||
}
|
||||
|
||||
CongestionController::CongestionController(
|
||||
Clock* clock,
|
||||
@ -174,15 +162,12 @@ CongestionController::CongestionController(
|
||||
observer_(observer),
|
||||
packet_router_(packet_router),
|
||||
pacer_(std::move(pacer)),
|
||||
remote_bitrate_estimator_(
|
||||
new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
|
||||
// Constructed last as this object calls the provided callback on
|
||||
// construction.
|
||||
bitrate_controller_(
|
||||
BitrateController::CreateBitrateController(clock_, event_log)),
|
||||
probe_controller_(new ProbeController(pacer_.get(), clock_)),
|
||||
retransmission_rate_limiter_(
|
||||
new RateLimiter(clock, kRetransmitWindowSizeMs)),
|
||||
remote_bitrate_estimator_(remote_bitrate_observer, clock_),
|
||||
remote_estimator_proxy_(clock_, packet_router_),
|
||||
transport_feedback_adapter_(clock_, bitrate_controller_.get()),
|
||||
min_bitrate_bps_(congestion_controller::GetMinBitrateBps()),
|
||||
@ -204,12 +189,9 @@ void CongestionController::OnReceivedPacket(int64_t arrival_time_ms,
|
||||
if (header.extension.hasTransportSequenceNumber) {
|
||||
remote_estimator_proxy_.IncomingPacket(arrival_time_ms, payload_size,
|
||||
header);
|
||||
return;
|
||||
}
|
||||
|
||||
// Receive-side BWE.
|
||||
if (remote_bitrate_estimator_) {
|
||||
remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
|
||||
} else {
|
||||
// Receive-side BWE.
|
||||
remote_bitrate_estimator_.IncomingPacket(arrival_time_ms, payload_size,
|
||||
header);
|
||||
}
|
||||
}
|
||||
@ -226,8 +208,7 @@ void CongestionController::SetBweBitrates(int min_bitrate_bps,
|
||||
max_bitrate_bps);
|
||||
max_bitrate_bps_ = max_bitrate_bps;
|
||||
|
||||
if (remote_bitrate_estimator_)
|
||||
remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
|
||||
remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps);
|
||||
min_bitrate_bps_ = min_bitrate_bps;
|
||||
transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps_);
|
||||
MaybeTriggerOnNetworkChanged();
|
||||
@ -245,8 +226,7 @@ void CongestionController::ResetBweAndBitrates(int bitrate_bps,
|
||||
max_bitrate_bps_ = max_bitrate_bps;
|
||||
// TODO(honghaiz): Recreate this object once the remote bitrate estimator is
|
||||
// no longer exposed outside CongestionController.
|
||||
if (remote_bitrate_estimator_)
|
||||
remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
|
||||
remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps);
|
||||
|
||||
transport_feedback_adapter_.InitBwe();
|
||||
transport_feedback_adapter_.SetMinBitrate(min_bitrate_bps);
|
||||
@ -263,7 +243,7 @@ RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
|
||||
if (send_side_bwe) {
|
||||
return &remote_estimator_proxy_;
|
||||
} else {
|
||||
return remote_bitrate_estimator_.get();
|
||||
return &remote_bitrate_estimator_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,18 +302,18 @@ void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
|
||||
}
|
||||
|
||||
void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
|
||||
remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
||||
remote_bitrate_estimator_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
||||
transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
||||
}
|
||||
|
||||
int64_t CongestionController::TimeUntilNextProcess() {
|
||||
return std::min(bitrate_controller_->TimeUntilNextProcess(),
|
||||
remote_bitrate_estimator_->TimeUntilNextProcess());
|
||||
remote_bitrate_estimator_.TimeUntilNextProcess());
|
||||
}
|
||||
|
||||
void CongestionController::Process() {
|
||||
bitrate_controller_->Process();
|
||||
remote_bitrate_estimator_->Process();
|
||||
remote_bitrate_estimator_.Process();
|
||||
probe_controller_->Process();
|
||||
MaybeTriggerOnNetworkChanged();
|
||||
}
|
||||
|
||||
@ -12,9 +12,10 @@
|
||||
#define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/deprecation.h"
|
||||
#include "webrtc/base/criticalsection.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/congestion_controller/transport_feedback_adapter.h"
|
||||
#include "webrtc/modules/include/module.h"
|
||||
@ -117,6 +118,44 @@ class CongestionController : public CallStatsObserver, public Module {
|
||||
void Process() override;
|
||||
|
||||
private:
|
||||
class WrappingBitrateEstimator : public RemoteBitrateEstimator {
|
||||
public:
|
||||
WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock);
|
||||
|
||||
virtual ~WrappingBitrateEstimator() {}
|
||||
|
||||
void IncomingPacket(int64_t arrival_time_ms,
|
||||
size_t payload_size,
|
||||
const RTPHeader& header) override;
|
||||
|
||||
void Process() override;
|
||||
|
||||
int64_t TimeUntilNextProcess() override;
|
||||
|
||||
void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
|
||||
|
||||
void RemoveStream(unsigned int ssrc) override;
|
||||
|
||||
bool LatestEstimate(std::vector<unsigned int>* ssrcs,
|
||||
unsigned int* bitrate_bps) const override;
|
||||
|
||||
void SetMinBitrate(int min_bitrate_bps) override;
|
||||
|
||||
private:
|
||||
void PickEstimatorFromHeader(const RTPHeader& header)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
|
||||
void PickEstimator() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
|
||||
RemoteBitrateObserver* observer_;
|
||||
Clock* const clock_;
|
||||
rtc::CriticalSection crit_sect_;
|
||||
std::unique_ptr<RemoteBitrateEstimator> rbe_;
|
||||
bool using_absolute_send_time_;
|
||||
uint32_t packets_since_absolute_send_time_;
|
||||
int min_bitrate_bps_;
|
||||
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
|
||||
};
|
||||
|
||||
void MaybeTriggerOnNetworkChanged();
|
||||
|
||||
bool IsSendQueueFull() const;
|
||||
@ -128,10 +167,10 @@ class CongestionController : public CallStatsObserver, public Module {
|
||||
Observer* const observer_;
|
||||
PacketRouter* const packet_router_;
|
||||
const std::unique_ptr<PacedSender> pacer_;
|
||||
const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
|
||||
const std::unique_ptr<BitrateController> bitrate_controller_;
|
||||
const std::unique_ptr<ProbeController> probe_controller_;
|
||||
const std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
|
||||
WrappingBitrateEstimator remote_bitrate_estimator_;
|
||||
RemoteEstimatorProxy remote_estimator_proxy_;
|
||||
TransportFeedbackAdapter transport_feedback_adapter_;
|
||||
int min_bitrate_bps_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user