mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |
| 13 | |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/interface/module.h" |
| 15 | #include "webrtc/system_wrappers/interface/constructor_magic.h" |
| 16 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class Clock; |
| 21 | class CriticalSectionWrapper; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 22 | class CpuOveruseObserver; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame^] | 24 | // TODO(pbos): Move this somewhere appropriate |
| 25 | class Statistics { |
| 26 | public: |
| 27 | Statistics(); |
| 28 | |
| 29 | void AddSample(double sample); |
| 30 | void Reset(); |
| 31 | |
| 32 | double Mean() const; |
| 33 | double Variance() const; |
| 34 | double StdDev() const; |
| 35 | uint64_t Samples() const; |
| 36 | |
| 37 | private: |
| 38 | double sum_; |
| 39 | double sum_squared_; |
| 40 | uint64_t count_; |
| 41 | }; |
| 42 | |
| 43 | // Use to detect system overuse based on jitter in incoming frames. |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 44 | class OveruseFrameDetector : public Module { |
| 45 | public: |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 46 | explicit OveruseFrameDetector(Clock* clock); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 47 | ~OveruseFrameDetector(); |
| 48 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 49 | // Registers an observer receiving overuse and underuse callbacks. Set |
| 50 | // 'observer' to NULL to disable callbacks. |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 51 | void SetObserver(CpuOveruseObserver* observer); |
| 52 | |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 53 | // Called for each captured frame. |
| 54 | void FrameCaptured(); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 55 | |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 56 | // Implements Module. |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame^] | 57 | virtual int32_t TimeUntilNextProcess() OVERRIDE; |
| 58 | virtual int32_t Process() OVERRIDE; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 59 | |
| 60 | private: |
mflodman@webrtc.org | d4412fe | 2013-07-31 16:42:21 +0000 | [diff] [blame] | 61 | bool IsOverusing(); |
| 62 | bool IsUnderusing(int64_t time_now); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 63 | |
| 64 | // Protecting all members. |
| 65 | scoped_ptr<CriticalSectionWrapper> crit_; |
| 66 | |
| 67 | // Observer getting overuse reports. |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 68 | CpuOveruseObserver* observer_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 69 | |
| 70 | Clock* clock_; |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame^] | 71 | int64_t next_process_time_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame^] | 73 | Statistics capture_deltas_; |
| 74 | int64_t last_capture_time_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 75 | |
pbos@webrtc.org | a957570 | 2013-08-30 17:16:32 +0000 | [diff] [blame^] | 76 | int64_t last_overuse_time_; |
| 77 | int checks_above_threshold_; |
| 78 | |
| 79 | int64_t last_rampup_time_; |
| 80 | bool in_quick_rampup_; |
| 81 | int current_rampup_delay_ms_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 82 | |
| 83 | DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
| 84 | }; |
| 85 | |
| 86 | } // namespace webrtc |
| 87 | |
| 88 | #endif // WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |