| OLD | NEW |
| 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 |
| 11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" | 11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/logging/rtc_event_log/events/rtc_event_probe_result_failure.h" |
| 16 #include "webrtc/logging/rtc_event_log/events/rtc_event_probe_result_success.h" |
| 15 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 16 #include "webrtc/rtc_base/checks.h" | 18 #include "webrtc/rtc_base/checks.h" |
| 17 #include "webrtc/rtc_base/logging.h" | 19 #include "webrtc/rtc_base/logging.h" |
| 20 #include "webrtc/rtc_base/ptr_util.h" |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 // The minumum number of probes we need to receive feedback about in percent | 23 // The minumum number of probes we need to receive feedback about in percent |
| 21 // in order to have a valid estimate. | 24 // in order to have a valid estimate. |
| 22 constexpr int kMinReceivedProbesPercent = 80; | 25 constexpr int kMinReceivedProbesPercent = 80; |
| 23 | 26 |
| 24 // The minumum number of bytes we need to receive feedback about in percent | 27 // The minumum number of bytes we need to receive feedback about in percent |
| 25 // in order to have a valid estimate. | 28 // in order to have a valid estimate. |
| 26 constexpr int kMinReceivedBytesPercent = 80; | 29 constexpr int kMinReceivedBytesPercent = 80; |
| 27 | 30 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 float receive_interval_ms = | 99 float receive_interval_ms = |
| 97 cluster->last_receive_ms - cluster->first_receive_ms; | 100 cluster->last_receive_ms - cluster->first_receive_ms; |
| 98 | 101 |
| 99 if (send_interval_ms <= 0 || send_interval_ms > kMaxProbeIntervalMs || | 102 if (send_interval_ms <= 0 || send_interval_ms > kMaxProbeIntervalMs || |
| 100 receive_interval_ms <= 0 || receive_interval_ms > kMaxProbeIntervalMs) { | 103 receive_interval_ms <= 0 || receive_interval_ms > kMaxProbeIntervalMs) { |
| 101 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" | 104 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" |
| 102 << " [cluster id: " << cluster_id | 105 << " [cluster id: " << cluster_id |
| 103 << "] [send interval: " << send_interval_ms << " ms]" | 106 << "] [send interval: " << send_interval_ms << " ms]" |
| 104 << " [receive interval: " << receive_interval_ms << " ms]"; | 107 << " [receive interval: " << receive_interval_ms << " ms]"; |
| 105 if (event_log_) { | 108 if (event_log_) { |
| 106 event_log_->LogProbeResultFailure(cluster_id, | 109 event_log_->Log(rtc::MakeUnique<RtcEventProbeResultFailure>( |
| 107 kInvalidSendReceiveInterval); | 110 cluster_id, kInvalidSendReceiveInterval)); |
| 108 } | 111 } |
| 109 return -1; | 112 return -1; |
| 110 } | 113 } |
| 111 // Since the |send_interval_ms| does not include the time it takes to actually | 114 // Since the |send_interval_ms| does not include the time it takes to actually |
| 112 // send the last packet the size of the last sent packet should not be | 115 // send the last packet the size of the last sent packet should not be |
| 113 // included when calculating the send bitrate. | 116 // included when calculating the send bitrate. |
| 114 RTC_DCHECK_GT(cluster->size_total, cluster->size_last_send); | 117 RTC_DCHECK_GT(cluster->size_total, cluster->size_last_send); |
| 115 float send_size = cluster->size_total - cluster->size_last_send; | 118 float send_size = cluster->size_total - cluster->size_last_send; |
| 116 float send_bps = send_size / send_interval_ms * 1000; | 119 float send_bps = send_size / send_interval_ms * 1000; |
| 117 | 120 |
| 118 // Since the |receive_interval_ms| does not include the time it takes to | 121 // Since the |receive_interval_ms| does not include the time it takes to |
| 119 // actually receive the first packet the size of the first received packet | 122 // actually receive the first packet the size of the first received packet |
| 120 // should not be included when calculating the receive bitrate. | 123 // should not be included when calculating the receive bitrate. |
| 121 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive); | 124 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive); |
| 122 float receive_size = cluster->size_total - cluster->size_first_receive; | 125 float receive_size = cluster->size_total - cluster->size_first_receive; |
| 123 float receive_bps = receive_size / receive_interval_ms * 1000; | 126 float receive_bps = receive_size / receive_interval_ms * 1000; |
| 124 | 127 |
| 125 float ratio = receive_bps / send_bps; | 128 float ratio = receive_bps / send_bps; |
| 126 if (ratio > kMaxValidRatio) { | 129 if (ratio > kMaxValidRatio) { |
| 127 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" | 130 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" |
| 128 << " [cluster id: " << cluster_id << "] [send: " << send_size | 131 << " [cluster id: " << cluster_id << "] [send: " << send_size |
| 129 << " bytes / " << send_interval_ms | 132 << " bytes / " << send_interval_ms |
| 130 << " ms = " << send_bps / 1000 << " kb/s]" | 133 << " ms = " << send_bps / 1000 << " kb/s]" |
| 131 << " [receive: " << receive_size << " bytes / " | 134 << " [receive: " << receive_size << " bytes / " |
| 132 << receive_interval_ms << " ms = " << receive_bps / 1000 | 135 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 133 << " kb/s]" | 136 << " kb/s]" |
| 134 << " [ratio: " << receive_bps / 1000 << " / " | 137 << " [ratio: " << receive_bps / 1000 << " / " |
| 135 << send_bps / 1000 << " = " << ratio << " > kMaxValidRatio (" | 138 << send_bps / 1000 << " = " << ratio << " > kMaxValidRatio (" |
| 136 << kMaxValidRatio << ")]"; | 139 << kMaxValidRatio << ")]"; |
| 137 if (event_log_) | 140 if (event_log_) { |
| 138 event_log_->LogProbeResultFailure(cluster_id, kInvalidSendReceiveRatio); | 141 event_log_->Log(rtc::MakeUnique<RtcEventProbeResultFailure>( |
| 142 cluster_id, kInvalidSendReceiveRatio)); |
| 143 } |
| 139 return -1; | 144 return -1; |
| 140 } | 145 } |
| 141 LOG(LS_INFO) << "Probing successful" | 146 LOG(LS_INFO) << "Probing successful" |
| 142 << " [cluster id: " << cluster_id << "] [send: " << send_size | 147 << " [cluster id: " << cluster_id << "] [send: " << send_size |
| 143 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000 | 148 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000 |
| 144 << " kb/s]" | 149 << " kb/s]" |
| 145 << " [receive: " << receive_size << " bytes / " | 150 << " [receive: " << receive_size << " bytes / " |
| 146 << receive_interval_ms << " ms = " << receive_bps / 1000 | 151 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 147 << " kb/s]"; | 152 << " kb/s]"; |
| 148 | 153 |
| 149 float res = std::min(send_bps, receive_bps); | 154 float res = std::min(send_bps, receive_bps); |
| 150 // If we're receiving at significantly lower bitrate than we were sending at, | 155 // If we're receiving at significantly lower bitrate than we were sending at, |
| 151 // it suggests that we've found the true capacity of the link. In this case, | 156 // it suggests that we've found the true capacity of the link. In this case, |
| 152 // set the target bitrate slightly lower to not immediately overuse. | 157 // set the target bitrate slightly lower to not immediately overuse. |
| 153 if (receive_bps < kMinRatioForUnsaturatedLink * send_bps) { | 158 if (receive_bps < kMinRatioForUnsaturatedLink * send_bps) { |
| 154 RTC_DCHECK_GT(send_bps, receive_bps); | 159 RTC_DCHECK_GT(send_bps, receive_bps); |
| 155 res = kTargetUtilizationFraction * receive_bps; | 160 res = kTargetUtilizationFraction * receive_bps; |
| 156 } | 161 } |
| 157 if (event_log_) | 162 if (event_log_) { |
| 158 event_log_->LogProbeResultSuccess(cluster_id, res); | 163 event_log_->Log( |
| 164 rtc::MakeUnique<RtcEventProbeResultSuccess>(cluster_id, res)); |
| 165 } |
| 159 estimated_bitrate_bps_ = rtc::Optional<int>(res); | 166 estimated_bitrate_bps_ = rtc::Optional<int>(res); |
| 160 return *estimated_bitrate_bps_; | 167 return *estimated_bitrate_bps_; |
| 161 } | 168 } |
| 162 | 169 |
| 163 rtc::Optional<int> | 170 rtc::Optional<int> |
| 164 ProbeBitrateEstimator::FetchAndResetLastEstimatedBitrateBps() { | 171 ProbeBitrateEstimator::FetchAndResetLastEstimatedBitrateBps() { |
| 165 rtc::Optional<int> estimated_bitrate_bps = estimated_bitrate_bps_; | 172 rtc::Optional<int> estimated_bitrate_bps = estimated_bitrate_bps_; |
| 166 estimated_bitrate_bps_.reset(); | 173 estimated_bitrate_bps_.reset(); |
| 167 return estimated_bitrate_bps; | 174 return estimated_bitrate_bps; |
| 168 } | 175 } |
| 169 | 176 |
| 170 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) { | 177 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) { |
| 171 for (auto it = clusters_.begin(); it != clusters_.end();) { | 178 for (auto it = clusters_.begin(); it != clusters_.end();) { |
| 172 if (it->second.last_receive_ms < timestamp_ms) { | 179 if (it->second.last_receive_ms < timestamp_ms) { |
| 173 it = clusters_.erase(it); | 180 it = clusters_.erase(it); |
| 174 } else { | 181 } else { |
| 175 ++it; | 182 ++it; |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 } // namespace webrtc | 186 } // namespace webrtc |
| OLD | NEW |