| 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/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 // The minumum number of probes we need to receive feedback about in percent | 20 // The minumum number of probes we need to receive feedback about in percent |
| 20 // in order to have a valid estimate. | 21 // in order to have a valid estimate. |
| 21 constexpr int kMinReceivedProbesPercent = 80; | 22 constexpr int kMinReceivedProbesPercent = 80; |
| 22 | 23 |
| 23 // The minumum number of bytes we need to receive feedback about in percent | 24 // The minumum number of bytes we need to receive feedback about in percent |
| 24 // in order to have a valid estimate. | 25 // in order to have a valid estimate. |
| 25 constexpr int kMinReceivedBytesPercent = 80; | 26 constexpr int kMinReceivedBytesPercent = 80; |
| 26 | 27 |
| 27 // The maximum (receive rate)/(send rate) ratio for a valid estimate. | 28 // The maximum (receive rate)/(send rate) ratio for a valid estimate. |
| 28 constexpr float kValidRatio = 2.0f; | 29 constexpr float kValidRatio = 2.0f; |
| 29 | 30 |
| 30 // The maximum time period over which the cluster history is retained. | 31 // The maximum time period over which the cluster history is retained. |
| 31 // This is also the maximum time period beyond which a probing burst is not | 32 // This is also the maximum time period beyond which a probing burst is not |
| 32 // expected to last. | 33 // expected to last. |
| 33 constexpr int kMaxClusterHistoryMs = 1000; | 34 constexpr int kMaxClusterHistoryMs = 1000; |
| 34 | 35 |
| 35 // The maximum time interval between first and the last probe on a cluster | 36 // The maximum time interval between first and the last probe on a cluster |
| 36 // on the sender side as well as the receive side. | 37 // on the sender side as well as the receive side. |
| 37 constexpr int kMaxProbeIntervalMs = 1000; | 38 constexpr int kMaxProbeIntervalMs = 1000; |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| 40 namespace webrtc { | 41 namespace webrtc { |
| 41 | 42 |
| 42 ProbeBitrateEstimator::ProbeBitrateEstimator() {} | 43 ProbeBitrateEstimator::ProbeBitrateEstimator(RtcEventLog* event_log) |
| 44 : event_log_(event_log) {} |
| 43 | 45 |
| 44 int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate( | 46 int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate( |
| 45 const PacketFeedback& packet_feedback) { | 47 const PacketFeedback& packet_feedback) { |
| 46 int cluster_id = packet_feedback.pacing_info.probe_cluster_id; | 48 int cluster_id = packet_feedback.pacing_info.probe_cluster_id; |
| 47 RTC_DCHECK_NE(cluster_id, PacedPacketInfo::kNotAProbe); | 49 RTC_DCHECK_NE(cluster_id, PacedPacketInfo::kNotAProbe); |
| 48 | 50 |
| 49 EraseOldClusters(packet_feedback.arrival_time_ms - kMaxClusterHistoryMs); | 51 EraseOldClusters(packet_feedback.arrival_time_ms - kMaxClusterHistoryMs); |
| 50 | 52 |
| 51 int payload_size_bits = packet_feedback.payload_size * 8; | 53 int payload_size_bits = packet_feedback.payload_size * 8; |
| 52 AggregatedCluster* cluster = &clusters_[cluster_id]; | 54 AggregatedCluster* cluster = &clusters_[cluster_id]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 81 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; | 83 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; |
| 82 float receive_interval_ms = | 84 float receive_interval_ms = |
| 83 cluster->last_receive_ms - cluster->first_receive_ms; | 85 cluster->last_receive_ms - cluster->first_receive_ms; |
| 84 | 86 |
| 85 if (send_interval_ms <= 0 || send_interval_ms > kMaxProbeIntervalMs || | 87 if (send_interval_ms <= 0 || send_interval_ms > kMaxProbeIntervalMs || |
| 86 receive_interval_ms <= 0 || receive_interval_ms > kMaxProbeIntervalMs) { | 88 receive_interval_ms <= 0 || receive_interval_ms > kMaxProbeIntervalMs) { |
| 87 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" | 89 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" |
| 88 << " [cluster id: " << cluster_id | 90 << " [cluster id: " << cluster_id |
| 89 << "] [send interval: " << send_interval_ms << " ms]" | 91 << "] [send interval: " << send_interval_ms << " ms]" |
| 90 << " [receive interval: " << receive_interval_ms << " ms]"; | 92 << " [receive interval: " << receive_interval_ms << " ms]"; |
| 93 if (event_log_) { |
| 94 event_log_->LogProbeResultFailure(cluster_id, |
| 95 kInvalidSendReceiveInterval); |
| 96 } |
| 91 return -1; | 97 return -1; |
| 92 } | 98 } |
| 93 // Since the |send_interval_ms| does not include the time it takes to actually | 99 // Since the |send_interval_ms| does not include the time it takes to actually |
| 94 // send the last packet the size of the last sent packet should not be | 100 // send the last packet the size of the last sent packet should not be |
| 95 // included when calculating the send bitrate. | 101 // included when calculating the send bitrate. |
| 96 RTC_DCHECK_GT(cluster->size_total, cluster->size_last_send); | 102 RTC_DCHECK_GT(cluster->size_total, cluster->size_last_send); |
| 97 float send_size = cluster->size_total - cluster->size_last_send; | 103 float send_size = cluster->size_total - cluster->size_last_send; |
| 98 float send_bps = send_size / send_interval_ms * 1000; | 104 float send_bps = send_size / send_interval_ms * 1000; |
| 99 | 105 |
| 100 // Since the |receive_interval_ms| does not include the time it takes to | 106 // Since the |receive_interval_ms| does not include the time it takes to |
| 101 // actually receive the first packet the size of the first received packet | 107 // actually receive the first packet the size of the first received packet |
| 102 // should not be included when calculating the receive bitrate. | 108 // should not be included when calculating the receive bitrate. |
| 103 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive); | 109 RTC_DCHECK_GT(cluster->size_total, cluster->size_first_receive); |
| 104 float receive_size = cluster->size_total - cluster->size_first_receive; | 110 float receive_size = cluster->size_total - cluster->size_first_receive; |
| 105 float receive_bps = receive_size / receive_interval_ms * 1000; | 111 float receive_bps = receive_size / receive_interval_ms * 1000; |
| 106 | 112 |
| 107 float ratio = receive_bps / send_bps; | 113 float ratio = receive_bps / send_bps; |
| 108 if (ratio > kValidRatio) { | 114 if (ratio > kValidRatio) { |
| 109 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" | 115 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" |
| 110 << " [cluster id: " << cluster_id << "] [send: " << send_size | 116 << " [cluster id: " << cluster_id << "] [send: " << send_size |
| 111 << " bytes / " << send_interval_ms | 117 << " bytes / " << send_interval_ms |
| 112 << " ms = " << send_bps / 1000 << " kb/s]" | 118 << " ms = " << send_bps / 1000 << " kb/s]" |
| 113 << " [receive: " << receive_size << " bytes / " | 119 << " [receive: " << receive_size << " bytes / " |
| 114 << receive_interval_ms << " ms = " << receive_bps / 1000 | 120 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 115 << " kb/s]" | 121 << " kb/s]" |
| 116 << " [ratio: " << receive_bps / 1000 << " / " | 122 << " [ratio: " << receive_bps / 1000 << " / " |
| 117 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" | 123 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" |
| 118 << kValidRatio << ")]"; | 124 << kValidRatio << ")]"; |
| 125 if (event_log_) |
| 126 event_log_->LogProbeResultFailure(cluster_id, kInvalidSendReceiveRatio); |
| 119 return -1; | 127 return -1; |
| 120 } | 128 } |
| 121 LOG(LS_INFO) << "Probing successful" | 129 LOG(LS_INFO) << "Probing successful" |
| 122 << " [cluster id: " << cluster_id << "] [send: " << send_size | 130 << " [cluster id: " << cluster_id << "] [send: " << send_size |
| 123 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000 | 131 << " bytes / " << send_interval_ms << " ms = " << send_bps / 1000 |
| 124 << " kb/s]" | 132 << " kb/s]" |
| 125 << " [receive: " << receive_size << " bytes / " | 133 << " [receive: " << receive_size << " bytes / " |
| 126 << receive_interval_ms << " ms = " << receive_bps / 1000 | 134 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 127 << " kb/s]"; | 135 << " kb/s]"; |
| 128 return std::min(send_bps, receive_bps); | 136 float res = std::min(send_bps, receive_bps); |
| 137 if (event_log_) |
| 138 event_log_->LogProbeResultSuccess(cluster_id, res); |
| 139 return res; |
| 129 } | 140 } |
| 130 | 141 |
| 131 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) { | 142 void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) { |
| 132 for (auto it = clusters_.begin(); it != clusters_.end();) { | 143 for (auto it = clusters_.begin(); it != clusters_.end();) { |
| 133 if (it->second.last_receive_ms < timestamp_ms) { | 144 if (it->second.last_receive_ms < timestamp_ms) { |
| 134 it = clusters_.erase(it); | 145 it = clusters_.erase(it); |
| 135 } else { | 146 } else { |
| 136 ++it; | 147 ++it; |
| 137 } | 148 } |
| 138 } | 149 } |
| 139 } | 150 } |
| 140 } // namespace webrtc | 151 } // namespace webrtc |
| OLD | NEW |