| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 max_data_payload_length_(0), | 263 max_data_payload_length_(0), |
| 264 nack_enabled_(false), | 264 nack_enabled_(false), |
| 265 last_observed_bitrate_bps_(0), | 265 last_observed_bitrate_bps_(0), |
| 266 encoder_paused_and_dropped_frame_(false), | 266 encoder_paused_and_dropped_frame_(false), |
| 267 has_received_sli_(false), | 267 has_received_sli_(false), |
| 268 picture_id_sli_(0), | 268 picture_id_sli_(0), |
| 269 has_received_rpsi_(false), | 269 has_received_rpsi_(false), |
| 270 picture_id_rpsi_(0), | 270 picture_id_rpsi_(0), |
| 271 clock_(Clock::GetRealTimeClock()), | 271 clock_(Clock::GetRealTimeClock()), |
| 272 scale_counter_(kScaleReasonSize, 0), | 272 scale_counter_(kScaleReasonSize, 0), |
| 273 last_frame_width_(0), | |
| 274 last_frame_height_(0), | |
| 275 last_captured_timestamp_(0), | 273 last_captured_timestamp_(0), |
| 276 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 274 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 277 clock_->TimeInMilliseconds()), | 275 clock_->TimeInMilliseconds()), |
| 278 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 276 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
| 279 captured_frame_count_(0), | 277 captured_frame_count_(0), |
| 280 dropped_frame_count_(0), | 278 dropped_frame_count_(0), |
| 281 bitrate_observer_(nullptr), | 279 bitrate_observer_(nullptr), |
| 282 encoder_queue_("EncoderQueue") { | 280 encoder_queue_("EncoderQueue") { |
| 283 encoder_queue_.PostTask([this] { | 281 encoder_queue_.PostTask([this] { |
| 284 RTC_DCHECK_RUN_ON(&encoder_queue_); | 282 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 if (pending_encoder_reconfiguration_) { | 548 if (pending_encoder_reconfiguration_) { |
| 551 ReconfigureEncoder(); | 549 ReconfigureEncoder(); |
| 552 } | 550 } |
| 553 | 551 |
| 554 if (EncoderPaused()) { | 552 if (EncoderPaused()) { |
| 555 TraceFrameDropStart(); | 553 TraceFrameDropStart(); |
| 556 return; | 554 return; |
| 557 } | 555 } |
| 558 TraceFrameDropEnd(); | 556 TraceFrameDropEnd(); |
| 559 | 557 |
| 560 last_frame_height_ = video_frame.height(); | |
| 561 last_frame_width_ = video_frame.width(); | |
| 562 | |
| 563 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 558 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 564 "Encode"); | 559 "Encode"); |
| 565 | 560 |
| 566 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 561 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
| 567 | 562 |
| 568 if (codec_type_ == webrtc::kVideoCodecVP8) { | 563 if (codec_type_ == webrtc::kVideoCodecVP8) { |
| 569 webrtc::CodecSpecificInfo codec_specific_info; | 564 webrtc::CodecSpecificInfo codec_specific_info; |
| 570 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 565 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 571 | 566 |
| 572 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 567 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 stats_proxy_->OnSuspendChange(video_is_suspended); | 691 stats_proxy_->OnSuspendChange(video_is_suspended); |
| 697 } | 692 } |
| 698 } | 693 } |
| 699 | 694 |
| 700 void ViEEncoder::ScaleDown(ScaleReason reason) { | 695 void ViEEncoder::ScaleDown(ScaleReason reason) { |
| 701 RTC_DCHECK_RUN_ON(&encoder_queue_); | 696 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 702 if (!scaling_enabled_) | 697 if (!scaling_enabled_) |
| 703 return; | 698 return; |
| 704 // Request lower resolution if the current resolution is lower than last time | 699 // Request lower resolution if the current resolution is lower than last time |
| 705 // we asked for the resolution to be lowered. | 700 // we asked for the resolution to be lowered. |
| 706 int current_pixel_count = last_frame_height_ * last_frame_width_; | 701 int current_pixel_count = |
| 702 last_frame_info_ ? last_frame_info_->pixel_count() : 0; |
| 707 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) | 703 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) |
| 708 return; | 704 return; |
| 709 switch (reason) { | 705 switch (reason) { |
| 710 case kQuality: | 706 case kQuality: |
| 711 stats_proxy_->OnQualityRestrictedResolutionChanged( | 707 stats_proxy_->OnQualityRestrictedResolutionChanged( |
| 712 scale_counter_[reason] + 1); | 708 scale_counter_[reason] + 1); |
| 713 break; | 709 break; |
| 714 case kCpu: | 710 case kCpu: |
| 715 if (scale_counter_[reason] >= kMaxCpuDowngrades) | 711 if (scale_counter_[reason] >= kMaxCpuDowngrades) |
| 716 return; | 712 return; |
| 717 // Update stats accordingly. | 713 // Update stats accordingly. |
| 718 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | 714 stats_proxy_->OnCpuRestrictedResolutionChanged(true); |
| 719 break; | 715 break; |
| 720 } | 716 } |
| 721 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | 717 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); |
| 722 max_pixel_count_step_up_ = rtc::Optional<int>(); | 718 max_pixel_count_step_up_ = rtc::Optional<int>(); |
| 723 ++scale_counter_[reason]; | 719 ++scale_counter_[reason]; |
| 724 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 720 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
| 725 LOG(LS_INFO) << "Scaling down resolution."; | 721 LOG(LS_INFO) << "Scaling down resolution."; |
| 726 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 722 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 727 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 723 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 728 << " times for reason: " << (i ? "quality" : "cpu"); | 724 << " times for reason: " << (i ? "cpu" : "quality"); |
| 729 } | 725 } |
| 730 } | 726 } |
| 731 | 727 |
| 732 void ViEEncoder::ScaleUp(ScaleReason reason) { | 728 void ViEEncoder::ScaleUp(ScaleReason reason) { |
| 733 RTC_DCHECK_RUN_ON(&encoder_queue_); | 729 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 734 if (scale_counter_[reason] == 0 || !scaling_enabled_) | 730 if (scale_counter_[reason] == 0 || !scaling_enabled_) |
| 735 return; | 731 return; |
| 736 // Only scale if resolution is higher than last time | 732 // Only scale if resolution is higher than last time |
| 737 // we requested higher resolution. | 733 // we requested higher resolution. |
| 738 int current_pixel_count = last_frame_height_ * last_frame_width_; | 734 int current_pixel_count = |
| 735 last_frame_info_ ? last_frame_info_->pixel_count() : 0; |
| 739 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) | 736 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) |
| 740 return; | 737 return; |
| 741 switch (reason) { | 738 switch (reason) { |
| 742 case kQuality: | 739 case kQuality: |
| 743 stats_proxy_->OnQualityRestrictedResolutionChanged( | 740 stats_proxy_->OnQualityRestrictedResolutionChanged( |
| 744 scale_counter_[reason] - 1); | 741 scale_counter_[reason] - 1); |
| 745 break; | 742 break; |
| 746 case kCpu: | 743 case kCpu: |
| 747 // Update stats accordingly. | 744 // Update stats accordingly. |
| 748 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | 745 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > |
| 749 1); | 746 1); |
| 750 break; | 747 break; |
| 751 } | 748 } |
| 752 max_pixel_count_ = rtc::Optional<int>(); | 749 max_pixel_count_ = rtc::Optional<int>(); |
| 753 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 750 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
| 754 --scale_counter_[reason]; | 751 --scale_counter_[reason]; |
| 755 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 752 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 756 LOG(LS_INFO) << "Scaling up resolution."; | 753 LOG(LS_INFO) << "Scaling up resolution."; |
| 757 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 754 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 758 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 755 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 759 << " times for reason: " << (i ? "cpu" : "quality"); | 756 << " times for reason: " << (i ? "cpu" : "quality"); |
| 760 } | 757 } |
| 761 } | 758 } |
| 762 | 759 |
| 763 } // namespace webrtc | 760 } // namespace webrtc |
| OLD | NEW |