Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 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 #include "webrtc/modules/congestion_controller/probing_calculator.h" | |
| 12 | |
| 13 #include <algorithm> | |
| 14 | |
| 15 #include "webrtc/base/logging.h" | |
| 16 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | |
| 17 | |
| 18 namespace { | |
| 19 // The minumum number of probes we need for a valid cluster. | |
| 20 constexpr int kMinNumProbesValidCluster = 4; | |
| 21 | |
| 22 // The maximum (receive rate)/(send rate) ratio for a valid estimate. | |
| 23 constexpr float kValidRatio = 1.2; | |
| 24 } | |
| 25 | |
| 26 namespace webrtc { | |
| 27 | |
| 28 ProbingCalculator::ProbingCalculator(AimdRateControl* rate_controller) | |
| 29 : rate_controller_(rate_controller), last_valid_cluster_id_(0) {} | |
| 30 | |
| 31 void ProbingCalculator::PacketFeedback(const PacketInfo& packet_info) { | |
| 32 // If this is not probing packet or if this probing packet | |
| 33 // belongs to an old cluster, do nothing. | |
| 34 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || | |
| 35 packet_info.probe_cluster_id < last_valid_cluster_id_) { | |
| 36 return; | |
| 37 } | |
| 38 | |
| 39 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; | |
| 40 cluster->first_send_ms = | |
| 41 std::min(cluster->first_send_ms, packet_info.send_time_ms); | |
| 42 cluster->last_send_ms = | |
| 43 std::max(cluster->last_send_ms, packet_info.send_time_ms); | |
| 44 cluster->first_receive_ms = | |
| 45 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); | |
| 46 cluster->last_receive_ms = | |
| 47 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); | |
| 48 cluster->size += packet_info.payload_size; | |
| 49 cluster->num_probes += 1; | |
| 50 | |
| 51 if (cluster->num_probes < kMinNumProbesValidCluster) | |
| 52 return; | |
| 53 | |
| 54 int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; | |
| 55 int receive_interval_ms = | |
| 56 cluster->last_receive_ms - cluster->first_receive_ms; | |
| 57 | |
| 58 if (send_interval_ms == 0 || receive_interval_ms == 0) { | |
| 59 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval!" | |
| 60 << " [cluster id: " << packet_info.probe_cluster_id | |
| 61 << "] [send interval: " << send_interval_ms << " ms]" | |
| 62 << " [receive interval: " << receive_interval_ms << " ms]"; | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 int send_bps = cluster->size / send_interval_ms * 1000; | |
| 67 int receive_bps = receive_bps = cluster->size / receive_interval_ms * 1000; | |
| 68 float ratio = receive_bps / static_cast<float>(send_bps); | |
| 69 if (ratio > kValidRatio) { | |
| 70 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio to high!" | |
| 71 << " [cluster id: " << packet_info.probe_cluster_id | |
| 72 << "] [send: " << cluster->size << " bytes / " | |
| 73 << send_interval_ms << " ms = " << send_bps / 1000 | |
| 74 << " kB/s]" | |
| 75 << " [receive: " << cluster->size << " bytes / " | |
| 76 << receive_interval_ms << " ms = " << receive_bps / 1000 | |
| 77 << " kB/s]" | |
| 78 << " [ratio: " << receive_bps / 1000 << " / " | |
| 79 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" | |
| 80 << kValidRatio << ")]"; | |
| 81 return; | |
| 82 } | |
| 83 // We have a valid estimate. | |
| 84 int result_bps = std::min(send_bps, receive_bps); | |
| 85 rate_controller_->SetEstimate(result_bps, packet_info.arrival_time_ms); | |
| 86 last_valid_cluster_id_ = packet_info.probe_cluster_id; | |
| 87 LOG(LS_INFO) << "Probing successful!" | |
| 88 << " [cluster id: " << packet_info.probe_cluster_id | |
| 89 << "] [send: " << cluster->size << " bytes / " | |
| 90 << send_interval_ms << " ms = " << send_bps / 1000 | |
| 91 << " kB/s]" | |
|
stefan-webrtc
2016/07/15 11:05:31
kbps or possibly kb/s (but the former is more comm
| |
| 92 << " [receive: " << cluster->size << " bytes / " | |
| 93 << receive_interval_ms << " ms = " << receive_bps / 1000 | |
| 94 << " kB/s]"; | |
| 95 | |
| 96 // Clean up old clusters. | |
| 97 auto erase_to = clusters_.lower_bound(packet_info.probe_cluster_id); | |
| 98 clusters_.erase(clusters_.begin(), erase_to); | |
| 99 } | |
| 100 } // namespace webrtc | |
| OLD | NEW |