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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 time_when_posted_ms_(time_when_posted_in_ms), | 219 time_when_posted_ms_(time_when_posted_in_ms), |
220 log_stats_(log_stats) { | 220 log_stats_(log_stats) { |
221 frame_.ShallowCopy(frame); | 221 frame_.ShallowCopy(frame); |
222 ++vie_encoder_->posted_frames_waiting_for_encode_; | 222 ++vie_encoder_->posted_frames_waiting_for_encode_; |
223 } | 223 } |
224 | 224 |
225 private: | 225 private: |
226 bool Run() override { | 226 bool Run() override { |
227 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_); | 227 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_); |
228 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); | 228 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); |
229 vie_encoder_->stats_proxy_->OnIncomingFrame( | 229 vie_encoder_->stats_proxy_->OnIncomingFrame(frame_.width(), |
230 frame_.width(), frame_.height(), | 230 frame_.height()); |
231 vie_encoder_->cpu_restricted_counter_ != 0); | |
232 ++vie_encoder_->captured_frame_count_; | 231 ++vie_encoder_->captured_frame_count_; |
233 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { | 232 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { |
234 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); | 233 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); |
235 } else { | 234 } else { |
236 // There is a newer frame in flight. Do not encode this frame. | 235 // There is a newer frame in flight. Do not encode this frame. |
237 LOG(LS_VERBOSE) | 236 LOG(LS_VERBOSE) |
238 << "Incoming frame dropped due to that the encoder is blocked."; | 237 << "Incoming frame dropped due to that the encoder is blocked."; |
239 ++vie_encoder_->dropped_frame_count_; | 238 ++vie_encoder_->dropped_frame_count_; |
240 } | 239 } |
241 if (log_stats_) { | 240 if (log_stats_) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 331 } |
333 // The input video frame size will have a resolution with "one step up" | 332 // The input video frame size will have a resolution with "one step up" |
334 // pixels than |max_pixel_count_step_up| where "one step up" depends on | 333 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
335 // how the source can scale the input frame size. | 334 // how the source can scale the input frame size. |
336 sink_wants_.max_pixel_count = rtc::Optional<int>(); | 335 sink_wants_.max_pixel_count = rtc::Optional<int>(); |
337 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | 336 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); |
338 if (source_) | 337 if (source_) |
339 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 338 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
340 } | 339 } |
341 | 340 |
341 bool CanScaleResolution() { | |
342 rtc::CritScope lock(&crit_); | |
343 return !resolution_scaling_disabled_; | |
344 } | |
345 | |
342 private: | 346 private: |
343 rtc::CriticalSection crit_; | 347 rtc::CriticalSection crit_; |
344 rtc::SequencedTaskChecker main_checker_; | 348 rtc::SequencedTaskChecker main_checker_; |
345 ViEEncoder* const vie_encoder_; | 349 ViEEncoder* const vie_encoder_; |
346 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); | 350 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); |
347 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_); | 351 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_); |
348 bool resolution_scaling_disabled_ GUARDED_BY(&crit_); | 352 bool resolution_scaling_disabled_ GUARDED_BY(&crit_); |
349 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | 353 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); |
350 | 354 |
351 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 355 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
352 }; | 356 }; |
353 | 357 |
354 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 358 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
355 SendStatisticsProxy* stats_proxy, | 359 SendStatisticsProxy* stats_proxy, |
356 const VideoSendStream::Config::EncoderSettings& settings, | 360 const VideoSendStream::Config::EncoderSettings& settings, |
357 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 361 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
358 EncodedFrameObserver* encoder_timing) | 362 EncodedFrameObserver* encoder_timing) |
359 : shutdown_event_(true /* manual_reset */, false), | 363 : shutdown_event_(true /* manual_reset */, false), |
360 number_of_cores_(number_of_cores), | 364 number_of_cores_(number_of_cores), |
361 source_proxy_(new VideoSourceProxy(this)), | 365 source_proxy_(new VideoSourceProxy(this)), |
362 sink_(nullptr), | 366 sink_(nullptr), |
363 settings_(settings), | 367 settings_(settings), |
364 codec_type_(PayloadNameToCodecType(settings.payload_name)), | 368 codec_type_(PayloadNameToCodecType(settings.payload_name)), |
365 video_sender_(Clock::GetRealTimeClock(), this, this), | 369 video_sender_(Clock::GetRealTimeClock(), this, this), |
366 disable_resolution_scaling_(false), | 370 enable_quality_scaling_(false), |
367 overuse_detector_(Clock::GetRealTimeClock(), | 371 overuse_detector_(Clock::GetRealTimeClock(), |
368 GetCpuOveruseOptions(settings.full_overuse_time), | 372 GetCpuOveruseOptions(settings.full_overuse_time), |
369 this, | 373 this, |
370 encoder_timing, | 374 encoder_timing, |
371 stats_proxy), | 375 stats_proxy), |
376 quality_scaler_(new QualityScaler(this)), | |
372 stats_proxy_(stats_proxy), | 377 stats_proxy_(stats_proxy), |
373 pre_encode_callback_(pre_encode_callback), | 378 pre_encode_callback_(pre_encode_callback), |
374 module_process_thread_(nullptr), | 379 module_process_thread_(nullptr), |
375 pending_encoder_reconfiguration_(false), | 380 pending_encoder_reconfiguration_(false), |
376 encoder_start_bitrate_bps_(0), | 381 encoder_start_bitrate_bps_(0), |
377 max_data_payload_length_(0), | 382 max_data_payload_length_(0), |
378 last_observed_bitrate_bps_(0), | 383 last_observed_bitrate_bps_(0), |
379 encoder_paused_and_dropped_frame_(false), | 384 encoder_paused_and_dropped_frame_(false), |
380 has_received_sli_(false), | 385 has_received_sli_(false), |
381 picture_id_sli_(0), | 386 picture_id_sli_(0), |
382 has_received_rpsi_(false), | 387 has_received_rpsi_(false), |
383 picture_id_rpsi_(0), | 388 picture_id_rpsi_(0), |
384 clock_(Clock::GetRealTimeClock()), | 389 clock_(Clock::GetRealTimeClock()), |
385 cpu_restricted_counter_(0), | |
386 last_frame_width_(0), | 390 last_frame_width_(0), |
387 last_frame_height_(0), | 391 last_frame_height_(0), |
388 last_captured_timestamp_(0), | 392 last_captured_timestamp_(0), |
389 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 393 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
390 clock_->TimeInMilliseconds()), | 394 clock_->TimeInMilliseconds()), |
391 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 395 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
392 captured_frame_count_(0), | 396 captured_frame_count_(0), |
393 dropped_frame_count_(0), | 397 dropped_frame_count_(0), |
394 encoder_queue_("EncoderQueue") { | 398 encoder_queue_("EncoderQueue") { |
395 encoder_queue_.PostTask([this, encoder_timing] { | 399 encoder_queue_.PostTask([this, encoder_timing] { |
(...skipping 11 matching lines...) Expand all Loading... | |
407 } | 411 } |
408 | 412 |
409 void ViEEncoder::Stop() { | 413 void ViEEncoder::Stop() { |
410 RTC_DCHECK_RUN_ON(&thread_checker_); | 414 RTC_DCHECK_RUN_ON(&thread_checker_); |
411 source_proxy_->SetSource(nullptr, false); | 415 source_proxy_->SetSource(nullptr, false); |
412 encoder_queue_.PostTask([this] { | 416 encoder_queue_.PostTask([this] { |
413 RTC_DCHECK_RUN_ON(&encoder_queue_); | 417 RTC_DCHECK_RUN_ON(&encoder_queue_); |
414 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 418 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
415 false); | 419 false); |
416 overuse_detector_.StopCheckForOveruse(); | 420 overuse_detector_.StopCheckForOveruse(); |
421 if (enable_quality_scaling_) | |
422 quality_scaler_->Stop(); | |
417 shutdown_event_.Set(); | 423 shutdown_event_.Set(); |
418 }); | 424 }); |
419 | 425 |
420 shutdown_event_.Wait(rtc::Event::kForever); | 426 shutdown_event_.Wait(rtc::Event::kForever); |
421 } | 427 } |
422 | 428 |
423 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 429 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
424 RTC_DCHECK_RUN_ON(&thread_checker_); | 430 RTC_DCHECK_RUN_ON(&thread_checker_); |
425 RTC_DCHECK(!module_process_thread_); | 431 RTC_DCHECK(!module_process_thread_); |
426 module_process_thread_ = module_process_thread; | 432 module_process_thread_ = module_process_thread; |
427 module_process_thread_->RegisterModule(&video_sender_); | 433 module_process_thread_->RegisterModule(&video_sender_); |
428 module_process_thread_checker_.DetachFromThread(); | 434 module_process_thread_checker_.DetachFromThread(); |
429 } | 435 } |
430 | 436 |
431 void ViEEncoder::DeRegisterProcessThread() { | 437 void ViEEncoder::DeRegisterProcessThread() { |
432 RTC_DCHECK_RUN_ON(&thread_checker_); | 438 RTC_DCHECK_RUN_ON(&thread_checker_); |
433 module_process_thread_->DeRegisterModule(&video_sender_); | 439 module_process_thread_->DeRegisterModule(&video_sender_); |
434 } | 440 } |
435 | 441 |
436 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source, | 442 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source, |
437 bool disable_resolution_scaling) { | 443 bool disable_resolution_scaling) { |
438 RTC_DCHECK_RUN_ON(&thread_checker_); | 444 RTC_DCHECK_RUN_ON(&thread_checker_); |
439 source_proxy_->SetSource(source, disable_resolution_scaling); | 445 source_proxy_->SetSource(source, disable_resolution_scaling); |
440 encoder_queue_.PostTask([this, disable_resolution_scaling] { | 446 stats_proxy_->SetResolutionRestrictionStats( |
441 RTC_DCHECK_RUN_ON(&encoder_queue_); | 447 !disable_resolution_scaling && scale_counter_[kQuality] > 0, |
442 if (disable_resolution_scaling_ != disable_resolution_scaling) { | 448 !disable_resolution_scaling && scale_counter_[kCpu] > 0); |
443 stats_proxy_->SetCpuRestrictedResolution(!disable_resolution_scaling && | |
444 cpu_restricted_counter_ != 0); | |
445 } | |
446 disable_resolution_scaling_ = disable_resolution_scaling; | |
447 }); | |
448 } | 449 } |
449 | 450 |
450 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { | 451 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
451 source_proxy_->SetWantsRotationApplied(rotation_applied); | 452 source_proxy_->SetWantsRotationApplied(rotation_applied); |
452 encoder_queue_.PostTask([this, sink, rotation_applied] { | 453 encoder_queue_.PostTask([this, sink, rotation_applied] { |
453 RTC_DCHECK_RUN_ON(&encoder_queue_); | 454 RTC_DCHECK_RUN_ON(&encoder_queue_); |
454 sink_ = sink; | 455 sink_ = sink; |
455 }); | 456 }); |
456 } | 457 } |
457 | 458 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 | 511 |
511 bool success = video_sender_.RegisterSendCodec( | 512 bool success = video_sender_.RegisterSendCodec( |
512 &codec, number_of_cores_, | 513 &codec, number_of_cores_, |
513 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 514 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
514 if (!success) { | 515 if (!success) { |
515 LOG(LS_ERROR) << "Failed to configure encoder."; | 516 LOG(LS_ERROR) << "Failed to configure encoder."; |
516 RTC_DCHECK(success); | 517 RTC_DCHECK(success); |
517 } | 518 } |
518 | 519 |
519 rate_allocator_.reset(new SimulcastRateAllocator(codec)); | 520 rate_allocator_.reset(new SimulcastRateAllocator(codec)); |
520 if (stats_proxy_) { | |
521 stats_proxy_->OnEncoderReconfigured(encoder_config_, | |
522 rate_allocator_->GetPreferedBitrate()); | |
523 } | |
524 | 521 |
525 pending_encoder_reconfiguration_ = false; | 522 pending_encoder_reconfiguration_ = false; |
526 if (stats_proxy_) { | 523 if (stats_proxy_) { |
527 stats_proxy_->OnEncoderReconfigured(encoder_config_, | 524 stats_proxy_->OnEncoderReconfigured(encoder_config_, |
528 rate_allocator_->GetPreferedBitrate()); | 525 rate_allocator_->GetPreferedBitrate()); |
529 } | 526 } |
530 sink_->OnEncoderConfigurationChanged( | 527 sink_->OnEncoderConfigurationChanged( |
531 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 528 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
529 | |
530 const auto scaling_settings = settings_.encoder->GetQPThresholds(); | |
531 enable_quality_scaling_ = scaling_settings.enabled; | |
532 if (enable_quality_scaling_) { | |
533 LOG(LS_INFO) << "Initializing quality scaler."; | |
534 if (quality_scaler_) | |
535 quality_scaler_->Stop(); | |
536 if (scaling_settings.thresholds) { | |
537 quality_scaler_->Init(*(scaling_settings.thresholds)); | |
538 } else { | |
539 quality_scaler_->Init(codec_type_); | |
540 } | |
541 } | |
532 } | 542 } |
533 | 543 |
534 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 544 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
535 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 545 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
536 VideoFrame incoming_frame = video_frame; | 546 VideoFrame incoming_frame = video_frame; |
537 | 547 |
538 // Local time in webrtc time base. | 548 // Local time in webrtc time base. |
539 int64_t current_time = clock_->TimeInMilliseconds(); | 549 int64_t current_time = clock_->TimeInMilliseconds(); |
540 incoming_frame.set_render_time_ms(current_time); | 550 incoming_frame.set_render_time_ms(current_time); |
541 | 551 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 // running in parallel on different threads. | 691 // running in parallel on different threads. |
682 if (stats_proxy_) { | 692 if (stats_proxy_) { |
683 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 693 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
684 } | 694 } |
685 | 695 |
686 EncodedImageCallback::Result result = | 696 EncodedImageCallback::Result result = |
687 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 697 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
688 | 698 |
689 int64_t time_sent = clock_->TimeInMilliseconds(); | 699 int64_t time_sent = clock_->TimeInMilliseconds(); |
690 uint32_t timestamp = encoded_image._timeStamp; | 700 uint32_t timestamp = encoded_image._timeStamp; |
691 encoder_queue_.PostTask([this, timestamp, time_sent] { | 701 encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { |
perkj_webrtc
2016/10/26 15:53:50
This may contain invalid pointers. Copy only the v
kthelgason
2016/10/26 19:02:50
Sorry, I'm not following. Can you elaborate?
| |
692 RTC_DCHECK_RUN_ON(&encoder_queue_); | 702 RTC_DCHECK_RUN_ON(&encoder_queue_); |
693 overuse_detector_.FrameSent(timestamp, time_sent); | 703 overuse_detector_.FrameSent(timestamp, time_sent); |
704 if (enable_quality_scaling_) | |
705 quality_scaler_->ReportQP(encoded_image.qp_); | |
694 }); | 706 }); |
695 return result; | 707 return result; |
696 } | 708 } |
697 | 709 |
698 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { | 710 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { |
699 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); | 711 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
700 if (stats_proxy_) | 712 if (stats_proxy_) |
701 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); | 713 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); |
702 } | 714 } |
703 | 715 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 video_is_suspended != (last_observed_bitrate_bps_ == 0); | 772 video_is_suspended != (last_observed_bitrate_bps_ == 0); |
761 last_observed_bitrate_bps_ = bitrate_bps; | 773 last_observed_bitrate_bps_ = bitrate_bps; |
762 | 774 |
763 if (stats_proxy_ && video_suspension_changed) { | 775 if (stats_proxy_ && video_suspension_changed) { |
764 LOG(LS_INFO) << "Video suspend state changed to: " | 776 LOG(LS_INFO) << "Video suspend state changed to: " |
765 << (video_is_suspended ? "suspended" : "not suspended"); | 777 << (video_is_suspended ? "suspended" : "not suspended"); |
766 stats_proxy_->OnSuspendChange(video_is_suspended); | 778 stats_proxy_->OnSuspendChange(video_is_suspended); |
767 } | 779 } |
768 } | 780 } |
769 | 781 |
770 void ViEEncoder::OveruseDetected() { | 782 void ViEEncoder::ScaleDown(ScaleReason reason) { |
771 RTC_DCHECK_RUN_ON(&encoder_queue_); | 783 RTC_DCHECK_RUN_ON(&encoder_queue_); |
772 | 784 // Request lower resolution if the current resolution is lower than last time |
773 if (disable_resolution_scaling_) | 785 // we asked for the resolution to be lowered. |
774 return; | 786 int current_pixel_count = last_frame_height_ * last_frame_width_; |
775 | 787 if (current_pixel_count >= |
776 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { | 788 max_pixel_count_.value_or(current_pixel_count + 1)) { |
777 return; | 789 return; |
778 } | 790 } |
779 // Request lower resolution if the current resolution is lower than last time | 791 if (!source_proxy_->CanScaleResolution()) |
780 // we asked for the resolution to be lowered. | 792 return; |
781 // Update stats accordingly. | 793 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
782 int current_pixel_count = last_frame_height_ * last_frame_width_; | 794 max_pixel_count_step_up_ = rtc::Optional<int>(); |
783 if (current_pixel_count < | 795 |
784 max_pixel_count_.value_or(current_pixel_count + 1)) { | 796 switch (reason) { |
785 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 797 case kQuality: |
786 max_pixel_count_step_up_ = rtc::Optional<int>(); | 798 if (!enable_quality_scaling_) |
787 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 799 return; |
788 ++cpu_restricted_counter_; | 800 stats_proxy_->OnQualityRestrictedResolutionChanged(true); |
789 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 801 break; |
802 case kCpu: | |
803 if (scale_counter_[reason] >= kMaxCpuDowngrades) | |
804 return; | |
805 // Update stats accordingly. | |
806 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | |
807 break; | |
790 } | 808 } |
809 ++scale_counter_[reason]; | |
810 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | |
791 } | 811 } |
792 | 812 |
793 void ViEEncoder::NormalUsage() { | 813 void ViEEncoder::ScaleUp(ScaleReason reason) { |
794 RTC_DCHECK_RUN_ON(&encoder_queue_); | 814 RTC_DCHECK_RUN_ON(&encoder_queue_); |
795 if (disable_resolution_scaling_) | 815 RTC_DCHECK_GE(scale_counter_[reason], 0); |
796 return; | |
797 | |
798 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
799 // Request higher resolution if we are cpu restricted and the the current | 816 // Request higher resolution if we are cpu restricted and the the current |
800 // resolution is higher than last time we requested higher resolution. | 817 // resolution is higher than last time we requested higher resolution. |
801 // Update stats accordingly. | 818 if (scale_counter_[reason] == 0) |
802 if (cpu_restricted_counter_ > 0 && | 819 return; |
803 current_pixel_count > max_pixel_count_step_up_.value_or(0)) { | 820 if (!source_proxy_->CanScaleResolution()) |
804 max_pixel_count_ = rtc::Optional<int>(); | 821 return; |
805 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 822 int current_pixel_count = last_frame_height_ * last_frame_width_; |
806 --cpu_restricted_counter_; | 823 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) |
807 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | 824 return; |
808 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 825 max_pixel_count_ = rtc::Optional<int>(); |
826 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | |
827 switch (reason) { | |
828 case kQuality: | |
829 if (!enable_quality_scaling_) | |
830 return; | |
831 stats_proxy_->OnQualityRestrictedResolutionChanged( | |
832 scale_counter_[reason] > 1); | |
833 break; | |
834 case kCpu: | |
835 // Update stats accordingly. | |
836 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | |
837 1); | |
838 break; | |
809 } | 839 } |
840 --scale_counter_[reason]; | |
841 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | |
810 } | 842 } |
811 | 843 |
812 } // namespace webrtc | 844 } // namespace webrtc |
OLD | NEW |