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

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

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: implement getQPThresholds for various wrappers 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) 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 const VideoSendStream::Config::EncoderSettings& settings, 356 const VideoSendStream::Config::EncoderSettings& settings,
357 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, 357 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
358 EncodedFrameObserver* encoder_timing) 358 EncodedFrameObserver* encoder_timing)
359 : shutdown_event_(true /* manual_reset */, false), 359 : shutdown_event_(true /* manual_reset */, false),
360 number_of_cores_(number_of_cores), 360 number_of_cores_(number_of_cores),
361 source_proxy_(new VideoSourceProxy(this)), 361 source_proxy_(new VideoSourceProxy(this)),
362 sink_(nullptr), 362 sink_(nullptr),
363 settings_(settings), 363 settings_(settings),
364 codec_type_(PayloadNameToCodecType(settings.payload_name)), 364 codec_type_(PayloadNameToCodecType(settings.payload_name)),
365 video_sender_(Clock::GetRealTimeClock(), this, this), 365 video_sender_(Clock::GetRealTimeClock(), this, this),
366 disable_resolution_scaling_(false), 366 disable_cpu_adaptation_(false),
367 disable_quality_scaling_(true),
367 overuse_detector_(Clock::GetRealTimeClock(), 368 overuse_detector_(Clock::GetRealTimeClock(),
368 GetCpuOveruseOptions(settings.full_overuse_time), 369 GetCpuOveruseOptions(settings.full_overuse_time),
369 this, 370 this,
370 encoder_timing, 371 encoder_timing,
371 stats_proxy), 372 stats_proxy),
372 stats_proxy_(stats_proxy), 373 stats_proxy_(stats_proxy),
373 pre_encode_callback_(pre_encode_callback), 374 pre_encode_callback_(pre_encode_callback),
374 module_process_thread_(nullptr), 375 module_process_thread_(nullptr),
375 pending_encoder_reconfiguration_(false), 376 pending_encoder_reconfiguration_(false),
376 encoder_start_bitrate_bps_(0), 377 encoder_start_bitrate_bps_(0),
(...skipping 30 matching lines...) Expand all
407 } 408 }
408 409
409 void ViEEncoder::Stop() { 410 void ViEEncoder::Stop() {
410 RTC_DCHECK_RUN_ON(&thread_checker_); 411 RTC_DCHECK_RUN_ON(&thread_checker_);
411 source_proxy_->SetSource(nullptr, false); 412 source_proxy_->SetSource(nullptr, false);
412 encoder_queue_.PostTask([this] { 413 encoder_queue_.PostTask([this] {
413 RTC_DCHECK_RUN_ON(&encoder_queue_); 414 RTC_DCHECK_RUN_ON(&encoder_queue_);
414 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, 415 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type,
415 false); 416 false);
416 overuse_detector_.StopCheckForOveruse(); 417 overuse_detector_.StopCheckForOveruse();
418 if (!disable_quality_scaling_)
419 quality_scaler_.Stop();
417 shutdown_event_.Set(); 420 shutdown_event_.Set();
418 }); 421 });
419 422
420 shutdown_event_.Wait(rtc::Event::kForever); 423 shutdown_event_.Wait(rtc::Event::kForever);
421 } 424 }
422 425
423 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { 426 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) {
424 RTC_DCHECK_RUN_ON(&thread_checker_); 427 RTC_DCHECK_RUN_ON(&thread_checker_);
425 RTC_DCHECK(!module_process_thread_); 428 RTC_DCHECK(!module_process_thread_);
426 module_process_thread_ = module_process_thread; 429 module_process_thread_ = module_process_thread;
427 module_process_thread_->RegisterModule(&video_sender_); 430 module_process_thread_->RegisterModule(&video_sender_);
428 module_process_thread_checker_.DetachFromThread(); 431 module_process_thread_checker_.DetachFromThread();
429 } 432 }
430 433
431 void ViEEncoder::DeRegisterProcessThread() { 434 void ViEEncoder::DeRegisterProcessThread() {
432 RTC_DCHECK_RUN_ON(&thread_checker_); 435 RTC_DCHECK_RUN_ON(&thread_checker_);
433 module_process_thread_->DeRegisterModule(&video_sender_); 436 module_process_thread_->DeRegisterModule(&video_sender_);
434 } 437 }
435 438
436 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source, 439 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
437 bool disable_resolution_scaling) { 440 bool disable_resolution_scaling) {
438 RTC_DCHECK_RUN_ON(&thread_checker_); 441 RTC_DCHECK_RUN_ON(&thread_checker_);
439 source_proxy_->SetSource(source, disable_resolution_scaling); 442 source_proxy_->SetSource(source, disable_resolution_scaling);
440 encoder_queue_.PostTask([this, disable_resolution_scaling] { 443 encoder_queue_.PostTask([this, disable_resolution_scaling] {
441 RTC_DCHECK_RUN_ON(&encoder_queue_); 444 RTC_DCHECK_RUN_ON(&encoder_queue_);
442 if (disable_resolution_scaling_ != disable_resolution_scaling) { 445 if (disable_cpu_adaptation_ != disable_resolution_scaling) {
443 stats_proxy_->SetCpuRestrictedResolution(!disable_resolution_scaling && 446 stats_proxy_->SetCpuRestrictedResolution(!disable_resolution_scaling &&
444 cpu_restricted_counter_ != 0); 447 cpu_restricted_counter_ != 0);
445 } 448 }
446 disable_resolution_scaling_ = disable_resolution_scaling; 449 disable_cpu_adaptation_ = disable_resolution_scaling;
447 }); 450 });
448 } 451 }
449 452
450 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { 453 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) {
451 source_proxy_->SetWantsRotationApplied(rotation_applied); 454 source_proxy_->SetWantsRotationApplied(rotation_applied);
452 encoder_queue_.PostTask([this, sink, rotation_applied] { 455 encoder_queue_.PostTask([this, sink, rotation_applied] {
453 RTC_DCHECK_RUN_ON(&encoder_queue_); 456 RTC_DCHECK_RUN_ON(&encoder_queue_);
454 sink_ = sink; 457 sink_ = sink;
455 }); 458 });
456 } 459 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 rate_allocator_->GetPreferedBitrate()); 525 rate_allocator_->GetPreferedBitrate());
523 } 526 }
524 527
525 pending_encoder_reconfiguration_ = false; 528 pending_encoder_reconfiguration_ = false;
526 if (stats_proxy_) { 529 if (stats_proxy_) {
527 stats_proxy_->OnEncoderReconfigured(encoder_config_, 530 stats_proxy_->OnEncoderReconfigured(encoder_config_,
528 rate_allocator_->GetPreferedBitrate()); 531 rate_allocator_->GetPreferedBitrate());
529 } 532 }
530 sink_->OnEncoderConfigurationChanged( 533 sink_->OnEncoderConfigurationChanged(
531 std::move(streams), encoder_config_.min_transmit_bitrate_bps); 534 std::move(streams), encoder_config_.min_transmit_bitrate_bps);
535
536 const auto scaling_settings = settings_.encoder->GetQPThresholds();
537 LOG(LS_INFO) << settings_.encoder->ImplementationName();
538 disable_quality_scaling_ = !scaling_settings.enabled;
539 if (!disable_quality_scaling_) {
540 LOG(LS_INFO) << "Initializing quality scaler.";
541 if (scaling_settings.thresholds) {
542 const auto thresholds = *scaling_settings.thresholds;
543 quality_scaler_.Init(this, thresholds.first, thresholds.second);
544 } else {
545 quality_scaler_.Init(this, codec_type_);
546 }
547 }
532 } 548 }
533 549
534 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { 550 void ViEEncoder::OnFrame(const VideoFrame& video_frame) {
535 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); 551 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_);
536 VideoFrame incoming_frame = video_frame; 552 VideoFrame incoming_frame = video_frame;
537 553
538 // Local time in webrtc time base. 554 // Local time in webrtc time base.
539 int64_t current_time = clock_->TimeInMilliseconds(); 555 int64_t current_time = clock_->TimeInMilliseconds();
540 incoming_frame.set_render_time_ms(current_time); 556 incoming_frame.set_render_time_ms(current_time);
541 557
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // running in parallel on different threads. 697 // running in parallel on different threads.
682 if (stats_proxy_) { 698 if (stats_proxy_) {
683 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); 699 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info);
684 } 700 }
685 701
686 EncodedImageCallback::Result result = 702 EncodedImageCallback::Result result =
687 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); 703 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation);
688 704
689 int64_t time_sent = clock_->TimeInMilliseconds(); 705 int64_t time_sent = clock_->TimeInMilliseconds();
690 uint32_t timestamp = encoded_image._timeStamp; 706 uint32_t timestamp = encoded_image._timeStamp;
691 encoder_queue_.PostTask([this, timestamp, time_sent] { 707 encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] {
692 RTC_DCHECK_RUN_ON(&encoder_queue_); 708 RTC_DCHECK_RUN_ON(&encoder_queue_);
693 overuse_detector_.FrameSent(timestamp, time_sent); 709 overuse_detector_.FrameSent(timestamp, time_sent);
710 if (!disable_quality_scaling_)
711 quality_scaler_.ReportQP(encoded_image.qp_);
694 }); 712 });
695 return result; 713 return result;
696 } 714 }
697 715
698 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { 716 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) {
699 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); 717 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
700 if (stats_proxy_) 718 if (stats_proxy_)
701 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); 719 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate);
702 } 720 }
703 721
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 video_is_suspended != (last_observed_bitrate_bps_ == 0); 778 video_is_suspended != (last_observed_bitrate_bps_ == 0);
761 last_observed_bitrate_bps_ = bitrate_bps; 779 last_observed_bitrate_bps_ = bitrate_bps;
762 780
763 if (stats_proxy_ && video_suspension_changed) { 781 if (stats_proxy_ && video_suspension_changed) {
764 LOG(LS_INFO) << "Video suspend state changed to: " 782 LOG(LS_INFO) << "Video suspend state changed to: "
765 << (video_is_suspended ? "suspended" : "not suspended"); 783 << (video_is_suspended ? "suspended" : "not suspended");
766 stats_proxy_->OnSuspendChange(video_is_suspended); 784 stats_proxy_->OnSuspendChange(video_is_suspended);
767 } 785 }
768 } 786 }
769 787
770 void ViEEncoder::OveruseDetected() { 788 void ViEEncoder::ScaleDown() {
771 RTC_DCHECK_RUN_ON(&encoder_queue_); 789 RTC_DCHECK_RUN_ON(&encoder_queue_);
772 790
773 if (disable_resolution_scaling_) 791 if (disable_cpu_adaptation_)
774 return; 792 return;
775 793
776 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { 794 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) {
777 return; 795 return;
778 } 796 }
779 // Request lower resolution if the current resolution is lower than last time 797 // Request lower resolution if the current resolution is lower than last time
780 // we asked for the resolution to be lowered. 798 // we asked for the resolution to be lowered.
781 // Update stats accordingly. 799 // Update stats accordingly.
782 int current_pixel_count = last_frame_height_ * last_frame_width_; 800 int current_pixel_count = last_frame_height_ * last_frame_width_;
783 if (current_pixel_count < 801 if (current_pixel_count <
784 max_pixel_count_.value_or(current_pixel_count + 1)) { 802 max_pixel_count_.value_or(current_pixel_count + 1)) {
785 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); 803 max_pixel_count_ = rtc::Optional<int>(current_pixel_count);
786 max_pixel_count_step_up_ = rtc::Optional<int>(); 804 max_pixel_count_step_up_ = rtc::Optional<int>();
787 stats_proxy_->OnCpuRestrictedResolutionChanged(true); 805 stats_proxy_->OnCpuRestrictedResolutionChanged(true);
788 ++cpu_restricted_counter_; 806 ++cpu_restricted_counter_;
789 source_proxy_->RequestResolutionLowerThan(current_pixel_count); 807 source_proxy_->RequestResolutionLowerThan(current_pixel_count);
790 } 808 }
791 } 809 }
792 810
793 void ViEEncoder::NormalUsage() { 811 void ViEEncoder::ScaleUp() {
794 RTC_DCHECK_RUN_ON(&encoder_queue_); 812 RTC_DCHECK_RUN_ON(&encoder_queue_);
795 if (disable_resolution_scaling_) 813 if (disable_cpu_adaptation_)
796 return; 814 return;
797 815
798 int current_pixel_count = last_frame_height_ * last_frame_width_; 816 int current_pixel_count = last_frame_height_ * last_frame_width_;
799 // Request higher resolution if we are cpu restricted and the the current 817 // Request higher resolution if we are cpu restricted and the the current
800 // resolution is higher than last time we requested higher resolution. 818 // resolution is higher than last time we requested higher resolution.
801 // Update stats accordingly. 819 // Update stats accordingly.
802 if (cpu_restricted_counter_ > 0 && 820 if (cpu_restricted_counter_ > 0 &&
803 current_pixel_count > max_pixel_count_step_up_.value_or(0)) { 821 current_pixel_count > max_pixel_count_step_up_.value_or(0)) {
804 max_pixel_count_ = rtc::Optional<int>(); 822 max_pixel_count_ = rtc::Optional<int>();
805 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); 823 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count);
806 --cpu_restricted_counter_; 824 --cpu_restricted_counter_;
807 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); 825 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0);
808 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 826 source_proxy_->RequestHigherResolutionThan(current_pixel_count);
809 } 827 }
810 } 828 }
811 829
812 } // namespace webrtc 830 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698