Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: webrtc/modules/congestion_controller/delay_based_bwe.cc

Issue 2126793002: Reset InterArrival if arrival time clock makes a jump. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a few test issues. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 namespace webrtc { 62 namespace webrtc {
63 63
64 void DelayBasedBwe::AddCluster(std::list<Cluster>* clusters, Cluster* cluster) { 64 void DelayBasedBwe::AddCluster(std::list<Cluster>* clusters, Cluster* cluster) {
65 cluster->send_mean_ms /= static_cast<float>(cluster->count); 65 cluster->send_mean_ms /= static_cast<float>(cluster->count);
66 cluster->recv_mean_ms /= static_cast<float>(cluster->count); 66 cluster->recv_mean_ms /= static_cast<float>(cluster->count);
67 cluster->mean_size /= cluster->count; 67 cluster->mean_size /= cluster->count;
68 clusters->push_back(*cluster); 68 clusters->push_back(*cluster);
69 } 69 }
70 70
71 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer) 71 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer, Clock* clock)
72 : observer_(observer), 72 : clock_(clock),
73 observer_(observer),
73 inter_arrival_(), 74 inter_arrival_(),
74 estimator_(), 75 estimator_(),
75 detector_(OverUseDetectorOptions()), 76 detector_(OverUseDetectorOptions()),
76 incoming_bitrate_(kBitrateWindowMs, 8000), 77 incoming_bitrate_(kBitrateWindowMs, 8000),
77 total_probes_received_(0), 78 total_probes_received_(0),
78 first_packet_time_ms_(-1), 79 first_packet_time_ms_(-1),
79 last_update_ms_(-1), 80 last_update_ms_(-1),
80 ssrcs_() { 81 ssrcs_() {
81 RTC_DCHECK(observer_); 82 RTC_DCHECK(observer_);
82 // NOTE! The BitrateEstimatorTest relies on this EXACT log line. 83 // NOTE! The BitrateEstimatorTest relies on this EXACT log line.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const std::vector<PacketInfo>& packet_feedback_vector) { 197 const std::vector<PacketInfo>& packet_feedback_vector) {
197 RTC_DCHECK(network_thread_.CalledOnValidThread()); 198 RTC_DCHECK(network_thread_.CalledOnValidThread());
198 for (const auto& packet_info : packet_feedback_vector) { 199 for (const auto& packet_info : packet_feedback_vector) {
199 IncomingPacketInfo(packet_info.arrival_time_ms, 200 IncomingPacketInfo(packet_info.arrival_time_ms,
200 ConvertMsTo24Bits(packet_info.send_time_ms), 201 ConvertMsTo24Bits(packet_info.send_time_ms),
201 packet_info.payload_size, 0, 202 packet_info.payload_size, 0,
202 packet_info.probe_cluster_id); 203 packet_info.probe_cluster_id);
203 } 204 }
204 } 205 }
205 206
206 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms,
207 size_t payload_size,
208 const RTPHeader& header) {
209 RTC_DCHECK(network_thread_.CalledOnValidThread());
210 if (!header.extension.hasAbsoluteSendTime) {
211 // NOTE! The BitrateEstimatorTest relies on this EXACT log line.
212 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet "
213 "is missing absolute send time extension!";
214 return;
215 }
216 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime,
217 payload_size, header.ssrc, PacketInfo::kNotAProbe);
218 }
219
220 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms,
221 size_t payload_size,
222 const RTPHeader& header,
223 int probe_cluster_id) {
224 RTC_DCHECK(network_thread_.CalledOnValidThread());
225 if (!header.extension.hasAbsoluteSendTime) {
226 // NOTE! The BitrateEstimatorTest relies on this EXACT log line.
227 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet "
228 "is missing absolute send time extension!";
229 return;
230 }
231 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime,
232 payload_size, header.ssrc, probe_cluster_id);
233 }
234
235 void DelayBasedBwe::IncomingPacketInfo(int64_t arrival_time_ms, 207 void DelayBasedBwe::IncomingPacketInfo(int64_t arrival_time_ms,
236 uint32_t send_time_24bits, 208 uint32_t send_time_24bits,
237 size_t payload_size, 209 size_t payload_size,
238 uint32_t ssrc, 210 uint32_t ssrc,
239 int probe_cluster_id) { 211 int probe_cluster_id) {
240 assert(send_time_24bits < (1ul << 24)); 212 assert(send_time_24bits < (1ul << 24));
241 // Shift up send time to use the full 32 bits that inter_arrival works with, 213 // Shift up send time to use the full 32 bits that inter_arrival works with,
242 // so wrapping works properly. 214 // so wrapping works properly.
243 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; 215 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift;
244 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; 216 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs;
245 217
246 int64_t now_ms = arrival_time_ms; 218 int64_t now_ms = clock_->TimeInMilliseconds();
247 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from 219 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from
248 // here. 220 // here.
249 incoming_bitrate_.Update(payload_size, now_ms); 221 incoming_bitrate_.Update(payload_size, arrival_time_ms);
250 222
251 if (first_packet_time_ms_ == -1) 223 if (first_packet_time_ms_ == -1)
252 first_packet_time_ms_ = arrival_time_ms; 224 first_packet_time_ms_ = now_ms;
253 225
254 uint32_t ts_delta = 0; 226 uint32_t ts_delta = 0;
255 int64_t t_delta = 0; 227 int64_t t_delta = 0;
256 int size_delta = 0; 228 int size_delta = 0;
257 229
258 bool update_estimate = false; 230 bool update_estimate = false;
259 uint32_t target_bitrate_bps = 0; 231 uint32_t target_bitrate_bps = 0;
260 std::vector<uint32_t> ssrcs; 232 std::vector<uint32_t> ssrcs;
261 { 233 {
262 rtc::CritScope lock(&crit_); 234 rtc::CritScope lock(&crit_);
(...skipping 24 matching lines...) Expand all
287 << " ms, recv delta=" << recv_delta_ms << " ms."; 259 << " ms, recv delta=" << recv_delta_ms << " ms.";
288 } 260 }
289 probes_.push_back( 261 probes_.push_back(
290 Probe(send_time_ms, arrival_time_ms, payload_size, probe_cluster_id)); 262 Probe(send_time_ms, arrival_time_ms, payload_size, probe_cluster_id));
291 ++total_probes_received_; 263 ++total_probes_received_;
292 // Make sure that a probe which updated the bitrate immediately has an 264 // Make sure that a probe which updated the bitrate immediately has an
293 // effect by calling the OnReceiveBitrateChanged callback. 265 // effect by calling the OnReceiveBitrateChanged callback.
294 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) 266 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated)
295 update_estimate = true; 267 update_estimate = true;
296 } 268 }
297 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, 269 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, now_ms,
298 &ts_delta, &t_delta, &size_delta)) { 270 payload_size, &ts_delta, &t_delta,
271 &size_delta)) {
299 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); 272 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift);
300 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); 273 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State());
301 detector_.Detect(estimator_->offset(), ts_delta_ms, 274 detector_.Detect(estimator_->offset(), ts_delta_ms,
302 estimator_->num_of_deltas(), arrival_time_ms); 275 estimator_->num_of_deltas(), arrival_time_ms);
303 } 276 }
304 277
305 if (!update_estimate) { 278 if (!update_estimate) {
306 // Check if it's time for a periodic update or if we should update because 279 // Check if it's time for a periodic update or if we should update because
307 // of an over-use. 280 // of an over-use.
308 if (last_update_ms_ == -1 || 281 if (last_update_ms_ == -1 ||
309 now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) { 282 now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) {
310 update_estimate = true; 283 update_estimate = true;
311 } else if (detector_.State() == kBwOverusing) { 284 } else if (detector_.State() == kBwOverusing) {
312 rtc::Optional<uint32_t> incoming_rate = incoming_bitrate_.Rate(now_ms); 285 rtc::Optional<uint32_t> incoming_rate =
286 incoming_bitrate_.Rate(arrival_time_ms);
313 if (incoming_rate && 287 if (incoming_rate &&
314 remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) { 288 remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) {
315 update_estimate = true; 289 update_estimate = true;
316 } 290 }
317 } 291 }
318 } 292 }
319 293
320 if (update_estimate) { 294 if (update_estimate) {
321 // The first overuse should immediately trigger a new estimate. 295 // The first overuse should immediately trigger a new estimate.
322 // We also have to update the estimate immediately if we are overusing 296 // We also have to update the estimate immediately if we are overusing
323 // and the target bitrate is too high compared to what we are receiving. 297 // and the target bitrate is too high compared to what we are receiving.
324 const RateControlInput input(detector_.State(), 298 const RateControlInput input(detector_.State(),
325 incoming_bitrate_.Rate(now_ms), 299 incoming_bitrate_.Rate(arrival_time_ms),
326 estimator_->var_noise()); 300 estimator_->var_noise());
327 remote_rate_.Update(&input, now_ms); 301 remote_rate_.Update(&input, now_ms);
328 target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms); 302 target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms);
329 update_estimate = remote_rate_.ValidEstimate(); 303 update_estimate = remote_rate_.ValidEstimate();
330 ssrcs = Keys(ssrcs_); 304 ssrcs = Keys(ssrcs_);
331 } 305 }
332 } 306 }
333 if (update_estimate) { 307 if (update_estimate) {
334 last_update_ms_ = now_ms; 308 last_update_ms_ = now_ms;
335 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); 309 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return true; 367 return true;
394 } 368 }
395 369
396 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { 370 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) {
397 // Called from both the configuration thread and the network thread. Shouldn't 371 // Called from both the configuration thread and the network thread. Shouldn't
398 // be called from the network thread in the future. 372 // be called from the network thread in the future.
399 rtc::CritScope lock(&crit_); 373 rtc::CritScope lock(&crit_);
400 remote_rate_.SetMinBitrate(min_bitrate_bps); 374 remote_rate_.SetMinBitrate(min_bitrate_bps);
401 } 375 }
402 } // namespace webrtc 376 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698