pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | * |
| 10 | */ |
| 11 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 12 | #include "modules/bitrate_controller/bitrate_controller_impl.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 13 | |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 | [diff] [blame] | 14 | #include <algorithm> |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 15 | #include <utility> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
| 18 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 19 | #include "rtc_base/checks.h" |
| 20 | #include "rtc_base/logging.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 23 | namespace { |
| 24 | absl::optional<DataRate> ToOptionalDataRate(int send_bitrate_bps) { |
| 25 | if (send_bitrate_bps > 0) |
| 26 | return DataRate::bps(send_bitrate_bps); |
| 27 | return absl::nullopt; |
| 28 | } |
| 29 | DataRate MaxRate(int max_bitrate_bps) { |
| 30 | if (max_bitrate_bps == -1) |
| 31 | return DataRate::Infinity(); |
| 32 | return DataRate::bps(max_bitrate_bps); |
| 33 | } |
| 34 | } // namespace |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 | [diff] [blame] | 35 | class BitrateControllerImpl::RtcpBandwidthObserverImpl |
| 36 | : public RtcpBandwidthObserver { |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 37 | public: |
| 38 | explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 39 | : owner_(owner) {} |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 40 | ~RtcpBandwidthObserverImpl() override = default; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 41 | // Received RTCP REMB or TMMBR. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 42 | void OnReceivedEstimatedBitrate(uint32_t bitrate) override { |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 43 | owner_->OnReceivedEstimatedBitrate(bitrate); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 44 | } |
| 45 | // Received RTCP receiver block. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 46 | void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, |
| 47 | int64_t rtt, |
| 48 | int64_t now_ms) override { |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 49 | owner_->OnReceivedRtcpReceiverReport(report_blocks, rtt, now_ms); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 50 | } |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 | [diff] [blame] | 51 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 52 | private: |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 53 | BitrateControllerImpl* const owner_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 54 | }; |
| 55 | |
henrik.lundin@webrtc.org | 29dd0de | 2013-10-21 14:00:01 | [diff] [blame] | 56 | BitrateController* BitrateController::CreateBitrateController( |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 57 | Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 58 | BitrateObserver* observer, |
| 59 | RtcEventLog* event_log) { |
| 60 | return new BitrateControllerImpl(clock, observer, event_log); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 61 | } |
| 62 | |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 63 | BitrateController* BitrateController::CreateBitrateController( |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 64 | Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 65 | RtcEventLog* event_log) { |
| 66 | return CreateBitrateController(clock, nullptr, event_log); |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 67 | } |
| 68 | |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 69 | BitrateControllerImpl::BitrateControllerImpl(Clock* clock, |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 70 | BitrateObserver* observer, |
| 71 | RtcEventLog* event_log) |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 72 | : clock_(clock), |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 73 | observer_(observer), |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 74 | last_bitrate_update_ms_(clock_->TimeInMilliseconds()), |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 75 | event_log_(event_log), |
| 76 | bandwidth_estimation_(event_log), |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 77 | last_bitrate_bps_(0), |
solenberg@webrtc.org | 4e65602 | 2014-03-26 14:32:47 | [diff] [blame] | 78 | last_fraction_loss_(0), |
Sebastian Jansson | 803e3ff | 2018-08-06 17:14:37 | [diff] [blame] | 79 | last_rtt_ms_(0) { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 80 | // This calls the observer_ if set, which means that the observer provided by |
| 81 | // the user must be ready to accept a bitrate update when it constructs the |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 82 | // controller. We do this to avoid having to keep synchronized initial values |
| 83 | // in both the controller and the allocator. |
| 84 | MaybeTriggerOnNetworkChanged(); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { |
| 88 | return new RtcpBandwidthObserverImpl(this); |
| 89 | } |
| 90 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 91 | void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 92 | { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 93 | rtc::CritScope cs(&critsect_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 94 | bandwidth_estimation_.SetSendBitrate( |
| 95 | DataRate::bps(start_bitrate_bps), |
| 96 | Timestamp::ms(clock_->TimeInMilliseconds())); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 97 | } |
| 98 | MaybeTriggerOnNetworkChanged(); |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 99 | } |
| 100 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 101 | void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps, |
| 102 | int max_bitrate_bps) { |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 103 | { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 104 | rtc::CritScope cs(&critsect_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 105 | bandwidth_estimation_.SetMinMaxBitrate(DataRate::bps(min_bitrate_bps), |
| 106 | DataRate::bps(max_bitrate_bps)); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 107 | } |
| 108 | MaybeTriggerOnNetworkChanged(); |
henrik.lundin@webrtc.org | 845862f | 2014-03-06 07:19:28 | [diff] [blame] | 109 | } |
| 110 | |
philipel | c6957c7 | 2016-04-28 13:52:49 | [diff] [blame] | 111 | void BitrateControllerImpl::SetBitrates(int start_bitrate_bps, |
| 112 | int min_bitrate_bps, |
| 113 | int max_bitrate_bps) { |
| 114 | { |
| 115 | rtc::CritScope cs(&critsect_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 116 | bandwidth_estimation_.SetBitrates( |
| 117 | ToOptionalDataRate(start_bitrate_bps), DataRate::bps(min_bitrate_bps), |
| 118 | MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); |
philipel | c6957c7 | 2016-04-28 13:52:49 | [diff] [blame] | 119 | } |
| 120 | MaybeTriggerOnNetworkChanged(); |
| 121 | } |
| 122 | |
honghaiz | 059e183 | 2016-06-24 18:03:55 | [diff] [blame] | 123 | void BitrateControllerImpl::ResetBitrates(int bitrate_bps, |
| 124 | int min_bitrate_bps, |
| 125 | int max_bitrate_bps) { |
| 126 | { |
| 127 | rtc::CritScope cs(&critsect_); |
ivoc | 14d5dbe | 2016-07-04 14:06:55 | [diff] [blame] | 128 | bandwidth_estimation_ = SendSideBandwidthEstimation(event_log_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 129 | bandwidth_estimation_.SetBitrates( |
| 130 | ToOptionalDataRate(bitrate_bps), DataRate::bps(min_bitrate_bps), |
| 131 | MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); |
honghaiz | 059e183 | 2016-06-24 18:03:55 | [diff] [blame] | 132 | } |
| 133 | MaybeTriggerOnNetworkChanged(); |
| 134 | } |
| 135 | |
Irfan Sheriff | b2540bb | 2016-09-12 19:28:54 | [diff] [blame] | 136 | // This is called upon reception of REMB or TMMBR. |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 137 | void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) { |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 138 | { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 139 | rtc::CritScope cs(&critsect_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 140 | bandwidth_estimation_.UpdateReceiverEstimate( |
| 141 | Timestamp::ms(clock_->TimeInMilliseconds()), DataRate::bps(bitrate)); |
gaetano.carlucci | 61050f6 | 2016-09-30 13:29:54 | [diff] [blame] | 142 | BWE_TEST_LOGGING_PLOT(1, "REMB_kbps", clock_->TimeInMilliseconds(), |
gaetano.carlucci | 52a5703 | 2016-09-14 12:04:36 | [diff] [blame] | 143 | bitrate / 1000); |
sprang@webrtc.org | 9b79197 | 2014-12-18 11:53:59 | [diff] [blame] | 144 | } |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 145 | MaybeTriggerOnNetworkChanged(); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 146 | } |
| 147 | |
Stefan Holmer | 280de9e | 2016-09-30 08:06:51 | [diff] [blame] | 148 | void BitrateControllerImpl::OnDelayBasedBweResult( |
| 149 | const DelayBasedBwe::Result& result) { |
| 150 | if (!result.updated) |
| 151 | return; |
philipel | 0aa9d18 | 2016-08-24 09:45:35 | [diff] [blame] | 152 | { |
| 153 | rtc::CritScope cs(&critsect_); |
Stefan Holmer | 280de9e | 2016-09-30 08:06:51 | [diff] [blame] | 154 | if (result.probe) { |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 155 | bandwidth_estimation_.SetSendBitrate( |
Sebastian Jansson | b6787bc | 2018-11-19 17:01:17 | [diff] [blame] | 156 | result.target_bitrate, Timestamp::ms(clock_->TimeInMilliseconds())); |
Stefan Holmer | 280de9e | 2016-09-30 08:06:51 | [diff] [blame] | 157 | } |
Bjorn Terelius | 29cb0e7 | 2017-11-08 13:41:12 | [diff] [blame] | 158 | // Since SetSendBitrate now resets the delay-based estimate, we have to call |
| 159 | // UpdateDelayBasedEstimate after SetSendBitrate. |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 160 | bandwidth_estimation_.UpdateDelayBasedEstimate( |
Sebastian Jansson | b6787bc | 2018-11-19 17:01:17 | [diff] [blame] | 161 | Timestamp::ms(clock_->TimeInMilliseconds()), result.target_bitrate); |
stefan | 32f8154 | 2016-01-20 15:13:58 | [diff] [blame] | 162 | } |
| 163 | MaybeTriggerOnNetworkChanged(); |
| 164 | } |
| 165 | |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 | [diff] [blame] | 166 | int64_t BitrateControllerImpl::TimeUntilNextProcess() { |
| 167 | const int64_t kBitrateControllerUpdateIntervalMs = 25; |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 168 | rtc::CritScope cs(&critsect_); |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 | [diff] [blame] | 169 | int64_t time_since_update_ms = |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 170 | clock_->TimeInMilliseconds() - last_bitrate_update_ms_; |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 | [diff] [blame] | 171 | return std::max<int64_t>( |
| 172 | kBitrateControllerUpdateIntervalMs - time_since_update_ms, 0); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 173 | } |
| 174 | |
pbos | a26ac92 | 2016-02-25 12:50:01 | [diff] [blame] | 175 | void BitrateControllerImpl::Process() { |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 176 | { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 177 | rtc::CritScope cs(&critsect_); |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 178 | bandwidth_estimation_.UpdateEstimate( |
| 179 | Timestamp::ms(clock_->TimeInMilliseconds())); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 180 | } |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 181 | MaybeTriggerOnNetworkChanged(); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 182 | last_bitrate_update_ms_ = clock_->TimeInMilliseconds(); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 | [diff] [blame] | 183 | } |
| 184 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 185 | void BitrateControllerImpl::OnReceivedRtcpReceiverReport( |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 186 | const ReportBlockList& report_blocks, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 187 | int64_t rtt, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 | [diff] [blame] | 188 | int64_t now_ms) { |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 189 | if (report_blocks.empty()) |
| 190 | return; |
| 191 | |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 192 | { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 193 | rtc::CritScope cs(&critsect_); |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 194 | int fraction_lost_aggregate = 0; |
| 195 | int total_number_of_packets = 0; |
| 196 | |
| 197 | // Compute the a weighted average of the fraction loss from all report |
| 198 | // blocks. |
| 199 | for (const RTCPReportBlock& report_block : report_blocks) { |
| 200 | std::map<uint32_t, uint32_t>::iterator seq_num_it = |
| 201 | ssrc_to_last_received_extended_high_seq_num_.find( |
srte | 3e69e5c | 2017-08-09 13:13:45 | [diff] [blame] | 202 | report_block.source_ssrc); |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 203 | |
| 204 | int number_of_packets = 0; |
| 205 | if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) { |
| 206 | number_of_packets = |
srte | 3e69e5c | 2017-08-09 13:13:45 | [diff] [blame] | 207 | report_block.extended_highest_sequence_number - seq_num_it->second; |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 208 | } |
| 209 | |
srte | 3e69e5c | 2017-08-09 13:13:45 | [diff] [blame] | 210 | fraction_lost_aggregate += number_of_packets * report_block.fraction_lost; |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 211 | total_number_of_packets += number_of_packets; |
| 212 | |
| 213 | // Update last received for this SSRC. |
srte | 3e69e5c | 2017-08-09 13:13:45 | [diff] [blame] | 214 | ssrc_to_last_received_extended_high_seq_num_[report_block.source_ssrc] = |
| 215 | report_block.extended_highest_sequence_number; |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 216 | } |
| 217 | if (total_number_of_packets < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 218 | RTC_LOG(LS_WARNING) |
| 219 | << "Received report block where extended high sequence " |
| 220 | "number goes backwards, ignoring."; |
Danil Chapovalov | 38018ba | 2017-06-12 14:29:45 | [diff] [blame] | 221 | return; |
| 222 | } |
| 223 | if (total_number_of_packets == 0) |
| 224 | fraction_lost_aggregate = 0; |
| 225 | else |
| 226 | fraction_lost_aggregate = |
| 227 | (fraction_lost_aggregate + total_number_of_packets / 2) / |
| 228 | total_number_of_packets; |
| 229 | if (fraction_lost_aggregate > 255) |
| 230 | return; |
| 231 | |
| 232 | RTC_DCHECK_GE(total_number_of_packets, 0); |
| 233 | |
Sebastian Jansson | 7c1744d | 2018-10-08 09:00:50 | [diff] [blame] | 234 | bandwidth_estimation_.UpdateReceiverBlock( |
| 235 | fraction_lost_aggregate, TimeDelta::ms(rtt), total_number_of_packets, |
| 236 | Timestamp::ms(now_ms)); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 | [diff] [blame] | 237 | } |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 238 | MaybeTriggerOnNetworkChanged(); |
| 239 | } |
| 240 | |
| 241 | void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 242 | if (!observer_) |
| 243 | return; |
| 244 | |
| 245 | uint32_t bitrate_bps; |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 246 | uint8_t fraction_loss; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 247 | int64_t rtt; |
perkj | ec81bcd | 2016-05-11 13:01:13 | [diff] [blame] | 248 | |
| 249 | if (GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt)) |
| 250 | observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); |
andresp@webrtc.org | 16b75c2 | 2014-03-21 14:00:51 | [diff] [blame] | 251 | } |
| 252 | |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 253 | bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, |
| 254 | uint8_t* fraction_loss, |
| 255 | int64_t* rtt) { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 256 | rtc::CritScope cs(&critsect_); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 257 | int current_bitrate; |
| 258 | bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); |
| 259 | *bitrate = current_bitrate; |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 260 | *bitrate = |
| 261 | std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); |
| 262 | |
| 263 | bool new_bitrate = false; |
| 264 | if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || |
Sebastian Jansson | 803e3ff | 2018-08-06 17:14:37 | [diff] [blame] | 265 | *rtt != last_rtt_ms_) { |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 266 | last_bitrate_bps_ = *bitrate; |
| 267 | last_fraction_loss_ = *fraction_loss; |
| 268 | last_rtt_ms_ = *rtt; |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 269 | new_bitrate = true; |
| 270 | } |
gaetano.carlucci | 52a5703 | 2016-09-14 12:04:36 | [diff] [blame] | 271 | |
gaetano.carlucci | 61050f6 | 2016-09-30 13:29:54 | [diff] [blame] | 272 | BWE_TEST_LOGGING_PLOT(1, "fraction_loss_%", clock_->TimeInMilliseconds(), |
gaetano.carlucci | 52a5703 | 2016-09-14 12:04:36 | [diff] [blame] | 273 | (last_fraction_loss_ * 100) / 256); |
gaetano.carlucci | 61050f6 | 2016-09-30 13:29:54 | [diff] [blame] | 274 | BWE_TEST_LOGGING_PLOT(1, "rtt_ms", clock_->TimeInMilliseconds(), |
gaetano.carlucci | 52a5703 | 2016-09-14 12:04:36 | [diff] [blame] | 275 | last_rtt_ms_); |
gaetano.carlucci | 61050f6 | 2016-09-30 13:29:54 | [diff] [blame] | 276 | BWE_TEST_LOGGING_PLOT(1, "Target_bitrate_kbps", clock_->TimeInMilliseconds(), |
gaetano.carlucci | 52a5703 | 2016-09-14 12:04:36 | [diff] [blame] | 277 | last_bitrate_bps_ / 1000); |
| 278 | |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 279 | return new_bitrate; |
| 280 | } |
| 281 | |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 | [diff] [blame] | 282 | bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 283 | rtc::CritScope cs(&critsect_); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 284 | int bitrate; |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 285 | uint8_t fraction_loss; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 286 | int64_t rtt; |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 287 | bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 288 | if (bitrate > 0) { |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 289 | bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); |
| 290 | *bandwidth = bitrate; |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 | [diff] [blame] | 291 | return true; |
| 292 | } |
| 293 | return false; |
pwestin@webrtc.org | a2cd732 | 2012-04-23 08:32:47 | [diff] [blame] | 294 | } |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 | [diff] [blame] | 295 | } // namespace webrtc |