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

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

Issue 2883963002: Periodically update codec bit/frame rate settings. (Closed)
Patch Set: Dumb typo Created 3 years, 6 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
« 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...) Expand 10 before | Expand all | Expand 10 after
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();
215 case VideoSendStream::DegradationPreference::kMaintainFramerate: 214 case VideoSendStream::DegradationPreference::kMaintainFramerate:
216 wants.max_framerate_fps = std::numeric_limits<int>::max(); 215 wants.max_framerate_fps = std::numeric_limits<int>::max();
217 break; 216 break;
218 case VideoSendStream::DegradationPreference::kMaintainResolution: 217 case VideoSendStream::DegradationPreference::kMaintainResolution:
219 wants.max_pixel_count = std::numeric_limits<int>::max(); 218 wants.max_pixel_count = std::numeric_limits<int>::max();
220 wants.target_pixel_count.reset(); 219 wants.target_pixel_count.reset();
221 break; 220 break;
222 case VideoSendStream::DegradationPreference::kDegradationDisabled: 221 case VideoSendStream::DegradationPreference::kDegradationDisabled:
223 wants.max_pixel_count = std::numeric_limits<int>::max(); 222 wants.max_pixel_count = std::numeric_limits<int>::max();
224 wants.target_pixel_count.reset(); 223 wants.target_pixel_count.reset();
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; 669 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate.";
671 AdaptDown(kQuality); 670 AdaptDown(kQuality);
672 ++initial_rampup_; 671 ++initial_rampup_;
673 return; 672 return;
674 } 673 }
675 initial_rampup_ = kMaxInitialFramedrop; 674 initial_rampup_ = kMaxInitialFramedrop;
676 675
677 int64_t now_ms = clock_->TimeInMilliseconds(); 676 int64_t now_ms = clock_->TimeInMilliseconds();
678 if (pending_encoder_reconfiguration_) { 677 if (pending_encoder_reconfiguration_) {
679 ReconfigureEncoder(); 678 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);
685 } 686 }
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...) Expand 10 before | Expand all | Expand 10 after
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();
810 case VideoSendStream::DegradationPreference::kMaintainFramerate: 809 case VideoSendStream::DegradationPreference::kMaintainFramerate:
811 max_downgrades = kMaxCpuResolutionDowngrades; 810 max_downgrades = kMaxCpuResolutionDowngrades;
812 if (downgrade_requested && 811 if (downgrade_requested &&
813 adaptation_request.input_pixel_count_ >= 812 adaptation_request.input_pixel_count_ >=
814 last_adaptation_request_->input_pixel_count_) { 813 last_adaptation_request_->input_pixel_count_) {
815 // Don't request lower resolution if the current resolution is not 814 // Don't request lower resolution if the current resolution is not
816 // lower than the last time we asked for the resolution to be lowered. 815 // lower than the last time we asked for the resolution to be lowered.
817 return; 816 return;
818 } 817 }
819 break; 818 break;
(...skipping 15 matching lines...) Expand all
835 return; 834 return;
836 } 835 }
837 836
838 if (reason == kCpu) { 837 if (reason == kCpu) {
839 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades) 838 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades)
840 return; 839 return;
841 } 840 }
842 841
843 switch (degradation_preference_) { 842 switch (degradation_preference_) {
844 case VideoSendStream::DegradationPreference::kBalanced: 843 case VideoSendStream::DegradationPreference::kBalanced:
845 FALLTHROUGH();
846 case VideoSendStream::DegradationPreference::kMaintainFramerate: 844 case VideoSendStream::DegradationPreference::kMaintainFramerate:
847 // Scale down resolution. 845 // Scale down resolution.
848 if (!source_proxy_->RequestResolutionLowerThan( 846 if (!source_proxy_->RequestResolutionLowerThan(
849 adaptation_request.input_pixel_count_)) { 847 adaptation_request.input_pixel_count_)) {
850 return; 848 return;
851 } 849 }
852 GetAdaptCounter().IncrementResolution(reason, 1); 850 GetAdaptCounter().IncrementResolution(reason, 1);
853 break; 851 break;
854 case VideoSendStream::DegradationPreference::kMaintainResolution: 852 case VideoSendStream::DegradationPreference::kMaintainResolution:
855 // Scale down framerate. 853 // Scale down framerate.
(...skipping 27 matching lines...) Expand all
883 last_frame_info_->pixel_count(), 881 last_frame_info_->pixel_count(),
884 stats_proxy_->GetStats().input_frame_rate, 882 stats_proxy_->GetStats().input_frame_rate,
885 AdaptationRequest::Mode::kAdaptUp}; 883 AdaptationRequest::Mode::kAdaptUp};
886 884
887 bool adapt_up_requested = 885 bool adapt_up_requested =
888 last_adaptation_request_ && 886 last_adaptation_request_ &&
889 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; 887 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp;
890 888
891 switch (degradation_preference_) { 889 switch (degradation_preference_) {
892 case VideoSendStream::DegradationPreference::kBalanced: 890 case VideoSendStream::DegradationPreference::kBalanced:
893 FALLTHROUGH();
894 case VideoSendStream::DegradationPreference::kMaintainFramerate: 891 case VideoSendStream::DegradationPreference::kMaintainFramerate:
895 if (adapt_up_requested && 892 if (adapt_up_requested &&
896 adaptation_request.input_pixel_count_ <= 893 adaptation_request.input_pixel_count_ <=
897 last_adaptation_request_->input_pixel_count_) { 894 last_adaptation_request_->input_pixel_count_) {
898 // Don't request higher resolution if the current resolution is not 895 // Don't request higher resolution if the current resolution is not
899 // higher than the last time we asked for the resolution to be higher. 896 // higher than the last time we asked for the resolution to be higher.
900 return; 897 return;
901 } 898 }
902 break; 899 break;
903 case VideoSendStream::DegradationPreference::kMaintainResolution: 900 case VideoSendStream::DegradationPreference::kMaintainResolution:
904 // TODO(sprang): Don't request higher framerate if we are already at 901 // TODO(sprang): Don't request higher framerate if we are already at
905 // max requested fps? 902 // max requested fps?
906 break; 903 break;
907 case VideoSendStream::DegradationPreference::kDegradationDisabled: 904 case VideoSendStream::DegradationPreference::kDegradationDisabled:
908 return; 905 return;
909 } 906 }
910 907
911 switch (degradation_preference_) { 908 switch (degradation_preference_) {
912 case VideoSendStream::DegradationPreference::kBalanced: 909 case VideoSendStream::DegradationPreference::kBalanced:
913 FALLTHROUGH();
914 case VideoSendStream::DegradationPreference::kMaintainFramerate: { 910 case VideoSendStream::DegradationPreference::kMaintainFramerate: {
915 // Scale up resolution. 911 // Scale up resolution.
916 int pixel_count = adaptation_request.input_pixel_count_; 912 int pixel_count = adaptation_request.input_pixel_count_;
917 if (adapt_counter.ResolutionCount() == 1) { 913 if (adapt_counter.ResolutionCount() == 1) {
918 LOG(LS_INFO) << "Removing resolution down-scaling setting."; 914 LOG(LS_INFO) << "Removing resolution down-scaling setting.";
919 pixel_count = std::numeric_limits<int>::max(); 915 pixel_count = std::numeric_limits<int>::max();
920 } 916 }
921 if (!source_proxy_->RequestHigherResolutionThan(pixel_count)) 917 if (!source_proxy_->RequestHigherResolutionThan(pixel_count))
922 return; 918 return;
923 GetAdaptCounter().IncrementResolution(reason, -1); 919 GetAdaptCounter().IncrementResolution(reason, -1);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 std::string ViEEncoder::AdaptCounter::ToString( 1047 std::string ViEEncoder::AdaptCounter::ToString(
1052 const std::vector<int>& counters) const { 1048 const std::vector<int>& counters) const {
1053 std::stringstream ss; 1049 std::stringstream ss;
1054 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { 1050 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) {
1055 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; 1051 ss << (reason ? " cpu" : "quality") << ":" << counters[reason];
1056 } 1052 }
1057 return ss.str(); 1053 return ss.str();
1058 } 1054 }
1059 1055
1060 } // namespace webrtc 1056 } // 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
This is Rietveld 408576698