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

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

Issue 1688703002: Prevent busy-looping PacedSender on small packets. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps; 67 bitrates_bps[i] = kProbeBitrateMultipliers[i] * bitrate_bps;
68 bitrate_log << " " << bitrates_bps[i]; 68 bitrate_log << " " << bitrates_bps[i];
69 // We need one extra to get 5 deltas for the first probe. 69 // We need one extra to get 5 deltas for the first probe.
70 if (i == 0) 70 if (i == 0)
71 probe_bitrates_.push_back(bitrates_bps[i]); 71 probe_bitrates_.push_back(bitrates_bps[i]);
72 for (int j = 0; j < kPacketsPerProbe; ++j) 72 for (int j = 0; j < kPacketsPerProbe; ++j)
73 probe_bitrates_.push_back(bitrates_bps[i]); 73 probe_bitrates_.push_back(bitrates_bps[i]);
74 } 74 }
75 bitrate_log << ", num packets: " << probe_bitrates_.size(); 75 bitrate_log << ", num packets: " << probe_bitrates_.size();
76 LOG(LS_INFO) << bitrate_log.str().c_str(); 76 LOG(LS_INFO) << bitrate_log.str().c_str();
77 // Set last send time to non-(-1) so TimeUntilNextProbe doesn't short circuit.
78 time_last_send_ms_ = 0;
77 probing_state_ = kProbing; 79 probing_state_ = kProbing;
78 } 80 }
79 81
80 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) { 82 int BitrateProber::TimeUntilNextProbe(int64_t now_ms) {
81 if (probing_state_ != kDisabled && probe_bitrates_.empty()) { 83 if (probing_state_ != kDisabled && probe_bitrates_.empty()) {
82 probing_state_ = kWait; 84 probing_state_ = kWait;
83 } 85 }
84 if (probe_bitrates_.empty()) { 86 if (probe_bitrates_.empty() || time_last_send_ms_ == -1) {
85 // No probe started, or waiting for next probe. 87 // No probe started, or waiting for next probe.
stefan-webrtc 2016/02/10 10:56:19 Given line 78, is this comment still correct?
pbos-webrtc 2016/02/10 13:19:08 Done.
86 return -1; 88 return -1;
87 } 89 }
88 int64_t elapsed_time_ms = now_ms - time_last_send_ms_; 90 int64_t elapsed_time_ms = now_ms - time_last_send_ms_;
91 // If no packets have been sent for n milliseconds, inactivate to not keep
stefan-webrtc 2016/02/10 10:56:19 deactivate
pbos-webrtc 2016/02/10 13:19:08 Done.
92 // spinning.
93 static const int kSendDeltaUntilConsideredInactiveMs = 5000;
94 if (elapsed_time_ms > kSendDeltaUntilConsideredInactiveMs) {
95 time_last_send_ms_ = -1;
96 packet_size_last_send_ = 0;
97 return -1;
98 }
stefan-webrtc 2016/02/10 10:56:19 Shouldn't we change the state to say we're no long
pbos-webrtc 2016/02/10 13:19:08 Changed state to allow a fresh probe.
89 // We will send the first probe packet immediately if no packet has been 99 // We will send the first probe packet immediately if no packet has been
90 // sent before. 100 // sent before.
91 int time_until_probe_ms = 0; 101 int time_until_probe_ms = 0;
92 if (packet_size_last_send_ > PacedSender::kMinProbePacketSize && 102 if (packet_size_last_send_ != 0 && probing_state_ == kProbing) {
93 probing_state_ == kProbing) {
94 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_, 103 int next_delta_ms = ComputeDeltaFromBitrate(packet_size_last_send_,
95 probe_bitrates_.front()); 104 probe_bitrates_.front());
96 time_until_probe_ms = next_delta_ms - elapsed_time_ms; 105 time_until_probe_ms = next_delta_ms - elapsed_time_ms;
97 // There is no point in trying to probe with less than 1 ms between packets 106 // There is no point in trying to probe with less than 1 ms between packets
98 // as it essentially means trying to probe at infinite bandwidth. 107 // as it essentially means trying to probe at infinite bandwidth.
99 const int kMinProbeDeltaMs = 1; 108 const int kMinProbeDeltaMs = 1;
100 // If we have waited more than 3 ms for a new packet to probe with we will 109 // If we have waited more than 3 ms for a new packet to probe with we will
101 // consider this probing session over. 110 // consider this probing session over.
102 const int kMaxProbeDelayMs = 3; 111 const int kMaxProbeDelayMs = 3;
103 if (next_delta_ms < kMinProbeDeltaMs || 112 if (next_delta_ms < kMinProbeDeltaMs ||
104 time_until_probe_ms < -kMaxProbeDelayMs) { 113 time_until_probe_ms < -kMaxProbeDelayMs) {
105 // We currently disable probing after the first probe, as we only want 114 // We currently disable probing after the first probe, as we only want
106 // to probe at the beginning of a connection. We should set this to 115 // to probe at the beginning of a connection. We should set this to
107 // kWait if we later want to probe periodically. 116 // kWait if we later want to probe periodically.
108 probing_state_ = kWait; 117 probing_state_ = kWait;
109 LOG(LS_INFO) << "Next delta too small, stop probing."; 118 LOG(LS_INFO) << "Next delta too small, stop probing.";
110 time_until_probe_ms = 0; 119 time_until_probe_ms = 0;
111 } 120 }
112 } 121 }
113 return std::max(time_until_probe_ms, 0); 122 return std::max(time_until_probe_ms, 0);
114 } 123 }
115 124
116 size_t BitrateProber::RecommendedPacketSize() const { 125 size_t BitrateProber::RecommendedPacketSize() const {
117 return packet_size_last_send_; 126 return packet_size_last_send_;
118 } 127 }
119 128
120 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) { 129 void BitrateProber::PacketSent(int64_t now_ms, size_t packet_size) {
121 assert(packet_size > 0); 130 assert(packet_size > 0);
131 if (packet_size < PacedSender::kMinProbePacketSize)
132 return;
122 packet_size_last_send_ = packet_size; 133 packet_size_last_send_ = packet_size;
123 time_last_send_ms_ = now_ms; 134 time_last_send_ms_ = now_ms;
124 if (probing_state_ != kProbing) 135 if (probing_state_ != kProbing)
125 return; 136 return;
126 if (!probe_bitrates_.empty()) 137 if (!probe_bitrates_.empty())
127 probe_bitrates_.pop_front(); 138 probe_bitrates_.pop_front();
128 } 139 }
129 } // namespace webrtc 140 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/pacing/bitrate_prober_unittest.cc » ('j') | webrtc/modules/pacing/paced_sender.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698