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

Side by Side Diff: webrtc/modules/pacing/bitrate_prober.cc

Issue 2681733004: Fix bug in BitrateProber where an old probe added at a high bitrate will stay active indefinit… (Closed)
Patch Set: Add unittest. Created 3 years, 10 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
(...skipping 23 matching lines...) Expand all
34 constexpr int kMaxProbeDelayMs = 3; 34 constexpr int kMaxProbeDelayMs = 3;
35 35
36 // Number of times probing is retried before the cluster is dropped. 36 // Number of times probing is retried before the cluster is dropped.
37 constexpr int kMaxRetryAttempts = 3; 37 constexpr int kMaxRetryAttempts = 3;
38 38
39 // The min probe packet size is scaled with the bitrate we're probing at. 39 // The min probe packet size is scaled with the bitrate we're probing at.
40 // This defines the max min probe packet size, meaning that on high bitrates 40 // This defines the max min probe packet size, meaning that on high bitrates
41 // we have a min probe packet size of 200 bytes. 41 // we have a min probe packet size of 200 bytes.
42 constexpr size_t kMinProbePacketSize = 200; 42 constexpr size_t kMinProbePacketSize = 200;
43 43
44 constexpr int64_t kProbeClusterTimeoutMs = 5000;
45
44 } // namespace 46 } // namespace
45 47
46 BitrateProber::BitrateProber() 48 BitrateProber::BitrateProber()
47 : probing_state_(ProbingState::kDisabled), 49 : probing_state_(ProbingState::kDisabled),
48 next_probe_time_ms_(-1), 50 next_probe_time_ms_(-1),
49 next_cluster_id_(0) { 51 next_cluster_id_(0) {
50 SetEnabled(true); 52 SetEnabled(true);
51 } 53 }
52 54
53 void BitrateProber::SetEnabled(bool enable) { 55 void BitrateProber::SetEnabled(bool enable) {
(...skipping 17 matching lines...) Expand all
71 // probing. 73 // probing.
72 if (probing_state_ == ProbingState::kInactive && !clusters_.empty() && 74 if (probing_state_ == ProbingState::kInactive && !clusters_.empty() &&
73 packet_size >= 75 packet_size >=
74 std::min<size_t>(RecommendedMinProbeSize(), kMinProbePacketSize)) { 76 std::min<size_t>(RecommendedMinProbeSize(), kMinProbePacketSize)) {
75 // Send next probe right away. 77 // Send next probe right away.
76 next_probe_time_ms_ = -1; 78 next_probe_time_ms_ = -1;
77 probing_state_ = ProbingState::kActive; 79 probing_state_ = ProbingState::kActive;
78 } 80 }
79 } 81 }
80 82
81 void BitrateProber::CreateProbeCluster(int bitrate_bps) { 83 void BitrateProber::CreateProbeCluster(int bitrate_bps, int64_t now_ms) {
82 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); 84 RTC_DCHECK(probing_state_ != ProbingState::kDisabled);
85 while (!clusters_.empty() &&
86 now_ms - clusters_.front().time_created_ms > kProbeClusterTimeoutMs) {
87 clusters_.pop();
88 }
89
83 ProbeCluster cluster; 90 ProbeCluster cluster;
84 cluster.min_probes = kMinProbePacketsSent; 91 cluster.min_probes = kMinProbePacketsSent;
85 cluster.min_bytes = bitrate_bps * kMinProbeDurationMs / 8000; 92 cluster.min_bytes = bitrate_bps * kMinProbeDurationMs / 8000;
86 cluster.bitrate_bps = bitrate_bps; 93 cluster.bitrate_bps = bitrate_bps;
94 cluster.time_created_ms = now_ms;
87 cluster.id = next_cluster_id_++; 95 cluster.id = next_cluster_id_++;
88 clusters_.push(cluster); 96 clusters_.push(cluster);
89 97
90 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): (" 98 LOG(LS_INFO) << "Probe cluster (bitrate:min bytes:min packets): ("
91 << cluster.bitrate_bps << ":" << cluster.min_bytes << ":" 99 << cluster.bitrate_bps << ":" << cluster.min_bytes << ":"
92 << cluster.min_probes << ")"; 100 << cluster.min_probes << ")";
93 // If we are already probing, continue to do so. Otherwise set it to 101 // If we are already probing, continue to do so. Otherwise set it to
94 // kInactive and wait for OnIncomingPacket to start the probing. 102 // kInactive and wait for OnIncomingPacket to start the probing.
95 if (probing_state_ != ProbingState::kActive) 103 if (probing_state_ != ProbingState::kActive)
96 probing_state_ = ProbingState::kInactive; 104 probing_state_ = ProbingState::kInactive;
97 } 105 }
98 106
99 void BitrateProber::ResetState() { 107 void BitrateProber::ResetState(int64_t now_ms) {
100 RTC_DCHECK(probing_state_ == ProbingState::kActive); 108 RTC_DCHECK(probing_state_ == ProbingState::kActive);
101 109
102 // Recreate all probing clusters. 110 // Recreate all probing clusters.
103 std::queue<ProbeCluster> clusters; 111 std::queue<ProbeCluster> clusters;
104 clusters.swap(clusters_); 112 clusters.swap(clusters_);
105 while (!clusters.empty()) { 113 while (!clusters.empty()) {
106 if (clusters.front().retries < kMaxRetryAttempts) { 114 if (clusters.front().retries < kMaxRetryAttempts) {
107 CreateProbeCluster(clusters.front().bitrate_bps); 115 CreateProbeCluster(clusters.front().bitrate_bps, now_ms);
108 clusters_.back().retries = clusters.front().retries + 1; 116 clusters_.back().retries = clusters.front().retries + 1;
109 } 117 }
110 clusters.pop(); 118 clusters.pop();
111 } 119 }
112 120
113 probing_state_ = ProbingState::kInactive; 121 probing_state_ = ProbingState::kInactive;
114 } 122 }
115 123
116 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { 124 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) {
117 // Probing is not active or probing is already complete. 125 // Probing is not active or probing is already complete.
118 if (probing_state_ != ProbingState::kActive || clusters_.empty()) 126 if (probing_state_ != ProbingState::kActive || clusters_.empty())
119 return -1; 127 return -1;
120 128
121 int time_until_probe_ms = 0; 129 int time_until_probe_ms = 0;
122 if (next_probe_time_ms_ >= 0) { 130 if (next_probe_time_ms_ >= 0) {
123 time_until_probe_ms = next_probe_time_ms_ - now_ms; 131 time_until_probe_ms = next_probe_time_ms_ - now_ms;
124 if (time_until_probe_ms < -kMaxProbeDelayMs) { 132 if (time_until_probe_ms < -kMaxProbeDelayMs) {
125 ResetState(); 133 ResetState(now_ms);
126 return -1; 134 return -1;
127 } 135 }
128 } 136 }
129 137
130 return std::max(time_until_probe_ms, 0); 138 return std::max(time_until_probe_ms, 0);
131 } 139 }
132 140
133 int BitrateProber::CurrentClusterId() const { 141 int BitrateProber::CurrentClusterId() const {
134 RTC_DCHECK(!clusters_.empty()); 142 RTC_DCHECK(!clusters_.empty());
135 RTC_DCHECK(ProbingState::kActive == probing_state_); 143 RTC_DCHECK(ProbingState::kActive == probing_state_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 180
173 // Compute the time delta from the cluster start to ensure probe bitrate stays 181 // Compute the time delta from the cluster start to ensure probe bitrate stays
174 // close to the target bitrate. Result is in milliseconds. 182 // close to the target bitrate. Result is in milliseconds.
175 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) / 183 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) /
176 cluster.bitrate_bps; 184 cluster.bitrate_bps;
177 return cluster.time_started_ms + delta_ms; 185 return cluster.time_started_ms + delta_ms;
178 } 186 }
179 187
180 188
181 } // namespace webrtc 189 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/bitrate_prober.h ('k') | webrtc/modules/pacing/bitrate_prober_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698