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..edee61edb5fef0bf3eba8ca81530a89df1d83fdc 100644 |
--- a/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc |
+++ b/webrtc/modules/congestion_controller/probe_bitrate_estimator.cc |
@@ -12,6 +12,7 @@ |
#include <algorithm> |
+#include "webrtc/base/checks.h" |
#include "webrtc/base/logging.h" |
namespace { |
@@ -27,25 +28,17 @@ constexpr float kValidRatio = 1.2f; |
namespace webrtc { |
-ProbingResult::ProbingResult() : bps(kNoEstimate), timestamp(0) {} |
- |
-ProbingResult::ProbingResult(int bps, int64_t timestamp) |
- : bps(bps), timestamp(timestamp) {} |
- |
-bool ProbingResult::valid() const { |
- return bps != kNoEstimate; |
-} |
- |
ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {} |
-ProbingResult ProbeBitrateEstimator::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 ProbingResult(); |
- } |
+int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate( |
+ const PacketInfo& packet_info, |
+ size_t min_clusters) { |
+ RTC_DCHECK(packet_info.probe_cluster_id == PacketInfo::kNotAProbe); |
+ |
+ // If this probing packet belongs to an old cluster, do nothing. |
+ if (packet_info.probe_cluster_id < last_valid_cluster_id_) |
+ return -1; |
+ last_valid_cluster_id_ = packet_info.probe_cluster_id; |
philipel
2016/08/12 13:51:42
|last_valid_cluster_id_| tracks the last cluster w
|
AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; |
cluster->first_send_ms = |
@@ -59,13 +52,16 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback( |
cluster->size += packet_info.payload_size * 8; |
cluster->num_probes += 1; |
+ if (cluster->num_probes < kMinNumProbesValidCluster) |
+ return -1; |
+ |
+ if (clusters_.size() < min_clusters) |
+ return -1; |
+ |
// Clean up old clusters. |
while (clusters_.size() > kMaxNumSavedClusters) |
clusters_.erase(clusters_.begin()); |
- if (cluster->num_probes < kMinNumProbesValidCluster) |
- return ProbingResult(); |
- |
float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; |
float receive_interval_ms = |
cluster->last_receive_ms - cluster->first_receive_ms; |
@@ -83,8 +79,7 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback( |
<< " [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 +96,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 +105,18 @@ ProbingResult ProbeBitrateEstimator::PacketFeedback( |
<< " [receive: " << cluster->size << " bytes / " |
<< receive_interval_ms << " ms = " << receive_bps / 1000 |
<< " kb/s]"; |
+ cluster->bps = std::min(send_bps, receive_bps); |
+ int highest_bps = HighestBitrateOnClusters(); |
+ clusters_.clear(); |
+ return highest_bps; |
+} |
- return ProbingResult(result_bps, packet_info.arrival_time_ms); |
+int ProbeBitrateEstimator::HighestBitrateOnClusters() { |
+ int highest_bps = 0; |
+ for (const auto& kv : clusters_) { |
+ if (kv.second.bps > highest_bps) |
+ highest_bps = kv.second.bps; |
+ } |
+ return highest_bps; |
} |
} // namespace webrtc |