| OLD | NEW |
| 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 | 11 |
| 12 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/congestion_win
dow.h" | 12 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/congestion_win
dow.h" |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.h" | 16 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/bbr.h" |
| 17 | 17 |
| 18 namespace webrtc { | 18 namespace webrtc { |
| 19 namespace testing { | 19 namespace testing { |
| 20 namespace bwe { | 20 namespace bwe { |
| 21 namespace { | 21 namespace { |
| 22 // kStartingCongestionWindow is used to set congestion window when bandwidth | 22 // kStartingCongestionWindowBytes is used to set congestion window when |
| 23 // delay product is equal to zero, so that we don't set window to zero as well. | 23 // bandwidth delay product is equal to zero, so that we don't set window to zero |
| 24 // Chosen randomly by me, because this value shouldn't make any significant | 24 // as well. Chosen randomly by me, because this value shouldn't make any |
| 25 // difference, as bandwidth delay product is more than zero almost every time. | 25 // significant difference, as bandwidth delay product is more than zero almost |
| 26 const int kStartingCongestionWindow = 6000; | 26 // every time. |
| 27 // Size of congestion window while in PROBE_RTT mode, suggested by BBR's source | 27 const int kStartingCongestionWindowBytes = 6000; |
| 28 // code of QUIC's implementation. | |
| 29 const int kMinimumCongestionWindow = 5840; | |
| 30 } // namespace | 28 } // namespace |
| 31 | 29 |
| 30 const int CongestionWindow::kMinimumCongestionWindowBytes; |
| 31 |
| 32 CongestionWindow::CongestionWindow() : data_inflight_bytes_(0) {} | 32 CongestionWindow::CongestionWindow() : data_inflight_bytes_(0) {} |
| 33 | 33 |
| 34 CongestionWindow::~CongestionWindow() {} | 34 CongestionWindow::~CongestionWindow() {} |
| 35 | 35 |
| 36 int CongestionWindow::GetCongestionWindow( | 36 int CongestionWindow::GetCongestionWindow(BbrBweSender::Mode mode, |
| 37 BbrBweSender::Mode mode, | 37 int64_t bandwidth_estimate_bps, |
| 38 int64_t bandwidth_estimate_bytes_per_ms, | 38 rtc::Optional<int64_t> min_rtt_ms, |
| 39 int64_t min_rtt_ms, | 39 float gain) { |
| 40 float gain) { | |
| 41 if (mode == BbrBweSender::PROBE_RTT) | 40 if (mode == BbrBweSender::PROBE_RTT) |
| 42 return kMinimumCongestionWindow; | 41 return CongestionWindow::kMinimumCongestionWindowBytes; |
| 43 return GetTargetCongestionWindow(bandwidth_estimate_bytes_per_ms, min_rtt_ms, | 42 return GetTargetCongestionWindow(bandwidth_estimate_bps, min_rtt_ms, gain); |
| 44 gain); | |
| 45 } | 43 } |
| 46 | 44 |
| 47 void CongestionWindow::PacketSent(size_t sent_packet_size_bytes) { | 45 void CongestionWindow::PacketSent(size_t sent_packet_size_bytes) { |
| 48 data_inflight_bytes_ += sent_packet_size_bytes; | 46 data_inflight_bytes_ += sent_packet_size_bytes; |
| 49 } | 47 } |
| 50 | 48 |
| 51 void CongestionWindow::AckReceived(size_t received_packet_size_bytes) { | 49 void CongestionWindow::AckReceived(size_t received_packet_size_bytes) { |
| 52 data_inflight_bytes_ -= received_packet_size_bytes; | 50 data_inflight_bytes_ -= received_packet_size_bytes; |
| 53 } | 51 } |
| 54 | 52 |
| 55 int CongestionWindow::GetTargetCongestionWindow( | 53 int CongestionWindow::GetTargetCongestionWindow( |
| 56 int64_t bandwidth_estimate_bytes_per_ms, | 54 int64_t bandwidth_estimate_bps, |
| 57 int64_t min_rtt_ms, | 55 rtc::Optional<int64_t> min_rtt_ms, |
| 58 float gain) { | 56 float gain) { |
| 59 int bdp = min_rtt_ms * bandwidth_estimate_bytes_per_ms; | 57 // If we have no rtt sample yet, return the starting congestion window size. |
| 58 if (!min_rtt_ms) |
| 59 return gain * kStartingCongestionWindowBytes; |
| 60 int bdp = *min_rtt_ms * bandwidth_estimate_bps; |
| 60 int congestion_window = bdp * gain; | 61 int congestion_window = bdp * gain; |
| 61 // Congestion window could be zero in rare cases, when either no bandwidth | 62 // Congestion window could be zero in rare cases, when either no bandwidth |
| 62 // estimate is available, or path's min_rtt value is zero. | 63 // estimate is available, or path's min_rtt value is zero. |
| 63 if (!congestion_window) | 64 if (!congestion_window) |
| 64 congestion_window = gain * kStartingCongestionWindow; | 65 congestion_window = gain * kStartingCongestionWindowBytes; |
| 65 return std::max(congestion_window, kMinimumCongestionWindow); | 66 return std::max(congestion_window, |
| 67 CongestionWindow::kMinimumCongestionWindowBytes); |
| 66 } | 68 } |
| 67 } // namespace bwe | 69 } // namespace bwe |
| 68 } // namespace testing | 70 } // namespace testing |
| 69 } // namespace webrtc | 71 } // namespace webrtc |
| OLD | NEW |