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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.cc

Issue 2029593002: Update RateStatistics to handle too-little-data case. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment Created 4 years, 6 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 26 matching lines...) Expand all
37 kTimestampToMs, 37 kTimestampToMs,
38 enable_burst_grouping), 38 enable_burst_grouping),
39 estimator(options), 39 estimator(options),
40 detector(options) {} 40 detector(options) {}
41 int64_t last_packet_time_ms; 41 int64_t last_packet_time_ms;
42 InterArrival inter_arrival; 42 InterArrival inter_arrival;
43 OveruseEstimator estimator; 43 OveruseEstimator estimator;
44 OveruseDetector detector; 44 OveruseDetector detector;
45 }; 45 };
46 46
47 RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( 47 RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(
48 RemoteBitrateObserver* observer, 48 RemoteBitrateObserver* observer,
49 Clock* clock) 49 Clock* clock)
50 : clock_(clock), 50 : clock_(clock),
51 incoming_bitrate_(kBitrateWindowMs, 8000), 51 incoming_bitrate_(kBitrateWindowMs, 8000),
52 remote_rate_(new AimdRateControl()), 52 last_valid_incoming_bitrate_(0),
53 observer_(observer), 53 remote_rate_(new AimdRateControl()),
54 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 54 observer_(observer),
55 last_process_time_(-1), 55 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
56 process_interval_ms_(kProcessIntervalMs) { 56 last_process_time_(-1),
57 process_interval_ms_(kProcessIntervalMs) {
57 assert(observer_); 58 assert(observer_);
58 LOG(LS_INFO) << "RemoteBitrateEstimatorSingleStream: Instantiating."; 59 LOG(LS_INFO) << "RemoteBitrateEstimatorSingleStream: Instantiating.";
59 } 60 }
60 61
61 RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream() { 62 RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream() {
62 while (!overuse_detectors_.empty()) { 63 while (!overuse_detectors_.empty()) {
63 SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.begin(); 64 SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.begin();
64 delete it->second; 65 delete it->second;
65 overuse_detectors_.erase(it); 66 overuse_detectors_.erase(it);
66 } 67 }
(...skipping 16 matching lines...) Expand all
83 // callback will no longer be called for the old SSRC. This will be 84 // callback will no longer be called for the old SSRC. This will be
84 // automatically cleaned up when we have one RemoteBitrateEstimator per REMB 85 // automatically cleaned up when we have one RemoteBitrateEstimator per REMB
85 // group. 86 // group.
86 std::pair<SsrcOveruseEstimatorMap::iterator, bool> insert_result = 87 std::pair<SsrcOveruseEstimatorMap::iterator, bool> insert_result =
87 overuse_detectors_.insert(std::make_pair( 88 overuse_detectors_.insert(std::make_pair(
88 ssrc, new Detector(now_ms, OverUseDetectorOptions(), true))); 89 ssrc, new Detector(now_ms, OverUseDetectorOptions(), true)));
89 it = insert_result.first; 90 it = insert_result.first;
90 } 91 }
91 Detector* estimator = it->second; 92 Detector* estimator = it->second;
92 estimator->last_packet_time_ms = now_ms; 93 estimator->last_packet_time_ms = now_ms;
94
95 // Check if incoming bitrate estimate is valid, and if it needs to be reset.
96 rtc::Optional<uint32_t> incoming_bitrate = incoming_bitrate_.Rate(now_ms);
97 if (incoming_bitrate) {
98 last_valid_incoming_bitrate_ = *incoming_bitrate;
99 } else if (last_valid_incoming_bitrate_ > 0) {
100 // Incoming bitrate had a previous valid value, but now not enough data
101 // point are left within the current window. Reset incoming bitrate
102 // estimator so that the window size will only contain new data points.
103 incoming_bitrate_.Reset();
104 last_valid_incoming_bitrate_ = 0;
105 }
93 incoming_bitrate_.Update(payload_size, now_ms); 106 incoming_bitrate_.Update(payload_size, now_ms);
107
94 const BandwidthUsage prior_state = estimator->detector.State(); 108 const BandwidthUsage prior_state = estimator->detector.State();
95 uint32_t timestamp_delta = 0; 109 uint32_t timestamp_delta = 0;
96 int64_t time_delta = 0; 110 int64_t time_delta = 0;
97 int size_delta = 0; 111 int size_delta = 0;
98 if (estimator->inter_arrival.ComputeDeltas(rtp_timestamp, arrival_time_ms, 112 if (estimator->inter_arrival.ComputeDeltas(rtp_timestamp, arrival_time_ms,
99 payload_size, &timestamp_delta, 113 payload_size, &timestamp_delta,
100 &time_delta, &size_delta)) { 114 &time_delta, &size_delta)) {
101 double timestamp_delta_ms = timestamp_delta * kTimestampToMs; 115 double timestamp_delta_ms = timestamp_delta * kTimestampToMs;
102 estimator->estimator.Update(time_delta, timestamp_delta_ms, size_delta, 116 estimator->estimator.Update(time_delta, timestamp_delta_ms, size_delta,
103 estimator->detector.State()); 117 estimator->detector.State());
104 estimator->detector.Detect(estimator->estimator.offset(), 118 estimator->detector.Detect(estimator->estimator.offset(),
105 timestamp_delta_ms, 119 timestamp_delta_ms,
106 estimator->estimator.num_of_deltas(), now_ms); 120 estimator->estimator.num_of_deltas(), now_ms);
107 } 121 }
108 if (estimator->detector.State() == kBwOverusing) { 122 if (estimator->detector.State() == kBwOverusing) {
109 uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); 123 rtc::Optional<uint32_t> incoming_bitrate_bps =
110 if (prior_state != kBwOverusing || 124 incoming_bitrate_.Rate(now_ms);
111 remote_rate_->TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { 125 if (incoming_bitrate_bps &&
126 (prior_state != kBwOverusing ||
127 remote_rate_->TimeToReduceFurther(now_ms, *incoming_bitrate_bps))) {
112 // The first overuse should immediately trigger a new estimate. 128 // The first overuse should immediately trigger a new estimate.
113 // We also have to update the estimate immediately if we are overusing 129 // We also have to update the estimate immediately if we are overusing
114 // and the target bitrate is too high compared to what we are receiving. 130 // and the target bitrate is too high compared to what we are receiving.
115 UpdateEstimate(now_ms); 131 UpdateEstimate(now_ms);
116 } 132 }
117 } 133 }
118 } 134 }
119 135
120 void RemoteBitrateEstimatorSingleStream::Process() { 136 void RemoteBitrateEstimatorSingleStream::Process() {
121 if (TimeUntilNextProcess() > 0) { 137 if (TimeUntilNextProcess() > 0) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 bw_state = it->second->detector.State(); 176 bw_state = it->second->detector.State();
161 } 177 }
162 ++it; 178 ++it;
163 } 179 }
164 } 180 }
165 // We can't update the estimate if we don't have any active streams. 181 // We can't update the estimate if we don't have any active streams.
166 if (overuse_detectors_.empty()) { 182 if (overuse_detectors_.empty()) {
167 remote_rate_.reset(new AimdRateControl()); 183 remote_rate_.reset(new AimdRateControl());
168 return; 184 return;
169 } 185 }
186
170 double mean_noise_var = sum_var_noise / 187 double mean_noise_var = sum_var_noise /
171 static_cast<double>(overuse_detectors_.size()); 188 static_cast<double>(overuse_detectors_.size());
172 const RateControlInput input(bw_state, 189 const RateControlInput input(bw_state,
173 incoming_bitrate_.Rate(now_ms), 190 incoming_bitrate_.Rate(now_ms),
174 mean_noise_var); 191 mean_noise_var);
175 remote_rate_->Update(&input, now_ms); 192 remote_rate_->Update(&input, now_ms);
176 uint32_t target_bitrate = remote_rate_->UpdateBandwidthEstimate(now_ms); 193 uint32_t target_bitrate = remote_rate_->UpdateBandwidthEstimate(now_ms);
177 if (remote_rate_->ValidEstimate()) { 194 if (remote_rate_->ValidEstimate()) {
178 process_interval_ms_ = remote_rate_->GetFeedbackInterval(); 195 process_interval_ms_ = remote_rate_->GetFeedbackInterval();
179 std::vector<uint32_t> ssrcs; 196 std::vector<uint32_t> ssrcs;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 (*ssrcs)[i] = it->first; 240 (*ssrcs)[i] = it->first;
224 } 241 }
225 } 242 }
226 243
227 void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) { 244 void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) {
228 CriticalSectionScoped cs(crit_sect_.get()); 245 CriticalSectionScoped cs(crit_sect_.get());
229 remote_rate_->SetMinBitrate(min_bitrate_bps); 246 remote_rate_->SetMinBitrate(min_bitrate_bps);
230 } 247 }
231 248
232 } // namespace webrtc 249 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698