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 | |
| 17 namespace { | |
| 18 // The minumum number of probes we need for a valid cluster. | |
| 19 constexpr int kMinNumProbesValidCluster = 4; | |
| 20 | |
| 21 // The maximum (receive rate)/(send rate) ratio for a valid estimate. | |
| 22 constexpr float kValidRatio = 1.2f; | |
| 23 } | |
| 24 | |
| 25 namespace webrtc { | |
| 26 | |
| 27 ProbingCalculator::ProbingCalculator(ProbingResultCallback* result_callback) | |
| 28 : result_callback_(result_callback), last_valid_cluster_id_(0) {} | |
| 29 | |
| 30 void ProbingCalculator::PacketFeedback(const PacketInfo& packet_info) { | |
| 31 // If this is not a probing packet or if this probing packet | |
| 32 // belongs to an old cluster, do nothing. | |
| 33 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || | |
| 34 packet_info.probe_cluster_id < last_valid_cluster_id_) { | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; | |
| 39 cluster->first_send_ms = | |
| 40 std::min(cluster->first_send_ms, packet_info.send_time_ms); | |
| 41 cluster->last_send_ms = | |
| 42 std::max(cluster->last_send_ms, packet_info.send_time_ms); | |
| 43 cluster->first_receive_ms = | |
| 44 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); | |
| 45 cluster->last_receive_ms = | |
| 46 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); | |
| 47 cluster->size += packet_info.payload_size; | |
| 48 cluster->num_probes += 1; | |
| 49 | |
| 50 if (cluster->num_probes < kMinNumProbesValidCluster) | |
|
terelius
2016/07/11 10:07:48
Question about future follow up: Do we have any pl
philipel
2016/07/11 11:18:55
Might be something that's interesting in the futur
terelius
2016/07/11 11:34:51
Acknowledged.
| |
| 51 return; | |
| 52 | |
| 53 int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; | |
| 54 int receive_interval_ms = | |
| 55 cluster->last_receive_ms - cluster->first_receive_ms; | |
| 56 | |
| 57 if (send_interval_ms == 0 || receive_interval_ms == 0) { | |
| 58 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval!" | |
| 59 << " [cluster id: " << packet_info.probe_cluster_id | |
| 60 << "] [send interval: " << send_interval_ms << " ms]" | |
| 61 << " [receive interval: " << receive_interval_ms << " ms]"; | |
| 62 return; | |
| 63 } | |
| 64 | |
| 65 float send_bps = | |
| 66 static_cast<float>(cluster->size) / send_interval_ms * 1000; | |
| 67 float receive_bps = | |
| 68 static_cast<float>(cluster->size) / receive_interval_ms * 1000; | |
| 69 float ratio = receive_bps / send_bps; | |
| 70 if (ratio > kValidRatio) { | |
| 71 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio to high!" | |
| 72 << " [cluster id: " << packet_info.probe_cluster_id | |
| 73 << "] [send: " << cluster->size << " bytes / " | |
| 74 << send_interval_ms << " ms = " << send_bps / 1000 << " 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 result_callback_->ProbingResult(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 << " kB/s]" | |
| 91 << " [receive: " << cluster->size << " bytes / " | |
| 92 << receive_interval_ms << " ms = " << receive_bps / 1000 | |
| 93 << " kB/s]"; | |
| 94 | |
| 95 // Clean up old clusters. | |
| 96 auto erase_to = clusters_.lower_bound(packet_info.probe_cluster_id); | |
| 97 clusters_.erase(clusters_.begin(), erase_to); | |
|
terelius
2016/07/11 10:07:48
We only clear the map after a successful probe? Wh
philipel
2016/07/11 11:18:55
fixed.
| |
| 98 } | |
| 99 } // namespace webrtc | |
| OLD | NEW |