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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // task queue. | 182 // task queue. |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 // The input video frame size will have a resolution with less than or | 185 // The input video frame size will have a resolution with less than or |
| 186 // equal to |max_pixel_count| depending on how the source can scale the | 186 // equal to |max_pixel_count| depending on how the source can scale the |
| 187 // input frame size. | 187 // input frame size. |
| 188 const int pixels_wanted = (pixel_count * 3) / 5; | 188 const int pixels_wanted = (pixel_count * 3) / 5; |
| 189 if (pixels_wanted < kMinPixelsPerFrame) | 189 if (pixels_wanted < kMinPixelsPerFrame) |
| 190 return; | 190 return; |
| 191 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted); | 191 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted); |
| 192 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); | 192 sink_wants_.target_pixel_count = rtc::Optional<int>(); |
| 193 if (source_) | 193 if (source_) |
| 194 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 194 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void RequestHigherResolutionThan(int pixel_count) { | 197 void RequestHigherResolutionThan(int pixel_count) { |
| 198 rtc::CritScope lock(&crit_); | 198 rtc::CritScope lock(&crit_); |
| 199 if (!IsResolutionScalingEnabledLocked()) { | 199 if (!IsResolutionScalingEnabledLocked()) { |
| 200 // This can happen since |degradation_preference_| is set on | 200 // This can happen since |degradation_preference_| is set on |
| 201 // libjingle's worker thread but the adaptation is done on the encoder | 201 // libjingle's worker thread but the adaptation is done on the encoder |
| 202 // task queue. | 202 // task queue. |
| 203 return; | 203 return; |
| 204 } | 204 } |
| 205 // The input video frame size will have a resolution with "one step up" | 205 // The input video frame size will have a resolution with "one step up" |
| 206 // pixels than |max_pixel_count_step_up| where "one step up" depends on | 206 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
| 207 // how the source can scale the input frame size. | 207 // how the source can scale the input frame size. We still cap the step up |
| 208 sink_wants_.max_pixel_count = rtc::Optional<int>(); | 208 // to be at most twice the number of pixels. |
| 209 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | 209 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3); |
| 210 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4); | |
| 210 if (source_) | 211 if (source_) |
| 211 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 212 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
| 212 } | 213 } |
| 213 | 214 |
| 214 private: | 215 private: |
| 215 bool IsResolutionScalingEnabledLocked() const | 216 bool IsResolutionScalingEnabledLocked() const |
| 216 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 217 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
| 217 return degradation_preference_ != | 218 return degradation_preference_ != |
| 218 DegradationPreference::kMaintainResolution; | 219 DegradationPreference::kMaintainResolution; |
| 219 } | 220 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 610 |
| 610 EncodedImageCallback::Result result = | 611 EncodedImageCallback::Result result = |
| 611 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 612 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
| 612 | 613 |
| 613 int64_t time_sent_us = rtc::TimeMicros(); | 614 int64_t time_sent_us = rtc::TimeMicros(); |
| 614 uint32_t timestamp = encoded_image._timeStamp; | 615 uint32_t timestamp = encoded_image._timeStamp; |
| 615 const int qp = encoded_image.qp_; | 616 const int qp = encoded_image.qp_; |
| 616 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { | 617 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { |
| 617 RTC_DCHECK_RUN_ON(&encoder_queue_); | 618 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 618 overuse_detector_.FrameSent(timestamp, time_sent_us); | 619 overuse_detector_.FrameSent(timestamp, time_sent_us); |
| 619 if (quality_scaler_) | 620 if (quality_scaler_ && qp >= 0) |
|
nisse-webrtc
2017/02/06 08:43:19
Is this fix related to the other changes?
sprang_webrtc
2017/02/06 10:34:02
This is to prevent the quality scaler from using -
kthelgason
2017/02/06 13:31:05
SGTM. As part of the quality scaler work I tried t
sprang_webrtc
2017/02/06 13:49:53
Acknowledged.
| |
| 620 quality_scaler_->ReportQP(qp); | 621 quality_scaler_->ReportQP(qp); |
| 621 }); | 622 }); |
| 622 | 623 |
| 623 return result; | 624 return result; |
| 624 } | 625 } |
| 625 | 626 |
| 626 void ViEEncoder::OnDroppedFrame() { | 627 void ViEEncoder::OnDroppedFrame() { |
| 627 encoder_queue_.PostTask([this] { | 628 encoder_queue_.PostTask([this] { |
| 628 RTC_DCHECK_RUN_ON(&encoder_queue_); | 629 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 629 if (quality_scaler_) | 630 if (quality_scaler_) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 | 699 |
| 699 if (stats_proxy_ && video_suspension_changed) { | 700 if (stats_proxy_ && video_suspension_changed) { |
| 700 LOG(LS_INFO) << "Video suspend state changed to: " | 701 LOG(LS_INFO) << "Video suspend state changed to: " |
| 701 << (video_is_suspended ? "suspended" : "not suspended"); | 702 << (video_is_suspended ? "suspended" : "not suspended"); |
| 702 stats_proxy_->OnSuspendChange(video_is_suspended); | 703 stats_proxy_->OnSuspendChange(video_is_suspended); |
| 703 } | 704 } |
| 704 } | 705 } |
| 705 | 706 |
| 706 void ViEEncoder::AdaptDown(AdaptReason reason) { | 707 void ViEEncoder::AdaptDown(AdaptReason reason) { |
| 707 RTC_DCHECK_RUN_ON(&encoder_queue_); | 708 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 708 if (degradation_preference_ != DegradationPreference::kBalanced) | 709 if (degradation_preference_ != DegradationPreference::kBalanced || |
| 710 !last_frame_info_) { | |
| 709 return; | 711 return; |
| 710 // Request lower resolution if the current resolution is lower than last time | 712 } |
| 711 // we asked for the resolution to be lowered. | 713 int current_pixel_count = last_frame_info_->pixel_count(); |
| 712 int current_pixel_count = | 714 if (last_adaptation_request_ && last_adaptation_request_->adapt_down_ && |
| 713 last_frame_info_ ? last_frame_info_->pixel_count() : 0; | 715 current_pixel_count >= last_adaptation_request_->input_pixel_count_) { |
| 714 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) | 716 // Don't request lower resolution if the current resolution is not lower |
|
nisse-webrtc
2017/02/06 08:43:19
When do you expect this to be true? When the sourc
sprang_webrtc
2017/02/06 10:34:02
When the source hasn't yet acted on the previous r
| |
| 717 // than the last time we asked for the resolution to be lowered. | |
| 715 return; | 718 return; |
| 719 } | |
| 720 last_adaptation_request_.emplace( | |
| 721 AdaptationRequest{current_pixel_count, true}); | |
| 722 | |
| 716 switch (reason) { | 723 switch (reason) { |
| 717 case kQuality: | 724 case kQuality: |
| 718 stats_proxy_->OnQualityRestrictedResolutionChanged( | 725 stats_proxy_->OnQualityRestrictedResolutionChanged( |
| 719 scale_counter_[reason] + 1); | 726 scale_counter_[reason] + 1); |
| 720 break; | 727 break; |
| 721 case kCpu: | 728 case kCpu: |
| 722 if (scale_counter_[reason] >= kMaxCpuDowngrades) | 729 if (scale_counter_[reason] >= kMaxCpuDowngrades) |
| 723 return; | 730 return; |
| 724 // Update stats accordingly. | 731 // Update stats accordingly. |
| 725 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 732 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
| 726 break; | 733 break; |
| 727 } | 734 } |
| 728 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | |
| 729 max_pixel_count_step_up_ = rtc::Optional<int>(); | |
| 730 ++scale_counter_[reason]; | 735 ++scale_counter_[reason]; |
| 731 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 736 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
| 732 LOG(LS_INFO) << "Scaling down resolution."; | 737 LOG(LS_INFO) << "Scaling down resolution."; |
| 733 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 738 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 734 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 739 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 735 << " times for reason: " << (i ? "cpu" : "quality"); | 740 << " times for reason: " << (i ? "cpu" : "quality"); |
| 736 } | 741 } |
| 737 } | 742 } |
| 738 | 743 |
| 739 void ViEEncoder::AdaptUp(AdaptReason reason) { | 744 void ViEEncoder::AdaptUp(AdaptReason reason) { |
| 740 RTC_DCHECK_RUN_ON(&encoder_queue_); | 745 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 741 if (scale_counter_[reason] == 0 || | 746 if (scale_counter_[reason] == 0 || |
| 742 degradation_preference_ != DegradationPreference::kBalanced) { | 747 degradation_preference_ != DegradationPreference::kBalanced || |
| 748 !last_frame_info_) { | |
| 743 return; | 749 return; |
| 744 } | 750 } |
| 745 // Only scale if resolution is higher than last time | 751 // Only scale if resolution is higher than last time we requested higher |
| 746 // we requested higher resolution. | 752 // resolution. |
| 747 int current_pixel_count = | 753 int current_pixel_count = last_frame_info_->pixel_count(); |
| 748 last_frame_info_ ? last_frame_info_->pixel_count() : 0; | 754 if (last_adaptation_request_ && !last_adaptation_request_->adapt_down_ && |
| 749 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) | 755 current_pixel_count <= last_adaptation_request_->input_pixel_count_) { |
| 756 // Don't request higher resolution if the current resolution is not higher | |
| 757 // than the last time we asked for the resolution to be higher. | |
| 750 return; | 758 return; |
| 759 } | |
| 760 last_adaptation_request_.emplace( | |
| 761 AdaptationRequest{current_pixel_count, false}); | |
| 762 | |
| 751 switch (reason) { | 763 switch (reason) { |
| 752 case kQuality: | 764 case kQuality: |
| 753 stats_proxy_->OnQualityRestrictedResolutionChanged( | 765 stats_proxy_->OnQualityRestrictedResolutionChanged( |
| 754 scale_counter_[reason] - 1); | 766 scale_counter_[reason] - 1); |
| 755 break; | 767 break; |
| 756 case kCpu: | 768 case kCpu: |
| 757 // Update stats accordingly. | 769 // Update stats accordingly. |
| 758 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | 770 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > |
| 759 1); | 771 1); |
| 760 break; | 772 break; |
| 761 } | 773 } |
| 762 max_pixel_count_ = rtc::Optional<int>(); | |
| 763 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | |
| 764 --scale_counter_[reason]; | 774 --scale_counter_[reason]; |
| 765 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 775 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 766 LOG(LS_INFO) << "Scaling up resolution."; | 776 LOG(LS_INFO) << "Scaling up resolution."; |
| 767 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 777 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 768 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 778 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 769 << " times for reason: " << (i ? "cpu" : "quality"); | 779 << " times for reason: " << (i ? "cpu" : "quality"); |
| 770 } | 780 } |
| 771 } | 781 } |
| 772 | 782 |
| 773 } // namespace webrtc | 783 } // namespace webrtc |
| OLD | NEW |