Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Unified Diff: webrtc/modules/congestion_controller/probing_calculator.cc

Issue 2121183002: New ProbingCalculator class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added kMaxNumSavedClusters. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/congestion_controller/probing_calculator.cc
diff --git a/webrtc/modules/congestion_controller/probing_calculator.cc b/webrtc/modules/congestion_controller/probing_calculator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1f02ecd21476f42cdfb3332ae4056eebc3633e8
--- /dev/null
+++ b/webrtc/modules/congestion_controller/probing_calculator.cc
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/congestion_controller/probing_calculator.h"
+
+#include <algorithm>
+
+#include "webrtc/base/logging.h"
+
+namespace {
+// Max number of saved clusters.
+constexpr size_t kMaxNumSavedClusters = 5;
+
+// The minumum number of probes we need for a valid cluster.
+constexpr int kMinNumProbesValidCluster = 4;
+
+// The maximum (receive rate)/(send rate) ratio for a valid estimate.
+constexpr float kValidRatio = 1.2f;
+}
+
+namespace webrtc {
+
+ProbingCalculator::ProbingCalculator(ProbingResultCallback* result_callback)
+ : result_callback_(result_callback), last_valid_cluster_id_(0) {}
+
+void ProbingCalculator::PacketFeedback(const PacketInfo& packet_info) {
+ // If this is not a probing packet or if this probing packet
+ // belongs to an old cluster, do nothing.
+ if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe ||
+ packet_info.probe_cluster_id < last_valid_cluster_id_) {
+ return;
+ }
+
+ AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id];
+ cluster->first_send_ms =
+ std::min(cluster->first_send_ms, packet_info.send_time_ms);
+ cluster->last_send_ms =
+ std::max(cluster->last_send_ms, packet_info.send_time_ms);
+ cluster->first_receive_ms =
+ std::min(cluster->first_receive_ms, packet_info.arrival_time_ms);
+ cluster->last_receive_ms =
+ std::max(cluster->last_receive_ms, packet_info.arrival_time_ms);
+ cluster->size += packet_info.payload_size;
+ cluster->num_probes += 1;
+
+ // Clean up old clusters.
+ while (clusters_.size() > kMaxNumSavedClusters)
+ clusters_.erase(clusters_.begin());
+
+ if (cluster->num_probes < kMinNumProbesValidCluster)
+ return;
+
+ int send_interval_ms = cluster->last_send_ms - cluster->first_send_ms;
+ int receive_interval_ms =
+ cluster->last_receive_ms - cluster->first_receive_ms;
+
+ if (send_interval_ms == 0 || receive_interval_ms == 0) {
+ LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval!"
stefan-webrtc 2016/07/15 11:05:31 Can we change from "interval!" to "interval."? Jus
philipel 2016/07/15 12:54:18 Done.
+ << " [cluster id: " << packet_info.probe_cluster_id
+ << "] [send interval: " << send_interval_ms << " ms]"
+ << " [receive interval: " << receive_interval_ms << " ms]";
+ return;
+ }
+
+ float send_bps =
+ static_cast<float>(cluster->size) / send_interval_ms * 1000;
+ float receive_bps =
+ static_cast<float>(cluster->size) / receive_interval_ms * 1000;
+ float ratio = receive_bps / send_bps;
+ if (ratio > kValidRatio) {
+ LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio to high!"
stefan-webrtc 2016/07/15 11:05:31 Same here.
terelius 2016/07/15 11:13:01 Also s/to/too/
philipel 2016/07/15 12:54:18 Done.
philipel 2016/07/15 12:54:18 Done.
+ << " [cluster id: " << packet_info.probe_cluster_id
+ << "] [send: " << cluster->size << " bytes / "
+ << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]"
stefan-webrtc 2016/07/15 11:05:31 kbps instead of kB/s. B == bytes.
philipel 2016/07/15 12:54:18 Done.
+ << " [receive: " << cluster->size << " bytes / "
+ << receive_interval_ms << " ms = " << receive_bps / 1000
+ << " kB/s]"
+ << " [ratio: " << receive_bps / 1000 << " / "
+ << send_bps / 1000 << " = " << ratio << " > kValidRatio ("
+ << kValidRatio << ")]";
+ return;
+ }
+ // We have a valid estimate.
+ int result_bps = std::min(send_bps, receive_bps);
+ result_callback_->ProbingResult(result_bps, packet_info.arrival_time_ms);
stefan-webrtc 2016/07/15 11:05:31 Maybe we can change this class to simply return th
philipel 2016/07/15 12:54:19 Done.
+ last_valid_cluster_id_ = packet_info.probe_cluster_id;
+ LOG(LS_INFO) << "Probing successful!"
+ << " [cluster id: " << packet_info.probe_cluster_id
+ << "] [send: " << cluster->size << " bytes / "
+ << send_interval_ms << " ms = " << send_bps / 1000 << " kB/s]"
+ << " [receive: " << cluster->size << " bytes / "
+ << receive_interval_ms << " ms = " << receive_bps / 1000
+ << " kB/s]";
+}
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698