OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 12 matching lines...) Expand all Loading... | |
23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
24 #include "webrtc/video/overuse_frame_detector.h" | 24 #include "webrtc/video/overuse_frame_detector.h" |
25 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
26 #include "webrtc/video_frame.h" | 26 #include "webrtc/video_frame.h" |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 | 29 |
30 namespace { | 30 namespace { |
31 // Time interval for logging frame counts. | 31 // Time interval for logging frame counts. |
32 const int64_t kFrameLogIntervalMs = 60000; | 32 const int64_t kFrameLogIntervalMs = 60000; |
33 // Downscale resolution at most 2 times for CPU reasons. | |
34 static const int kMaxCpuDowngrades = 2; | |
35 // Downscale resolution at most 4 times for low-quality reasons. | |
36 static const int kMaxQualityDowngrades = 4; | |
33 | 37 |
34 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) { | 38 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) { |
35 if (payload_name == "VP8") | 39 if (payload_name == "VP8") |
36 return kVideoCodecVP8; | 40 return kVideoCodecVP8; |
37 if (payload_name == "VP9") | 41 if (payload_name == "VP9") |
38 return kVideoCodecVP9; | 42 return kVideoCodecVP9; |
39 if (payload_name == "H264") | 43 if (payload_name == "H264") |
40 return kVideoCodecH264; | 44 return kVideoCodecH264; |
41 return kVideoCodecGeneric; | 45 return kVideoCodecGeneric; |
42 } | 46 } |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 } | 334 } |
331 // The input video frame size will have a resolution with "one step up" | 335 // The input video frame size will have a resolution with "one step up" |
332 // pixels than |max_pixel_count_step_up| where "one step up" depends on | 336 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
333 // how the source can scale the input frame size. | 337 // how the source can scale the input frame size. |
334 sink_wants_.max_pixel_count = rtc::Optional<int>(); | 338 sink_wants_.max_pixel_count = rtc::Optional<int>(); |
335 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | 339 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); |
336 if (source_) | 340 if (source_) |
337 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 341 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
338 } | 342 } |
339 | 343 |
344 bool IsResolutionScalingEnabled() const { | |
345 rtc::CritScope lock(&crit_); | |
346 return IsResolutionScalingEnabledLocked(); | |
347 } | |
348 | |
340 private: | 349 private: |
341 bool IsResolutionScalingEnabledLocked() const | 350 bool IsResolutionScalingEnabledLocked() const |
342 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 351 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
343 return degradation_preference_ != | 352 return degradation_preference_ != |
344 VideoSendStream::DegradationPreference::kMaintainResolution; | 353 VideoSendStream::DegradationPreference::kMaintainResolution; |
345 } | 354 } |
346 | 355 |
347 const rtc::VideoSinkWants& current_wants() const | 356 const rtc::VideoSinkWants& current_wants() const |
348 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 357 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
349 return IsResolutionScalingEnabledLocked() ? sink_wants_ | 358 return IsResolutionScalingEnabledLocked() ? sink_wants_ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 pending_encoder_reconfiguration_(false), | 394 pending_encoder_reconfiguration_(false), |
386 encoder_start_bitrate_bps_(0), | 395 encoder_start_bitrate_bps_(0), |
387 max_data_payload_length_(0), | 396 max_data_payload_length_(0), |
388 last_observed_bitrate_bps_(0), | 397 last_observed_bitrate_bps_(0), |
389 encoder_paused_and_dropped_frame_(false), | 398 encoder_paused_and_dropped_frame_(false), |
390 has_received_sli_(false), | 399 has_received_sli_(false), |
391 picture_id_sli_(0), | 400 picture_id_sli_(0), |
392 has_received_rpsi_(false), | 401 has_received_rpsi_(false), |
393 picture_id_rpsi_(0), | 402 picture_id_rpsi_(0), |
394 clock_(Clock::GetRealTimeClock()), | 403 clock_(Clock::GetRealTimeClock()), |
395 degradation_preference_( | |
396 VideoSendStream::DegradationPreference::kBalanced), | |
397 cpu_restricted_counter_(0), | |
398 last_frame_width_(0), | 404 last_frame_width_(0), |
399 last_frame_height_(0), | 405 last_frame_height_(0), |
400 last_captured_timestamp_(0), | 406 last_captured_timestamp_(0), |
401 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 407 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
402 clock_->TimeInMilliseconds()), | 408 clock_->TimeInMilliseconds()), |
403 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 409 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
404 captured_frame_count_(0), | 410 captured_frame_count_(0), |
405 dropped_frame_count_(0), | 411 dropped_frame_count_(0), |
406 encoder_queue_("EncoderQueue") { | 412 encoder_queue_("EncoderQueue") { |
407 encoder_queue_.PostTask([this] { | 413 encoder_queue_.PostTask([this] { |
(...skipping 11 matching lines...) Expand all Loading... | |
419 } | 425 } |
420 | 426 |
421 void ViEEncoder::Stop() { | 427 void ViEEncoder::Stop() { |
422 RTC_DCHECK_RUN_ON(&thread_checker_); | 428 RTC_DCHECK_RUN_ON(&thread_checker_); |
423 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); | 429 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); |
424 encoder_queue_.PostTask([this] { | 430 encoder_queue_.PostTask([this] { |
425 RTC_DCHECK_RUN_ON(&encoder_queue_); | 431 RTC_DCHECK_RUN_ON(&encoder_queue_); |
426 overuse_detector_.StopCheckForOveruse(); | 432 overuse_detector_.StopCheckForOveruse(); |
427 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 433 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
428 false); | 434 false); |
435 quality_scaler_ = nullptr; | |
429 shutdown_event_.Set(); | 436 shutdown_event_.Set(); |
430 }); | 437 }); |
431 | 438 |
432 shutdown_event_.Wait(rtc::Event::kForever); | 439 shutdown_event_.Wait(rtc::Event::kForever); |
433 } | 440 } |
434 | 441 |
435 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 442 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
436 RTC_DCHECK_RUN_ON(&thread_checker_); | 443 RTC_DCHECK_RUN_ON(&thread_checker_); |
437 RTC_DCHECK(!module_process_thread_); | 444 RTC_DCHECK(!module_process_thread_); |
438 module_process_thread_ = module_process_thread; | 445 module_process_thread_ = module_process_thread; |
439 module_process_thread_->RegisterModule(&video_sender_); | 446 module_process_thread_->RegisterModule(&video_sender_); |
440 module_process_thread_checker_.DetachFromThread(); | 447 module_process_thread_checker_.DetachFromThread(); |
441 } | 448 } |
442 | 449 |
443 void ViEEncoder::DeRegisterProcessThread() { | 450 void ViEEncoder::DeRegisterProcessThread() { |
444 RTC_DCHECK_RUN_ON(&thread_checker_); | 451 RTC_DCHECK_RUN_ON(&thread_checker_); |
445 module_process_thread_->DeRegisterModule(&video_sender_); | 452 module_process_thread_->DeRegisterModule(&video_sender_); |
446 } | 453 } |
447 | 454 |
448 void ViEEncoder::SetSource( | 455 void ViEEncoder::SetSource( |
449 rtc::VideoSourceInterface<VideoFrame>* source, | 456 rtc::VideoSourceInterface<VideoFrame>* source, |
450 const VideoSendStream::DegradationPreference& degradation_preference) { | 457 const VideoSendStream::DegradationPreference& degradation_preference) { |
451 RTC_DCHECK_RUN_ON(&thread_checker_); | 458 RTC_DCHECK_RUN_ON(&thread_checker_); |
459 const bool scaling_enabled = | |
460 degradation_preference != | |
461 VideoSendStream::DegradationPreference::kMaintainResolution; | |
452 source_proxy_->SetSource(source, degradation_preference); | 462 source_proxy_->SetSource(source, degradation_preference); |
453 encoder_queue_.PostTask([this, degradation_preference] { | 463 encoder_queue_.PostTask([this, scaling_enabled] { |
454 RTC_DCHECK_RUN_ON(&encoder_queue_); | 464 RTC_DCHECK_RUN_ON(&encoder_queue_); |
455 degradation_preference_ = degradation_preference; | 465 stats_proxy_->SetResolutionRestrictionStats( |
456 // Set the stats for if we are currently CPU restricted. We are CPU | 466 scaling_enabled && scale_counter_[kQuality] > 0, |
457 // restricted depending on degradation preference and | 467 scaling_enabled && scale_counter_[kCpu] > 0); |
458 // if the overusedetector has currently detected overuse which is counted in | |
459 // |cpu_restricted_counter_| | |
460 // We do this on the encoder task queue to avoid a race with the stats set | |
461 // in ViEEncoder::NormalUsage and ViEEncoder::OveruseDetected. | |
462 stats_proxy_->SetCpuRestrictedResolution( | |
463 degradation_preference_ != | |
464 VideoSendStream::DegradationPreference::kMaintainResolution && | |
465 cpu_restricted_counter_ != 0); | |
466 }); | 468 }); |
467 } | 469 } |
468 | 470 |
469 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { | 471 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
470 source_proxy_->SetWantsRotationApplied(rotation_applied); | 472 source_proxy_->SetWantsRotationApplied(rotation_applied); |
471 encoder_queue_.PostTask([this, sink] { | 473 encoder_queue_.PostTask([this, sink] { |
472 RTC_DCHECK_RUN_ON(&encoder_queue_); | 474 RTC_DCHECK_RUN_ON(&encoder_queue_); |
473 sink_ = sink; | 475 sink_ = sink; |
474 }); | 476 }); |
475 } | 477 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 | 530 |
529 bool success = video_sender_.RegisterSendCodec( | 531 bool success = video_sender_.RegisterSendCodec( |
530 &codec, number_of_cores_, | 532 &codec, number_of_cores_, |
531 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 533 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
532 if (!success) { | 534 if (!success) { |
533 LOG(LS_ERROR) << "Failed to configure encoder."; | 535 LOG(LS_ERROR) << "Failed to configure encoder."; |
534 RTC_DCHECK(success); | 536 RTC_DCHECK(success); |
535 } | 537 } |
536 | 538 |
537 rate_allocator_.reset(new SimulcastRateAllocator(codec)); | 539 rate_allocator_.reset(new SimulcastRateAllocator(codec)); |
538 if (stats_proxy_) { | |
539 stats_proxy_->OnEncoderReconfigured(encoder_config_, | |
540 rate_allocator_->GetPreferedBitrate()); | |
541 } | |
542 | 540 |
543 pending_encoder_reconfiguration_ = false; | 541 pending_encoder_reconfiguration_ = false; |
544 if (stats_proxy_) { | 542 if (stats_proxy_) { |
545 stats_proxy_->OnEncoderReconfigured(encoder_config_, | 543 stats_proxy_->OnEncoderReconfigured(encoder_config_, |
546 rate_allocator_->GetPreferedBitrate()); | 544 rate_allocator_->GetPreferedBitrate()); |
547 } | 545 } |
548 sink_->OnEncoderConfigurationChanged( | 546 sink_->OnEncoderConfigurationChanged( |
549 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 547 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
548 | |
549 const auto scaling_settings = settings_.encoder->GetQPThresholds(); | |
550 if (scaling_settings.enabled && source_proxy_->IsResolutionScalingEnabled()) { | |
551 LOG(LS_INFO) << "Initializing quality scaler."; | |
552 if (scaling_settings.thresholds) { | |
553 quality_scaler_.reset( | |
554 new QualityScaler(this, *(scaling_settings.thresholds))); | |
555 } else { | |
556 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | |
557 } | |
558 } | |
550 } | 559 } |
551 | 560 |
552 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 561 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
553 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 562 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
554 VideoFrame incoming_frame = video_frame; | 563 VideoFrame incoming_frame = video_frame; |
555 | 564 |
556 // Local time in webrtc time base. | 565 // Local time in webrtc time base. |
557 int64_t current_time = clock_->TimeInMilliseconds(); | 566 int64_t current_time = clock_->TimeInMilliseconds(); |
558 incoming_frame.set_render_time_ms(current_time); | 567 incoming_frame.set_render_time_ms(current_time); |
559 | 568 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 // End trace event on first frame after encoder resumes, if frame was dropped. | 626 // End trace event on first frame after encoder resumes, if frame was dropped. |
618 if (encoder_paused_and_dropped_frame_) { | 627 if (encoder_paused_and_dropped_frame_) { |
619 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); | 628 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
620 } | 629 } |
621 encoder_paused_and_dropped_frame_ = false; | 630 encoder_paused_and_dropped_frame_ = false; |
622 } | 631 } |
623 | 632 |
624 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, | 633 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, |
625 int64_t time_when_posted_in_ms) { | 634 int64_t time_when_posted_in_ms) { |
626 RTC_DCHECK_RUN_ON(&encoder_queue_); | 635 RTC_DCHECK_RUN_ON(&encoder_queue_); |
636 | |
627 if (pre_encode_callback_) | 637 if (pre_encode_callback_) |
628 pre_encode_callback_->OnFrame(video_frame); | 638 pre_encode_callback_->OnFrame(video_frame); |
629 | 639 |
630 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || | 640 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || |
631 video_frame.height() != last_frame_info_->height || | 641 video_frame.height() != last_frame_info_->height || |
632 video_frame.rotation() != last_frame_info_->rotation || | 642 video_frame.rotation() != last_frame_info_->rotation || |
633 video_frame.is_texture() != last_frame_info_->is_texture) { | 643 video_frame.is_texture() != last_frame_info_->is_texture) { |
634 pending_encoder_reconfiguration_ = true; | 644 pending_encoder_reconfiguration_ = true; |
635 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 645 last_frame_info_ = rtc::Optional<VideoFrameInfo>( |
636 VideoFrameInfo(video_frame.width(), video_frame.height(), | 646 VideoFrameInfo(video_frame.width(), video_frame.height(), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 // running in parallel on different threads. | 708 // running in parallel on different threads. |
699 if (stats_proxy_) { | 709 if (stats_proxy_) { |
700 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 710 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
701 } | 711 } |
702 | 712 |
703 EncodedImageCallback::Result result = | 713 EncodedImageCallback::Result result = |
704 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 714 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
705 | 715 |
706 int64_t time_sent = clock_->TimeInMilliseconds(); | 716 int64_t time_sent = clock_->TimeInMilliseconds(); |
707 uint32_t timestamp = encoded_image._timeStamp; | 717 uint32_t timestamp = encoded_image._timeStamp; |
708 | 718 encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { |
709 encoder_queue_.PostTask([this, timestamp, time_sent] { | |
710 RTC_DCHECK_RUN_ON(&encoder_queue_); | 719 RTC_DCHECK_RUN_ON(&encoder_queue_); |
711 overuse_detector_.FrameSent(timestamp, time_sent); | 720 overuse_detector_.FrameSent(timestamp, time_sent); |
721 if (quality_scaler_) | |
722 quality_scaler_->ReportQP(encoded_image.qp_); | |
712 }); | 723 }); |
713 | 724 |
714 return result; | 725 return result; |
715 } | 726 } |
716 | 727 |
717 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { | 728 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { |
718 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); | 729 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
719 if (stats_proxy_) | 730 if (stats_proxy_) |
720 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); | 731 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); |
721 } | 732 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 video_is_suspended != (last_observed_bitrate_bps_ == 0); | 790 video_is_suspended != (last_observed_bitrate_bps_ == 0); |
780 last_observed_bitrate_bps_ = bitrate_bps; | 791 last_observed_bitrate_bps_ = bitrate_bps; |
781 | 792 |
782 if (stats_proxy_ && video_suspension_changed) { | 793 if (stats_proxy_ && video_suspension_changed) { |
783 LOG(LS_INFO) << "Video suspend state changed to: " | 794 LOG(LS_INFO) << "Video suspend state changed to: " |
784 << (video_is_suspended ? "suspended" : "not suspended"); | 795 << (video_is_suspended ? "suspended" : "not suspended"); |
785 stats_proxy_->OnSuspendChange(video_is_suspended); | 796 stats_proxy_->OnSuspendChange(video_is_suspended); |
786 } | 797 } |
787 } | 798 } |
788 | 799 |
789 void ViEEncoder::OveruseDetected() { | 800 void ViEEncoder::ScaleDown(ScaleReason reason) { |
magjed_webrtc
2016/11/10 13:07:00
Wouldn't it be easier to send |current_pixel_count
kthelgason
2016/11/10 15:38:28
The QualityScaler and CpuOveruseDetector don't kno
magjed_webrtc
2016/11/10 19:29:07
QualityScaler used to store the resolution in 'Res
| |
790 RTC_DCHECK_RUN_ON(&encoder_queue_); | 801 RTC_DCHECK_RUN_ON(&encoder_queue_); |
791 if (degradation_preference_ == | 802 |
792 VideoSendStream::DegradationPreference::kMaintainResolution || | 803 // Request lower resolution if the current resolution is lower than last time |
793 cpu_restricted_counter_ >= kMaxCpuDowngrades) { | 804 // we asked for the resolution to be lowered. |
805 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
806 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { | |
794 return; | 807 return; |
795 } | 808 } |
796 LOG(LS_INFO) << "CPU overuse detected. Requesting lower resolution."; | 809 switch (reason) { |
797 // Request lower resolution if the current resolution is lower than last time | 810 case kQuality: |
798 // we asked for the resolution to be lowered. | 811 if (scale_counter_[reason] >= kMaxQualityDowngrades) |
799 // Update stats accordingly. | 812 return; |
800 int current_pixel_count = last_frame_height_ * last_frame_width_; | 813 stats_proxy_->OnQualityRestrictedResolutionChanged(true); |
801 if (!max_pixel_count_ || current_pixel_count < *max_pixel_count_) { | 814 break; |
802 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 815 case kCpu: |
803 max_pixel_count_step_up_ = rtc::Optional<int>(); | 816 if (scale_counter_[reason] >= kMaxCpuDowngrades) |
804 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 817 return; |
805 ++cpu_restricted_counter_; | 818 // Update stats accordingly. |
806 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 819 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
820 break; | |
807 } | 821 } |
822 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | |
823 max_pixel_count_step_up_ = rtc::Optional<int>(); | |
824 ++scale_counter_[reason]; | |
825 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | |
808 } | 826 } |
809 | 827 |
810 void ViEEncoder::NormalUsage() { | 828 void ViEEncoder::ScaleUp(ScaleReason reason) { |
811 RTC_DCHECK_RUN_ON(&encoder_queue_); | 829 RTC_DCHECK_RUN_ON(&encoder_queue_); |
812 if (degradation_preference_ == | 830 if (scale_counter_[reason] == 0) |
813 VideoSendStream::DegradationPreference::kMaintainResolution || | |
814 cpu_restricted_counter_ == 0) { | |
815 return; | 831 return; |
832 | |
833 // Request higher resolution if we are cpu restricted and the the current | |
834 // resolution is higher than last time we requested higher resolution. | |
835 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
836 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) | |
837 return; | |
838 switch (reason) { | |
839 case kQuality: | |
840 stats_proxy_->OnQualityRestrictedResolutionChanged( | |
841 scale_counter_[reason] > 1); | |
842 break; | |
843 case kCpu: | |
844 // Update stats accordingly. | |
845 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | |
846 1); | |
847 break; | |
816 } | 848 } |
817 | 849 max_pixel_count_ = rtc::Optional<int>(); |
818 LOG(LS_INFO) << "CPU underuse detected. Requesting higher resolution."; | 850 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
819 int current_pixel_count = last_frame_height_ * last_frame_width_; | 851 --scale_counter_[reason]; |
820 // Request higher resolution if we are CPU restricted and the the current | 852 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
821 // resolution is higher than last time we requested higher resolution. | |
822 // Update stats accordingly. | |
823 if (!max_pixel_count_step_up_ || | |
824 current_pixel_count > *max_pixel_count_step_up_) { | |
825 max_pixel_count_ = rtc::Optional<int>(); | |
826 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | |
827 --cpu_restricted_counter_; | |
828 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | |
829 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | |
830 } | |
831 } | 853 } |
832 | 854 |
833 } // namespace webrtc | 855 } // namespace webrtc |
OLD | NEW |