Chromium Code Reviews| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 if (source_) | 188 if (source_) |
| 189 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 189 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 192 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
| 193 rtc::VideoSinkWants wants = sink_wants_; | 193 rtc::VideoSinkWants wants = sink_wants_; |
| 194 // Clear any constraints from the current sink wants that don't apply to | 194 // Clear any constraints from the current sink wants that don't apply to |
| 195 // the used degradation_preference. | 195 // the used degradation_preference. |
| 196 switch (degradation_preference_) { | 196 switch (degradation_preference_) { |
| 197 case VideoSendStream::DegradationPreference::kBalanced: | 197 case VideoSendStream::DegradationPreference::kBalanced: |
| 198 FALLTHROUGH(); | |
|
stefan-webrtc
2017/05/23 17:03:20
If we remove this I assume we should add a break i
sprang_webrtc
2017/05/24 09:07:07
FALLTHROUGH() macro is actually only there to prev
| |
| 199 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 198 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 200 wants.max_framerate_fps = std::numeric_limits<int>::max(); | 199 wants.max_framerate_fps = std::numeric_limits<int>::max(); |
| 201 break; | 200 break; |
| 202 case VideoSendStream::DegradationPreference::kMaintainResolution: | 201 case VideoSendStream::DegradationPreference::kMaintainResolution: |
| 203 wants.max_pixel_count = std::numeric_limits<int>::max(); | 202 wants.max_pixel_count = std::numeric_limits<int>::max(); |
| 204 wants.target_pixel_count.reset(); | 203 wants.target_pixel_count.reset(); |
| 205 break; | 204 break; |
| 206 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 205 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 207 wants.max_pixel_count = std::numeric_limits<int>::max(); | 206 wants.max_pixel_count = std::numeric_limits<int>::max(); |
| 208 wants.target_pixel_count.reset(); | 207 wants.target_pixel_count.reset(); |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; | 668 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; |
| 670 AdaptDown(kQuality); | 669 AdaptDown(kQuality); |
| 671 ++initial_rampup_; | 670 ++initial_rampup_; |
| 672 return; | 671 return; |
| 673 } | 672 } |
| 674 initial_rampup_ = kMaxInitialFramedrop; | 673 initial_rampup_ = kMaxInitialFramedrop; |
| 675 | 674 |
| 676 int64_t now_ms = clock_->TimeInMilliseconds(); | 675 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 677 if (pending_encoder_reconfiguration_) { | 676 if (pending_encoder_reconfiguration_) { |
| 678 ReconfigureEncoder(); | 677 ReconfigureEncoder(); |
| 678 last_parameters_update_ms_.emplace(now_ms); | |
| 679 } else if (!last_parameters_update_ms_ || | 679 } else if (!last_parameters_update_ms_ || |
| 680 now_ms - *last_parameters_update_ms_ >= | 680 now_ms - *last_parameters_update_ms_ >= |
| 681 vcm::VCMProcessTimer::kDefaultProcessIntervalMs) { | 681 vcm::VCMProcessTimer::kDefaultProcessIntervalMs) { |
| 682 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), | 682 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), |
| 683 bitrate_observer_); | 683 bitrate_observer_); |
| 684 last_parameters_update_ms_.emplace(now_ms); | |
| 684 } | 685 } |
| 685 last_parameters_update_ms_.emplace(now_ms); | |
| 686 | 686 |
| 687 if (EncoderPaused()) { | 687 if (EncoderPaused()) { |
| 688 TraceFrameDropStart(); | 688 TraceFrameDropStart(); |
| 689 return; | 689 return; |
| 690 } | 690 } |
| 691 TraceFrameDropEnd(); | 691 TraceFrameDropEnd(); |
| 692 | 692 |
| 693 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 693 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 694 "Encode"); | 694 "Encode"); |
| 695 | 695 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 797 last_frame_info_->pixel_count(), | 797 last_frame_info_->pixel_count(), |
| 798 stats_proxy_->GetStats().input_frame_rate, | 798 stats_proxy_->GetStats().input_frame_rate, |
| 799 AdaptationRequest::Mode::kAdaptDown}; | 799 AdaptationRequest::Mode::kAdaptDown}; |
| 800 bool downgrade_requested = | 800 bool downgrade_requested = |
| 801 last_adaptation_request_ && | 801 last_adaptation_request_ && |
| 802 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; | 802 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; |
| 803 | 803 |
| 804 int max_downgrades = 0; | 804 int max_downgrades = 0; |
| 805 switch (degradation_preference_) { | 805 switch (degradation_preference_) { |
| 806 case VideoSendStream::DegradationPreference::kBalanced: | 806 case VideoSendStream::DegradationPreference::kBalanced: |
| 807 FALLTHROUGH(); | |
| 808 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 807 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 809 max_downgrades = kMaxCpuResolutionDowngrades; | 808 max_downgrades = kMaxCpuResolutionDowngrades; |
| 810 if (downgrade_requested && | 809 if (downgrade_requested && |
| 811 adaptation_request.input_pixel_count_ >= | 810 adaptation_request.input_pixel_count_ >= |
| 812 last_adaptation_request_->input_pixel_count_) { | 811 last_adaptation_request_->input_pixel_count_) { |
| 813 // Don't request lower resolution if the current resolution is not | 812 // Don't request lower resolution if the current resolution is not |
| 814 // lower than the last time we asked for the resolution to be lowered. | 813 // lower than the last time we asked for the resolution to be lowered. |
| 815 return; | 814 return; |
| 816 } | 815 } |
| 817 break; | 816 break; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 834 } | 833 } |
| 835 | 834 |
| 836 if (reason == kCpu) { | 835 if (reason == kCpu) { |
| 837 const int cpu_scale_counter = GetScaleCounters()[reason]; | 836 const int cpu_scale_counter = GetScaleCounters()[reason]; |
| 838 if (cpu_scale_counter >= max_downgrades) | 837 if (cpu_scale_counter >= max_downgrades) |
| 839 return; | 838 return; |
| 840 } | 839 } |
| 841 | 840 |
| 842 switch (degradation_preference_) { | 841 switch (degradation_preference_) { |
| 843 case VideoSendStream::DegradationPreference::kBalanced: | 842 case VideoSendStream::DegradationPreference::kBalanced: |
| 844 FALLTHROUGH(); | |
| 845 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 843 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 846 if (!source_proxy_->RequestResolutionLowerThan( | 844 if (!source_proxy_->RequestResolutionLowerThan( |
| 847 adaptation_request.input_pixel_count_)) { | 845 adaptation_request.input_pixel_count_)) { |
| 848 return; | 846 return; |
| 849 } | 847 } |
| 850 LOG(LS_INFO) << "Scaling down resolution."; | 848 LOG(LS_INFO) << "Scaling down resolution."; |
| 851 break; | 849 break; |
| 852 case VideoSendStream::DegradationPreference::kMaintainResolution: | 850 case VideoSendStream::DegradationPreference::kMaintainResolution: |
| 853 source_proxy_->RequestFramerateLowerThan( | 851 source_proxy_->RequestFramerateLowerThan( |
| 854 adaptation_request.framerate_fps_); | 852 adaptation_request.framerate_fps_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 AdaptationRequest adaptation_request = { | 887 AdaptationRequest adaptation_request = { |
| 890 last_frame_info_->pixel_count(), | 888 last_frame_info_->pixel_count(), |
| 891 stats_proxy_->GetStats().input_frame_rate, | 889 stats_proxy_->GetStats().input_frame_rate, |
| 892 AdaptationRequest::Mode::kAdaptUp}; | 890 AdaptationRequest::Mode::kAdaptUp}; |
| 893 | 891 |
| 894 bool adapt_up_requested = | 892 bool adapt_up_requested = |
| 895 last_adaptation_request_ && | 893 last_adaptation_request_ && |
| 896 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; | 894 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; |
| 897 switch (degradation_preference_) { | 895 switch (degradation_preference_) { |
| 898 case VideoSendStream::DegradationPreference::kBalanced: | 896 case VideoSendStream::DegradationPreference::kBalanced: |
| 899 FALLTHROUGH(); | |
| 900 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 897 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 901 if (adapt_up_requested && | 898 if (adapt_up_requested && |
| 902 adaptation_request.input_pixel_count_ <= | 899 adaptation_request.input_pixel_count_ <= |
| 903 last_adaptation_request_->input_pixel_count_) { | 900 last_adaptation_request_->input_pixel_count_) { |
| 904 // Don't request higher resolution if the current resolution is not | 901 // Don't request higher resolution if the current resolution is not |
| 905 // higher than the last time we asked for the resolution to be higher. | 902 // higher than the last time we asked for the resolution to be higher. |
| 906 return; | 903 return; |
| 907 } | 904 } |
| 908 break; | 905 break; |
| 909 case VideoSendStream::DegradationPreference::kMaintainResolution: | 906 case VideoSendStream::DegradationPreference::kMaintainResolution: |
| 910 // TODO(sprang): Don't request higher framerate if we are already at | 907 // TODO(sprang): Don't request higher framerate if we are already at |
| 911 // max requested fps? | 908 // max requested fps? |
| 912 break; | 909 break; |
| 913 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 910 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 914 return; | 911 return; |
| 915 } | 912 } |
| 916 | 913 |
| 917 // Decrease counter of how many times we have scaled down, for this | 914 // Decrease counter of how many times we have scaled down, for this |
| 918 // degradation preference mode and reason. | 915 // degradation preference mode and reason. |
| 919 IncrementScaleCounter(reason, -1); | 916 IncrementScaleCounter(reason, -1); |
| 920 | 917 |
| 921 // Get a sum of how many times have scaled down, in total, for this | 918 // Get a sum of how many times have scaled down, in total, for this |
| 922 // degradation preference mode. If it is 0, remove any restraints. | 919 // degradation preference mode. If it is 0, remove any restraints. |
| 923 const std::vector<int>& scale_counters = GetScaleCounters(); | 920 const std::vector<int>& scale_counters = GetScaleCounters(); |
| 924 const int scale_sum = | 921 const int scale_sum = |
| 925 std::accumulate(scale_counters.begin(), scale_counters.end(), 0); | 922 std::accumulate(scale_counters.begin(), scale_counters.end(), 0); |
| 926 switch (degradation_preference_) { | 923 switch (degradation_preference_) { |
| 927 case VideoSendStream::DegradationPreference::kBalanced: | 924 case VideoSendStream::DegradationPreference::kBalanced: |
| 928 FALLTHROUGH(); | |
| 929 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 925 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 930 if (scale_sum == 0) { | 926 if (scale_sum == 0) { |
| 931 LOG(LS_INFO) << "Removing resolution down-scaling setting."; | 927 LOG(LS_INFO) << "Removing resolution down-scaling setting."; |
| 932 source_proxy_->RequestHigherResolutionThan( | 928 source_proxy_->RequestHigherResolutionThan( |
| 933 std::numeric_limits<int>::max()); | 929 std::numeric_limits<int>::max()); |
| 934 } else { | 930 } else { |
| 935 source_proxy_->RequestHigherResolutionThan( | 931 source_proxy_->RequestHigherResolutionThan( |
| 936 adaptation_request.input_pixel_count_); | 932 adaptation_request.input_pixel_count_); |
| 937 LOG(LS_INFO) << "Scaling up resolution."; | 933 LOG(LS_INFO) << "Scaling up resolution."; |
| 938 } | 934 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 984 void ViEEncoder::IncrementScaleCounter(int reason, int delta) { | 980 void ViEEncoder::IncrementScaleCounter(int reason, int delta) { |
| 985 // Get the counters and validate. This may also lazily initialize the state. | 981 // Get the counters and validate. This may also lazily initialize the state. |
| 986 const std::vector<int>& counter = GetScaleCounters(); | 982 const std::vector<int>& counter = GetScaleCounters(); |
| 987 if (delta < 0) { | 983 if (delta < 0) { |
| 988 RTC_DCHECK_GE(counter[reason], delta); | 984 RTC_DCHECK_GE(counter[reason], delta); |
| 989 } | 985 } |
| 990 scale_counters_[degradation_preference_][reason] += delta; | 986 scale_counters_[degradation_preference_][reason] += delta; |
| 991 } | 987 } |
| 992 | 988 |
| 993 } // namespace webrtc | 989 } // namespace webrtc |
| OLD | NEW |