| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 210 } |
| 211 | 211 |
| 212 void RequestHigherResolutionThan(int pixel_count) { | 212 void RequestHigherResolutionThan(int pixel_count) { |
| 213 rtc::CritScope lock(&crit_); | 213 rtc::CritScope lock(&crit_); |
| 214 if (!IsResolutionScalingEnabledLocked()) { | 214 if (!IsResolutionScalingEnabledLocked()) { |
| 215 // This can happen since |degradation_preference_| is set on | 215 // This can happen since |degradation_preference_| is set on |
| 216 // libjingle's worker thread but the adaptation is done on the encoder | 216 // libjingle's worker thread but the adaptation is done on the encoder |
| 217 // task queue. | 217 // task queue. |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 // The input video frame size will have a resolution with "one step up" | 220 // On step down we request at most 3/5 the pixel count of the previous |
| 221 // pixels than |max_pixel_count_step_up| where "one step up" depends on | 221 // resolution, so in order to take "one step up" we request a resolution as |
| 222 // how the source can scale the input frame size. We still cap the step up | 222 // close as possible to 5/3 of the current resolution. The actual pixel |
| 223 // to be at most twice the number of pixels. | 223 // count selected depends on the capabilities of the source. In order to not |
| 224 // take a too large step up, we cap the requested pixel count to be at most |
| 225 // four time the current number of pixels. |
| 224 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3); | 226 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3); |
| 225 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4); | 227 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4); |
| 226 if (source_) | 228 if (source_) |
| 227 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 229 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
| 228 } | 230 } |
| 229 | 231 |
| 230 private: | 232 private: |
| 231 bool IsResolutionScalingEnabledLocked() const | 233 bool IsResolutionScalingEnabledLocked() const |
| 232 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 234 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
| 233 return degradation_preference_ != | 235 return degradation_preference_ != |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 736 |
| 735 if (stats_proxy_ && video_suspension_changed) { | 737 if (stats_proxy_ && video_suspension_changed) { |
| 736 LOG(LS_INFO) << "Video suspend state changed to: " | 738 LOG(LS_INFO) << "Video suspend state changed to: " |
| 737 << (video_is_suspended ? "suspended" : "not suspended"); | 739 << (video_is_suspended ? "suspended" : "not suspended"); |
| 738 stats_proxy_->OnSuspendChange(video_is_suspended); | 740 stats_proxy_->OnSuspendChange(video_is_suspended); |
| 739 } | 741 } |
| 740 } | 742 } |
| 741 | 743 |
| 742 void ViEEncoder::AdaptDown(AdaptReason reason) { | 744 void ViEEncoder::AdaptDown(AdaptReason reason) { |
| 743 RTC_DCHECK_RUN_ON(&encoder_queue_); | 745 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 744 if (degradation_preference_ != DegradationPreference::kBalanced || | 746 if (degradation_preference_ != DegradationPreference::kBalanced) |
| 745 !last_frame_info_) { | |
| 746 return; | 747 return; |
| 747 } | 748 RTC_DCHECK(static_cast<bool>(last_frame_info_)); |
| 748 int current_pixel_count = last_frame_info_->pixel_count(); | 749 int current_pixel_count = last_frame_info_->pixel_count(); |
| 749 if (last_adaptation_request_ && | 750 if (last_adaptation_request_ && |
| 750 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown && | 751 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown && |
| 751 current_pixel_count >= last_adaptation_request_->input_pixel_count_) { | 752 current_pixel_count >= last_adaptation_request_->input_pixel_count_) { |
| 752 // Don't request lower resolution if the current resolution is not lower | 753 // Don't request lower resolution if the current resolution is not lower |
| 753 // than the last time we asked for the resolution to be lowered. | 754 // than the last time we asked for the resolution to be lowered. |
| 754 return; | 755 return; |
| 755 } | 756 } |
| 756 last_adaptation_request_.emplace(AdaptationRequest{ | 757 last_adaptation_request_.emplace(AdaptationRequest{ |
| 757 current_pixel_count, AdaptationRequest::Mode::kAdaptDown}); | 758 current_pixel_count, AdaptationRequest::Mode::kAdaptDown}); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 773 LOG(LS_INFO) << "Scaling down resolution."; | 774 LOG(LS_INFO) << "Scaling down resolution."; |
| 774 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 775 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 775 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 776 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 776 << " times for reason: " << (i ? "cpu" : "quality"); | 777 << " times for reason: " << (i ? "cpu" : "quality"); |
| 777 } | 778 } |
| 778 } | 779 } |
| 779 | 780 |
| 780 void ViEEncoder::AdaptUp(AdaptReason reason) { | 781 void ViEEncoder::AdaptUp(AdaptReason reason) { |
| 781 RTC_DCHECK_RUN_ON(&encoder_queue_); | 782 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 782 if (scale_counter_[reason] == 0 || | 783 if (scale_counter_[reason] == 0 || |
| 783 degradation_preference_ != DegradationPreference::kBalanced || | 784 degradation_preference_ != DegradationPreference::kBalanced) { |
| 784 !last_frame_info_) { | |
| 785 return; | 785 return; |
| 786 } | 786 } |
| 787 // Only scale if resolution is higher than last time we requested higher | 787 // Only scale if resolution is higher than last time we requested higher |
| 788 // resolution. | 788 // resolution. |
| 789 RTC_DCHECK(static_cast<bool>(last_frame_info_)); |
| 789 int current_pixel_count = last_frame_info_->pixel_count(); | 790 int current_pixel_count = last_frame_info_->pixel_count(); |
| 790 if (last_adaptation_request_ && | 791 if (last_adaptation_request_ && |
| 791 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp && | 792 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp && |
| 792 current_pixel_count <= last_adaptation_request_->input_pixel_count_) { | 793 current_pixel_count <= last_adaptation_request_->input_pixel_count_) { |
| 793 // Don't request higher resolution if the current resolution is not higher | 794 // Don't request higher resolution if the current resolution is not higher |
| 794 // than the last time we asked for the resolution to be higher. | 795 // than the last time we asked for the resolution to be higher. |
| 795 return; | 796 return; |
| 796 } | 797 } |
| 797 last_adaptation_request_.emplace(AdaptationRequest{ | 798 last_adaptation_request_.emplace(AdaptationRequest{ |
| 798 current_pixel_count, AdaptationRequest::Mode::kAdaptUp}); | 799 current_pixel_count, AdaptationRequest::Mode::kAdaptUp}); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 811 --scale_counter_[reason]; | 812 --scale_counter_[reason]; |
| 812 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 813 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 813 LOG(LS_INFO) << "Scaling up resolution."; | 814 LOG(LS_INFO) << "Scaling up resolution."; |
| 814 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 815 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 815 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 816 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 816 << " times for reason: " << (i ? "cpu" : "quality"); | 817 << " times for reason: " << (i ? "cpu" : "quality"); |
| 817 } | 818 } |
| 818 } | 819 } |
| 819 | 820 |
| 820 } // namespace webrtc | 821 } // namespace webrtc |
| OLD | NEW |