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 <list> | |
15 | |
14 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
15 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
16 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/base/exp_filter.h" | 19 #include "webrtc/base/exp_filter.h" |
18 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/base/thread_checker.h" | 21 #include "webrtc/base/thread_checker.h" |
20 #include "webrtc/modules/include/module.h" | 22 #include "webrtc/modules/include/module.h" |
21 | 23 |
22 namespace webrtc { | 24 namespace webrtc { |
23 | 25 |
24 class Clock; | 26 class Clock; |
27 class EncodedImage; | |
28 class VideoFrame; | |
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 |
(...skipping 26 matching lines...) Expand all Loading... | |
61 struct CpuOveruseMetrics { | 65 struct CpuOveruseMetrics { |
62 CpuOveruseMetrics() : encode_usage_percent(-1) {} | 66 CpuOveruseMetrics() : encode_usage_percent(-1) {} |
63 | 67 |
64 int encode_usage_percent; // Average encode time divided by the average time | 68 int encode_usage_percent; // Average encode time divided by the average time |
65 // difference between incoming captured frames. | 69 // difference between incoming captured frames. |
66 }; | 70 }; |
67 | 71 |
68 class CpuOveruseMetricsObserver { | 72 class CpuOveruseMetricsObserver { |
69 public: | 73 public: |
70 virtual ~CpuOveruseMetricsObserver() {} | 74 virtual ~CpuOveruseMetricsObserver() {} |
71 virtual void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) = 0; | 75 virtual void OnEncodedFrameTimeMeasured(int encode_time_ms, |
76 const CpuOveruseMetrics& metrics) = 0; | |
72 }; | 77 }; |
73 | 78 |
74 | 79 |
75 // Use to detect system overuse based on the send-side processing time of | 80 // Use to detect system overuse based on the send-side processing time of |
76 // incoming frames. | 81 // incoming frames. |
77 class OveruseFrameDetector : public Module { | 82 class OveruseFrameDetector : public Module { |
78 public: | 83 public: |
79 OveruseFrameDetector(Clock* clock, | 84 OveruseFrameDetector(Clock* clock, |
80 const CpuOveruseOptions& options, | 85 const CpuOveruseOptions& options, |
81 CpuOveruseObserver* overuse_observer, | 86 CpuOveruseObserver* overuse_observer, |
82 CpuOveruseMetricsObserver* metrics_observer); | 87 CpuOveruseMetricsObserver* metrics_observer); |
83 ~OveruseFrameDetector(); | 88 ~OveruseFrameDetector(); |
84 | 89 |
85 // Called for each captured frame. | 90 // Called for each captured frame. |
86 void FrameCaptured(int width, int height, int64_t capture_time_ms); | 91 void FrameCaptured(const VideoFrame& frame); |
87 | 92 |
88 // Called for each sent frame. | 93 // Called for each sent frame. |
89 void FrameSent(int64_t capture_time_ms); | 94 void FrameSent(const EncodedImage& encoded_image); |
mflodman
2016/01/21 08:00:05
I'd prefer to only have the timing value as an arg
pbos-webrtc
2016/01/21 14:18:33
Done.
| |
90 | |
91 // Only public for testing. | |
92 int LastProcessingTimeMs() const; | |
93 int FramesInQueue() const; | |
94 | 95 |
95 // Implements Module. | 96 // Implements Module. |
96 int64_t TimeUntilNextProcess() override; | 97 int64_t TimeUntilNextProcess() override; |
97 int32_t Process() override; | 98 int32_t Process() override; |
98 | 99 |
99 private: | 100 private: |
100 class SendProcessingUsage; | 101 class SendProcessingUsage; |
101 class FrameQueue; | 102 struct FrameTiming { |
103 FrameTiming(uint32_t timestamp, int64_t now) | |
104 : timestamp(timestamp), capture_ms(now), last_send_ms(-1) {} | |
105 uint32_t timestamp; | |
106 int64_t capture_ms; | |
107 int64_t last_send_ms; | |
108 }; | |
102 | 109 |
103 void UpdateCpuOveruseMetrics() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 110 void EncodedFrameTimeMeasured(int encode_time_ms) |
111 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
104 | 112 |
105 // TODO(asapersson): This method is only used on one thread, so it shouldn't | 113 // TODO(asapersson): This method is only used on one thread, so it shouldn't |
106 // need a guard. | 114 // need a guard. |
107 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 115 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
108 | 116 |
109 // Only called on the processing thread. | 117 // Only called on the processing thread. |
110 bool IsOverusing(const CpuOveruseMetrics& metrics); | 118 bool IsOverusing(const CpuOveruseMetrics& metrics); |
111 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); | 119 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); |
112 | 120 |
113 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 121 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
114 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 122 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
115 | 123 |
116 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 124 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
117 | 125 |
118 // Protecting all members except const and those that are only accessed on the | 126 // Protecting all members except const and those that are only accessed on the |
119 // processing thread. | 127 // processing thread. |
120 // TODO(asapersson): See if we can reduce locking. As is, video frame | 128 // TODO(asapersson): See if we can reduce locking. As is, video frame |
121 // processing contends with reading stats and the processing thread. | 129 // processing contends with reading stats and the processing thread. |
122 mutable rtc::CriticalSection crit_; | 130 mutable rtc::CriticalSection crit_; |
123 | 131 |
124 const CpuOveruseOptions options_; | 132 const CpuOveruseOptions options_; |
125 | 133 |
126 // Observer getting overuse reports. | 134 // Observer getting overuse reports. |
127 CpuOveruseObserver* const observer_; | 135 CpuOveruseObserver* const observer_; |
128 | 136 |
129 // Stats metrics. | 137 // Stats metrics. |
130 CpuOveruseMetricsObserver* const metrics_observer_; | 138 CpuOveruseMetricsObserver* const metrics_observer_; |
139 int last_encode_time_ms_ GUARDED_BY(crit_); | |
mflodman
2016/01/21 08:00:05
I prefer int64_t, following the rest of this class
pbos-webrtc
2016/01/21 14:18:33
Removed per other feedback.
| |
131 CpuOveruseMetrics metrics_ GUARDED_BY(crit_); | 140 CpuOveruseMetrics metrics_ GUARDED_BY(crit_); |
132 | 141 |
133 Clock* const clock_; | 142 Clock* const clock_; |
134 int64_t num_process_times_ GUARDED_BY(crit_); | 143 int64_t num_process_times_ GUARDED_BY(crit_); |
135 | 144 |
136 int64_t last_capture_time_ GUARDED_BY(crit_); | 145 int64_t last_capture_time_ GUARDED_BY(crit_); |
137 | 146 |
138 // Number of pixels of last captured frame. | 147 // Number of pixels of last captured frame. |
139 int num_pixels_ GUARDED_BY(crit_); | 148 int num_pixels_ GUARDED_BY(crit_); |
140 | 149 |
141 // These seven members are only accessed on the processing thread. | 150 // These seven members are only accessed on the processing thread. |
142 int64_t next_process_time_; | 151 int64_t next_process_time_; |
143 int64_t last_overuse_time_; | 152 int64_t last_overuse_time_; |
144 int checks_above_threshold_; | 153 int checks_above_threshold_; |
145 int num_overuse_detections_; | 154 int num_overuse_detections_; |
146 int64_t last_rampup_time_; | 155 int64_t last_rampup_time_; |
147 bool in_quick_rampup_; | 156 bool in_quick_rampup_; |
148 int current_rampup_delay_ms_; | 157 int current_rampup_delay_ms_; |
149 | 158 |
150 int64_t last_sample_time_ms_; // Only accessed by one thread. | 159 int64_t last_sample_time_ms_; // Only accessed by one thread. |
151 | 160 |
152 // TODO(asapersson): Can these be regular members (avoid separate heap | 161 // TODO(asapersson): Can these be regular members (avoid separate heap |
153 // allocs)? | 162 // allocs)? |
154 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_); | 163 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_); |
155 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); | 164 std::list<FrameTiming> frame_timing_ GUARDED_BY(crit_); |
156 | 165 |
157 rtc::ThreadChecker processing_thread_; | 166 rtc::ThreadChecker processing_thread_; |
158 | 167 |
159 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); | 168 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
160 }; | 169 }; |
161 | 170 |
162 } // namespace webrtc | 171 } // namespace webrtc |
163 | 172 |
164 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 173 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
OLD | NEW |