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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 frame_.width(), frame_.height(), | 230 frame_.width(), frame_.height(), |
231 vie_encoder_->cpu_restricted_counter_ != 0); | 231 vie_encoder_->cpu_restricted_counter_ != 0); |
232 ++vie_encoder_->captured_frame_count_; | 232 ++vie_encoder_->captured_frame_count_; |
233 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { | 233 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { |
234 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); | 234 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); |
235 } else { | 235 } else { |
236 // There is a newer frame in flight. Do not encode this frame. | 236 // There is a newer frame in flight. Do not encode this frame. |
237 LOG(LS_VERBOSE) | 237 LOG(LS_VERBOSE) |
238 << "Incoming frame dropped due to that the encoder is blocked."; | 238 << "Incoming frame dropped due to that the encoder is blocked."; |
239 ++vie_encoder_->dropped_frame_count_; | 239 ++vie_encoder_->dropped_frame_count_; |
240 vie_encoder_->quality_scaler_.ReportDroppedFrame(); | |
240 } | 241 } |
241 if (log_stats_) { | 242 if (log_stats_) { |
242 LOG(LS_INFO) << "Number of frames: captured " | 243 LOG(LS_INFO) << "Number of frames: captured " |
243 << vie_encoder_->captured_frame_count_ | 244 << vie_encoder_->captured_frame_count_ |
244 << ", dropped (due to encoder blocked) " | 245 << ", dropped (due to encoder blocked) " |
245 << vie_encoder_->dropped_frame_count_ << ", interval_ms " | 246 << vie_encoder_->dropped_frame_count_ << ", interval_ms " |
246 << kFrameLogIntervalMs; | 247 << kFrameLogIntervalMs; |
247 vie_encoder_->captured_frame_count_ = 0; | 248 vie_encoder_->captured_frame_count_ = 0; |
248 vie_encoder_->dropped_frame_count_ = 0; | 249 vie_encoder_->dropped_frame_count_ = 0; |
249 } | 250 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 quality_scaler_.Stop(); | |
417 shutdown_event_.Set(); | 419 shutdown_event_.Set(); |
418 }); | 420 }); |
419 | 421 |
420 shutdown_event_.Wait(rtc::Event::kForever); | 422 shutdown_event_.Wait(rtc::Event::kForever); |
421 } | 423 } |
422 | 424 |
423 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 425 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
424 RTC_DCHECK_RUN_ON(&thread_checker_); | 426 RTC_DCHECK_RUN_ON(&thread_checker_); |
425 RTC_DCHECK(!module_process_thread_); | 427 RTC_DCHECK(!module_process_thread_); |
426 module_process_thread_ = module_process_thread; | 428 module_process_thread_ = module_process_thread; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 last_frame_info_->width, last_frame_info_->height, encoder_config_); | 503 last_frame_info_->width, last_frame_info_->height, encoder_config_); |
502 | 504 |
503 VideoCodec codec = VideoEncoderConfigToVideoCodec( | 505 VideoCodec codec = VideoEncoderConfigToVideoCodec( |
504 encoder_config_, streams, settings_.payload_name, settings_.payload_type); | 506 encoder_config_, streams, settings_.payload_name, settings_.payload_type); |
505 | 507 |
506 codec.startBitrate = | 508 codec.startBitrate = |
507 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); | 509 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); |
508 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); | 510 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); |
509 codec.expect_encode_from_texture = last_frame_info_->is_texture; | 511 codec.expect_encode_from_texture = last_frame_info_->is_texture; |
510 | 512 |
513 const auto thresholds = settings_.encoder->GetQPThresholds(); | |
514 if (thresholds) { | |
515 quality_scaler_.Init(this, thresholds->first, thresholds->second); | |
516 } else { | |
517 quality_scaler_.Init(this, codec_type_); | |
magjed_webrtc
2016/10/07 12:02:54
No thresholds should mean no quality scaling, not
| |
518 } | |
519 | |
511 bool success = video_sender_.RegisterSendCodec( | 520 bool success = video_sender_.RegisterSendCodec( |
512 &codec, number_of_cores_, | 521 &codec, number_of_cores_, |
513 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 522 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
514 if (!success) { | 523 if (!success) { |
515 LOG(LS_ERROR) << "Failed to configure encoder."; | 524 LOG(LS_ERROR) << "Failed to configure encoder."; |
516 RTC_DCHECK(success); | 525 RTC_DCHECK(success); |
517 } | 526 } |
518 | 527 |
519 rate_allocator_.reset(new SimulcastRateAllocator(codec)); | 528 rate_allocator_.reset(new SimulcastRateAllocator(codec)); |
520 if (stats_proxy_) { | 529 if (stats_proxy_) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 // running in parallel on different threads. | 690 // running in parallel on different threads. |
682 if (stats_proxy_) { | 691 if (stats_proxy_) { |
683 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 692 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
684 } | 693 } |
685 | 694 |
686 EncodedImageCallback::Result result = | 695 EncodedImageCallback::Result result = |
687 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 696 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
688 | 697 |
689 int64_t time_sent = clock_->TimeInMilliseconds(); | 698 int64_t time_sent = clock_->TimeInMilliseconds(); |
690 uint32_t timestamp = encoded_image._timeStamp; | 699 uint32_t timestamp = encoded_image._timeStamp; |
691 encoder_queue_.PostTask([this, timestamp, time_sent] { | 700 encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { |
692 RTC_DCHECK_RUN_ON(&encoder_queue_); | 701 RTC_DCHECK_RUN_ON(&encoder_queue_); |
693 overuse_detector_.FrameSent(timestamp, time_sent); | 702 overuse_detector_.FrameSent(timestamp, time_sent); |
703 quality_scaler_.ReportQP(encoded_image.qp_); | |
694 }); | 704 }); |
695 return result; | 705 return result; |
696 } | 706 } |
697 | 707 |
698 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { | 708 void ViEEncoder::SendStatistics(uint32_t bit_rate, uint32_t frame_rate) { |
699 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); | 709 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread()); |
700 if (stats_proxy_) | 710 if (stats_proxy_) |
701 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); | 711 stats_proxy_->OnEncoderStatsUpdate(frame_rate, bit_rate); |
702 } | 712 } |
703 | 713 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 video_is_suspended != (last_observed_bitrate_bps_ == 0); | 770 video_is_suspended != (last_observed_bitrate_bps_ == 0); |
761 last_observed_bitrate_bps_ = bitrate_bps; | 771 last_observed_bitrate_bps_ = bitrate_bps; |
762 | 772 |
763 if (stats_proxy_ && video_suspension_changed) { | 773 if (stats_proxy_ && video_suspension_changed) { |
764 LOG(LS_INFO) << "Video suspend state changed to: " | 774 LOG(LS_INFO) << "Video suspend state changed to: " |
765 << (video_is_suspended ? "suspended" : "not suspended"); | 775 << (video_is_suspended ? "suspended" : "not suspended"); |
766 stats_proxy_->OnSuspendChange(video_is_suspended); | 776 stats_proxy_->OnSuspendChange(video_is_suspended); |
767 } | 777 } |
768 } | 778 } |
769 | 779 |
770 void ViEEncoder::OveruseDetected() { | 780 void ViEEncoder::ScaleDown() { |
771 RTC_DCHECK_RUN_ON(&encoder_queue_); | 781 RTC_DCHECK_RUN_ON(&encoder_queue_); |
772 | 782 |
773 if (disable_resolution_scaling_) | 783 if (disable_resolution_scaling_) |
774 return; | 784 return; |
775 | 785 |
776 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { | 786 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { |
777 return; | 787 return; |
778 } | 788 } |
779 // Request lower resolution if the current resolution is lower than last time | 789 // Request lower resolution if the current resolution is lower than last time |
780 // we asked for the resolution to be lowered. | 790 // we asked for the resolution to be lowered. |
781 // Update stats accordingly. | 791 // Update stats accordingly. |
782 int current_pixel_count = last_frame_height_ * last_frame_width_; | 792 int current_pixel_count = last_frame_height_ * last_frame_width_; |
783 if (current_pixel_count < | 793 if (current_pixel_count < |
784 max_pixel_count_.value_or(current_pixel_count + 1)) { | 794 max_pixel_count_.value_or(current_pixel_count + 1)) { |
785 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 795 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
786 max_pixel_count_step_up_ = rtc::Optional<int>(); | 796 max_pixel_count_step_up_ = rtc::Optional<int>(); |
787 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 797 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
788 ++cpu_restricted_counter_; | 798 ++cpu_restricted_counter_; |
789 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 799 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
790 } | 800 } |
791 } | 801 } |
792 | 802 |
793 void ViEEncoder::NormalUsage() { | 803 void ViEEncoder::ScaleUp() { |
794 RTC_DCHECK_RUN_ON(&encoder_queue_); | 804 RTC_DCHECK_RUN_ON(&encoder_queue_); |
795 if (disable_resolution_scaling_) | 805 if (disable_resolution_scaling_) |
796 return; | 806 return; |
797 | 807 |
798 int current_pixel_count = last_frame_height_ * last_frame_width_; | 808 int current_pixel_count = last_frame_height_ * last_frame_width_; |
799 // Request higher resolution if we are cpu restricted and the the current | 809 // Request higher resolution if we are cpu restricted and the the current |
800 // resolution is higher than last time we requested higher resolution. | 810 // resolution is higher than last time we requested higher resolution. |
801 // Update stats accordingly. | 811 // Update stats accordingly. |
802 if (cpu_restricted_counter_ > 0 && | 812 if (cpu_restricted_counter_ > 0 && |
803 current_pixel_count > max_pixel_count_step_up_.value_or(0)) { | 813 current_pixel_count > max_pixel_count_step_up_.value_or(0)) { |
804 max_pixel_count_ = rtc::Optional<int>(); | 814 max_pixel_count_ = rtc::Optional<int>(); |
805 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 815 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
806 --cpu_restricted_counter_; | 816 --cpu_restricted_counter_; |
807 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | 817 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); |
808 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 818 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
809 } | 819 } |
810 } | 820 } |
811 | 821 |
812 } // namespace webrtc | 822 } // namespace webrtc |
OLD | NEW |