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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 disabled_scaling_sink_wants_.rotation_applied = rotation_applied; | 298 disabled_scaling_sink_wants_.rotation_applied = rotation_applied; |
299 if (source_) { | 299 if (source_) { |
300 source_->AddOrUpdateSink(vie_encoder_, current_wants()); | 300 source_->AddOrUpdateSink(vie_encoder_, current_wants()); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 void RequestResolutionLowerThan(int pixel_count) { | 304 void RequestResolutionLowerThan(int pixel_count) { |
305 // Called on the encoder task queue. | 305 // Called on the encoder task queue. |
306 rtc::CritScope lock(&crit_); | 306 rtc::CritScope lock(&crit_); |
307 if (!IsResolutionScalingEnabledLocked()) { | 307 if (!IsResolutionScalingEnabledLocked()) { |
308 // This can happen since |degradation_preference_| is set on | 308 // This can happen since |degradation_preference_| is set on |
perkj_webrtc
2016/11/16 20:56:13
You have removed the degradation_preference_.
| |
309 // libjingle's worker thread but the adaptation is done on the encoder | 309 // libjingle's worker thread but the adaptation is done on the encoder |
310 // task queue. | 310 // task queue. |
311 return; | 311 return; |
312 } | 312 } |
313 // The input video frame size will have a resolution with less than or | 313 // The input video frame size will have a resolution with less than or |
314 // equal to |max_pixel_count| depending on how the source can scale the | 314 // equal to |max_pixel_count| depending on how the source can scale the |
315 // input frame size. | 315 // input frame size. |
316 sink_wants_.max_pixel_count = rtc::Optional<int>((pixel_count * 3) / 5); | 316 sink_wants_.max_pixel_count = rtc::Optional<int>((pixel_count * 3) / 5); |
317 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); | 317 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); |
318 if (source_) | 318 if (source_) |
319 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 319 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
320 } | 320 } |
321 | 321 |
322 void RequestHigherResolutionThan(int pixel_count) { | 322 void RequestHigherResolutionThan(int pixel_count) { |
323 rtc::CritScope lock(&crit_); | 323 rtc::CritScope lock(&crit_); |
324 if (!IsResolutionScalingEnabledLocked()) { | 324 if (!IsResolutionScalingEnabledLocked()) { |
perkj_webrtc
2016/11/16 20:56:13
and here
| |
325 // This can happen since |degradation_preference_| is set on | 325 // This can happen since |degradation_preference_| is set on |
326 // libjingle's worker thread but the adaptation is done on the encoder | 326 // libjingle's worker thread but the adaptation is done on the encoder |
327 // task | 327 // task |
328 // queue. | 328 // queue. |
329 return; | 329 return; |
330 } | 330 } |
331 // The input video frame size will have a resolution with "one step up" | 331 // 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 | 332 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
333 // how the source can scale the input frame size. | 333 // how the source can scale the input frame size. |
334 sink_wants_.max_pixel_count = rtc::Optional<int>(); | 334 sink_wants_.max_pixel_count = rtc::Optional<int>(); |
335 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | 335 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); |
336 if (source_) | 336 if (source_) |
337 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 337 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
338 } | 338 } |
339 | 339 |
340 bool IsResolutionScalingEnabled() const { | |
341 rtc::CritScope lock(&crit_); | |
342 return IsResolutionScalingEnabledLocked(); | |
343 } | |
344 | |
340 private: | 345 private: |
341 bool IsResolutionScalingEnabledLocked() const | 346 bool IsResolutionScalingEnabledLocked() const |
342 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 347 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
343 return degradation_preference_ != | 348 return degradation_preference_ != |
344 VideoSendStream::DegradationPreference::kMaintainResolution; | 349 VideoSendStream::DegradationPreference::kMaintainResolution; |
345 } | 350 } |
346 | 351 |
347 const rtc::VideoSinkWants& current_wants() const | 352 const rtc::VideoSinkWants& current_wants() const |
348 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 353 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
349 return IsResolutionScalingEnabledLocked() ? sink_wants_ | 354 return IsResolutionScalingEnabledLocked() ? sink_wants_ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 pending_encoder_reconfiguration_(false), | 390 pending_encoder_reconfiguration_(false), |
386 encoder_start_bitrate_bps_(0), | 391 encoder_start_bitrate_bps_(0), |
387 max_data_payload_length_(0), | 392 max_data_payload_length_(0), |
388 last_observed_bitrate_bps_(0), | 393 last_observed_bitrate_bps_(0), |
389 encoder_paused_and_dropped_frame_(false), | 394 encoder_paused_and_dropped_frame_(false), |
390 has_received_sli_(false), | 395 has_received_sli_(false), |
391 picture_id_sli_(0), | 396 picture_id_sli_(0), |
392 has_received_rpsi_(false), | 397 has_received_rpsi_(false), |
393 picture_id_rpsi_(0), | 398 picture_id_rpsi_(0), |
394 clock_(Clock::GetRealTimeClock()), | 399 clock_(Clock::GetRealTimeClock()), |
395 degradation_preference_( | |
396 VideoSendStream::DegradationPreference::kBalanced), | |
397 cpu_restricted_counter_(0), | |
398 last_frame_width_(0), | 400 last_frame_width_(0), |
399 last_frame_height_(0), | 401 last_frame_height_(0), |
400 last_captured_timestamp_(0), | 402 last_captured_timestamp_(0), |
401 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 403 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
402 clock_->TimeInMilliseconds()), | 404 clock_->TimeInMilliseconds()), |
403 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 405 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
404 captured_frame_count_(0), | 406 captured_frame_count_(0), |
405 dropped_frame_count_(0), | 407 dropped_frame_count_(0), |
406 encoder_queue_("EncoderQueue") { | 408 encoder_queue_("EncoderQueue") { |
407 encoder_queue_.PostTask([this] { | 409 encoder_queue_.PostTask([this] { |
(...skipping 11 matching lines...) Expand all Loading... | |
419 } | 421 } |
420 | 422 |
421 void ViEEncoder::Stop() { | 423 void ViEEncoder::Stop() { |
422 RTC_DCHECK_RUN_ON(&thread_checker_); | 424 RTC_DCHECK_RUN_ON(&thread_checker_); |
423 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); | 425 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); |
424 encoder_queue_.PostTask([this] { | 426 encoder_queue_.PostTask([this] { |
425 RTC_DCHECK_RUN_ON(&encoder_queue_); | 427 RTC_DCHECK_RUN_ON(&encoder_queue_); |
426 overuse_detector_.StopCheckForOveruse(); | 428 overuse_detector_.StopCheckForOveruse(); |
427 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 429 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
428 false); | 430 false); |
431 quality_scaler_ = nullptr; | |
429 shutdown_event_.Set(); | 432 shutdown_event_.Set(); |
430 }); | 433 }); |
431 | 434 |
432 shutdown_event_.Wait(rtc::Event::kForever); | 435 shutdown_event_.Wait(rtc::Event::kForever); |
433 } | 436 } |
434 | 437 |
435 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 438 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
436 RTC_DCHECK_RUN_ON(&thread_checker_); | 439 RTC_DCHECK_RUN_ON(&thread_checker_); |
437 RTC_DCHECK(!module_process_thread_); | 440 RTC_DCHECK(!module_process_thread_); |
438 module_process_thread_ = module_process_thread; | 441 module_process_thread_ = module_process_thread; |
439 module_process_thread_->RegisterModule(&video_sender_); | 442 module_process_thread_->RegisterModule(&video_sender_); |
440 module_process_thread_checker_.DetachFromThread(); | 443 module_process_thread_checker_.DetachFromThread(); |
441 } | 444 } |
442 | 445 |
443 void ViEEncoder::DeRegisterProcessThread() { | 446 void ViEEncoder::DeRegisterProcessThread() { |
444 RTC_DCHECK_RUN_ON(&thread_checker_); | 447 RTC_DCHECK_RUN_ON(&thread_checker_); |
445 module_process_thread_->DeRegisterModule(&video_sender_); | 448 module_process_thread_->DeRegisterModule(&video_sender_); |
446 } | 449 } |
447 | 450 |
448 void ViEEncoder::SetSource( | 451 void ViEEncoder::SetSource( |
449 rtc::VideoSourceInterface<VideoFrame>* source, | 452 rtc::VideoSourceInterface<VideoFrame>* source, |
450 const VideoSendStream::DegradationPreference& degradation_preference) { | 453 const VideoSendStream::DegradationPreference& degradation_preference) { |
451 RTC_DCHECK_RUN_ON(&thread_checker_); | 454 RTC_DCHECK_RUN_ON(&thread_checker_); |
455 const bool scaling_enabled = | |
456 degradation_preference != | |
457 VideoSendStream::DegradationPreference::kMaintainResolution; | |
452 source_proxy_->SetSource(source, degradation_preference); | 458 source_proxy_->SetSource(source, degradation_preference); |
453 encoder_queue_.PostTask([this, degradation_preference] { | 459 encoder_queue_.PostTask([this, scaling_enabled] { |
454 RTC_DCHECK_RUN_ON(&encoder_queue_); | 460 RTC_DCHECK_RUN_ON(&encoder_queue_); |
455 degradation_preference_ = degradation_preference; | 461 stats_proxy_->SetResolutionRestrictionStats( |
456 // Set the stats for if we are currently CPU restricted. We are CPU | 462 scaling_enabled && scale_counter_[kQuality] > 0, |
457 // restricted depending on degradation preference and | 463 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 }); | 464 }); |
467 } | 465 } |
468 | 466 |
469 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { | 467 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
470 source_proxy_->SetWantsRotationApplied(rotation_applied); | 468 source_proxy_->SetWantsRotationApplied(rotation_applied); |
471 encoder_queue_.PostTask([this, sink] { | 469 encoder_queue_.PostTask([this, sink] { |
472 RTC_DCHECK_RUN_ON(&encoder_queue_); | 470 RTC_DCHECK_RUN_ON(&encoder_queue_); |
473 sink_ = sink; | 471 sink_ = sink; |
474 }); | 472 }); |
475 } | 473 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 | 526 |
529 bool success = video_sender_.RegisterSendCodec( | 527 bool success = video_sender_.RegisterSendCodec( |
530 &codec, number_of_cores_, | 528 &codec, number_of_cores_, |
531 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 529 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
532 if (!success) { | 530 if (!success) { |
533 LOG(LS_ERROR) << "Failed to configure encoder."; | 531 LOG(LS_ERROR) << "Failed to configure encoder."; |
534 RTC_DCHECK(success); | 532 RTC_DCHECK(success); |
535 } | 533 } |
536 | 534 |
537 rate_allocator_.reset(new SimulcastRateAllocator(codec)); | 535 rate_allocator_.reset(new SimulcastRateAllocator(codec)); |
538 if (stats_proxy_) { | |
539 stats_proxy_->OnEncoderReconfigured(encoder_config_, | |
540 rate_allocator_->GetPreferedBitrate()); | |
541 } | |
542 | 536 |
543 pending_encoder_reconfiguration_ = false; | 537 pending_encoder_reconfiguration_ = false; |
544 if (stats_proxy_) { | 538 if (stats_proxy_) { |
545 stats_proxy_->OnEncoderReconfigured(encoder_config_, | 539 stats_proxy_->OnEncoderReconfigured(encoder_config_, |
546 rate_allocator_->GetPreferedBitrate()); | 540 rate_allocator_->GetPreferedBitrate()); |
547 } | 541 } |
548 sink_->OnEncoderConfigurationChanged( | 542 sink_->OnEncoderConfigurationChanged( |
549 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 543 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
544 | |
545 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | |
546 if (scaling_settings.enabled && source_proxy_->IsResolutionScalingEnabled()) { | |
547 LOG(LS_INFO) << "Initializing quality scaler."; | |
548 if (scaling_settings.thresholds) { | |
549 quality_scaler_.reset( | |
550 new QualityScaler(this, *(scaling_settings.thresholds))); | |
551 } else { | |
552 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | |
553 } | |
554 } else { | |
555 quality_scaler_.reset(nullptr); | |
556 } | |
550 } | 557 } |
551 | 558 |
552 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 559 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
553 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 560 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
554 VideoFrame incoming_frame = video_frame; | 561 VideoFrame incoming_frame = video_frame; |
555 | 562 |
556 // Local time in webrtc time base. | 563 // Local time in webrtc time base. |
557 int64_t current_time = clock_->TimeInMilliseconds(); | 564 int64_t current_time = clock_->TimeInMilliseconds(); |
558 incoming_frame.set_render_time_ms(current_time); | 565 incoming_frame.set_render_time_ms(current_time); |
559 | 566 |
(...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. | 624 // End trace event on first frame after encoder resumes, if frame was dropped. |
618 if (encoder_paused_and_dropped_frame_) { | 625 if (encoder_paused_and_dropped_frame_) { |
619 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); | 626 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
620 } | 627 } |
621 encoder_paused_and_dropped_frame_ = false; | 628 encoder_paused_and_dropped_frame_ = false; |
622 } | 629 } |
623 | 630 |
624 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, | 631 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, |
625 int64_t time_when_posted_in_ms) { | 632 int64_t time_when_posted_in_ms) { |
626 RTC_DCHECK_RUN_ON(&encoder_queue_); | 633 RTC_DCHECK_RUN_ON(&encoder_queue_); |
634 | |
627 if (pre_encode_callback_) | 635 if (pre_encode_callback_) |
628 pre_encode_callback_->OnFrame(video_frame); | 636 pre_encode_callback_->OnFrame(video_frame); |
629 | 637 |
630 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || | 638 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || |
631 video_frame.height() != last_frame_info_->height || | 639 video_frame.height() != last_frame_info_->height || |
632 video_frame.rotation() != last_frame_info_->rotation || | 640 video_frame.rotation() != last_frame_info_->rotation || |
633 video_frame.is_texture() != last_frame_info_->is_texture) { | 641 video_frame.is_texture() != last_frame_info_->is_texture) { |
634 pending_encoder_reconfiguration_ = true; | 642 pending_encoder_reconfiguration_ = true; |
635 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 643 last_frame_info_ = rtc::Optional<VideoFrameInfo>( |
636 VideoFrameInfo(video_frame.width(), video_frame.height(), | 644 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. | 706 // running in parallel on different threads. |
699 if (stats_proxy_) { | 707 if (stats_proxy_) { |
700 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 708 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
701 } | 709 } |
702 | 710 |
703 EncodedImageCallback::Result result = | 711 EncodedImageCallback::Result result = |
704 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 712 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
705 | 713 |
706 int64_t time_sent = clock_->TimeInMilliseconds(); | 714 int64_t time_sent = clock_->TimeInMilliseconds(); |
707 uint32_t timestamp = encoded_image._timeStamp; | 715 uint32_t timestamp = encoded_image._timeStamp; |
708 | 716 encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { |
709 encoder_queue_.PostTask([this, timestamp, time_sent] { | |
710 RTC_DCHECK_RUN_ON(&encoder_queue_); | 717 RTC_DCHECK_RUN_ON(&encoder_queue_); |
711 overuse_detector_.FrameSent(timestamp, time_sent); | 718 overuse_detector_.FrameSent(timestamp, time_sent); |
719 if (quality_scaler_) | |
720 quality_scaler_->ReportQP(encoded_image.qp_); | |
712 }); | 721 }); |
713 | 722 |
714 return result; | 723 return result; |
715 } | 724 } |
716 | 725 |
717 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { | 726 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { |
718 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); | 727 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
719 if (stats_proxy_) | 728 if (stats_proxy_) |
720 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); | 729 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); |
721 } | 730 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 video_is_suspended != (last_observed_bitrate_bps_ == 0); | 788 video_is_suspended != (last_observed_bitrate_bps_ == 0); |
780 last_observed_bitrate_bps_ = bitrate_bps; | 789 last_observed_bitrate_bps_ = bitrate_bps; |
781 | 790 |
782 if (stats_proxy_ && video_suspension_changed) { | 791 if (stats_proxy_ && video_suspension_changed) { |
783 LOG(LS_INFO) << "Video suspend state changed to: " | 792 LOG(LS_INFO) << "Video suspend state changed to: " |
784 << (video_is_suspended ? "suspended" : "not suspended"); | 793 << (video_is_suspended ? "suspended" : "not suspended"); |
785 stats_proxy_->OnSuspendChange(video_is_suspended); | 794 stats_proxy_->OnSuspendChange(video_is_suspended); |
786 } | 795 } |
787 } | 796 } |
788 | 797 |
789 void ViEEncoder::OveruseDetected() { | 798 void ViEEncoder::ScaleDown(ScaleReason reason) { |
790 RTC_DCHECK_RUN_ON(&encoder_queue_); | 799 RTC_DCHECK_RUN_ON(&encoder_queue_); |
791 if (degradation_preference_ == | 800 |
792 VideoSendStream::DegradationPreference::kMaintainResolution || | 801 // Request lower resolution if the current resolution is lower than last time |
793 cpu_restricted_counter_ >= kMaxCpuDowngrades) { | 802 // we asked for the resolution to be lowered. |
803 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
perkj_webrtc
2016/11/16 20:56:13
Hm, you need to check the degradation_preference h
| |
804 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { | |
794 return; | 805 return; |
795 } | 806 } |
796 LOG(LS_INFO) << "CPU overuse detected. Requesting lower resolution."; | 807 switch (reason) { |
797 // Request lower resolution if the current resolution is lower than last time | 808 case kQuality: |
798 // we asked for the resolution to be lowered. | 809 if (scale_counter_[reason] >= kMaxQualityDowngrades) |
799 // Update stats accordingly. | 810 return; |
800 int current_pixel_count = last_frame_height_ * last_frame_width_; | 811 stats_proxy_->OnQualityRestrictedResolutionChanged(true); |
801 if (!max_pixel_count_ || current_pixel_count < *max_pixel_count_) { | 812 break; |
802 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 813 case kCpu: |
803 max_pixel_count_step_up_ = rtc::Optional<int>(); | 814 if (scale_counter_[reason] >= kMaxCpuDowngrades) |
804 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 815 return; |
805 ++cpu_restricted_counter_; | 816 // Update stats accordingly. |
806 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 817 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
818 break; | |
819 } | |
820 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | |
821 max_pixel_count_step_up_ = rtc::Optional<int>(); | |
822 ++scale_counter_[reason]; | |
823 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | |
824 LOG(LS_INFO) << "Scaling down resolution."; | |
825 for (size_t i = 0; i < kScaleReasonSize; ++i) { | |
826 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | |
827 << " times for reason: " << (i ? "quality" : "cpu"); | |
807 } | 828 } |
808 } | 829 } |
809 | 830 |
810 void ViEEncoder::NormalUsage() { | 831 void ViEEncoder::ScaleUp(ScaleReason reason) { |
811 RTC_DCHECK_RUN_ON(&encoder_queue_); | 832 RTC_DCHECK_RUN_ON(&encoder_queue_); |
812 if (degradation_preference_ == | 833 if (scale_counter_[reason] == 0) |
813 VideoSendStream::DegradationPreference::kMaintainResolution || | |
814 cpu_restricted_counter_ == 0) { | |
815 return; | 834 return; |
835 | |
836 // Only scale if resolution is higher than last time | |
837 // we requested higher resolution. | |
838 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
839 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) | |
840 return; | |
841 switch (reason) { | |
842 case kQuality: | |
843 stats_proxy_->OnQualityRestrictedResolutionChanged( | |
844 scale_counter_[reason] > 1); | |
845 break; | |
846 case kCpu: | |
847 // Update stats accordingly. | |
848 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | |
849 1); | |
850 break; | |
816 } | 851 } |
817 | 852 max_pixel_count_ = rtc::Optional<int>(); |
818 LOG(LS_INFO) << "CPU underuse detected. Requesting higher resolution."; | 853 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
819 int current_pixel_count = last_frame_height_ * last_frame_width_; | 854 --scale_counter_[reason]; |
820 // Request higher resolution if we are CPU restricted and the the current | 855 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
821 // resolution is higher than last time we requested higher resolution. | 856 LOG(LS_INFO) << "Scaling up resolution."; |
822 // Update stats accordingly. | 857 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
823 if (!max_pixel_count_step_up_ || | 858 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
824 current_pixel_count > *max_pixel_count_step_up_) { | 859 << " times for reason: " << (i ? "quality" : "cpu"); |
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 } | 860 } |
831 } | 861 } |
832 | 862 |
833 } // namespace webrtc | 863 } // namespace webrtc |
OLD | NEW |