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

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

Issue 2931873002: Test and fix for huge bwe drop after alr state. (Closed)
Patch Set: Created 3 years, 6 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) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 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
11 #include "webrtc/modules/congestion_controller/acknowledge_bitrate_estimator.h" 11 #include "webrtc/modules/congestion_controller/bitrate_estimator.h"
12 12
13 #include <cmath> 13 #include <cmath>
14 14
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16
17 namespace webrtc { 15 namespace webrtc {
18 16
19 namespace { 17 namespace {
20 constexpr int kInitialRateWindowMs = 500; 18 constexpr int kInitialRateWindowMs = 500;
21 constexpr int kRateWindowMs = 150; 19 constexpr int kRateWindowMs = 150;
22
23 bool IsInSendTimeHistory(const PacketFeedback& packet) {
24 return packet.send_time_ms >= 0;
25 }
26
27 } // namespace 20 } // namespace
28 21
29 AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator() 22 BitrateEstimator::BitrateEstimator()
30 : sum_(0), 23 : sum_(0),
31 current_win_ms_(0), 24 current_win_ms_(0),
32 prev_time_ms_(-1), 25 prev_time_ms_(-1),
33 bitrate_estimate_(-1.0f), 26 bitrate_estimate_(-1.0f),
34 bitrate_estimate_var_(50.0f) {} 27 bitrate_estimate_var_(50.0f) {}
35 28
36 void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( 29 BitrateEstimator::~BitrateEstimator() = default;
37 const std::vector<PacketFeedback>& packet_feedback_vector) {
38 RTC_DCHECK(std::is_sorted(packet_feedback_vector.begin(),
39 packet_feedback_vector.end(),
40 PacketFeedbackComparator()));
41 for (const auto& packet : packet_feedback_vector) {
42 if (IsInSendTimeHistory(packet))
43 Update(packet.arrival_time_ms, packet.payload_size);
44 }
45 }
46 30
47 void AcknowledgedBitrateEstimator::Update(int64_t now_ms, int bytes) { 31 void BitrateEstimator::Update(int64_t now_ms, int bytes) {
48 int rate_window_ms = kRateWindowMs; 32 int rate_window_ms = kRateWindowMs;
49 // We use a larger window at the beginning to get a more stable sample that 33 // We use a larger window at the beginning to get a more stable sample that
50 // we can use to initialize the estimate. 34 // we can use to initialize the estimate.
51 if (bitrate_estimate_ < 0.f) 35 if (bitrate_estimate_ < 0.f)
52 rate_window_ms = kInitialRateWindowMs; 36 rate_window_ms = kInitialRateWindowMs;
53 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); 37 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms);
54 if (bitrate_sample < 0.0f) 38 if (bitrate_sample < 0.0f)
55 return; 39 return;
56 if (bitrate_estimate_ < 0.0f) { 40 if (bitrate_estimate_ < 0.0f) {
57 // This is the very first sample we get. Use it to initialize the estimate. 41 // This is the very first sample we get. Use it to initialize the estimate.
(...skipping 10 matching lines...) Expand all
68 // The bitrate estimate uncertainty is increased with each update to model 52 // The bitrate estimate uncertainty is increased with each update to model
69 // that the bitrate changes over time. 53 // that the bitrate changes over time.
70 float pred_bitrate_estimate_var = bitrate_estimate_var_ + 5.f; 54 float pred_bitrate_estimate_var = bitrate_estimate_var_ + 5.f;
71 bitrate_estimate_ = (sample_var * bitrate_estimate_ + 55 bitrate_estimate_ = (sample_var * bitrate_estimate_ +
72 pred_bitrate_estimate_var * bitrate_sample) / 56 pred_bitrate_estimate_var * bitrate_sample) /
73 (sample_var + pred_bitrate_estimate_var); 57 (sample_var + pred_bitrate_estimate_var);
74 bitrate_estimate_var_ = sample_var * pred_bitrate_estimate_var / 58 bitrate_estimate_var_ = sample_var * pred_bitrate_estimate_var /
75 (sample_var + pred_bitrate_estimate_var); 59 (sample_var + pred_bitrate_estimate_var);
76 } 60 }
77 61
78 float AcknowledgedBitrateEstimator::UpdateWindow(int64_t now_ms, 62 float BitrateEstimator::UpdateWindow(int64_t now_ms,
79 int bytes, 63 int bytes,
80 int rate_window_ms) { 64 int rate_window_ms) {
81 // Reset if time moves backwards. 65 // Reset if time moves backwards.
82 if (now_ms < prev_time_ms_) { 66 if (now_ms < prev_time_ms_) {
83 prev_time_ms_ = -1; 67 prev_time_ms_ = -1;
84 sum_ = 0; 68 sum_ = 0;
85 current_win_ms_ = 0; 69 current_win_ms_ = 0;
86 } 70 }
87 if (prev_time_ms_ >= 0) { 71 if (prev_time_ms_ >= 0) {
88 current_win_ms_ += now_ms - prev_time_ms_; 72 current_win_ms_ += now_ms - prev_time_ms_;
89 // Reset if nothing has been received for more than a full window. 73 // Reset if nothing has been received for more than a full window.
90 if (now_ms - prev_time_ms_ > rate_window_ms) { 74 if (now_ms - prev_time_ms_ > rate_window_ms) {
91 sum_ = 0; 75 sum_ = 0;
92 current_win_ms_ %= rate_window_ms; 76 current_win_ms_ %= rate_window_ms;
93 } 77 }
94 } 78 }
95 prev_time_ms_ = now_ms; 79 prev_time_ms_ = now_ms;
96 float bitrate_sample = -1.0f; 80 float bitrate_sample = -1.0f;
97 if (current_win_ms_ >= rate_window_ms) { 81 if (current_win_ms_ >= rate_window_ms) {
98 bitrate_sample = 8.0f * sum_ / static_cast<float>(rate_window_ms); 82 bitrate_sample = 8.0f * sum_ / static_cast<float>(rate_window_ms);
99 current_win_ms_ -= rate_window_ms; 83 current_win_ms_ -= rate_window_ms;
100 sum_ = 0; 84 sum_ = 0;
101 } 85 }
102 sum_ += bytes; 86 sum_ += bytes;
103 return bitrate_sample; 87 return bitrate_sample;
104 } 88 }
105 89
106 rtc::Optional<uint32_t> AcknowledgedBitrateEstimator::bitrate_bps() const { 90 rtc::Optional<uint32_t> BitrateEstimator::bitrate_bps() const {
107 if (bitrate_estimate_ < 0.f) 91 if (bitrate_estimate_ < 0.f)
108 return rtc::Optional<uint32_t>(); 92 return rtc::Optional<uint32_t>();
109 return rtc::Optional<uint32_t>(bitrate_estimate_ * 1000); 93 return rtc::Optional<uint32_t>(bitrate_estimate_ * 1000);
110 } 94 }
111 95
112 } // namespace webrtc 96 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698