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

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/screenshare_layers.cc

Issue 2529073003: Fix perf regression in screenshare temporal layer bitrate allocation (Closed)
Patch Set: Yet another failing test Created 4 years 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 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
2 * 2 *
3 * Use of this source code is governed by a BSD-style license 3 * Use of this source code is governed by a BSD-style license
4 * that can be found in the LICENSE file in the root of the source 4 * that can be found in the LICENSE file in the root of the source
5 * tree. An additional intellectual property rights grant can be found 5 * tree. An additional intellectual property rights grant can be found
6 * in the file PATENTS. All contributing project authors may 6 * in the file PATENTS. All contributing project authors may
7 * be found in the AUTHORS file in the root of the source tree. 7 * be found in the AUTHORS file in the root of the source tree.
8 */ 8 */
9 9
10 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" 10 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Make sure both frame droppers leak out bits. 155 // Make sure both frame droppers leak out bits.
156 layers_[0].UpdateDebt(ts_diff / 90); 156 layers_[0].UpdateDebt(ts_diff / 90);
157 layers_[1].UpdateDebt(ts_diff / 90); 157 layers_[1].UpdateDebt(ts_diff / 90);
158 last_timestamp_ = timestamp; 158 last_timestamp_ = timestamp;
159 return flags; 159 return flags;
160 } 160 }
161 161
162 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps, 162 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps,
163 int max_bitrate_kbps, 163 int max_bitrate_kbps,
164 int framerate) { 164 int framerate) {
165 bitrate_updated_ =
166 bitrate_kbps != static_cast<int>(layers_[0].target_rate_kbps_) ||
167 max_bitrate_kbps != static_cast<int>(layers_[1].target_rate_kbps_) ||
168 framerate != framerate_;
165 layers_[0].target_rate_kbps_ = bitrate_kbps; 169 layers_[0].target_rate_kbps_ = bitrate_kbps;
166 layers_[1].target_rate_kbps_ = max_bitrate_kbps; 170 layers_[1].target_rate_kbps_ = max_bitrate_kbps;
167 framerate_ = framerate; 171 framerate_ = framerate;
168 bitrate_updated_ = true;
169 172
170 std::vector<uint32_t> allocation; 173 std::vector<uint32_t> allocation;
171 allocation.push_back(bitrate_kbps); 174 allocation.push_back(bitrate_kbps);
172 if (max_bitrate_kbps > bitrate_kbps) 175 if (max_bitrate_kbps > bitrate_kbps)
173 allocation.push_back(max_bitrate_kbps - bitrate_kbps); 176 allocation.push_back(max_bitrate_kbps - bitrate_kbps);
174 return allocation; 177 return allocation;
175 } 178 }
176 179
177 void ScreenshareLayers::FrameEncoded(unsigned int size, 180 void ScreenshareLayers::FrameEncoded(unsigned int size,
178 uint32_t timestamp, 181 uint32_t timestamp,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // If too soon from previous sync frame, don't issue a new one. 258 // If too soon from previous sync frame, don't issue a new one.
256 return false; 259 return false;
257 } 260 }
258 // Issue a sync frame if difference in quality between TL0 and TL1 isn't too 261 // Issue a sync frame if difference in quality between TL0 and TL1 isn't too
259 // large. 262 // large.
260 if (layers_[0].last_qp - layers_[1].last_qp < kQpDeltaThresholdForSync) 263 if (layers_[0].last_qp - layers_[1].last_qp < kQpDeltaThresholdForSync)
261 return true; 264 return true;
262 return false; 265 return false;
263 } 266 }
264 267
268 uint32_t ScreenshareLayers::GetCodecTargetBitrateKbps() const {
269 uint32_t target_bitrate_kbps = layers_[0].target_rate_kbps_;
270
271 if (number_of_temporal_layers_ > 1) {
272 // Calculate a codec target bitrate. This may be higher than TL0, gaining
273 // quality at the expense of frame rate at TL0. Constraints:
274 // - TL0 frame rate no less than framerate / kMaxTL0FpsReduction.
275 // - Target rate * kAcceptableTargetOvershoot should not exceed TL1 rate.
276 target_bitrate_kbps =
277 std::min(layers_[0].target_rate_kbps_ * kMaxTL0FpsReduction,
278 layers_[1].target_rate_kbps_ / kAcceptableTargetOvershoot);
279 }
280
281 return std::max(layers_[0].target_rate_kbps_, target_bitrate_kbps);
282 }
283
265 bool ScreenshareLayers::UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) { 284 bool ScreenshareLayers::UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) {
266 bool cfg_updated = false; 285 bool cfg_updated = false;
267 if (bitrate_updated_) { 286 uint32_t target_bitrate_kbps = GetCodecTargetBitrateKbps();
268 uint32_t target_bitrate_kbps = layers_[0].target_rate_kbps_; 287 if (bitrate_updated_ || cfg->rc_target_bitrate != target_bitrate_kbps) {
269 288 cfg->rc_target_bitrate = target_bitrate_kbps;
270 if (number_of_temporal_layers_ > 1) {
271 // Calculate a codec target bitrate. This may be higher than TL0, gaining
272 // quality at the expense of frame rate at TL0. Constraints:
273 // - TL0 frame rate no less than framerate / kMaxTL0FpsReduction.
274 // - Target rate * kAcceptableTargetOvershoot should not exceed TL1 rate.
275 target_bitrate_kbps =
276 std::min(layers_[0].target_rate_kbps_ * kMaxTL0FpsReduction,
277 layers_[1].target_rate_kbps_ / kAcceptableTargetOvershoot);
278
279 cfg->rc_target_bitrate =
280 std::max(layers_[0].target_rate_kbps_, target_bitrate_kbps);
281 }
282 289
283 // Don't reconfigure qp limits during quality boost frames. 290 // Don't reconfigure qp limits during quality boost frames.
284 if (active_layer_ == -1 || 291 if (active_layer_ == -1 ||
285 layers_[active_layer_].state != TemporalLayer::State::kQualityBoost) { 292 layers_[active_layer_].state != TemporalLayer::State::kQualityBoost) {
286 min_qp_ = cfg->rc_min_quantizer; 293 min_qp_ = cfg->rc_min_quantizer;
287 max_qp_ = cfg->rc_max_quantizer; 294 max_qp_ = cfg->rc_max_quantizer;
288 // After a dropped frame, a frame with max qp will be encoded and the 295 // After a dropped frame, a frame with max qp will be encoded and the
289 // quality will then ramp up from there. To boost the speed of recovery, 296 // quality will then ramp up from there. To boost the speed of recovery,
290 // encode the next frame with lower max qp. TL0 is the most important to 297 // encode the next frame with lower max qp. TL0 is the most important to
291 // improve since the errors in this layer will propagate to TL1. 298 // improve since the errors in this layer will propagate to TL1.
(...skipping 30 matching lines...) Expand all
322 if (max_qp_ == -1) 329 if (max_qp_ == -1)
323 return cfg_updated; 330 return cfg_updated;
324 adjusted_max_qp = max_qp_; // Set the normal max qp. 331 adjusted_max_qp = max_qp_; // Set the normal max qp.
325 } 332 }
326 333
327 if (adjusted_max_qp == cfg->rc_max_quantizer) 334 if (adjusted_max_qp == cfg->rc_max_quantizer)
328 return cfg_updated; 335 return cfg_updated;
329 336
330 cfg->rc_max_quantizer = adjusted_max_qp; 337 cfg->rc_max_quantizer = adjusted_max_qp;
331 cfg_updated = true; 338 cfg_updated = true;
339
332 return cfg_updated; 340 return cfg_updated;
333 } 341 }
334 342
335 void ScreenshareLayers::TemporalLayer::UpdateDebt(int64_t delta_ms) { 343 void ScreenshareLayers::TemporalLayer::UpdateDebt(int64_t delta_ms) {
336 uint32_t debt_reduction_bytes = target_rate_kbps_ * delta_ms / 8; 344 uint32_t debt_reduction_bytes = target_rate_kbps_ * delta_ms / 8;
337 if (debt_reduction_bytes >= debt_bytes_) { 345 if (debt_reduction_bytes >= debt_bytes_) {
338 debt_bytes_ = 0; 346 debt_bytes_ = 0;
339 } else { 347 } else {
340 debt_bytes_ -= debt_reduction_bytes; 348 debt_bytes_ -= debt_reduction_bytes;
341 } 349 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", 381 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp",
374 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); 382 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_);
375 RTC_HISTOGRAM_COUNTS_10000( 383 RTC_HISTOGRAM_COUNTS_10000(
376 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", 384 "WebRTC.Video.Screenshare.Layer1.TargetBitrate",
377 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); 385 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_);
378 } 386 }
379 } 387 }
380 } 388 }
381 389
382 } // namespace webrtc 390 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698