Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: webrtc/video/overuse_frame_detector.cc

Issue 2304363002: Let ViEEncoder express resolution requests as Sinkwants (Closed)
Patch Set: Fix broken test RunOnTqNormalUsage. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return false; 198 return false;
199 } 199 }
200 rtc::SequencedTaskChecker task_checker_; 200 rtc::SequencedTaskChecker task_checker_;
201 OveruseFrameDetector* overuse_detector_; 201 OveruseFrameDetector* overuse_detector_;
202 }; 202 };
203 203
204 OveruseFrameDetector::OveruseFrameDetector( 204 OveruseFrameDetector::OveruseFrameDetector(
205 Clock* clock, 205 Clock* clock,
206 const CpuOveruseOptions& options, 206 const CpuOveruseOptions& options,
207 CpuOveruseObserver* observer, 207 CpuOveruseObserver* observer,
208 EncodedFrameObserver* encoder_timing,
209 CpuOveruseMetricsObserver* metrics_observer) 208 CpuOveruseMetricsObserver* metrics_observer)
210 : check_overuse_task_(nullptr), 209 : check_overuse_task_(nullptr),
211 options_(options), 210 options_(options),
212 observer_(observer), 211 observer_(observer),
213 encoder_timing_(encoder_timing),
214 metrics_observer_(metrics_observer), 212 metrics_observer_(metrics_observer),
215 clock_(clock), 213 clock_(clock),
216 num_process_times_(0), 214 num_process_times_(0),
217 last_capture_time_ms_(-1), 215 last_capture_time_ms_(-1),
218 last_processed_capture_time_ms_(-1), 216 last_processed_capture_time_ms_(-1),
219 num_pixels_(0), 217 num_pixels_(0),
220 last_overuse_time_ms_(-1), 218 last_overuse_time_ms_(-1),
221 checks_above_threshold_(0), 219 checks_above_threshold_(0),
222 num_overuse_detections_(0), 220 num_overuse_detections_(0),
223 last_rampup_time_ms_(-1), 221 last_rampup_time_ms_(-1),
224 in_quick_rampup_(false), 222 in_quick_rampup_(false),
225 current_rampup_delay_ms_(kStandardRampUpDelayMs), 223 current_rampup_delay_ms_(kStandardRampUpDelayMs),
226 usage_(new SendProcessingUsage(options)) { 224 usage_(new SendProcessingUsage(options)) {
227 task_checker_.Detach(); 225 task_checker_.Detach();
228 } 226 }
229 227
230 OveruseFrameDetector::~OveruseFrameDetector() { 228 OveruseFrameDetector::~OveruseFrameDetector() {
231 RTC_DCHECK(!check_overuse_task_) << "StopCheckForOverUse must be called."; 229 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
230 if (check_overuse_task_) {
231 check_overuse_task_->Stop();
232 }
232 } 233 }
233 234
234 void OveruseFrameDetector::StartCheckForOveruse() { 235 void OveruseFrameDetector::StartCheckForOveruse() {
235 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 236 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
236 RTC_DCHECK(!check_overuse_task_); 237 RTC_DCHECK(!check_overuse_task_);
237 check_overuse_task_ = new CheckOveruseTask(this); 238 check_overuse_task_ = new CheckOveruseTask(this);
238 } 239 }
239 void OveruseFrameDetector::StopCheckForOveruse() {
240 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
241 check_overuse_task_->Stop();
242 check_overuse_task_ = nullptr;
243 }
244 240
245 void OveruseFrameDetector::EncodedFrameTimeMeasured(int encode_duration_ms) { 241 void OveruseFrameDetector::EncodedFrameTimeMeasured(int encode_duration_ms) {
246 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 242 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
247 if (!metrics_) 243 if (!metrics_)
248 metrics_ = rtc::Optional<CpuOveruseMetrics>(CpuOveruseMetrics()); 244 metrics_ = rtc::Optional<CpuOveruseMetrics>(CpuOveruseMetrics());
249 metrics_->encode_usage_percent = usage_->Value(); 245 metrics_->encode_usage_percent = usage_->Value();
250 246
251 metrics_observer_->OnEncodedFrameTimeMeasured(encode_duration_ms, *metrics_); 247 metrics_observer_->OnEncodedFrameTimeMeasured(encode_duration_ms, *metrics_);
252 } 248 }
253 249
(...skipping 19 matching lines...) Expand all
273 frame_timing_.clear(); 269 frame_timing_.clear();
274 last_capture_time_ms_ = -1; 270 last_capture_time_ms_ = -1;
275 last_processed_capture_time_ms_ = -1; 271 last_processed_capture_time_ms_ = -1;
276 num_process_times_ = 0; 272 num_process_times_ = 0;
277 metrics_ = rtc::Optional<CpuOveruseMetrics>(); 273 metrics_ = rtc::Optional<CpuOveruseMetrics>();
278 } 274 }
279 275
280 void OveruseFrameDetector::FrameCaptured(const VideoFrame& frame, 276 void OveruseFrameDetector::FrameCaptured(const VideoFrame& frame,
281 int64_t time_when_first_seen_ms) { 277 int64_t time_when_first_seen_ms) {
282 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 278 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
283
284 if (FrameSizeChanged(frame.width() * frame.height()) || 279 if (FrameSizeChanged(frame.width() * frame.height()) ||
285 FrameTimeoutDetected(time_when_first_seen_ms)) { 280 FrameTimeoutDetected(time_when_first_seen_ms)) {
286 ResetAll(frame.width() * frame.height()); 281 ResetAll(frame.width() * frame.height());
287 } 282 }
288 283
289 if (last_capture_time_ms_ != -1) 284 if (last_capture_time_ms_ != -1)
290 usage_->AddCaptureSample(time_when_first_seen_ms - last_capture_time_ms_); 285 usage_->AddCaptureSample(time_when_first_seen_ms - last_capture_time_ms_);
291 286
292 last_capture_time_ms_ = time_when_first_seen_ms; 287 last_capture_time_ms_ = time_when_first_seen_ms;
293 288
(...skipping 22 matching lines...) Expand all
316 // This is currently the case for all frames on ChromeOS, so logging them 311 // This is currently the case for all frames on ChromeOS, so logging them
317 // would be spammy, and triggering overuse would be wrong. 312 // would be spammy, and triggering overuse would be wrong.
318 // https://crbug.com/350106 313 // https://crbug.com/350106
319 while (!frame_timing_.empty()) { 314 while (!frame_timing_.empty()) {
320 FrameTiming timing = frame_timing_.front(); 315 FrameTiming timing = frame_timing_.front();
321 if (time_sent_in_ms - timing.capture_ms < kEncodingTimeMeasureWindowMs) 316 if (time_sent_in_ms - timing.capture_ms < kEncodingTimeMeasureWindowMs)
322 break; 317 break;
323 if (timing.last_send_ms != -1) { 318 if (timing.last_send_ms != -1) {
324 int encode_duration_ms = 319 int encode_duration_ms =
325 static_cast<int>(timing.last_send_ms - timing.capture_ms); 320 static_cast<int>(timing.last_send_ms - timing.capture_ms);
326 if (encoder_timing_) {
327 encoder_timing_->OnEncodeTiming(timing.capture_ntp_ms,
328 encode_duration_ms);
329 }
330 if (last_processed_capture_time_ms_ != -1) { 321 if (last_processed_capture_time_ms_ != -1) {
331 int64_t diff_ms = timing.capture_ms - last_processed_capture_time_ms_; 322 int64_t diff_ms = timing.capture_ms - last_processed_capture_time_ms_;
332 usage_->AddSample(encode_duration_ms, diff_ms); 323 usage_->AddSample(encode_duration_ms, diff_ms);
333 } 324 }
334 last_processed_capture_time_ms_ = timing.capture_ms; 325 last_processed_capture_time_ms_ = timing.capture_ms;
335 EncodedFrameTimeMeasured(encode_duration_ms); 326 EncodedFrameTimeMeasured(encode_duration_ms);
336 } 327 }
337 frame_timing_.pop_front(); 328 frame_timing_.pop_front();
338 } 329 }
339 } 330 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 int64_t time_now) { 394 int64_t time_now) {
404 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); 395 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
405 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_; 396 int delay = in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
406 if (time_now < last_rampup_time_ms_ + delay) 397 if (time_now < last_rampup_time_ms_ + delay)
407 return false; 398 return false;
408 399
409 return metrics.encode_usage_percent < 400 return metrics.encode_usage_percent <
410 options_.low_encode_usage_threshold_percent; 401 options_.low_encode_usage_threshold_percent;
411 } 402 }
412 } // namespace webrtc 403 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698