-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive_side_congestion_controller.cc
executable file
·212 lines (184 loc) · 7.17 KB
/
receive_side_congestion_controller.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright (c) 2017 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 "modules/congestion_controller/include/receive_side_congestion_controller.h"
#include "api/units/data_rate.h"
#include "modules/pacing/packet_router.h"
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
#include "modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
#include "rtc_base/logging.h"
namespace webrtc {
namespace {
static const uint32_t kTimeOffsetSwitchThreshold = 30;
} // namespace
ReceiveSideCongestionController::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()) {}
ReceiveSideCongestionController::WrappingBitrateEstimator::
~WrappingBitrateEstimator() = default;
void ReceiveSideCongestionController::WrappingBitrateEstimator::IncomingPacket(
int64_t arrival_time_ms,
size_t payload_size,
const RTPHeader& header) {
MutexLock lock(&mutex_);
PickEstimatorFromHeader(header);
rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
}
void ReceiveSideCongestionController::WrappingBitrateEstimator::Process() {
MutexLock lock(&mutex_);
rbe_->Process();
}
int64_t ReceiveSideCongestionController::WrappingBitrateEstimator::
TimeUntilNextProcess() {
MutexLock lock(&mutex_);
return rbe_->TimeUntilNextProcess();
}
void ReceiveSideCongestionController::WrappingBitrateEstimator::OnRttUpdate(
int64_t avg_rtt_ms,
int64_t max_rtt_ms) {
MutexLock lock(&mutex_);
rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
}
void ReceiveSideCongestionController::WrappingBitrateEstimator::RemoveStream(
unsigned int ssrc) {
MutexLock lock(&mutex_);
rbe_->RemoveStream(ssrc);
}
bool ReceiveSideCongestionController::WrappingBitrateEstimator::LatestEstimate(
std::vector<unsigned int>* ssrcs,
unsigned int* bitrate_bps) const {
MutexLock lock(&mutex_);
return rbe_->LatestEstimate(ssrcs, bitrate_bps);
}
void ReceiveSideCongestionController::WrappingBitrateEstimator::SetMinBitrate(
int min_bitrate_bps) {
MutexLock lock(&mutex_);
rbe_->SetMinBitrate(min_bitrate_bps);
min_bitrate_bps_ = min_bitrate_bps;
}
void ReceiveSideCongestionController::WrappingBitrateEstimator::
PickEstimatorFromHeader(const RTPHeader& header) {
if (header.extension.hasAbsoluteSendTime) {
// If we see AST in header, switch RBE strategy immediately.
if (!using_absolute_send_time_) {
RTC_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) {
RTC_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 ReceiveSideCongestionController::WrappingBitrateEstimator::
PickEstimator() {
if (using_absolute_send_time_) {
rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_, clock_));
} else {
rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_));
}
rbe_->SetMinBitrate(min_bitrate_bps_);
}
ReceiveSideCongestionController::ReceiveSideCongestionController(
Clock* clock,
PacketRouter* packet_router)
: ReceiveSideCongestionController(clock, packet_router, nullptr) {}
ReceiveSideCongestionController::ReceiveSideCongestionController(
Clock* clock,
PacketRouter* packet_router,
NetworkStateEstimator* network_state_estimator)
: remb_throttler_([](auto...) {}, clock),
remote_bitrate_estimator_(packet_router, clock),
remote_estimator_proxy_(
clock,
[packet_router](
std::vector<std::unique_ptr<rtcp::RtcpPacket>> packets) {
packet_router->SendCombinedRtcpPacket(std::move(packets));
},
&field_trial_config_,
network_state_estimator) {}
ReceiveSideCongestionController::ReceiveSideCongestionController(
Clock* clock,
RemoteEstimatorProxy::TransportFeedbackSender feedback_sender,
RembThrottler::RembSender remb_sender,
NetworkStateEstimator* network_state_estimator)
: remb_throttler_(std::move(remb_sender), clock),
remote_bitrate_estimator_(&remb_throttler_, clock),
remote_estimator_proxy_(clock,
std::move(feedback_sender),
&field_trial_config_,
network_state_estimator) {}
void ReceiveSideCongestionController::OnReceivedPacket(
int64_t arrival_time_ms,
size_t payload_size,
const RTPHeader& header) {
remote_estimator_proxy_.IncomingPacket(arrival_time_ms, payload_size, header);
if (!header.extension.hasTransportSequenceNumber) {
// Receive-side BWE.
remote_bitrate_estimator_.IncomingPacket(arrival_time_ms, payload_size,
header);
}
}
void ReceiveSideCongestionController::SetSendPeriodicFeedback(
bool send_periodic_feedback) {
remote_estimator_proxy_.SetSendPeriodicFeedback(send_periodic_feedback);
}
RemoteBitrateEstimator*
ReceiveSideCongestionController::GetRemoteBitrateEstimator(bool send_side_bwe) {
if (send_side_bwe) {
return &remote_estimator_proxy_;
} else {
return &remote_bitrate_estimator_;
}
}
const RemoteBitrateEstimator*
ReceiveSideCongestionController::GetRemoteBitrateEstimator(
bool send_side_bwe) const {
if (send_side_bwe) {
return &remote_estimator_proxy_;
} else {
return &remote_bitrate_estimator_;
}
}
void ReceiveSideCongestionController::OnRttUpdate(int64_t avg_rtt_ms,
int64_t max_rtt_ms) {
remote_bitrate_estimator_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
}
void ReceiveSideCongestionController::OnBitrateChanged(int bitrate_bps) {
remote_estimator_proxy_.OnBitrateChanged(bitrate_bps);
}
int64_t ReceiveSideCongestionController::TimeUntilNextProcess() {
return remote_bitrate_estimator_.TimeUntilNextProcess();
}
void ReceiveSideCongestionController::Process() {
remote_bitrate_estimator_.Process();
}
void ReceiveSideCongestionController::SetMaxDesiredReceiveBitrate(
DataRate bitrate) {
remb_throttler_.SetMaxDesiredReceiveBitrate(bitrate);
}
} // namespace webrtc