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

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

Issue 2239143002: ProbingEstimator: Erase history based on time threshold (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 4 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/probe_bitrate_estimator.cc
diff --git a/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc b/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc
index 561fde939180b74e0cad8b606952487c984eabbd..137829662824176ec3c4949fa449ae5a4ece1fa7 100644
--- a/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc
+++ b/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc
@@ -12,40 +12,35 @@
#include <algorithm>
+#include "webrtc/base/checks.h"
#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 {
-ProbingResult::ProbingResult() : bps(kNoEstimate), timestamp(0) {}
+// The maximum time period over which the cluster history is retained.
+// This is also the maximum time period beyond which a probing burst is not
+// expected to last.
+constexpr int kMaxClusterHistoryMs = 1000;
-ProbingResult::ProbingResult(int bps, int64_t timestamp)
- : bps(bps), timestamp(timestamp) {}
+// The maximum time interval between first and the last probe on a cluster
+// on the sender side as well as the receive side.
+constexpr int kMaxProbeIntervalMs = 1000;
+} // namespace
-bool ProbingResult::valid() const {
- return bps != kNoEstimate;
-}
+namespace webrtc {
-ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {}
+ProbeBitrateEstimator::ProbeBitrateEstimator() {}
-ProbingResult ProbeBitrateEstimator::PacketFeedback(
+int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate(
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 ProbingResult();
- }
+ RTC_DCHECK_NE(packet_info.probe_cluster_id, PacketInfo::kNotAProbe);
+
+ EraseOldClusters(packet_info.arrival_time_ms - kMaxClusterHistoryMs);
AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id];
cluster->first_send_ms =
@@ -57,14 +52,10 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback(
cluster->last_receive_ms =
std::max(cluster->last_receive_ms, packet_info.arrival_time_ms);
cluster->size += packet_info.payload_size * 8;
- cluster->num_probes += 1;
-
- // Clean up old clusters.
- while (clusters_.size() > kMaxNumSavedClusters)
- clusters_.erase(clusters_.begin());
+ ++cluster->num_probes;
if (cluster->num_probes < kMinNumProbesValidCluster)
- return ProbingResult();
+ return -1;
float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms;
float receive_interval_ms =
@@ -78,13 +69,13 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback(
send_interval_ms *= interval_correction;
receive_interval_ms *= interval_correction;
- if (send_interval_ms == 0 || receive_interval_ms == 0) {
+ if (send_interval_ms <= 0 || send_interval_ms > kMaxProbeIntervalMs ||
+ receive_interval_ms <= 0 || receive_interval_ms > kMaxProbeIntervalMs) {
LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval"
<< " [cluster id: " << packet_info.probe_cluster_id
<< "] [send interval: " << send_interval_ms << " ms]"
<< " [receive interval: " << receive_interval_ms << " ms]";
-
- return ProbingResult();
+ return -1;
}
float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000;
float receive_bps =
@@ -101,12 +92,8 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback(
<< " [ratio: " << receive_bps / 1000 << " / "
<< send_bps / 1000 << " = " << ratio << " > kValidRatio ("
<< kValidRatio << ")]";
-
- return ProbingResult();
+ return -1;
}
- // We have a valid estimate.
- int result_bps = std::min(send_bps, receive_bps);
- 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 / "
@@ -114,7 +101,16 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback(
<< " [receive: " << cluster->size << " bytes / "
<< receive_interval_ms << " ms = " << receive_bps / 1000
<< " kb/s]";
+ return std::min(send_bps, receive_bps);
+}
- return ProbingResult(result_bps, packet_info.arrival_time_ms);
+void ProbeBitrateEstimator::EraseOldClusters(int64_t timestamp_ms) {
+ for (auto it = clusters_.begin(); it != clusters_.end();) {
+ if (it->second.last_receive_ms < timestamp_ms) {
+ it = clusters_.erase(it);
+ } else {
+ ++it;
+ }
+ }
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698