| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
| 11 #include "webrtc/video/overuse_frame_detector.h" | 11 #include "webrtc/video/overuse_frame_detector.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <math.h> | 14 #include <math.h> |
| 15 | 15 |
| 16 #include <algorithm> | 16 #include <algorithm> |
| 17 #include <list> | 17 #include <list> |
| 18 #include <map> | 18 #include <map> |
| 19 | 19 |
| 20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/exp_filter.h" | 21 #include "webrtc/base/exp_filter.h" |
| 22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
| 23 #include "webrtc/common_video/include/frame_callback.h" | 23 #include "webrtc/common_video/include/frame_callback.h" |
| 24 #include "webrtc/system_wrappers/include/clock.h" | 24 #include "webrtc/system_wrappers/include/clock.h" |
| 25 #include "webrtc/video_frame.h" | 25 #include "webrtc/video_frame.h" |
| 26 | 26 |
| 27 #if defined(WEBRTC_MAC) | 27 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 28 #include <mach/mach.h> | 28 #include <mach/mach.h> |
| 29 #endif | 29 #endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 const int64_t kProcessIntervalMs = 5000; | 34 const int64_t kProcessIntervalMs = 5000; |
| 35 | 35 |
| 36 // Delay between consecutive rampups. (Used for quick recovery.) | 36 // Delay between consecutive rampups. (Used for quick recovery.) |
| 37 const int kQuickRampUpDelayMs = 10 * 1000; | 37 const int kQuickRampUpDelayMs = 10 * 1000; |
| 38 // Delay between rampup attempts. Initially uses standard, scales up to max. | 38 // Delay between rampup attempts. Initially uses standard, scales up to max. |
| 39 const int kStandardRampUpDelayMs = 40 * 1000; | 39 const int kStandardRampUpDelayMs = 40 * 1000; |
| 40 const int kMaxRampUpDelayMs = 240 * 1000; | 40 const int kMaxRampUpDelayMs = 240 * 1000; |
| 41 // Expontential back-off factor, to prevent annoying up-down behaviour. | 41 // Expontential back-off factor, to prevent annoying up-down behaviour. |
| 42 const double kRampUpBackoffFactor = 2.0; | 42 const double kRampUpBackoffFactor = 2.0; |
| 43 | 43 |
| 44 // Max number of overuses detected before always applying the rampup delay. | 44 // Max number of overuses detected before always applying the rampup delay. |
| 45 const int kMaxOverusesBeforeApplyRampupDelay = 4; | 45 const int kMaxOverusesBeforeApplyRampupDelay = 4; |
| 46 | 46 |
| 47 // The maximum exponent to use in VCMExpFilter. | 47 // The maximum exponent to use in VCMExpFilter. |
| 48 const float kSampleDiffMs = 33.0f; | 48 const float kSampleDiffMs = 33.0f; |
| 49 const float kMaxExp = 7.0f; | 49 const float kMaxExp = 7.0f; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 CpuOveruseOptions::CpuOveruseOptions() | 53 CpuOveruseOptions::CpuOveruseOptions() |
| 54 : high_encode_usage_threshold_percent(85), | 54 : high_encode_usage_threshold_percent(85), |
| 55 frame_timeout_interval_ms(1500), | 55 frame_timeout_interval_ms(1500), |
| 56 min_frame_samples(120), | 56 min_frame_samples(120), |
| 57 min_process_count(3), | 57 min_process_count(3), |
| 58 high_threshold_consecutive_count(2) { | 58 high_threshold_consecutive_count(2) { |
| 59 #if defined(WEBRTC_MAC) | 59 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 60 // This is proof-of-concept code for letting the physical core count affect | 60 // This is proof-of-concept code for letting the physical core count affect |
| 61 // the interval into which we attempt to scale. For now, the code is Mac OS | 61 // the interval into which we attempt to scale. For now, the code is Mac OS |
| 62 // specific, since that's the platform were we saw most problems. | 62 // specific, since that's the platform were we saw most problems. |
| 63 // TODO(torbjorng): Enhance SystemInfo to return this metric. | 63 // TODO(torbjorng): Enhance SystemInfo to return this metric. |
| 64 | 64 |
| 65 mach_port_t mach_host = mach_host_self(); | 65 mach_port_t mach_host = mach_host_self(); |
| 66 host_basic_info hbi = {}; | 66 host_basic_info hbi = {}; |
| 67 mach_msg_type_number_t info_count = HOST_BASIC_INFO_COUNT; | 67 mach_msg_type_number_t info_count = HOST_BASIC_INFO_COUNT; |
| 68 kern_return_t kr = | 68 kern_return_t kr = |
| 69 host_info(mach_host, HOST_BASIC_INFO, reinterpret_cast<host_info_t>(&hbi), | 69 host_info(mach_host, HOST_BASIC_INFO, reinterpret_cast<host_info_t>(&hbi), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 // Change init list default for few core systems. The assumption here is that | 83 // Change init list default for few core systems. The assumption here is that |
| 84 // encoding, which we measure here, takes about 1/4 of the processing of a | 84 // encoding, which we measure here, takes about 1/4 of the processing of a |
| 85 // two-way call. This is roughly true for x86 using both vp8 and vp9 without | 85 // two-way call. This is roughly true for x86 using both vp8 and vp9 without |
| 86 // hardware encoding. Since we don't affect the incoming stream here, we only | 86 // hardware encoding. Since we don't affect the incoming stream here, we only |
| 87 // control about 1/2 of the total processing needs, but this is not taken into | 87 // control about 1/2 of the total processing needs, but this is not taken into |
| 88 // account. | 88 // account. |
| 89 if (n_physical_cores == 1) | 89 if (n_physical_cores == 1) |
| 90 high_encode_usage_threshold_percent = 20; // Roughly 1/4 of 100%. | 90 high_encode_usage_threshold_percent = 20; // Roughly 1/4 of 100%. |
| 91 else if (n_physical_cores == 2) | 91 else if (n_physical_cores == 2) |
| 92 high_encode_usage_threshold_percent = 40; // Roughly 1/4 of 200%. | 92 high_encode_usage_threshold_percent = 40; // Roughly 1/4 of 200%. |
| 93 #endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 93 | 94 |
| 94 #endif // WEBRTC_MAC | |
| 95 // Note that we make the interval 2x+epsilon wide, since libyuv scaling steps | 95 // Note that we make the interval 2x+epsilon wide, since libyuv scaling steps |
| 96 // are close to that (when squared). This wide interval makes sure that | 96 // are close to that (when squared). This wide interval makes sure that |
| 97 // scaling up or down does not jump all the way across the interval. | 97 // scaling up or down does not jump all the way across the interval. |
| 98 low_encode_usage_threshold_percent = | 98 low_encode_usage_threshold_percent = |
| 99 (high_encode_usage_threshold_percent - 1) / 2; | 99 (high_encode_usage_threshold_percent - 1) / 2; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Class for calculating the processing usage on the send-side (the average | 102 // Class for calculating the processing usage on the send-side (the average |
| 103 // processing time of a frame divided by the average time difference between | 103 // processing time of a frame divided by the average time difference between |
| 104 // captured frames). | 104 // captured frames). |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, | 373 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, |
| 374 int64_t time_now) { | 374 int64_t time_now) { |
| 375 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; | 375 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; |
| 376 if (time_now < last_rampup_time_ms_ + delay) | 376 if (time_now < last_rampup_time_ms_ + delay) |
| 377 return false; | 377 return false; |
| 378 | 378 |
| 379 return metrics.encode_usage_percent < | 379 return metrics.encode_usage_percent < |
| 380 options_.low_encode_usage_threshold_percent; | 380 options_.low_encode_usage_threshold_percent; |
| 381 } | 381 } |
| 382 } // namespace webrtc | 382 } // namespace webrtc |
| OLD | NEW |