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

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

Issue 2650393002: Improve bitrate probing for the audio-only case. (Closed)
Patch Set: comment addressed. Created 3 years, 11 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 18 matching lines...) Expand all
29 // The minimum probing duration in ms. 29 // The minimum probing duration in ms.
30 constexpr int kMinProbeDurationMs = 15; 30 constexpr int kMinProbeDurationMs = 15;
31 31
32 // Maximum amount of time each probe can be delayed. Probe cluster is reset and 32 // Maximum amount of time each probe can be delayed. Probe cluster is reset and
33 // retried from the start when this limit is reached. 33 // retried from the start when this limit is reached.
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.
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.
42 constexpr size_t kMinProbePacketSize = 200;
43
39 } // namespace 44 } // namespace
40 45
41 BitrateProber::BitrateProber() 46 BitrateProber::BitrateProber()
42 : probing_state_(ProbingState::kDisabled), 47 : probing_state_(ProbingState::kDisabled),
43 next_probe_time_ms_(-1), 48 next_probe_time_ms_(-1),
44 next_cluster_id_(0) { 49 next_cluster_id_(0) {
45 SetEnabled(true); 50 SetEnabled(true);
46 } 51 }
47 52
48 void BitrateProber::SetEnabled(bool enable) { 53 void BitrateProber::SetEnabled(bool enable) {
49 if (enable) { 54 if (enable) {
50 if (probing_state_ == ProbingState::kDisabled) { 55 if (probing_state_ == ProbingState::kDisabled) {
51 probing_state_ = ProbingState::kInactive; 56 probing_state_ = ProbingState::kInactive;
52 LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive"; 57 LOG(LS_INFO) << "Bandwidth probing enabled, set to inactive";
53 } 58 }
54 } else { 59 } else {
55 probing_state_ = ProbingState::kDisabled; 60 probing_state_ = ProbingState::kDisabled;
56 LOG(LS_INFO) << "Bandwidth probing disabled"; 61 LOG(LS_INFO) << "Bandwidth probing disabled";
57 } 62 }
58 } 63 }
59 64
60 bool BitrateProber::IsProbing() const { 65 bool BitrateProber::IsProbing() const {
61 return probing_state_ == ProbingState::kActive; 66 return probing_state_ == ProbingState::kActive;
62 } 67 }
63 68
64 void BitrateProber::OnIncomingPacket(size_t packet_size) { 69 void BitrateProber::OnIncomingPacket(size_t packet_size) {
65 // Don't initialize probing unless we have something large enough to start 70 // Don't initialize probing unless we have something large enough to start
66 // probing. 71 // probing.
67 if (probing_state_ == ProbingState::kInactive && 72 if (probing_state_ == ProbingState::kInactive && !clusters_.empty() &&
68 !clusters_.empty() && 73 packet_size >=
69 packet_size >= PacedSender::kMinProbePacketSize) { 74 std::min<size_t>(RecommendedMinProbeSize(), kMinProbePacketSize)) {
70 // Send next probe right away. 75 // Send next probe right away.
71 next_probe_time_ms_ = -1; 76 next_probe_time_ms_ = -1;
72 probing_state_ = ProbingState::kActive; 77 probing_state_ = ProbingState::kActive;
73 } 78 }
74 } 79 }
75 80
76 void BitrateProber::CreateProbeCluster(int bitrate_bps) { 81 void BitrateProber::CreateProbeCluster(int bitrate_bps) {
77 RTC_DCHECK(probing_state_ != ProbingState::kDisabled); 82 RTC_DCHECK(probing_state_ != ProbingState::kDisabled);
78 ProbeCluster cluster; 83 ProbeCluster cluster;
79 cluster.min_probes = kMinProbePacketsSent; 84 cluster.min_probes = kMinProbePacketsSent;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 RTC_DCHECK(!clusters_.empty()); 134 RTC_DCHECK(!clusters_.empty());
130 RTC_DCHECK(ProbingState::kActive == probing_state_); 135 RTC_DCHECK(ProbingState::kActive == probing_state_);
131 return clusters_.front().id; 136 return clusters_.front().id;
132 } 137 }
133 138
134 // Probe size is recommended based on the probe bitrate required. We choose 139 // Probe size is recommended based on the probe bitrate required. We choose
135 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be 140 // a minimum of twice |kMinProbeDeltaMs| interval to allow scheduling to be
136 // feasible. 141 // feasible.
137 size_t BitrateProber::RecommendedMinProbeSize() const { 142 size_t BitrateProber::RecommendedMinProbeSize() const {
138 RTC_DCHECK(!clusters_.empty()); 143 RTC_DCHECK(!clusters_.empty());
139 return clusters_.front().bitrate_bps * 2 * kMinProbeDeltaMs / (8 * 1000); 144 return clusters_.front().bitrate_bps * 3 * kMinProbeDeltaMs / (8 * 1000);
140 } 145 }
141 146
142 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) { 147 void BitrateProber::ProbeSent(int64_t now_ms, size_t bytes) {
143 RTC_DCHECK(probing_state_ == ProbingState::kActive); 148 RTC_DCHECK(probing_state_ == ProbingState::kActive);
144 RTC_DCHECK_GT(bytes, 0); 149 RTC_DCHECK_GT(bytes, 0);
145 150
146 if (!clusters_.empty()) { 151 if (!clusters_.empty()) {
147 ProbeCluster* cluster = &clusters_.front(); 152 ProbeCluster* cluster = &clusters_.front();
148 if (cluster->sent_probes == 0) { 153 if (cluster->sent_probes == 0) {
149 RTC_DCHECK_EQ(cluster->time_started_ms, -1); 154 RTC_DCHECK_EQ(cluster->time_started_ms, -1);
(...skipping 17 matching lines...) Expand all
167 172
168 // Compute the time delta from the cluster start to ensure probe bitrate stays 173 // Compute the time delta from the cluster start to ensure probe bitrate stays
169 // close to the target bitrate. Result is in milliseconds. 174 // close to the target bitrate. Result is in milliseconds.
170 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) / 175 int64_t delta_ms = (8000ll * cluster.sent_bytes + cluster.bitrate_bps / 2) /
171 cluster.bitrate_bps; 176 cluster.bitrate_bps;
172 return cluster.time_started_ms + delta_ms; 177 return cluster.time_started_ms + delta_ms;
173 } 178 }
174 179
175 180
176 } // namespace webrtc 181 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/alr_detector_unittest.cc ('k') | webrtc/modules/pacing/bitrate_prober_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698