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 | |
| 14 | #include <list> |
| 15 | |
| 16 | #include "webrtc/modules/interface/module.h" |
| 17 | #include "webrtc/system_wrappers/interface/constructor_magic.h" |
| 18 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class Clock; |
| 23 | class CriticalSectionWrapper; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 24 | class CpuOveruseObserver; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 25 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 26 | // Use to detect system overuse based on the number of captured frames vs the |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 27 | // number of encoded frames. |
| 28 | class OveruseFrameDetector : public Module { |
| 29 | public: |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 30 | explicit OveruseFrameDetector(Clock* clock); |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 31 | ~OveruseFrameDetector(); |
| 32 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 33 | void SetObserver(CpuOveruseObserver* observer); |
| 34 | |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 35 | // Called for each new captured frame. |
| 36 | void CapturedFrame(); |
| 37 | |
| 38 | // Called for every encoded frame. |
| 39 | void EncodedFrame(); |
| 40 | |
| 41 | // Implements Module. |
| 42 | virtual int32_t TimeUntilNextProcess(); |
| 43 | virtual int32_t Process(); |
| 44 | |
| 45 | private: |
| 46 | void CleanOldSamples(); |
| 47 | |
| 48 | // Protecting all members. |
| 49 | scoped_ptr<CriticalSectionWrapper> crit_; |
| 50 | |
| 51 | // Observer getting overuse reports. |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 52 | CpuOveruseObserver* observer_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 53 | |
| 54 | Clock* clock_; |
| 55 | int64_t last_process_time_; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 56 | int64_t last_callback_time_; |
mflodman@webrtc.org | e6168f5 | 2013-06-26 11:23:01 +0000 | [diff] [blame] | 57 | |
| 58 | // Capture time for frames. |
| 59 | std::list<int64_t> capture_times_; |
| 60 | |
| 61 | // Start encode time for a frame. |
| 62 | std::list<int64_t> encode_times_; |
| 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
| 65 | }; |
| 66 | |
| 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |