| OLD | NEW |
| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 flags = -1; | 148 flags = -1; |
| 149 ++stats_.num_dropped_frames_; | 149 ++stats_.num_dropped_frames_; |
| 150 break; | 150 break; |
| 151 default: | 151 default: |
| 152 flags = -1; | 152 flags = -1; |
| 153 RTC_NOTREACHED(); | 153 RTC_NOTREACHED(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 int64_t ts_diff; | 156 int64_t ts_diff; |
| 157 if (last_timestamp_ == -1) { | 157 if (last_timestamp_ == -1) { |
| 158 ts_diff = | 158 ts_diff = kOneSecond90Khz / capture_framerate_.value_or(*target_framerate_); |
| 159 kOneSecond90Khz / incoming_framerate_.value_or(*target_framerate_); | |
| 160 } else { | 159 } else { |
| 161 ts_diff = unwrapped_timestamp - last_timestamp_; | 160 ts_diff = unwrapped_timestamp - last_timestamp_; |
| 162 } | 161 } |
| 163 // Make sure both frame droppers leak out bits. | 162 // Make sure both frame droppers leak out bits. |
| 164 layers_[0].UpdateDebt(ts_diff / 90); | 163 layers_[0].UpdateDebt(ts_diff / 90); |
| 165 layers_[1].UpdateDebt(ts_diff / 90); | 164 layers_[1].UpdateDebt(ts_diff / 90); |
| 166 last_timestamp_ = timestamp; | 165 last_timestamp_ = timestamp; |
| 167 return flags; | 166 return flags; |
| 168 } | 167 } |
| 169 | 168 |
| 170 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps, | 169 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps, |
| 171 int max_bitrate_kbps, | 170 int max_bitrate_kbps, |
| 172 int framerate) { | 171 int framerate) { |
| 173 RTC_DCHECK_GT(framerate, 0); | 172 RTC_DCHECK_GT(framerate, 0); |
| 174 if (!target_framerate_) { | 173 if (!target_framerate_) { |
| 175 // First OnRatesUpdated() is called during construction, with the configured | 174 // First OnRatesUpdated() is called during construction, with the configured |
| 176 // targets as parameters. | 175 // targets as parameters. |
| 177 target_framerate_.emplace(framerate); | 176 target_framerate_.emplace(framerate); |
| 178 incoming_framerate_ = target_framerate_; | 177 capture_framerate_ = target_framerate_; |
| 179 bitrate_updated_ = true; | 178 bitrate_updated_ = true; |
| 180 } else { | 179 } else { |
| 181 bitrate_updated_ = | 180 bitrate_updated_ = |
| 182 bitrate_kbps != static_cast<int>(layers_[0].target_rate_kbps_) || | 181 bitrate_kbps != static_cast<int>(layers_[0].target_rate_kbps_) || |
| 183 max_bitrate_kbps != static_cast<int>(layers_[1].target_rate_kbps_) || | 182 max_bitrate_kbps != static_cast<int>(layers_[1].target_rate_kbps_) || |
| 184 (incoming_framerate_ && | 183 (capture_framerate_ && |
| 185 framerate != static_cast<int>(*incoming_framerate_)); | 184 framerate != static_cast<int>(*capture_framerate_)); |
| 186 if (framerate < 0) { | 185 if (framerate < 0) { |
| 187 incoming_framerate_.reset(); | 186 capture_framerate_.reset(); |
| 188 } else { | 187 } else { |
| 189 incoming_framerate_.emplace(framerate); | 188 capture_framerate_.emplace(framerate); |
| 190 } | 189 } |
| 191 } | 190 } |
| 192 | 191 |
| 193 layers_[0].target_rate_kbps_ = bitrate_kbps; | 192 layers_[0].target_rate_kbps_ = bitrate_kbps; |
| 194 layers_[1].target_rate_kbps_ = max_bitrate_kbps; | 193 layers_[1].target_rate_kbps_ = max_bitrate_kbps; |
| 195 | 194 |
| 196 std::vector<uint32_t> allocation; | 195 std::vector<uint32_t> allocation; |
| 197 allocation.push_back(bitrate_kbps); | 196 allocation.push_back(bitrate_kbps); |
| 198 if (max_bitrate_kbps > bitrate_kbps) | 197 if (max_bitrate_kbps > bitrate_kbps) |
| 199 allocation.push_back(max_bitrate_kbps - bitrate_kbps); | 198 allocation.push_back(max_bitrate_kbps - bitrate_kbps); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 max_qp_ = cfg->rc_max_quantizer; | 319 max_qp_ = cfg->rc_max_quantizer; |
| 321 // After a dropped frame, a frame with max qp will be encoded and the | 320 // After a dropped frame, a frame with max qp will be encoded and the |
| 322 // quality will then ramp up from there. To boost the speed of recovery, | 321 // quality will then ramp up from there. To boost the speed of recovery, |
| 323 // encode the next frame with lower max qp. TL0 is the most important to | 322 // encode the next frame with lower max qp. TL0 is the most important to |
| 324 // improve since the errors in this layer will propagate to TL1. | 323 // improve since the errors in this layer will propagate to TL1. |
| 325 // Currently, reduce max qp by 20% for TL0 and 15% for TL1. | 324 // Currently, reduce max qp by 20% for TL0 and 15% for TL1. |
| 326 layers_[0].enhanced_max_qp = min_qp_ + (((max_qp_ - min_qp_) * 80) / 100); | 325 layers_[0].enhanced_max_qp = min_qp_ + (((max_qp_ - min_qp_) * 80) / 100); |
| 327 layers_[1].enhanced_max_qp = min_qp_ + (((max_qp_ - min_qp_) * 85) / 100); | 326 layers_[1].enhanced_max_qp = min_qp_ + (((max_qp_ - min_qp_) * 85) / 100); |
| 328 } | 327 } |
| 329 | 328 |
| 330 if (incoming_framerate_) { | 329 if (capture_framerate_) { |
| 331 int avg_frame_size = | 330 int avg_frame_size = |
| 332 (target_bitrate_kbps * 1000) / (8 * *incoming_framerate_); | 331 (target_bitrate_kbps * 1000) / (8 * *capture_framerate_); |
| 333 max_debt_bytes_ = 4 * avg_frame_size; | 332 max_debt_bytes_ = 4 * avg_frame_size; |
| 334 } | 333 } |
| 335 | 334 |
| 336 bitrate_updated_ = false; | 335 bitrate_updated_ = false; |
| 337 cfg_updated = true; | 336 cfg_updated = true; |
| 338 } | 337 } |
| 339 | 338 |
| 340 // Don't try to update boosts state if not active yet. | 339 // Don't try to update boosts state if not active yet. |
| 341 if (active_layer_ == -1) | 340 if (active_layer_ == -1) |
| 342 return cfg_updated; | 341 return cfg_updated; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", | 407 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", |
| 409 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); | 408 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); |
| 410 RTC_HISTOGRAM_COUNTS_10000( | 409 RTC_HISTOGRAM_COUNTS_10000( |
| 411 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", | 410 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", |
| 412 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); | 411 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); |
| 413 } | 412 } |
| 414 } | 413 } |
| 415 } | 414 } |
| 416 | 415 |
| 417 } // namespace webrtc | 416 } // namespace webrtc |
| OLD | NEW |