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 #ifndef WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 11 #ifndef WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
12 #define WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 12 #define WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
13 | 13 |
14 #include "webrtc/base/constructormagic.h" | 14 #include "webrtc/base/constructormagic.h" |
15 #include "webrtc/base/criticalsection.h" | 15 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/base/exp_filter.h" | 17 #include "webrtc/base/exp_filter.h" |
18 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/base/thread_checker.h" | 19 #include "webrtc/base/thread_checker.h" |
20 #include "webrtc/modules/include/module.h" | 20 #include "webrtc/modules/include/module.h" |
21 | 21 |
22 #if defined(WEBRTC_MAC) | |
23 #include <mach/mach.h> | |
24 #endif | |
25 | |
22 namespace webrtc { | 26 namespace webrtc { |
23 | 27 |
24 class Clock; | 28 class Clock; |
25 | 29 |
26 // CpuOveruseObserver is called when a system overuse is detected and | 30 // CpuOveruseObserver is called when a system overuse is detected and |
27 // VideoEngine cannot keep up the encoding frequency. | 31 // VideoEngine cannot keep up the encoding frequency. |
28 class CpuOveruseObserver { | 32 class CpuOveruseObserver { |
29 public: | 33 public: |
30 // Called as soon as an overuse is detected. | 34 // Called as soon as an overuse is detected. |
31 virtual void OveruseDetected() = 0; | 35 virtual void OveruseDetected() = 0; |
32 // Called periodically when the system is not overused any longer. | 36 // Called periodically when the system is not overused any longer. |
33 virtual void NormalUsage() = 0; | 37 virtual void NormalUsage() = 0; |
34 | 38 |
35 protected: | 39 protected: |
36 virtual ~CpuOveruseObserver() {} | 40 virtual ~CpuOveruseObserver() {} |
37 }; | 41 }; |
38 | 42 |
39 struct CpuOveruseOptions { | 43 struct CpuOveruseOptions { |
40 CpuOveruseOptions() | 44 CpuOveruseOptions() |
41 : low_encode_usage_threshold_percent(55), | 45 : low_encode_usage_threshold_percent(42), |
42 high_encode_usage_threshold_percent(85), | |
43 frame_timeout_interval_ms(1500), | 46 frame_timeout_interval_ms(1500), |
44 min_frame_samples(120), | 47 min_frame_samples(120), |
45 min_process_count(3), | 48 min_process_count(3), |
46 high_threshold_consecutive_count(2) {} | 49 high_threshold_consecutive_count(2) { |
50 #if defined (WEBRTC_MAC) | |
tommi
2016/02/04 20:32:44
#if defined(WEBRTC_MAC)
torbjorng (webrtc)
2016/02/05 16:31:05
Done.
| |
51 // This is a proof-of-concept hack for letting the physical core count | |
52 // affect the interval into which we attempt to scale. For now, the code | |
53 // is Mac OS specific, since that's the platform were we saw the problem. | |
54 // Note that we make the interval 2x+epsilon wide, since scaling steps are | |
55 // close to that. | |
56 struct host_basic_info hbi; | |
57 mach_msg_type_number_t datasize; | |
58 // TODO(torbjorng): Add syscall error checking, fallback code. | |
59 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hbi, &datasize); | |
tommi
2016/02/04 20:32:44
Can you change the cast to a C++ cast? As is it l
Robert Sesek
2016/02/04 22:37:15
The result of mach_host_self must be deallocated.
tommi (sloooow) - chröme
2016/02/04 22:44:40
Ah, thanks for catching that!
Now this makes more
torbjorng (webrtc)
2016/02/05 16:31:05
Yes, host_info_t is a ptr (it is in fact int*).
F
torbjorng (webrtc)
2016/02/05 16:31:05
Robert: I changed the code to look more like in ot
tommi
2016/02/05 22:56:35
Thanks, I'm familiar with APIs like these :) I wa
Robert Sesek
2016/02/05 22:59:58
Thanks! This is now OK. mach_task_self() is actual
| |
60 | |
61 if (hbi.physical_cpu == 1) { | |
62 low_encode_usage_threshold_percent = 17; | |
63 } else if (hbi.physical_cpu == 2) { | |
64 low_encode_usage_threshold_percent = 27; | |
65 } else { | |
66 // Init list default. | |
67 } | |
68 #endif | |
tommi
2016/02/04 20:32:44
nit:
#endif // WEBRTC_MAC
torbjorng (webrtc)
2016/02/05 16:31:05
Done.
| |
69 // Make high = 2 * low + epsilon. | |
70 high_encode_usage_threshold_percent = | |
71 33 * low_encode_usage_threshold_percent / 16 + 1; | |
tommi
2016/02/04 20:32:44
4 space indent. (or just run git cl format?)
torbjorng (webrtc)
2016/02/05 16:31:06
Done.
| |
72 } | |
47 | 73 |
48 int low_encode_usage_threshold_percent; // Threshold for triggering underuse. | 74 int low_encode_usage_threshold_percent; // Threshold for triggering underuse. |
49 int high_encode_usage_threshold_percent; // Threshold for triggering overuse. | 75 int high_encode_usage_threshold_percent; // Threshold for triggering overuse. |
50 // General settings. | 76 // General settings. |
51 int frame_timeout_interval_ms; // The maximum allowed interval between two | 77 int frame_timeout_interval_ms; // The maximum allowed interval between two |
52 // frames before resetting estimations. | 78 // frames before resetting estimations. |
53 int min_frame_samples; // The minimum number of frames required. | 79 int min_frame_samples; // The minimum number of frames required. |
54 int min_process_count; // The number of initial process times required before | 80 int min_process_count; // The number of initial process times required before |
55 // triggering an overuse/underuse. | 81 // triggering an overuse/underuse. |
56 int high_threshold_consecutive_count; // The number of consecutive checks | 82 int high_threshold_consecutive_count; // The number of consecutive checks |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); | 181 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); |
156 | 182 |
157 rtc::ThreadChecker processing_thread_; | 183 rtc::ThreadChecker processing_thread_; |
158 | 184 |
159 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); | 185 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
160 }; | 186 }; |
161 | 187 |
162 } // namespace webrtc | 188 } // namespace webrtc |
163 | 189 |
164 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 190 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
OLD | NEW |