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

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: Move include to .cc file 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 : low_encode_usage_threshold_percent(42),
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 a proof-of-concept hack 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 the problem.
63 // TODO(torbjorng): Enhance SystemInfo to return this metric.
64
65 mach_port_t mach_host = mach_host_self();
66 host_basic_info hbi;
tommi 2016/02/05 22:56:35 zero initialize host_basic_info hbi = {};
torbjorng (webrtc) 2016/02/06 14:02:26 Done.
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),
tommi 2016/02/05 22:56:35 Can you confirm that this works within the sandbox
torbjorng (webrtc) 2016/02/06 14:02:26 It works fine in the current use. (I confess that
70 &info_count);
71 mach_port_deallocate(mach_task_self(), mach_host);
72
73 int ncpus;
74 if (kr != KERN_SUCCESS) {
75 // If we couldn't get # of physical CPUs, don't panic. Assume we have 1.
76 ncpus = 1;
77 LOG(LS_ERROR) << "Failed to determine number of physical cores, assuming 1";
78 } else {
79 ncpus = hbi.physical_cpu;
80 LOG(LS_INFO) << "Number of physical cores:" << ncpus;
81 }
82
83 // Change init list default for few core systems.
84 if (ncpus == 1)
85 low_encode_usage_threshold_percent = 17;
86 else if (ncpus == 2)
87 low_encode_usage_threshold_percent = 27;
88
89 #endif // WEBRTC_MAC
90 // Note that we make the interval 2x+epsilon wide, since scaling steps are
91 // close to that (when squared). This wide interval makes sure that scaling
92 // up or down does not jump all the way across the interval.
93 high_encode_usage_threshold_percent =
94 33 * low_encode_usage_threshold_percent / 16 + 1;
95 }
96
49 // Class for calculating the processing usage on the send-side (the average 97 // 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 98 // processing time of a frame divided by the average time difference between
51 // captured frames). 99 // captured frames).
52 class OveruseFrameDetector::SendProcessingUsage { 100 class OveruseFrameDetector::SendProcessingUsage {
53 public: 101 public:
54 explicit SendProcessingUsage(const CpuOveruseOptions& options) 102 explicit SendProcessingUsage(const CpuOveruseOptions& options)
55 : kWeightFactorFrameDiff(0.998f), 103 : kWeightFactorFrameDiff(0.998f),
56 kWeightFactorProcessing(0.995f), 104 kWeightFactorProcessing(0.995f),
57 kInitialSampleDiffMs(40.0f), 105 kInitialSampleDiffMs(40.0f),
58 kMaxSampleDiffMs(45.0f), 106 kMaxSampleDiffMs(45.0f),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics, 370 bool OveruseFrameDetector::IsUnderusing(const CpuOveruseMetrics& metrics,
323 int64_t time_now) { 371 int64_t time_now) {
324 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 372 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
325 if (time_now < last_rampup_time_ms_ + delay) 373 if (time_now < last_rampup_time_ms_ + delay)
326 return false; 374 return false;
327 375
328 return metrics.encode_usage_percent < 376 return metrics.encode_usage_percent <
329 options_.low_encode_usage_threshold_percent; 377 options_.low_encode_usage_threshold_percent;
330 } 378 }
331 } // namespace webrtc 379 } // 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