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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" 11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h"
15 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
16 17
17 namespace { 18 namespace {
18 // Max number of saved clusters. 19 // Max number of saved clusters.
19 constexpr size_t kMaxNumSavedClusters = 5; 20 constexpr size_t kMaxNumSavedClusters = 5;
20 21
21 // The minumum number of probes we need for a valid cluster. 22 // The minumum number of probes we need for a valid cluster.
22 constexpr int kMinNumProbesValidCluster = 4; 23 constexpr int kMinNumProbesValidCluster = 4;
23 24
24 // The maximum (receive rate)/(send rate) ratio for a valid estimate. 25 // The maximum (receive rate)/(send rate) ratio for a valid estimate.
25 constexpr float kValidRatio = 1.2f; 26 constexpr float kValidRatio = 1.2f;
26 } 27 }
27 28
28 namespace webrtc { 29 namespace webrtc {
29 30
30 ProbingResult::ProbingResult() : bps(kNoEstimate), timestamp(0) {}
31
32 ProbingResult::ProbingResult(int bps, int64_t timestamp)
33 : bps(bps), timestamp(timestamp) {}
34
35 bool ProbingResult::valid() const {
36 return bps != kNoEstimate;
37 }
38
39 ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {} 31 ProbeBitrateEstimator::ProbeBitrateEstimator() : last_valid_cluster_id_(0) {}
40 32
41 ProbingResult ProbeBitrateEstimator::PacketFeedback( 33 int ProbeBitrateEstimator::HandleProbeAndEstimateBitrate(
42 const PacketInfo& packet_info) { 34 const PacketInfo& packet_info,
43 // If this is not a probing packet or if this probing packet 35 size_t min_clusters) {
44 // belongs to an old cluster, do nothing. 36 RTC_DCHECK(packet_info.probe_cluster_id == PacketInfo::kNotAProbe);
45 if (packet_info.probe_cluster_id == PacketInfo::kNotAProbe || 37
46 packet_info.probe_cluster_id < last_valid_cluster_id_) { 38 // If this probing packet belongs to an old cluster, do nothing.
47 return ProbingResult(); 39 if (packet_info.probe_cluster_id < last_valid_cluster_id_)
48 } 40 return -1;
41 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
49 42
50 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id]; 43 AggregatedCluster* cluster = &clusters_[packet_info.probe_cluster_id];
51 cluster->first_send_ms = 44 cluster->first_send_ms =
52 std::min(cluster->first_send_ms, packet_info.send_time_ms); 45 std::min(cluster->first_send_ms, packet_info.send_time_ms);
53 cluster->last_send_ms = 46 cluster->last_send_ms =
54 std::max(cluster->last_send_ms, packet_info.send_time_ms); 47 std::max(cluster->last_send_ms, packet_info.send_time_ms);
55 cluster->first_receive_ms = 48 cluster->first_receive_ms =
56 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms); 49 std::min(cluster->first_receive_ms, packet_info.arrival_time_ms);
57 cluster->last_receive_ms = 50 cluster->last_receive_ms =
58 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms); 51 std::max(cluster->last_receive_ms, packet_info.arrival_time_ms);
59 cluster->size += packet_info.payload_size * 8; 52 cluster->size += packet_info.payload_size * 8;
60 cluster->num_probes += 1; 53 cluster->num_probes += 1;
61 54
55 if (cluster->num_probes < kMinNumProbesValidCluster)
56 return -1;
57
58 if (clusters_.size() < min_clusters)
59 return -1;
60
62 // Clean up old clusters. 61 // Clean up old clusters.
63 while (clusters_.size() > kMaxNumSavedClusters) 62 while (clusters_.size() > kMaxNumSavedClusters)
64 clusters_.erase(clusters_.begin()); 63 clusters_.erase(clusters_.begin());
65 64
66 if (cluster->num_probes < kMinNumProbesValidCluster)
67 return ProbingResult();
68
69 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms; 65 float send_interval_ms = cluster->last_send_ms - cluster->first_send_ms;
70 float receive_interval_ms = 66 float receive_interval_ms =
71 cluster->last_receive_ms - cluster->first_receive_ms; 67 cluster->last_receive_ms - cluster->first_receive_ms;
72 68
73 // Since the send/receive interval does not include the send/receive time of 69 // Since the send/receive interval does not include the send/receive time of
74 // the last/first packet we expand the interval by the average inverval 70 // the last/first packet we expand the interval by the average inverval
75 // between the probing packets. 71 // between the probing packets.
76 float interval_correction = 72 float interval_correction =
77 static_cast<float>(cluster->num_probes) / (cluster->num_probes - 1); 73 static_cast<float>(cluster->num_probes) / (cluster->num_probes - 1);
78 send_interval_ms *= interval_correction; 74 send_interval_ms *= interval_correction;
79 receive_interval_ms *= interval_correction; 75 receive_interval_ms *= interval_correction;
80 76
81 if (send_interval_ms == 0 || receive_interval_ms == 0) { 77 if (send_interval_ms == 0 || receive_interval_ms == 0) {
82 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval" 78 LOG(LS_INFO) << "Probing unsuccessful, invalid send/receive interval"
83 << " [cluster id: " << packet_info.probe_cluster_id 79 << " [cluster id: " << packet_info.probe_cluster_id
84 << "] [send interval: " << send_interval_ms << " ms]" 80 << "] [send interval: " << send_interval_ms << " ms]"
85 << " [receive interval: " << receive_interval_ms << " ms]"; 81 << " [receive interval: " << receive_interval_ms << " ms]";
86 82 return -1;
87 return ProbingResult();
88 } 83 }
89 float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000; 84 float send_bps = static_cast<float>(cluster->size) / send_interval_ms * 1000;
90 float receive_bps = 85 float receive_bps =
91 static_cast<float>(cluster->size) / receive_interval_ms * 1000; 86 static_cast<float>(cluster->size) / receive_interval_ms * 1000;
92 float ratio = receive_bps / send_bps; 87 float ratio = receive_bps / send_bps;
93 if (ratio > kValidRatio) { 88 if (ratio > kValidRatio) {
94 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high" 89 LOG(LS_INFO) << "Probing unsuccessful, receive/send ratio too high"
95 << " [cluster id: " << packet_info.probe_cluster_id 90 << " [cluster id: " << packet_info.probe_cluster_id
96 << "] [send: " << cluster->size << " bytes / " 91 << "] [send: " << cluster->size << " bytes / "
97 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" 92 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]"
98 << " [receive: " << cluster->size << " bytes / " 93 << " [receive: " << cluster->size << " bytes / "
99 << receive_interval_ms << " ms = " << receive_bps / 1000 94 << receive_interval_ms << " ms = " << receive_bps / 1000
100 << " kb/s]" 95 << " kb/s]"
101 << " [ratio: " << receive_bps / 1000 << " / " 96 << " [ratio: " << receive_bps / 1000 << " / "
102 << send_bps / 1000 << " = " << ratio << " > kValidRatio (" 97 << send_bps / 1000 << " = " << ratio << " > kValidRatio ("
103 << kValidRatio << ")]"; 98 << kValidRatio << ")]";
104 99 return -1;
105 return ProbingResult();
106 } 100 }
107 // We have a valid estimate.
108 int result_bps = std::min(send_bps, receive_bps);
109 last_valid_cluster_id_ = packet_info.probe_cluster_id;
110 LOG(LS_INFO) << "Probing successful" 101 LOG(LS_INFO) << "Probing successful"
111 << " [cluster id: " << packet_info.probe_cluster_id 102 << " [cluster id: " << packet_info.probe_cluster_id
112 << "] [send: " << cluster->size << " bytes / " 103 << "] [send: " << cluster->size << " bytes / "
113 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]" 104 << send_interval_ms << " ms = " << send_bps / 1000 << " kb/s]"
114 << " [receive: " << cluster->size << " bytes / " 105 << " [receive: " << cluster->size << " bytes / "
115 << receive_interval_ms << " ms = " << receive_bps / 1000 106 << receive_interval_ms << " ms = " << receive_bps / 1000
116 << " kb/s]"; 107 << " kb/s]";
108 cluster->bps = std::min(send_bps, receive_bps);
109 int highest_bps = HighestBitrateOnClusters();
110 clusters_.clear();
111 return highest_bps;
112 }
117 113
118 return ProbingResult(result_bps, packet_info.arrival_time_ms); 114 int ProbeBitrateEstimator::HighestBitrateOnClusters() {
115 int highest_bps = 0;
116 for (const auto& kv : clusters_) {
117 if (kv.second.bps > highest_bps)
118 highest_bps = kv.second.bps;
119 }
120 return highest_bps;
119 } 121 }
120 } // namespace webrtc 122 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698