Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 // remotely cope with the load right now. | 48 // remotely cope with the load right now. |
| 49 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { | 49 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { |
| 50 CpuOveruseOptions options; | 50 CpuOveruseOptions options; |
| 51 if (full_overuse_time) { | 51 if (full_overuse_time) { |
| 52 options.low_encode_usage_threshold_percent = 150; | 52 options.low_encode_usage_threshold_percent = 150; |
| 53 options.high_encode_usage_threshold_percent = 200; | 53 options.high_encode_usage_threshold_percent = 200; |
| 54 } | 54 } |
| 55 return options; | 55 return options; |
| 56 } | 56 } |
| 57 | 57 |
| 58 int MaximumFrameSizeForBitrate(int kbps) { | |
|
perkj_webrtc
2017/01/17 08:53:10
uint32_t encoder_start_bitrate_bps_
MaximumFrame
kthelgason
2017/01/18 09:16:16
Done.
| |
| 59 if (kbps > 0) { | |
| 60 if (kbps < 300 /* qvga */) { | |
| 61 return 320 * 240; | |
| 62 } else if (kbps < 500 /* vga */) { | |
| 63 return 640 * 480; | |
| 64 } | |
| 65 } | |
| 66 return std::numeric_limits<int>::max(); | |
| 67 } | |
| 68 | |
| 58 } // namespace | 69 } // namespace |
| 59 | 70 |
| 60 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { | 71 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { |
| 61 public: | 72 public: |
| 62 ConfigureEncoderTask(ViEEncoder* vie_encoder, | 73 ConfigureEncoderTask(ViEEncoder* vie_encoder, |
| 63 VideoEncoderConfig config, | 74 VideoEncoderConfig config, |
| 64 size_t max_data_payload_length, | 75 size_t max_data_payload_length, |
| 65 bool nack_enabled) | 76 bool nack_enabled) |
| 66 : vie_encoder_(vie_encoder), | 77 : vie_encoder_(vie_encoder), |
| 67 config_(std::move(config)), | 78 config_(std::move(config)), |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 248 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
| 238 }; | 249 }; |
| 239 | 250 |
| 240 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 251 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 241 SendStatisticsProxy* stats_proxy, | 252 SendStatisticsProxy* stats_proxy, |
| 242 const VideoSendStream::Config::EncoderSettings& settings, | 253 const VideoSendStream::Config::EncoderSettings& settings, |
| 243 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 254 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 244 EncodedFrameObserver* encoder_timing) | 255 EncodedFrameObserver* encoder_timing) |
| 245 : shutdown_event_(true /* manual_reset */, false), | 256 : shutdown_event_(true /* manual_reset */, false), |
| 246 number_of_cores_(number_of_cores), | 257 number_of_cores_(number_of_cores), |
| 258 initial_rampup_(false), | |
| 247 source_proxy_(new VideoSourceProxy(this)), | 259 source_proxy_(new VideoSourceProxy(this)), |
| 248 sink_(nullptr), | 260 sink_(nullptr), |
| 249 settings_(settings), | 261 settings_(settings), |
| 250 codec_type_(PayloadNameToCodecType(settings.payload_name) | 262 codec_type_(PayloadNameToCodecType(settings.payload_name) |
| 251 .value_or(VideoCodecType::kVideoCodecUnknown)), | 263 .value_or(VideoCodecType::kVideoCodecUnknown)), |
| 252 video_sender_(Clock::GetRealTimeClock(), this, this), | 264 video_sender_(Clock::GetRealTimeClock(), this, this), |
| 253 overuse_detector_(Clock::GetRealTimeClock(), | 265 overuse_detector_(Clock::GetRealTimeClock(), |
| 254 GetCpuOveruseOptions(settings.full_overuse_time), | 266 GetCpuOveruseOptions(settings.full_overuse_time), |
| 255 this, | 267 this, |
| 256 encoder_timing, | 268 encoder_timing, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); | 446 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); |
| 435 } | 447 } |
| 436 | 448 |
| 437 pending_encoder_reconfiguration_ = false; | 449 pending_encoder_reconfiguration_ = false; |
| 438 | 450 |
| 439 sink_->OnEncoderConfigurationChanged( | 451 sink_->OnEncoderConfigurationChanged( |
| 440 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 452 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
| 441 | 453 |
| 442 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | 454 const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
| 443 if (scaling_enabled_ && scaling_settings.enabled) { | 455 if (scaling_enabled_ && scaling_settings.enabled) { |
| 456 // Drop frames and scale down until desired quality is achieved. | |
| 457 initial_rampup_ = true; | |
| 444 if (scaling_settings.thresholds) { | 458 if (scaling_settings.thresholds) { |
| 445 quality_scaler_.reset( | 459 quality_scaler_.reset( |
| 446 new QualityScaler(this, *(scaling_settings.thresholds))); | 460 new QualityScaler(this, *(scaling_settings.thresholds))); |
| 447 } else { | 461 } else { |
| 448 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | 462 quality_scaler_.reset(new QualityScaler(this, codec_type_)); |
| 449 } | 463 } |
| 450 } else { | 464 } else { |
| 451 quality_scaler_.reset(nullptr); | 465 quality_scaler_.reset(nullptr); |
| 452 stats_proxy_->SetResolutionRestrictionStats( | 466 stats_proxy_->SetResolutionRestrictionStats( |
| 453 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); | 467 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 | 567 |
| 554 if (EncoderPaused()) { | 568 if (EncoderPaused()) { |
| 555 TraceFrameDropStart(); | 569 TraceFrameDropStart(); |
| 556 return; | 570 return; |
| 557 } | 571 } |
| 558 TraceFrameDropEnd(); | 572 TraceFrameDropEnd(); |
| 559 | 573 |
| 560 last_frame_height_ = video_frame.height(); | 574 last_frame_height_ = video_frame.height(); |
| 561 last_frame_width_ = video_frame.width(); | 575 last_frame_width_ = video_frame.width(); |
| 562 | 576 |
| 577 int expected_pixel_count = | |
|
perkj_webrtc
2017/01/17 08:53:10
nit: please remove this unnecessary temp.
perkj_webrtc
2017/01/17 10:30:02
oh, we should probably do this before Reconfigurin
kthelgason
2017/01/18 09:16:16
Done.
| |
| 578 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000); | |
|
perkj_webrtc
2017/01/17 08:53:10
nit: Why not use unit bps here too since that is w
kthelgason
2017/01/18 09:16:16
I started out implementing it that way, but change
| |
| 579 if (initial_rampup_ && video_frame.size() > expected_pixel_count) { | |
|
perkj_webrtc
2017/01/17 08:53:10
instead of initial_rampup being a bool- can we let
kthelgason
2017/01/18 09:16:16
That's a very good point, thanks. Done!
| |
| 580 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; | |
| 581 ScaleDown(kQuality); | |
| 582 return; | |
| 583 } | |
| 584 initial_rampup_ = false; | |
| 585 | |
| 563 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 586 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 564 "Encode"); | 587 "Encode"); |
| 565 | 588 |
| 566 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 589 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
| 567 | 590 |
| 568 if (codec_type_ == webrtc::kVideoCodecVP8) { | 591 if (codec_type_ == webrtc::kVideoCodecVP8) { |
| 569 webrtc::CodecSpecificInfo codec_specific_info; | 592 webrtc::CodecSpecificInfo codec_specific_info; |
| 570 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 593 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 571 | 594 |
| 572 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 595 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 741 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
| 719 break; | 742 break; |
| 720 } | 743 } |
| 721 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 744 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
| 722 max_pixel_count_step_up_ = rtc::Optional<int>(); | 745 max_pixel_count_step_up_ = rtc::Optional<int>(); |
| 723 ++scale_counter_[reason]; | 746 ++scale_counter_[reason]; |
| 724 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 747 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
| 725 LOG(LS_INFO) << "Scaling down resolution."; | 748 LOG(LS_INFO) << "Scaling down resolution."; |
| 726 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 749 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 727 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 750 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 728 << " times for reason: " << (i ? "quality" : "cpu"); | 751 << " times for reason: " << (i ? "cpu" : "quality"); |
| 729 } | 752 } |
| 730 } | 753 } |
| 731 | 754 |
| 732 void ViEEncoder::ScaleUp(ScaleReason reason) { | 755 void ViEEncoder::ScaleUp(ScaleReason reason) { |
| 733 RTC_DCHECK_RUN_ON(&encoder_queue_); | 756 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 734 if (scale_counter_[reason] == 0 || !scaling_enabled_) | 757 if (scale_counter_[reason] == 0 || !scaling_enabled_) |
| 735 return; | 758 return; |
| 736 // Only scale if resolution is higher than last time | 759 // Only scale if resolution is higher than last time |
| 737 // we requested higher resolution. | 760 // we requested higher resolution. |
| 738 int current_pixel_count = last_frame_height_ * last_frame_width_; | 761 int current_pixel_count = last_frame_height_ * last_frame_width_; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 754 --scale_counter_[reason]; | 777 --scale_counter_[reason]; |
| 755 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 778 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 756 LOG(LS_INFO) << "Scaling up resolution."; | 779 LOG(LS_INFO) << "Scaling up resolution."; |
| 757 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 780 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 758 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 781 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 759 << " times for reason: " << (i ? "cpu" : "quality"); | 782 << " times for reason: " << (i ? "cpu" : "quality"); |
| 760 } | 783 } |
| 761 } | 784 } |
| 762 | 785 |
| 763 } // namespace webrtc | 786 } // namespace webrtc |
| OLD | NEW |