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 14 matching lines...) Expand all Loading... |
25 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 25 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
26 #include "webrtc/video/overuse_frame_detector.h" | 26 #include "webrtc/video/overuse_frame_detector.h" |
27 #include "webrtc/video/send_statistics_proxy.h" | 27 #include "webrtc/video/send_statistics_proxy.h" |
28 #include "webrtc/video_frame.h" | 28 #include "webrtc/video_frame.h" |
29 | 29 |
30 namespace webrtc { | 30 namespace webrtc { |
31 | 31 |
32 namespace { | 32 namespace { |
33 // Time interval for logging frame counts. | 33 // Time interval for logging frame counts. |
34 const int64_t kFrameLogIntervalMs = 60000; | 34 const int64_t kFrameLogIntervalMs = 60000; |
| 35 // We will never ask for a resolution lower than this. |
| 36 const int kMinPixelsPerFrame = 120 * 90; |
35 | 37 |
36 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle | 38 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle |
37 // pipelining encoders better (multiple input frames before something comes | 39 // pipelining encoders better (multiple input frames before something comes |
38 // out). This should effectively turn off CPU adaptations for systems that | 40 // out). This should effectively turn off CPU adaptations for systems that |
39 // remotely cope with the load right now. | 41 // remotely cope with the load right now. |
40 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { | 42 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { |
41 CpuOveruseOptions options; | 43 CpuOveruseOptions options; |
42 if (full_overuse_time) { | 44 if (full_overuse_time) { |
43 options.low_encode_usage_threshold_percent = 150; | 45 options.low_encode_usage_threshold_percent = 150; |
44 options.high_encode_usage_threshold_percent = 200; | 46 options.high_encode_usage_threshold_percent = 200; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 rtc::CritScope lock(&crit_); | 171 rtc::CritScope lock(&crit_); |
170 if (!IsResolutionScalingEnabledLocked()) { | 172 if (!IsResolutionScalingEnabledLocked()) { |
171 // This can happen since |degradation_preference_| is set on | 173 // This can happen since |degradation_preference_| is set on |
172 // libjingle's worker thread but the adaptation is done on the encoder | 174 // libjingle's worker thread but the adaptation is done on the encoder |
173 // task queue. | 175 // task queue. |
174 return; | 176 return; |
175 } | 177 } |
176 // The input video frame size will have a resolution with less than or | 178 // The input video frame size will have a resolution with less than or |
177 // equal to |max_pixel_count| depending on how the source can scale the | 179 // equal to |max_pixel_count| depending on how the source can scale the |
178 // input frame size. | 180 // input frame size. |
179 sink_wants_.max_pixel_count = rtc::Optional<int>((pixel_count * 3) / 5); | 181 const int pixels_wanted = (pixel_count * 3) / 5; |
| 182 if (pixels_wanted < kMinPixelsPerFrame) |
| 183 return; |
| 184 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted); |
180 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); | 185 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); |
181 if (source_) | 186 if (source_) |
182 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 187 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
183 } | 188 } |
184 | 189 |
185 void RequestHigherResolutionThan(int pixel_count) { | 190 void RequestHigherResolutionThan(int pixel_count) { |
186 rtc::CritScope lock(&crit_); | 191 rtc::CritScope lock(&crit_); |
187 if (!IsResolutionScalingEnabledLocked()) { | 192 if (!IsResolutionScalingEnabledLocked()) { |
188 // This can happen since |degradation_preference_| is set on | 193 // This can happen since |degradation_preference_| is set on |
189 // libjingle's worker thread but the adaptation is done on the encoder | 194 // libjingle's worker thread but the adaptation is done on the encoder |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 RTC_DCHECK_RUN_ON(&encoder_queue_); | 679 RTC_DCHECK_RUN_ON(&encoder_queue_); |
675 if (!scaling_enabled_) | 680 if (!scaling_enabled_) |
676 return; | 681 return; |
677 // Request lower resolution if the current resolution is lower than last time | 682 // Request lower resolution if the current resolution is lower than last time |
678 // we asked for the resolution to be lowered. | 683 // we asked for the resolution to be lowered. |
679 int current_pixel_count = last_frame_height_ * last_frame_width_; | 684 int current_pixel_count = last_frame_height_ * last_frame_width_; |
680 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) | 685 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) |
681 return; | 686 return; |
682 switch (reason) { | 687 switch (reason) { |
683 case kQuality: | 688 case kQuality: |
684 if (scale_counter_[reason] >= kMaxQualityDowngrades) | |
685 return; | |
686 stats_proxy_->OnQualityRestrictedResolutionChanged(true); | 689 stats_proxy_->OnQualityRestrictedResolutionChanged(true); |
687 break; | 690 break; |
688 case kCpu: | 691 case kCpu: |
689 if (scale_counter_[reason] >= kMaxCpuDowngrades) | 692 if (scale_counter_[reason] >= kMaxCpuDowngrades) |
690 return; | 693 return; |
691 // Update stats accordingly. | 694 // Update stats accordingly. |
692 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 695 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
693 break; | 696 break; |
694 } | 697 } |
695 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 698 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 --scale_counter_[reason]; | 731 --scale_counter_[reason]; |
729 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 732 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
730 LOG(LS_INFO) << "Scaling up resolution."; | 733 LOG(LS_INFO) << "Scaling up resolution."; |
731 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 734 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
732 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 735 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
733 << " times for reason: " << (i ? "quality" : "cpu"); | 736 << " times for reason: " << (i ? "quality" : "cpu"); |
734 } | 737 } |
735 } | 738 } |
736 | 739 |
737 } // namespace webrtc | 740 } // namespace webrtc |
OLD | NEW |