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; |
| 24 | |
| 25 | class OveruseObserver { |
| 26 | public: |
| 27 | // Called when an overuse has been detected, based on the number of calls to |
| 28 | // 'CapturedFrame' and 'EncodedFrame'. |
| 29 | virtual void OveruseDetected() = 0; |
| 30 | virtual ~OveruseObserver() {} |
| 31 | }; |
| 32 | |
| 33 | // Use to detect system overuse based on the number of captured frames vs. the |
| 34 | // number of encoded frames. |
| 35 | class OveruseFrameDetector : public Module { |
| 36 | public: |
| 37 | OveruseFrameDetector(Clock* clock, OveruseObserver* observer); |
| 38 | ~OveruseFrameDetector(); |
| 39 | |
| 40 | // Called for each new captured frame. |
| 41 | void CapturedFrame(); |
| 42 | |
| 43 | // Called for every encoded frame. |
| 44 | void EncodedFrame(); |
| 45 | |
| 46 | // Implements Module. |
| 47 | virtual int32_t TimeUntilNextProcess(); |
| 48 | virtual int32_t Process(); |
| 49 | |
| 50 | private: |
| 51 | void CleanOldSamples(); |
| 52 | |
| 53 | // Protecting all members. |
| 54 | scoped_ptr<CriticalSectionWrapper> crit_; |
| 55 | |
| 56 | // Observer getting overuse reports. |
| 57 | OveruseObserver* observer_; |
| 58 | |
| 59 | Clock* clock_; |
| 60 | int64_t last_process_time_; |
| 61 | |
| 62 | // Capture time for frames. |
| 63 | std::list<int64_t> capture_times_; |
| 64 | |
| 65 | // Start encode time for a frame. |
| 66 | std::list<int64_t> encode_times_; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
| 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
| 73 | #endif // WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |