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

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

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: comments Created 3 years, 9 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
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 23 matching lines...) Expand all
34 using DegradationPreference = VideoSendStream::DegradationPreference; 34 using DegradationPreference = VideoSendStream::DegradationPreference;
35 35
36 // Time interval for logging frame counts. 36 // Time interval for logging frame counts.
37 const int64_t kFrameLogIntervalMs = 60000; 37 const int64_t kFrameLogIntervalMs = 60000;
38 38
39 // We will never ask for a resolution lower than this. 39 // We will never ask for a resolution lower than this.
40 // TODO(kthelgason): Lower this limit when better testing 40 // TODO(kthelgason): Lower this limit when better testing
41 // on MediaCodec and fallback implementations are in place. 41 // on MediaCodec and fallback implementations are in place.
42 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206 42 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206
43 const int kMinPixelsPerFrame = 320 * 180; 43 const int kMinPixelsPerFrame = 320 * 180;
44 const int kMinFramerateFps = 2;
44 45
45 // The maximum number of frames to drop at beginning of stream 46 // The maximum number of frames to drop at beginning of stream
46 // to try and achieve desired bitrate. 47 // to try and achieve desired bitrate.
47 const int kMaxInitialFramedrop = 4; 48 const int kMaxInitialFramedrop = 4;
48 49
49 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle 50 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle
50 // pipelining encoders better (multiple input frames before something comes 51 // pipelining encoders better (multiple input frames before something comes
51 // out). This should effectively turn off CPU adaptations for systems that 52 // out). This should effectively turn off CPU adaptations for systems that
52 // remotely cope with the load right now. 53 // remotely cope with the load right now.
53 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { 54 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 source_(nullptr) {} 154 source_(nullptr) {}
154 155
155 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source, 156 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
156 const DegradationPreference& degradation_preference) { 157 const DegradationPreference& degradation_preference) {
157 // Called on libjingle's worker thread. 158 // Called on libjingle's worker thread.
158 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); 159 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_);
159 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; 160 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr;
160 rtc::VideoSinkWants wants; 161 rtc::VideoSinkWants wants;
161 { 162 {
162 rtc::CritScope lock(&crit_); 163 rtc::CritScope lock(&crit_);
164 wants = sink_wants_;
165 // If changing degradation preference, clear any constraints from the
166 // current sink wants that will no longer apply.
167 if (degradation_preference_ != degradation_preference) {
168 switch (degradation_preference) {
169 case DegradationPreference::kBalanced:
170 wants.max_framerate_fps_.reset();
171 break;
172 case DegradationPreference::kMaintainResolution:
173 wants.max_pixel_count.reset();
174 wants.target_pixel_count.reset();
175 break;
176 }
177 }
178 degradation_preference_ = degradation_preference;
163 old_source = source_; 179 old_source = source_;
164 source_ = source; 180 source_ = source;
165 degradation_preference_ = degradation_preference;
166 wants = current_wants();
167 } 181 }
168 182
169 if (old_source != source && old_source != nullptr) { 183 if (old_source != source && old_source != nullptr) {
170 old_source->RemoveSink(vie_encoder_); 184 old_source->RemoveSink(vie_encoder_);
171 } 185 }
172 186
173 if (!source) { 187 if (!source) {
174 return; 188 return;
175 } 189 }
176 190
177 source->AddOrUpdateSink(vie_encoder_, wants); 191 source->AddOrUpdateSink(vie_encoder_, wants);
178 } 192 }
179 193
180 void SetWantsRotationApplied(bool rotation_applied) { 194 void SetWantsRotationApplied(bool rotation_applied) {
181 rtc::CritScope lock(&crit_); 195 rtc::CritScope lock(&crit_);
182 sink_wants_.rotation_applied = rotation_applied; 196 sink_wants_.rotation_applied = rotation_applied;
183 disabled_scaling_sink_wants_.rotation_applied = rotation_applied; 197 if (source_)
184 if (source_) { 198 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
185 source_->AddOrUpdateSink(vie_encoder_, current_wants());
186 }
187 } 199 }
188 200
189 void RequestResolutionLowerThan(int pixel_count) { 201 void RequestResolutionLowerThan(int pixel_count) {
190 // Called on the encoder task queue. 202 // Called on the encoder task queue.
191 rtc::CritScope lock(&crit_); 203 rtc::CritScope lock(&crit_);
192 if (!IsResolutionScalingEnabledLocked()) { 204 if (!IsResolutionScalingEnabledLocked()) {
193 // This can happen since |degradation_preference_| is set on 205 // This can happen since |degradation_preference_| is set on
194 // libjingle's worker thread but the adaptation is done on the encoder 206 // libjingle's worker thread but the adaptation is done on the encoder
195 // task queue. 207 // task queue.
196 return; 208 return;
197 } 209 }
198 // The input video frame size will have a resolution with less than or 210 // The input video frame size will have a resolution with less than or
199 // equal to |max_pixel_count| depending on how the source can scale the 211 // equal to |max_pixel_count| depending on how the source can scale the
200 // input frame size. 212 // input frame size.
201 const int pixels_wanted = (pixel_count * 3) / 5; 213 const int pixels_wanted = (pixel_count * 3) / 5;
202 if (pixels_wanted < kMinPixelsPerFrame) 214 if (pixels_wanted < kMinPixelsPerFrame)
203 return; 215 return;
204 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted); 216 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted);
205 sink_wants_.target_pixel_count = rtc::Optional<int>(); 217 sink_wants_.target_pixel_count = rtc::Optional<int>();
206 if (source_) 218 if (source_)
207 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); 219 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
208 } 220 }
209 221
222 void RequestFramerateLowerThan(int framerate_fps) {
223 // Called on the encoder task queue.
224 rtc::CritScope lock(&crit_);
225 if (!IsFramerateScalingEnabledLocked()) {
226 // This can happen since |degradation_preference_| is set on
227 // libjingle's worker thread but the adaptation is done on the encoder
228 // task queue.
229 return;
230 }
231 // The input video frame rate will be scaled down to 2/3 of input fps,
232 // rounding down.
233 const int framerate_wanted =
234 std::max(kMinFramerateFps, (framerate_fps * 2) / 3);
235 sink_wants_.max_framerate_fps_.emplace(framerate_wanted);
236 if (source_)
237 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
238 }
239
210 void RequestHigherResolutionThan(int pixel_count) { 240 void RequestHigherResolutionThan(int pixel_count) {
211 rtc::CritScope lock(&crit_); 241 rtc::CritScope lock(&crit_);
212 if (!IsResolutionScalingEnabledLocked()) { 242 if (!IsResolutionScalingEnabledLocked()) {
213 // This can happen since |degradation_preference_| is set on 243 // This can happen since |degradation_preference_| is set on
214 // libjingle's worker thread but the adaptation is done on the encoder 244 // libjingle's worker thread but the adaptation is done on the encoder
215 // task queue. 245 // task queue.
216 return; 246 return;
217 } 247 }
218 // On step down we request at most 3/5 the pixel count of the previous 248 // On step down we request at most 3/5 the pixel count of the previous
219 // resolution, so in order to take "one step up" we request a resolution as 249 // resolution, so in order to take "one step up" we request a resolution as
220 // close as possible to 5/3 of the current resolution. The actual pixel 250 // close as possible to 5/3 of the current resolution. The actual pixel
221 // count selected depends on the capabilities of the source. In order to not 251 // count selected depends on the capabilities of the source. In order to not
222 // take a too large step up, we cap the requested pixel count to be at most 252 // take a too large step up, we cap the requested pixel count to be at most
223 // four time the current number of pixels. 253 // four time the current number of pixels.
224 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3); 254 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3);
225 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4); 255 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4);
226 if (source_) 256 if (source_)
227 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); 257 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
228 } 258 }
229 259
260 void RequestHigherFramerateThan(int framerate_fps) {
261 // Called on the encoder task queue.
262 rtc::CritScope lock(&crit_);
263 if (!IsFramerateScalingEnabledLocked()) {
264 // This can happen since |degradation_preference_| is set on
265 // libjingle's worker thread but the adaptation is done on the encoder
266 // task queue.
267 return;
268 }
269 // The input video frame rate will be scaled up to the last step, with
270 // rounding.
271 const int framerate_wanted = (framerate_fps * 3) / 2;
272 sink_wants_.max_framerate_fps_.emplace(framerate_wanted);
273 if (source_)
274 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
275 }
276
230 private: 277 private:
231 bool IsResolutionScalingEnabledLocked() const 278 bool IsResolutionScalingEnabledLocked() const
232 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 279 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
233 return degradation_preference_ != 280 return degradation_preference_ !=
234 DegradationPreference::kMaintainResolution; 281 DegradationPreference::kMaintainResolution;
235 } 282 }
236 283
237 const rtc::VideoSinkWants& current_wants() const 284 bool IsFramerateScalingEnabledLocked() const
238 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 285 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
239 return IsResolutionScalingEnabledLocked() ? sink_wants_ 286 return degradation_preference_ ==
240 : disabled_scaling_sink_wants_; 287 DegradationPreference::kMaintainResolution;
241 } 288 }
242 289
243 rtc::CriticalSection crit_; 290 rtc::CriticalSection crit_;
244 rtc::SequencedTaskChecker main_checker_; 291 rtc::SequencedTaskChecker main_checker_;
245 ViEEncoder* const vie_encoder_; 292 ViEEncoder* const vie_encoder_;
246 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); 293 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_);
247 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_);
248 DegradationPreference degradation_preference_ GUARDED_BY(&crit_); 294 DegradationPreference degradation_preference_ GUARDED_BY(&crit_);
249 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); 295 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_);
250 296
251 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); 297 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy);
252 }; 298 };
253 299
254 ViEEncoder::ViEEncoder(uint32_t number_of_cores, 300 ViEEncoder::ViEEncoder(uint32_t number_of_cores,
255 SendStatisticsProxy* stats_proxy, 301 SendStatisticsProxy* stats_proxy,
256 const VideoSendStream::Config::EncoderSettings& settings, 302 const VideoSendStream::Config::EncoderSettings& settings,
257 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, 303 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
(...skipping 18 matching lines...) Expand all
276 encoder_start_bitrate_bps_(0), 322 encoder_start_bitrate_bps_(0),
277 max_data_payload_length_(0), 323 max_data_payload_length_(0),
278 nack_enabled_(false), 324 nack_enabled_(false),
279 last_observed_bitrate_bps_(0), 325 last_observed_bitrate_bps_(0),
280 encoder_paused_and_dropped_frame_(false), 326 encoder_paused_and_dropped_frame_(false),
281 has_received_sli_(false), 327 has_received_sli_(false),
282 picture_id_sli_(0), 328 picture_id_sli_(0),
283 has_received_rpsi_(false), 329 has_received_rpsi_(false),
284 picture_id_rpsi_(0), 330 picture_id_rpsi_(0),
285 clock_(Clock::GetRealTimeClock()), 331 clock_(Clock::GetRealTimeClock()),
286 scale_counter_(kScaleReasonSize, 0), 332 scale_counters_{
333 {VideoSendStream::DegradationPreference::kMaintainResolution,
334 std::vector<int>(kScaleReasonSize, 0)},
335 {VideoSendStream::DegradationPreference::kBalanced,
336 std::vector<int>(kScaleReasonSize, 0)}},
287 degradation_preference_(DegradationPreference::kMaintainResolution), 337 degradation_preference_(DegradationPreference::kMaintainResolution),
288 last_captured_timestamp_(0), 338 last_captured_timestamp_(0),
289 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 339 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
290 clock_->TimeInMilliseconds()), 340 clock_->TimeInMilliseconds()),
291 last_frame_log_ms_(clock_->TimeInMilliseconds()), 341 last_frame_log_ms_(clock_->TimeInMilliseconds()),
292 captured_frame_count_(0), 342 captured_frame_count_(0),
293 dropped_frame_count_(0), 343 dropped_frame_count_(0),
294 bitrate_observer_(nullptr), 344 bitrate_observer_(nullptr),
295 encoder_queue_("EncoderQueue") { 345 encoder_queue_("EncoderQueue") {
296 RTC_DCHECK(stats_proxy); 346 RTC_DCHECK(stats_proxy);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (scaling_settings.thresholds) { 517 if (scaling_settings.thresholds) {
468 quality_scaler_.reset( 518 quality_scaler_.reset(
469 new QualityScaler(this, *(scaling_settings.thresholds))); 519 new QualityScaler(this, *(scaling_settings.thresholds)));
470 } else { 520 } else {
471 quality_scaler_.reset(new QualityScaler(this, codec_type_)); 521 quality_scaler_.reset(new QualityScaler(this, codec_type_));
472 } 522 }
473 } else { 523 } else {
474 quality_scaler_.reset(nullptr); 524 quality_scaler_.reset(nullptr);
475 initial_rampup_ = kMaxInitialFramedrop; 525 initial_rampup_ = kMaxInitialFramedrop;
476 } 526 }
527 const std::vector<int>& scale_counter = *GetScaleCounters();
477 stats_proxy_->SetResolutionRestrictionStats( 528 stats_proxy_->SetResolutionRestrictionStats(
478 degradation_preference_allows_scaling, scale_counter_[kCpu] > 0, 529 degradation_preference_allows_scaling, scale_counter[kCpu] > 0,
479 scale_counter_[kQuality]); 530 scale_counter[kQuality]);
480 } 531 }
481 532
482 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { 533 void ViEEncoder::OnFrame(const VideoFrame& video_frame) {
483 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); 534 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_);
484 VideoFrame incoming_frame = video_frame; 535 VideoFrame incoming_frame = video_frame;
485 536
486 // Local time in webrtc time base. 537 // Local time in webrtc time base.
487 int64_t current_time_us = clock_->TimeInMicroseconds(); 538 int64_t current_time_us = clock_->TimeInMicroseconds();
488 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec; 539 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec;
489 // TODO(nisse): This always overrides the incoming timestamp. Don't 540 // TODO(nisse): This always overrides the incoming timestamp. Don't
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 783
733 if (video_suspension_changed) { 784 if (video_suspension_changed) {
734 LOG(LS_INFO) << "Video suspend state changed to: " 785 LOG(LS_INFO) << "Video suspend state changed to: "
735 << (video_is_suspended ? "suspended" : "not suspended"); 786 << (video_is_suspended ? "suspended" : "not suspended");
736 stats_proxy_->OnSuspendChange(video_is_suspended); 787 stats_proxy_->OnSuspendChange(video_is_suspended);
737 } 788 }
738 } 789 }
739 790
740 void ViEEncoder::AdaptDown(AdaptReason reason) { 791 void ViEEncoder::AdaptDown(AdaptReason reason) {
741 RTC_DCHECK_RUN_ON(&encoder_queue_); 792 RTC_DCHECK_RUN_ON(&encoder_queue_);
742 if (degradation_preference_ != DegradationPreference::kBalanced) 793 AdaptationRequest adaptation_request = {
743 return; 794 last_frame_info_->pixel_count(),
744 RTC_DCHECK(static_cast<bool>(last_frame_info_)); 795 stats_proxy_->GetStats().input_frame_rate,
745 int current_pixel_count = last_frame_info_->pixel_count(); 796 AdaptationRequest::Mode::kAdaptDown};
746 if (last_adaptation_request_ && 797
747 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown && 798 if (degradation_preference_ == DegradationPreference::kMaintainResolution &&
748 current_pixel_count >= last_adaptation_request_->input_pixel_count_) { 799 adaptation_request.framerate_fps_ <= 0) {
749 // Don't request lower resolution if the current resolution is not lower 800 // No input fps estimate available, can't determine how to scale down fps.
750 // than the last time we asked for the resolution to be lowered.
751 return; 801 return;
752 } 802 }
753 last_adaptation_request_.emplace(AdaptationRequest{ 803
754 current_pixel_count, AdaptationRequest::Mode::kAdaptDown}); 804 if (last_adaptation_request_ &&
805 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown) {
806 switch (degradation_preference_) {
807 case DegradationPreference::kBalanced:
808 if (adaptation_request.input_pixel_count_ >=
809 last_adaptation_request_->input_pixel_count_) {
810 // Don't request lower resolution if the current resolution is not
811 // lower than the last time we asked for the resolution to be lowered.
812 return;
813 }
814 break;
815 case DegradationPreference::kMaintainResolution:
816 if (adaptation_request.framerate_fps_ < kMinFramerateFps) {
817 // Don't request lower framerate if we don't have a valid frame rate.
818 // Since framerate, unlike resolution, is a measure we have to
819 // estimate, and can fluctuate naturally over time, don't make the
820 // same kind of limitations as for resolution, but trust the overuse
821 // detector to not trigger too often.
822 return;
823 }
824 break;
825 }
826 }
827
828 last_adaptation_request_.emplace(adaptation_request);
829 std::vector<int>* scale_counter = GetScaleCounters();
755 830
756 switch (reason) { 831 switch (reason) {
757 case kQuality: 832 case kQuality:
758 stats_proxy_->OnQualityRestrictedResolutionChanged( 833 stats_proxy_->OnQualityRestrictedResolutionChanged(
759 scale_counter_[reason] + 1); 834 (*scale_counter)[reason] + 1);
760 break; 835 break;
761 case kCpu: 836 case kCpu:
762 if (scale_counter_[reason] >= kMaxCpuDowngrades) 837 if ((*scale_counter)[reason] >= kMaxCpuDowngrades)
763 return; 838 return;
764 // Update stats accordingly. 839 // Update stats accordingly.
765 stats_proxy_->OnCpuRestrictedResolutionChanged(true); 840 stats_proxy_->OnCpuRestrictedResolutionChanged(true);
766 break; 841 break;
767 } 842 }
768 ++scale_counter_[reason]; 843 ++(*scale_counter)[reason];
769 source_proxy_->RequestResolutionLowerThan(current_pixel_count); 844
845 switch (degradation_preference_) {
846 case DegradationPreference::kBalanced:
847 source_proxy_->RequestResolutionLowerThan(
848 adaptation_request.input_pixel_count_);
849 LOG(LS_INFO) << "Scaling down resolution.";
850 break;
851 case DegradationPreference::kMaintainResolution:
852 source_proxy_->RequestFramerateLowerThan(
853 adaptation_request.framerate_fps_);
854 LOG(LS_INFO) << "Scaling down framerate.";
855 break;
856 }
857
770 LOG(LS_INFO) << "Scaling down resolution."; 858 LOG(LS_INFO) << "Scaling down resolution.";
771 for (size_t i = 0; i < kScaleReasonSize; ++i) { 859 for (size_t i = 0; i < kScaleReasonSize; ++i) {
772 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 860 LOG(LS_INFO) << "Scaled " << (*scale_counter)[i]
773 << " times for reason: " << (i ? "cpu" : "quality"); 861 << " times for reason: " << (i ? "cpu" : "quality");
774 } 862 }
775 } 863 }
776 864
777 void ViEEncoder::AdaptUp(AdaptReason reason) { 865 void ViEEncoder::AdaptUp(AdaptReason reason) {
778 RTC_DCHECK_RUN_ON(&encoder_queue_); 866 RTC_DCHECK_RUN_ON(&encoder_queue_);
779 if (scale_counter_[reason] == 0 || 867 std::vector<int>* scale_counter = GetScaleCounters();
780 degradation_preference_ != DegradationPreference::kBalanced) { 868 if ((*scale_counter)[reason] == 0)
781 return; 869 return;
870 AdaptationRequest adaptation_request = {
871 last_frame_info_->pixel_count(),
872 stats_proxy_->GetStats().input_frame_rate,
873 AdaptationRequest::Mode::kAdaptUp};
874
875 if (last_adaptation_request_ &&
876 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp) {
877 switch (degradation_preference_) {
878 case DegradationPreference::kBalanced:
879 if (adaptation_request.input_pixel_count_ <=
880 last_adaptation_request_->input_pixel_count_) {
881 // Don't request higher resolution if the current resolution is not
882 // higher than the last time we asked for the resolution to be higher.
883 return;
884 }
885 break;
886 case DegradationPreference::kMaintainResolution:
887 // TODO(sprang): Don't request higher framerate if we are already at
888 // max requested fps?
889 break;
890 }
782 } 891 }
783 // Only scale if resolution is higher than last time we requested higher
784 // resolution.
785 RTC_DCHECK(static_cast<bool>(last_frame_info_));
786 int current_pixel_count = last_frame_info_->pixel_count();
787 if (last_adaptation_request_ &&
788 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp &&
789 current_pixel_count <= last_adaptation_request_->input_pixel_count_) {
790 // Don't request higher resolution if the current resolution is not higher
791 // than the last time we asked for the resolution to be higher.
792 return;
793 }
794 last_adaptation_request_.emplace(AdaptationRequest{
795 current_pixel_count, AdaptationRequest::Mode::kAdaptUp});
796 892
797 switch (reason) { 893 switch (reason) {
798 case kQuality: 894 case kQuality:
799 stats_proxy_->OnQualityRestrictedResolutionChanged( 895 stats_proxy_->OnQualityRestrictedResolutionChanged(
800 scale_counter_[reason] - 1); 896 (*scale_counter)[reason] - 1);
801 break; 897 break;
802 case kCpu: 898 case kCpu:
803 // Update stats accordingly. 899 // Update stats accordingly.
804 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > 900 stats_proxy_->OnCpuRestrictedResolutionChanged((*scale_counter)[reason] >
805 1); 901 1);
806 break; 902 break;
807 } 903 }
808 --scale_counter_[reason]; 904 --(*scale_counter)[reason];
809 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 905
906 switch (degradation_preference_) {
907 case DegradationPreference::kBalanced:
908 source_proxy_->RequestHigherResolutionThan(
909 adaptation_request.input_pixel_count_);
910 LOG(LS_INFO) << "Scaling up resolution.";
911 break;
912 case DegradationPreference::kMaintainResolution:
913 source_proxy_->RequestHigherFramerateThan(
914 adaptation_request.framerate_fps_);
915 LOG(LS_INFO) << "Scaling up framerate.";
916 break;
917 }
918
810 LOG(LS_INFO) << "Scaling up resolution."; 919 LOG(LS_INFO) << "Scaling up resolution.";
811 for (size_t i = 0; i < kScaleReasonSize; ++i) { 920 for (size_t i = 0; i < kScaleReasonSize; ++i) {
812 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 921 LOG(LS_INFO) << "Scaled " << (*scale_counter)[i]
813 << " times for reason: " << (i ? "cpu" : "quality"); 922 << " times for reason: " << (i ? "cpu" : "quality");
814 } 923 }
815 } 924 }
816 925
926 std::vector<int>* ViEEncoder::GetScaleCounters() {
927 auto it = scale_counters_.find(degradation_preference_);
928 RTC_CHECK(it != scale_counters_.end());
929 return &it->second;
930 }
931
817 } // namespace webrtc 932 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698