Chromium Code Reviews

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

Issue 2923993002: Revert of Periodically update codec bit/frame rate settings. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « webrtc/video/video_send_stream_tests.cc ('k') | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 193 matching lines...)
204 if (source_) 204 if (source_)
205 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); 205 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
206 } 206 }
207 207
208 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 208 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
209 rtc::VideoSinkWants wants = sink_wants_; 209 rtc::VideoSinkWants wants = sink_wants_;
210 // Clear any constraints from the current sink wants that don't apply to 210 // Clear any constraints from the current sink wants that don't apply to
211 // the used degradation_preference. 211 // the used degradation_preference.
212 switch (degradation_preference_) { 212 switch (degradation_preference_) {
213 case VideoSendStream::DegradationPreference::kBalanced: 213 case VideoSendStream::DegradationPreference::kBalanced:
214 FALLTHROUGH();
214 case VideoSendStream::DegradationPreference::kMaintainFramerate: 215 case VideoSendStream::DegradationPreference::kMaintainFramerate:
215 wants.max_framerate_fps = std::numeric_limits<int>::max(); 216 wants.max_framerate_fps = std::numeric_limits<int>::max();
216 break; 217 break;
217 case VideoSendStream::DegradationPreference::kMaintainResolution: 218 case VideoSendStream::DegradationPreference::kMaintainResolution:
218 wants.max_pixel_count = std::numeric_limits<int>::max(); 219 wants.max_pixel_count = std::numeric_limits<int>::max();
219 wants.target_pixel_count.reset(); 220 wants.target_pixel_count.reset();
220 break; 221 break;
221 case VideoSendStream::DegradationPreference::kDegradationDisabled: 222 case VideoSendStream::DegradationPreference::kDegradationDisabled:
222 wants.max_pixel_count = std::numeric_limits<int>::max(); 223 wants.max_pixel_count = std::numeric_limits<int>::max();
223 wants.target_pixel_count.reset(); 224 wants.target_pixel_count.reset();
(...skipping 445 matching lines...)
669 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; 670 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate.";
670 AdaptDown(kQuality); 671 AdaptDown(kQuality);
671 ++initial_rampup_; 672 ++initial_rampup_;
672 return; 673 return;
673 } 674 }
674 initial_rampup_ = kMaxInitialFramedrop; 675 initial_rampup_ = kMaxInitialFramedrop;
675 676
676 int64_t now_ms = clock_->TimeInMilliseconds(); 677 int64_t now_ms = clock_->TimeInMilliseconds();
677 if (pending_encoder_reconfiguration_) { 678 if (pending_encoder_reconfiguration_) {
678 ReconfigureEncoder(); 679 ReconfigureEncoder();
679 last_parameters_update_ms_.emplace(now_ms);
680 } else if (!last_parameters_update_ms_ || 680 } else if (!last_parameters_update_ms_ ||
681 now_ms - *last_parameters_update_ms_ >= 681 now_ms - *last_parameters_update_ms_ >=
682 vcm::VCMProcessTimer::kDefaultProcessIntervalMs) { 682 vcm::VCMProcessTimer::kDefaultProcessIntervalMs) {
683 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), 683 video_sender_.UpdateChannelParemeters(rate_allocator_.get(),
684 bitrate_observer_); 684 bitrate_observer_);
685 last_parameters_update_ms_.emplace(now_ms);
686 } 685 }
686 last_parameters_update_ms_.emplace(now_ms);
687 687
688 if (EncoderPaused()) { 688 if (EncoderPaused()) {
689 TraceFrameDropStart(); 689 TraceFrameDropStart();
690 return; 690 return;
691 } 691 }
692 TraceFrameDropEnd(); 692 TraceFrameDropEnd();
693 693
694 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), 694 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(),
695 "Encode"); 695 "Encode");
696 696
(...skipping 102 matching lines...)
799 stats_proxy_->GetStats().input_frame_rate, 799 stats_proxy_->GetStats().input_frame_rate,
800 AdaptationRequest::Mode::kAdaptDown}; 800 AdaptationRequest::Mode::kAdaptDown};
801 801
802 bool downgrade_requested = 802 bool downgrade_requested =
803 last_adaptation_request_ && 803 last_adaptation_request_ &&
804 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; 804 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
805 805
806 int max_downgrades = 0; 806 int max_downgrades = 0;
807 switch (degradation_preference_) { 807 switch (degradation_preference_) {
808 case VideoSendStream::DegradationPreference::kBalanced: 808 case VideoSendStream::DegradationPreference::kBalanced:
809 FALLTHROUGH();
809 case VideoSendStream::DegradationPreference::kMaintainFramerate: 810 case VideoSendStream::DegradationPreference::kMaintainFramerate:
810 max_downgrades = kMaxCpuResolutionDowngrades; 811 max_downgrades = kMaxCpuResolutionDowngrades;
811 if (downgrade_requested && 812 if (downgrade_requested &&
812 adaptation_request.input_pixel_count_ >= 813 adaptation_request.input_pixel_count_ >=
813 last_adaptation_request_->input_pixel_count_) { 814 last_adaptation_request_->input_pixel_count_) {
814 // Don't request lower resolution if the current resolution is not 815 // Don't request lower resolution if the current resolution is not
815 // lower than the last time we asked for the resolution to be lowered. 816 // lower than the last time we asked for the resolution to be lowered.
816 return; 817 return;
817 } 818 }
818 break; 819 break;
(...skipping 15 matching lines...)
834 return; 835 return;
835 } 836 }
836 837
837 if (reason == kCpu) { 838 if (reason == kCpu) {
838 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades) 839 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades)
839 return; 840 return;
840 } 841 }
841 842
842 switch (degradation_preference_) { 843 switch (degradation_preference_) {
843 case VideoSendStream::DegradationPreference::kBalanced: 844 case VideoSendStream::DegradationPreference::kBalanced:
845 FALLTHROUGH();
844 case VideoSendStream::DegradationPreference::kMaintainFramerate: 846 case VideoSendStream::DegradationPreference::kMaintainFramerate:
845 // Scale down resolution. 847 // Scale down resolution.
846 if (!source_proxy_->RequestResolutionLowerThan( 848 if (!source_proxy_->RequestResolutionLowerThan(
847 adaptation_request.input_pixel_count_)) { 849 adaptation_request.input_pixel_count_)) {
848 return; 850 return;
849 } 851 }
850 GetAdaptCounter().IncrementResolution(reason, 1); 852 GetAdaptCounter().IncrementResolution(reason, 1);
851 break; 853 break;
852 case VideoSendStream::DegradationPreference::kMaintainResolution: 854 case VideoSendStream::DegradationPreference::kMaintainResolution:
853 // Scale down framerate. 855 // Scale down framerate.
(...skipping 27 matching lines...)
881 last_frame_info_->pixel_count(), 883 last_frame_info_->pixel_count(),
882 stats_proxy_->GetStats().input_frame_rate, 884 stats_proxy_->GetStats().input_frame_rate,
883 AdaptationRequest::Mode::kAdaptUp}; 885 AdaptationRequest::Mode::kAdaptUp};
884 886
885 bool adapt_up_requested = 887 bool adapt_up_requested =
886 last_adaptation_request_ && 888 last_adaptation_request_ &&
887 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; 889 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp;
888 890
889 switch (degradation_preference_) { 891 switch (degradation_preference_) {
890 case VideoSendStream::DegradationPreference::kBalanced: 892 case VideoSendStream::DegradationPreference::kBalanced:
893 FALLTHROUGH();
891 case VideoSendStream::DegradationPreference::kMaintainFramerate: 894 case VideoSendStream::DegradationPreference::kMaintainFramerate:
892 if (adapt_up_requested && 895 if (adapt_up_requested &&
893 adaptation_request.input_pixel_count_ <= 896 adaptation_request.input_pixel_count_ <=
894 last_adaptation_request_->input_pixel_count_) { 897 last_adaptation_request_->input_pixel_count_) {
895 // Don't request higher resolution if the current resolution is not 898 // Don't request higher resolution if the current resolution is not
896 // higher than the last time we asked for the resolution to be higher. 899 // higher than the last time we asked for the resolution to be higher.
897 return; 900 return;
898 } 901 }
899 break; 902 break;
900 case VideoSendStream::DegradationPreference::kMaintainResolution: 903 case VideoSendStream::DegradationPreference::kMaintainResolution:
901 // TODO(sprang): Don't request higher framerate if we are already at 904 // TODO(sprang): Don't request higher framerate if we are already at
902 // max requested fps? 905 // max requested fps?
903 break; 906 break;
904 case VideoSendStream::DegradationPreference::kDegradationDisabled: 907 case VideoSendStream::DegradationPreference::kDegradationDisabled:
905 return; 908 return;
906 } 909 }
907 910
908 switch (degradation_preference_) { 911 switch (degradation_preference_) {
909 case VideoSendStream::DegradationPreference::kBalanced: 912 case VideoSendStream::DegradationPreference::kBalanced:
913 FALLTHROUGH();
910 case VideoSendStream::DegradationPreference::kMaintainFramerate: { 914 case VideoSendStream::DegradationPreference::kMaintainFramerate: {
911 // Scale up resolution. 915 // Scale up resolution.
912 int pixel_count = adaptation_request.input_pixel_count_; 916 int pixel_count = adaptation_request.input_pixel_count_;
913 if (adapt_counter.ResolutionCount() == 1) { 917 if (adapt_counter.ResolutionCount() == 1) {
914 LOG(LS_INFO) << "Removing resolution down-scaling setting."; 918 LOG(LS_INFO) << "Removing resolution down-scaling setting.";
915 pixel_count = std::numeric_limits<int>::max(); 919 pixel_count = std::numeric_limits<int>::max();
916 } 920 }
917 if (!source_proxy_->RequestHigherResolutionThan(pixel_count)) 921 if (!source_proxy_->RequestHigherResolutionThan(pixel_count))
918 return; 922 return;
919 GetAdaptCounter().IncrementResolution(reason, -1); 923 GetAdaptCounter().IncrementResolution(reason, -1);
(...skipping 127 matching lines...)
1047 std::string ViEEncoder::AdaptCounter::ToString( 1051 std::string ViEEncoder::AdaptCounter::ToString(
1048 const std::vector<int>& counters) const { 1052 const std::vector<int>& counters) const {
1049 std::stringstream ss; 1053 std::stringstream ss;
1050 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { 1054 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) {
1051 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; 1055 ss << (reason ? " cpu" : "quality") << ":" << counters[reason];
1052 } 1056 }
1053 return ss.str(); 1057 return ss.str();
1054 } 1058 }
1055 1059
1056 } // namespace webrtc 1060 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream_tests.cc ('k') | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine