Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Side by Side Diff: webrtc/video/overuse_frame_detector.cc

Issue 1665173002: Experimental patch for adapting adaptation to CPU count on Mac. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rewrite again. Use 1/4 of a physical core as goal. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/overuse_frame_detector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/frame_callback.h" 23 #include "webrtc/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)
28 #include <mach/mach.h>
29 #endif
30
27 namespace webrtc { 31 namespace webrtc {
28 32
29 namespace { 33 namespace {
30 const int64_t kProcessIntervalMs = 5000; 34 const int64_t kProcessIntervalMs = 5000;
31 35
32 // Delay between consecutive rampups. (Used for quick recovery.) 36 // Delay between consecutive rampups. (Used for quick recovery.)
33 const int kQuickRampUpDelayMs = 10 * 1000; 37 const int kQuickRampUpDelayMs = 10 * 1000;
34 // Delay between rampup attempts. Initially uses standard, scales up to max. 38 // Delay between rampup attempts. Initially uses standard, scales up to max.
35 const int kStandardRampUpDelayMs = 40 * 1000; 39 const int kStandardRampUpDelayMs = 40 * 1000;
36 const int kMaxRampUpDelayMs = 240 * 1000; 40 const int kMaxRampUpDelayMs = 240 * 1000;
37 // Expontential back-off factor, to prevent annoying up-down behaviour. 41 // Expontential back-off factor, to prevent annoying up-down behaviour.
38 const double kRampUpBackoffFactor = 2.0; 42 const double kRampUpBackoffFactor = 2.0;
39 43
40 // Max number of overuses detected before always applying the rampup delay. 44 // Max number of overuses detected before always applying the rampup delay.
41 const int kMaxOverusesBeforeApplyRampupDelay = 4; 45 const int kMaxOverusesBeforeApplyRampupDelay = 4;
42 46
43 // The maximum exponent to use in VCMExpFilter. 47 // The maximum exponent to use in VCMExpFilter.
44 const float kSampleDiffMs = 33.0f; 48 const float kSampleDiffMs = 33.0f;
45 const float kMaxExp = 7.0f; 49 const float kMaxExp = 7.0f;
46 50
47 } // namespace 51 } // namespace
48 52
53 CpuOveruseOptions::CpuOveruseOptions()
54 : high_encode_usage_threshold_percent(85),
55 frame_timeout_interval_ms(1500),
56 min_frame_samples(120),
57 min_process_count(3),
58 high_threshold_consecutive_count(2) {
59 #if defined(WEBRTC_MAC)
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
62 // specific, since that's the platform were we saw most problems.
63 // TODO(torbjorng): Enhance SystemInfo to return this metric.
64
65 mach_port_t mach_host = mach_host_self();
66 host_basic_info hbi = {};
67 mach_msg_type_number_t info_count = HOST_BASIC_INFO_COUNT;
68 kern_return_t kr =
69 host_info(mach_host, HOST_BASIC_INFO, reinterpret_cast<host_info_t>(&hbi),
70 &info_count);
71 mach_port_deallocate(mach_task_self(), mach_host);
72
73 int n_physical_cores;
74 if (kr != KERN_SUCCESS) {
75 // If we couldn't get # of physical CPUs, don't panic. Assume we have 1.
76 n_physical_cores = 1;
77 LOG(LS_ERROR) << "Failed to determine number of physical cores, assuming 1";
78 } else {
79 n_physical_cores = hbi.physical_cpu;
80 LOG(LS_INFO) << "Number of physical cores:" << n_physical_cores;
81 }
82
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
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
87 // control about 1/2 of the total processing needs, but this is not taken into
88 // account.
89 if (n_physical_cores == 1)
90 high_encode_usage_threshold_percent = 20; // Roughly 1/4 of 100%.
91 else if (n_physical_cores == 2)
92 high_encode_usage_threshold_percent = 40; // Roughly 1/4 of 200%.
93
94 #endif // WEBRTC_MAC
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
97 // scaling up or down does not jump all the way across the interval.
98 low_encode_usage_threshold_percent =
99 (high_encode_usage_threshold_percent - 1) / 2;
100 }
101
49 // 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
50 // 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
51 // captured frames). 104 // captured frames).
52 class OveruseFrameDetector::SendProcessingUsage { 105 class OveruseFrameDetector::SendProcessingUsage {
53 public: 106 public:
54 explicit SendProcessingUsage(const CpuOveruseOptions& options) 107 explicit SendProcessingUsage(const CpuOveruseOptions& options)
55 : kWeightFactorFrameDiff(0.998f), 108 : kWeightFactorFrameDiff(0.998f),
56 kWeightFactorProcessing(0.995f), 109 kWeightFactorProcessing(0.995f),
57 kInitialSampleDiffMs(40.0f), 110 kInitialSampleDiffMs(40.0f),
58 kMaxSampleDiffMs(45.0f), 111 kMaxSampleDiffMs(45.0f),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, 375 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics,
323 int64_t time_now) { 376 int64_t time_now) {
324 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 377 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
325 if (time_now < last_rampup_time_ms_ + delay) 378 if (time_now < last_rampup_time_ms_ + delay)
326 return false; 379 return false;
327 380
328 return metrics.encode_usage_percent < 381 return metrics.encode_usage_percent <
329 options_.low_encode_usage_threshold_percent; 382 options_.low_encode_usage_threshold_percent;
330 } 383 }
331 } // namespace webrtc 384 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/overuse_frame_detector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698