| 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) { |
| 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); | 445 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); |
| 435 } | 446 } |
| 436 | 447 |
| 437 pending_encoder_reconfiguration_ = false; | 448 pending_encoder_reconfiguration_ = false; |
| 438 | 449 |
| 439 sink_->OnEncoderConfigurationChanged( | 450 sink_->OnEncoderConfigurationChanged( |
| 440 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 451 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
| 441 | 452 |
| 442 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | 453 const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
| 443 if (scaling_enabled_ && scaling_settings.enabled) { | 454 if (scaling_enabled_ && scaling_settings.enabled) { |
| 455 // Drop frames and scale down until desired quality is achieved. |
| 456 initial_rampup_ = true; |
| 444 if (scaling_settings.thresholds) { | 457 if (scaling_settings.thresholds) { |
| 445 quality_scaler_.reset( | 458 quality_scaler_.reset( |
| 446 new QualityScaler(this, *(scaling_settings.thresholds))); | 459 new QualityScaler(this, *(scaling_settings.thresholds))); |
| 447 } else { | 460 } else { |
| 448 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | 461 quality_scaler_.reset(new QualityScaler(this, codec_type_)); |
| 449 } | 462 } |
| 450 } else { | 463 } else { |
| 451 quality_scaler_.reset(nullptr); | 464 quality_scaler_.reset(nullptr); |
| 452 stats_proxy_->SetResolutionRestrictionStats( | 465 stats_proxy_->SetResolutionRestrictionStats( |
| 453 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); | 466 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 566 |
| 554 if (EncoderPaused()) { | 567 if (EncoderPaused()) { |
| 555 TraceFrameDropStart(); | 568 TraceFrameDropStart(); |
| 556 return; | 569 return; |
| 557 } | 570 } |
| 558 TraceFrameDropEnd(); | 571 TraceFrameDropEnd(); |
| 559 | 572 |
| 560 last_frame_height_ = video_frame.height(); | 573 last_frame_height_ = video_frame.height(); |
| 561 last_frame_width_ = video_frame.width(); | 574 last_frame_width_ = video_frame.width(); |
| 562 | 575 |
| 576 int expected_pixel_count = |
| 577 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000); |
| 578 if (initial_rampup_ && video_frame.size() > expected_pixel_count) { |
| 579 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; |
| 580 ScaleDown(kQuality); |
| 581 return; |
| 582 } |
| 583 initial_rampup_ = false; |
| 584 |
| 563 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 585 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 564 "Encode"); | 586 "Encode"); |
| 565 | 587 |
| 566 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 588 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
| 567 | 589 |
| 568 if (codec_type_ == webrtc::kVideoCodecVP8) { | 590 if (codec_type_ == webrtc::kVideoCodecVP8) { |
| 569 webrtc::CodecSpecificInfo codec_specific_info; | 591 webrtc::CodecSpecificInfo codec_specific_info; |
| 570 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 592 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 571 | 593 |
| 572 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 594 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); | 740 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
| 719 break; | 741 break; |
| 720 } | 742 } |
| 721 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 743 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
| 722 max_pixel_count_step_up_ = rtc::Optional<int>(); | 744 max_pixel_count_step_up_ = rtc::Optional<int>(); |
| 723 ++scale_counter_[reason]; | 745 ++scale_counter_[reason]; |
| 724 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 746 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
| 725 LOG(LS_INFO) << "Scaling down resolution."; | 747 LOG(LS_INFO) << "Scaling down resolution."; |
| 726 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 748 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 727 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 749 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 728 << " times for reason: " << (i ? "quality" : "cpu"); | 750 << " times for reason: " << (i ? "cpu" : "quality"); |
| 729 } | 751 } |
| 730 } | 752 } |
| 731 | 753 |
| 732 void ViEEncoder::ScaleUp(ScaleReason reason) { | 754 void ViEEncoder::ScaleUp(ScaleReason reason) { |
| 733 RTC_DCHECK_RUN_ON(&encoder_queue_); | 755 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 734 if (scale_counter_[reason] == 0 || !scaling_enabled_) | 756 if (scale_counter_[reason] == 0 || !scaling_enabled_) |
| 735 return; | 757 return; |
| 736 // Only scale if resolution is higher than last time | 758 // Only scale if resolution is higher than last time |
| 737 // we requested higher resolution. | 759 // we requested higher resolution. |
| 738 int current_pixel_count = last_frame_height_ * last_frame_width_; | 760 int current_pixel_count = last_frame_height_ * last_frame_width_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 754 --scale_counter_[reason]; | 776 --scale_counter_[reason]; |
| 755 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 777 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 756 LOG(LS_INFO) << "Scaling up resolution."; | 778 LOG(LS_INFO) << "Scaling up resolution."; |
| 757 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 779 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 758 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 780 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 759 << " times for reason: " << (i ? "cpu" : "quality"); | 781 << " times for reason: " << (i ? "cpu" : "quality"); |
| 760 } | 782 } |
| 761 } | 783 } |
| 762 | 784 |
| 763 } // namespace webrtc | 785 } // namespace webrtc |
| OLD | NEW |