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 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 class EncodeTimeAvg; | 114 class EncodeTimeAvg; |
115 class SendProcessingUsage; | 115 class SendProcessingUsage; |
116 class FrameQueue; | 116 class FrameQueue; |
117 | 117 |
118 void UpdateCpuOveruseMetrics() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 118 void UpdateCpuOveruseMetrics() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
119 | 119 |
120 // TODO(asapersson): This method is only used on one thread, so it shouldn't | 120 // TODO(asapersson): This method is only used on one thread, so it shouldn't |
121 // need a guard. | 121 // need a guard. |
122 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 122 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
123 | 123 |
124 // TODO(asapersson): This method is always called on the processing thread. | 124 // Only called on the processing thread. |
125 // If locking is required, consider doing that locking inside the | 125 bool IsOverusing(const CpuOveruseMetrics& metrics); |
126 // implementation and reduce scope as much as possible. We should also | 126 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); |
127 // see if we can avoid calling out to other methods while holding the lock. | |
128 bool IsOverusing() EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
129 bool IsUnderusing(int64_t time_now) EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
130 | 127 |
131 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 128 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
132 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_); | 129 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_); |
133 | 130 |
134 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 131 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
135 | 132 |
136 // Protecting all members except const and those that are only accessed on the | 133 // Protecting all members except const and those that are only accessed on the |
137 // processing thread. | 134 // processing thread. |
138 // TODO(asapersson): See if we can reduce locking. As is, video frame | 135 // TODO(asapersson): See if we can reduce locking. As is, video frame |
139 // processing contends with reading stats and the processing thread. | 136 // processing contends with reading stats and the processing thread. |
140 mutable rtc::CriticalSection crit_; | 137 mutable rtc::CriticalSection crit_; |
141 | 138 |
142 const CpuOveruseOptions options_; | 139 const CpuOveruseOptions options_; |
143 | 140 |
144 // Observer getting overuse reports. | 141 // Observer getting overuse reports. |
145 CpuOveruseObserver* const observer_; | 142 CpuOveruseObserver* const observer_; |
146 | 143 |
147 // Stats metrics. | 144 // Stats metrics. |
148 CpuOveruseMetricsObserver* const metrics_observer_; | 145 CpuOveruseMetricsObserver* const metrics_observer_; |
149 CpuOveruseMetrics metrics_ GUARDED_BY(crit_); | 146 CpuOveruseMetrics metrics_ GUARDED_BY(crit_); |
150 | 147 |
151 Clock* const clock_; | 148 Clock* const clock_; |
152 int64_t next_process_time_; // Only accessed on the processing thread. | |
153 int64_t num_process_times_ GUARDED_BY(crit_); | 149 int64_t num_process_times_ GUARDED_BY(crit_); |
154 | 150 |
155 int64_t last_capture_time_ GUARDED_BY(crit_); | 151 int64_t last_capture_time_ GUARDED_BY(crit_); |
156 | 152 |
157 // These six members are only accessed on the processing thread. | 153 // Number of pixels of last captured frame. |
| 154 int num_pixels_ GUARDED_BY(crit_); |
| 155 |
| 156 // These seven members are only accessed on the processing thread. |
| 157 int64_t next_process_time_; |
158 int64_t last_overuse_time_; | 158 int64_t last_overuse_time_; |
159 int checks_above_threshold_; | 159 int checks_above_threshold_; |
160 int num_overuse_detections_; | 160 int num_overuse_detections_; |
161 | |
162 int64_t last_rampup_time_; | 161 int64_t last_rampup_time_; |
163 bool in_quick_rampup_; | 162 bool in_quick_rampup_; |
164 int current_rampup_delay_ms_; | 163 int current_rampup_delay_ms_; |
165 | 164 |
166 // Number of pixels of last captured frame. | |
167 int num_pixels_ GUARDED_BY(crit_); | |
168 | |
169 int64_t last_encode_sample_ms_; // Only accessed by one thread. | 165 int64_t last_encode_sample_ms_; // Only accessed by one thread. |
| 166 int64_t last_sample_time_ms_; // Only accessed by one thread. |
170 | 167 |
171 // TODO(asapersson): Can these be regular members (avoid separate heap | 168 // TODO(asapersson): Can these be regular members (avoid separate heap |
172 // allocs)? | 169 // allocs)? |
173 const rtc::scoped_ptr<EncodeTimeAvg> encode_time_ GUARDED_BY(crit_); | 170 const rtc::scoped_ptr<EncodeTimeAvg> encode_time_ GUARDED_BY(crit_); |
174 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_); | 171 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_); |
175 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); | 172 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); |
176 | 173 |
177 int64_t last_sample_time_ms_; // Only accessed by one thread. | |
178 | |
179 rtc::ThreadChecker processing_thread_; | 174 rtc::ThreadChecker processing_thread_; |
180 | 175 |
181 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); | 176 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
182 }; | 177 }; |
183 | 178 |
184 } // namespace webrtc | 179 } // namespace webrtc |
185 | 180 |
186 #endif // WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ | 181 #endif // WEBRTC_VIDEO_ENGINE_OVERUSE_FRAME_DETECTOR_H_ |
OLD | NEW |