blob: e382c7da4bc04b71714ae4f40493feaea6fd98e9 [file] [log] [blame]
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +00001/*
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
20namespace webrtc {
21
22class Clock;
23class CriticalSectionWrapper;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000024class CpuOveruseObserver;
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000025
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000026// Use to detect system overuse based on the number of captured frames vs the
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000027// number of encoded frames.
28class OveruseFrameDetector : public Module {
29 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000030 explicit OveruseFrameDetector(Clock* clock);
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000031 ~OveruseFrameDetector();
32
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000033 void SetObserver(CpuOveruseObserver* observer);
34
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000035 // 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.org6879c8a2013-07-23 11:35:00 +000052 CpuOveruseObserver* observer_;
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000053
54 Clock* clock_;
55 int64_t last_process_time_;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000056 int64_t last_callback_time_;
mflodman@webrtc.orge6168f52013-06-26 11:23:01 +000057
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_