| 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) |
| 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 = cluster->size / send_interval_ms * 1000; |
| 66 float receive_bps = cluster->size / receive_interval_ms * 1000; |
| 67 float ratio = receive_bps / static_cast<float>(send_bps); |
| 68 if (ratio > kValidRatio) { |
| 69 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio to high!" |
| 70 << " [cluster id: " << packet_info.probe_cluster_id |
| 71 << "] [send: " << cluster->size << " bytes / " |
| 72 << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]" |
| 73 << " [receive: " << cluster->size << " bytes / " |
| 74 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 75 << " kB/s]" |
| 76 << " [ratio: " << receive_bps / 1000 << " / " |
| 77 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" |
| 78 << kValidRatio << ")]"; |
| 79 return; |
| 80 } |
| 81 // We have a valid estimate. |
| 82 int result_bps = std::min(send_bps, receive_bps); |
| 83 result_callback_->ProbingResult(result_bps, packet_info.arrival_time_ms); |
| 84 last_valid_cluster_id_ = packet_info.probe_cluster_id; |
| 85 LOG(LS_INFO) << "Probing successful!" |
| 86 << " [cluster id: " << packet_info.probe_cluster_id |
| 87 << "] [send: " << cluster->size << " bytes / " |
| 88 << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]" |
| 89 << " [receive: " << cluster->size << " bytes / " |
| 90 << receive_interval_ms << " ms = " << receive_bps / 1000 |
| 91 << " kB/s]"; |
| 92 |
| 93 // Clean up old clusters. |
| 94 auto erase_to = clusters_.lower_bound(packet_info.probe_cluster_id); |
| 95 clusters_.erase(clusters_.begin(), erase_to); |
| 96 } |
| 97 } // namespace webrtc |
| OLD | NEW |