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

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

Issue 2887303003: Implement kBalanced degradation preference. (Closed)
Patch Set: Created 3 years, 7 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/vie_encoder.h ('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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if (kbps > 0) { 66 if (kbps > 0) {
67 if (kbps < 300 /* qvga */) { 67 if (kbps < 300 /* qvga */) {
68 return 320 * 240; 68 return 320 * 240;
69 } else if (kbps < 500 /* vga */) { 69 } else if (kbps < 500 /* vga */) {
70 return 640 * 480; 70 return 640 * 480;
71 } 71 }
72 } 72 }
73 return std::numeric_limits<uint32_t>::max(); 73 return std::numeric_limits<uint32_t>::max();
74 } 74 }
75 75
76 // Limits for kBalanced degradation preference.
77 // >640x480: | max |
78 // <=640x480: | 15fps | max |
79 // <=480x270: | 10fps | 15fps |
80 // <=320x240: | 7fps | 10fps |
81 // ----------------------------------------------------------
82 // kbps: 0 60 130 500 |
kthelgason 2017/05/19 08:34:14 Just out of curiosity, how are these determined?
åsapersson 2017/06/08 13:55:32 The bitrate limits were set roughly to a value whe
83
84 int MinFps(int pixels) {
85 if (pixels <= 320 * 240)
86 return 7;
87 else if (pixels <= 480 * 270)
88 return 10;
89 else if (pixels <= 640 * 480)
90 return 15;
91 else
92 return std::numeric_limits<int>::max();
93 }
94
95 int MaxFps(int pixels) {
96 if (pixels <= 320 * 240)
97 return 10;
98 else if (pixels <= 480 * 270)
99 return 15;
100 else
101 return std::numeric_limits<int>::max();
102 }
103
104 uint32_t BitrateLimit(int pixels) {
105 if (pixels <= 320 * 240)
106 return 60000;
107 else if (pixels <= 480 * 270)
108 return 130000;
109 else if (pixels <= 640 * 480)
110 return 500000;
111 else
112 return std::numeric_limits<uint32_t>::max();
113 }
114
115 int MaxFpsForBitrateAndResolution(uint32_t bps, int pixels) {
116 return (bps <= BitrateLimit(pixels)) ? MinFps(pixels) : MaxFps(pixels);
117 }
118
76 bool IsResolutionScalingEnabled( 119 bool IsResolutionScalingEnabled(
77 VideoSendStream::DegradationPreference degradation_preference) { 120 VideoSendStream::DegradationPreference degradation_preference) {
78 return degradation_preference == 121 return degradation_preference ==
79 VideoSendStream::DegradationPreference::kMaintainFramerate || 122 VideoSendStream::DegradationPreference::kMaintainFramerate ||
80 degradation_preference == 123 degradation_preference ==
81 VideoSendStream::DegradationPreference::kBalanced; 124 VideoSendStream::DegradationPreference::kBalanced;
82 } 125 }
83 126
84 bool IsFramerateScalingEnabled( 127 bool IsFramerateScalingEnabled(
85 VideoSendStream::DegradationPreference degradation_preference) { 128 VideoSendStream::DegradationPreference degradation_preference) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (source_) 247 if (source_)
205 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); 248 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
206 } 249 }
207 250
208 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 251 rtc::VideoSinkWants GetActiveSinkWants() EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
209 rtc::VideoSinkWants wants = sink_wants_; 252 rtc::VideoSinkWants wants = sink_wants_;
210 // Clear any constraints from the current sink wants that don't apply to 253 // Clear any constraints from the current sink wants that don't apply to
211 // the used degradation_preference. 254 // the used degradation_preference.
212 switch (degradation_preference_) { 255 switch (degradation_preference_) {
213 case VideoSendStream::DegradationPreference::kBalanced: 256 case VideoSendStream::DegradationPreference::kBalanced:
214 FALLTHROUGH(); 257 break;
215 case VideoSendStream::DegradationPreference::kMaintainFramerate: 258 case VideoSendStream::DegradationPreference::kMaintainFramerate:
216 wants.max_framerate_fps = std::numeric_limits<int>::max(); 259 wants.max_framerate_fps = std::numeric_limits<int>::max();
217 break; 260 break;
218 case VideoSendStream::DegradationPreference::kMaintainResolution: 261 case VideoSendStream::DegradationPreference::kMaintainResolution:
219 wants.max_pixel_count = std::numeric_limits<int>::max(); 262 wants.max_pixel_count = std::numeric_limits<int>::max();
220 wants.target_pixel_count.reset(); 263 wants.target_pixel_count.reset();
221 break; 264 break;
222 case VideoSendStream::DegradationPreference::kDegradationDisabled: 265 case VideoSendStream::DegradationPreference::kDegradationDisabled:
223 wants.max_pixel_count = std::numeric_limits<int>::max(); 266 wants.max_pixel_count = std::numeric_limits<int>::max();
224 wants.target_pixel_count.reset(); 267 wants.target_pixel_count.reset();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } else { 350 } else {
308 // The input video frame rate will be scaled up to the last step, with 351 // The input video frame rate will be scaled up to the last step, with
309 // rounding. 352 // rounding.
310 const int framerate_wanted = (framerate_fps * 3) / 2; 353 const int framerate_wanted = (framerate_fps * 3) / 2;
311 sink_wants_.max_framerate_fps = framerate_wanted; 354 sink_wants_.max_framerate_fps = framerate_wanted;
312 } 355 }
313 if (source_) 356 if (source_)
314 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); 357 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants());
315 } 358 }
316 359
360 bool RestrictFpsOrRequestResolutionLowerThan(int max_fps,
361 int pixel_count,
362 bool* fps_changed) {
363 // Called on the encoder task queue.
kthelgason 2017/05/19 08:34:15 Do you want to add a thread_checker here to make t
åsapersson 2017/06/08 13:55:32 Can maybe do it in a separate cl.
364 rtc::CritScope lock(&crit_);
365 // Restrict framerate if it is lower.
366 *fps_changed = false;
367 const int fps_wanted = std::max(kMinFramerateFps, max_fps);
368 if (fps_wanted < sink_wants_.max_framerate_fps &&
369 RequestFramerateLocked(fps_wanted)) {
370 *fps_changed = true;
371 return true;
kthelgason 2017/05/19 08:34:14 I don't really like this weird way of signalling w
åsapersson 2017/06/08 13:55:32 This part has been changed in https://codereview.w
372 }
373 // Request lower resolution.
374 if (!IsResolutionScalingEnabledLocked())
375 return false;
376
377 // The input video frame size will have a resolution less than or equal to
378 // |max_pixel_count| depending on how the source can scale the frame size.
379 const int pixels_wanted = (pixel_count * 3) / 5;
380 if (pixels_wanted < kMinPixelsPerFrame ||
381 pixels_wanted >= sink_wants_.max_pixel_count) {
382 return false;
383 }
384 sink_wants_.max_pixel_count = pixels_wanted;
385 sink_wants_.target_pixel_count = rtc::Optional<int>();
386 if (source_)
kthelgason 2017/05/19 08:34:14 Maybe we should just bail out right at the start i
åsapersson 2017/06/08 13:55:32 Done in https://codereview.webrtc.org/2903563002/.
387 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants());
388 return true;
389 }
390
391 bool IncreaseFpsOrRequestHigherResolutionThan(int max_fps,
392 int pixel_count,
393 bool* fps_changed) {
394 // Called on the encoder task queue.
395 rtc::CritScope lock(&crit_);
396 // Increase framerate if it is higher.
397 *fps_changed = false;
398 const int fps_wanted = std::max(kMinFramerateFps, max_fps);
399 if (fps_wanted > sink_wants_.max_framerate_fps &&
400 RequestFramerateLocked(fps_wanted)) {
401 *fps_changed = true;
402 return true;
403 }
404 // Request higher resolution.
405 if (!IsResolutionScalingEnabledLocked())
406 return false;
407
408 int max_pixels_wanted = pixel_count;
409 if (max_pixels_wanted != std::numeric_limits<int>::max())
410 max_pixels_wanted = pixel_count * 4;
411
412 if (max_pixels_wanted <= sink_wants_.max_pixel_count)
413 return false;
414
415 sink_wants_.max_pixel_count = max_pixels_wanted;
416 if (max_pixels_wanted == std::numeric_limits<int>::max()) {
417 sink_wants_.target_pixel_count.reset();
418 } else {
419 sink_wants_.target_pixel_count =
420 rtc::Optional<int>((pixel_count * 5) / 3);
421 }
422 if (source_)
423 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants());
424 return true;
425 }
426
317 private: 427 private:
428 bool RequestFramerateLocked(int framerate_fps)
429 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
430 if (!IsFramerateScalingEnabledLocked())
431 return false;
432
433 sink_wants_.max_framerate_fps = framerate_fps;
434 if (source_)
435 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants());
436 return true;
437 }
438
318 bool IsResolutionScalingEnabledLocked() const 439 bool IsResolutionScalingEnabledLocked() const
319 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 440 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
320 return degradation_preference_ == 441 return degradation_preference_ ==
321 VideoSendStream::DegradationPreference::kMaintainFramerate || 442 VideoSendStream::DegradationPreference::kMaintainFramerate ||
322 degradation_preference_ == 443 degradation_preference_ ==
323 VideoSendStream::DegradationPreference::kBalanced; 444 VideoSendStream::DegradationPreference::kBalanced;
324 } 445 }
325 446
326 bool IsFramerateScalingEnabledLocked() const 447 bool IsFramerateScalingEnabledLocked() const
327 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 448 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
328 // TODO(sprang): Also accept kBalanced here?
329 return degradation_preference_ == 449 return degradation_preference_ ==
330 VideoSendStream::DegradationPreference::kMaintainResolution; 450 VideoSendStream::DegradationPreference::kMaintainResolution ||
451 degradation_preference_ ==
452 VideoSendStream::DegradationPreference::kBalanced;
331 } 453 }
332 454
333 rtc::CriticalSection crit_; 455 rtc::CriticalSection crit_;
334 rtc::SequencedTaskChecker main_checker_; 456 rtc::SequencedTaskChecker main_checker_;
335 ViEEncoder* const vie_encoder_; 457 ViEEncoder* const vie_encoder_;
336 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); 458 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_);
337 VideoSendStream::DegradationPreference degradation_preference_ 459 VideoSendStream::DegradationPreference degradation_preference_
338 GUARDED_BY(&crit_); 460 GUARDED_BY(&crit_);
339 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); 461 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_);
340 462
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 stats_proxy_->GetStats().input_frame_rate, 932 stats_proxy_->GetStats().input_frame_rate,
811 AdaptationRequest::Mode::kAdaptDown}; 933 AdaptationRequest::Mode::kAdaptDown};
812 934
813 bool downgrade_requested = 935 bool downgrade_requested =
814 last_adaptation_request_ && 936 last_adaptation_request_ &&
815 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; 937 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
816 938
817 int max_downgrades = 0; 939 int max_downgrades = 0;
818 switch (degradation_preference_) { 940 switch (degradation_preference_) {
819 case VideoSendStream::DegradationPreference::kBalanced: 941 case VideoSendStream::DegradationPreference::kBalanced:
820 FALLTHROUGH(); 942 max_downgrades = kMaxCpuResolutionDowngrades;
943 break;
821 case VideoSendStream::DegradationPreference::kMaintainFramerate: 944 case VideoSendStream::DegradationPreference::kMaintainFramerate:
822 max_downgrades = kMaxCpuResolutionDowngrades; 945 max_downgrades = kMaxCpuResolutionDowngrades;
823 if (downgrade_requested && 946 if (downgrade_requested &&
824 adaptation_request.input_pixel_count_ >= 947 adaptation_request.input_pixel_count_ >=
825 last_adaptation_request_->input_pixel_count_) { 948 last_adaptation_request_->input_pixel_count_) {
826 // Don't request lower resolution if the current resolution is not 949 // Don't request lower resolution if the current resolution is not
827 // lower than the last time we asked for the resolution to be lowered. 950 // lower than the last time we asked for the resolution to be lowered.
828 return; 951 return;
829 } 952 }
830 break; 953 break;
(...skipping 14 matching lines...) Expand all
845 case VideoSendStream::DegradationPreference::kDegradationDisabled: 968 case VideoSendStream::DegradationPreference::kDegradationDisabled:
846 return; 969 return;
847 } 970 }
848 971
849 if (reason == kCpu) { 972 if (reason == kCpu) {
850 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades) 973 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades)
851 return; 974 return;
852 } 975 }
853 976
854 switch (degradation_preference_) { 977 switch (degradation_preference_) {
855 case VideoSendStream::DegradationPreference::kBalanced: 978 case VideoSendStream::DegradationPreference::kBalanced: {
856 FALLTHROUGH(); 979 int max_fps = MaxFpsForBitrateAndResolution(
980 last_observed_bitrate_bps_, last_frame_info_->pixel_count());
981 bool fps_restricted;
982 if (!source_proxy_->RestrictFpsOrRequestResolutionLowerThan(
983 max_fps, adaptation_request.input_pixel_count_,
984 &fps_restricted)) {
985 return;
986 }
987 if (fps_restricted) {
988 LOG(LS_INFO) << "Scaling down framerate: " << max_fps;
989 GetAdaptCounter().IncrementFramerate(reason);
990 } else {
991 LOG(LS_INFO) << "Scaling down resolution.";
992 GetAdaptCounter().IncrementResolution(reason);
993 }
994 break;
995 }
857 case VideoSendStream::DegradationPreference::kMaintainFramerate: 996 case VideoSendStream::DegradationPreference::kMaintainFramerate:
858 if (!source_proxy_->RequestResolutionLowerThan( 997 if (!source_proxy_->RequestResolutionLowerThan(
859 adaptation_request.input_pixel_count_)) { 998 adaptation_request.input_pixel_count_)) {
860 return; 999 return;
861 } 1000 }
862 LOG(LS_INFO) << "Scaling down resolution."; 1001 LOG(LS_INFO) << "Scaling down resolution.";
863 GetAdaptCounter().IncrementResolution(reason, 1); 1002 GetAdaptCounter().IncrementResolution(reason);
864 break; 1003 break;
865 case VideoSendStream::DegradationPreference::kMaintainResolution: 1004 case VideoSendStream::DegradationPreference::kMaintainResolution:
866 source_proxy_->RequestFramerateLowerThan( 1005 source_proxy_->RequestFramerateLowerThan(
867 adaptation_request.framerate_fps_); 1006 adaptation_request.framerate_fps_);
868 LOG(LS_INFO) << "Scaling down framerate."; 1007 LOG(LS_INFO) << "Scaling down framerate.";
869 GetAdaptCounter().IncrementFramerate(reason, 1); 1008 GetAdaptCounter().IncrementFramerate(reason);
870 break; 1009 break;
871 case VideoSendStream::DegradationPreference::kDegradationDisabled: 1010 case VideoSendStream::DegradationPreference::kDegradationDisabled:
872 RTC_NOTREACHED(); 1011 RTC_NOTREACHED();
873 } 1012 }
874 1013
875 last_adaptation_request_.emplace(adaptation_request); 1014 last_adaptation_request_.emplace(adaptation_request);
876 1015
877 UpdateAdaptationStats(reason); 1016 UpdateAdaptationStats(reason);
878 1017
879 LOG(LS_INFO) << GetConstAdaptCounter().ToString(); 1018 LOG(LS_INFO) << GetConstAdaptCounter().ToString();
(...skipping 12 matching lines...) Expand all
892 last_frame_info_->pixel_count(), 1031 last_frame_info_->pixel_count(),
893 stats_proxy_->GetStats().input_frame_rate, 1032 stats_proxy_->GetStats().input_frame_rate,
894 AdaptationRequest::Mode::kAdaptUp}; 1033 AdaptationRequest::Mode::kAdaptUp};
895 1034
896 bool adapt_up_requested = 1035 bool adapt_up_requested =
897 last_adaptation_request_ && 1036 last_adaptation_request_ &&
898 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; 1037 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp;
899 1038
900 switch (degradation_preference_) { 1039 switch (degradation_preference_) {
901 case VideoSendStream::DegradationPreference::kBalanced: 1040 case VideoSendStream::DegradationPreference::kBalanced:
902 FALLTHROUGH(); 1041 break;
903 case VideoSendStream::DegradationPreference::kMaintainFramerate: 1042 case VideoSendStream::DegradationPreference::kMaintainFramerate:
904 if (adapt_up_requested && 1043 if (adapt_up_requested &&
905 adaptation_request.input_pixel_count_ <= 1044 adaptation_request.input_pixel_count_ <=
906 last_adaptation_request_->input_pixel_count_) { 1045 last_adaptation_request_->input_pixel_count_) {
907 // Don't request higher resolution if the current resolution is not 1046 // Don't request higher resolution if the current resolution is not
908 // higher than the last time we asked for the resolution to be higher. 1047 // higher than the last time we asked for the resolution to be higher.
909 return; 1048 return;
910 } 1049 }
911 break; 1050 break;
912 case VideoSendStream::DegradationPreference::kMaintainResolution: 1051 case VideoSendStream::DegradationPreference::kMaintainResolution:
913 // TODO(sprang): Don't request higher framerate if we are already at 1052 // TODO(sprang): Don't request higher framerate if we are already at
914 // max requested fps? 1053 // max requested fps?
915 break; 1054 break;
916 case VideoSendStream::DegradationPreference::kDegradationDisabled: 1055 case VideoSendStream::DegradationPreference::kDegradationDisabled:
917 return; 1056 return;
918 } 1057 }
919 1058
920 switch (degradation_preference_) { 1059 switch (degradation_preference_) {
kthelgason 2017/05/19 08:34:14 Why do we have these two identical switch statemen
åsapersson 2017/06/08 13:55:32 Removed the one above.
921 case VideoSendStream::DegradationPreference::kBalanced: 1060 case VideoSendStream::DegradationPreference::kBalanced: {
922 FALLTHROUGH(); 1061 int pixel_count = adaptation_request.input_pixel_count_;
1062 if (adapt_counter.ResolutionCount() == 1) {
1063 LOG(LS_INFO) << "Removing down-scaling setting.";
1064 pixel_count = std::numeric_limits<int>::max();
1065 }
1066 int fps = MaxFps(last_frame_info_->pixel_count());
1067 bool fps_changed;
1068 if (!source_proxy_->IncreaseFpsOrRequestHigherResolutionThan(
1069 fps, pixel_count, &fps_changed)) {
1070 return;
1071 }
1072 if (fps_changed) {
1073 LOG(LS_INFO) << "Scaling up framerate: " << fps;
1074 GetAdaptCounter().DecrementFramerate(reason);
1075 } else {
1076 LOG(LS_INFO) << "Scaling up resolution.";
1077 GetAdaptCounter().DecrementResolution(reason);
1078 }
1079 break;
1080 }
923 case VideoSendStream::DegradationPreference::kMaintainFramerate: 1081 case VideoSendStream::DegradationPreference::kMaintainFramerate:
924 if (adapt_counter.TotalCount() == 1) { 1082 if (adapt_counter.TotalCount() == 1) {
925 LOG(LS_INFO) << "Removing resolution down-scaling setting."; 1083 LOG(LS_INFO) << "Removing resolution down-scaling setting.";
926 source_proxy_->RequestHigherResolutionThan( 1084 source_proxy_->RequestHigherResolutionThan(
927 std::numeric_limits<int>::max()); 1085 std::numeric_limits<int>::max());
928 } else { 1086 } else {
929 source_proxy_->RequestHigherResolutionThan( 1087 source_proxy_->RequestHigherResolutionThan(
930 adaptation_request.input_pixel_count_); 1088 adaptation_request.input_pixel_count_);
931 LOG(LS_INFO) << "Scaling up resolution."; 1089 LOG(LS_INFO) << "Scaling up resolution.";
932 } 1090 }
933 GetAdaptCounter().IncrementResolution(reason, -1); 1091 GetAdaptCounter().DecrementResolution(reason);
934 break; 1092 break;
935 case VideoSendStream::DegradationPreference::kMaintainResolution: 1093 case VideoSendStream::DegradationPreference::kMaintainResolution:
936 if (adapt_counter.TotalCount() == 1) { 1094 if (adapt_counter.TotalCount() == 1) {
937 LOG(LS_INFO) << "Removing framerate down-scaling setting."; 1095 LOG(LS_INFO) << "Removing framerate down-scaling setting.";
938 source_proxy_->RequestHigherFramerateThan( 1096 source_proxy_->RequestHigherFramerateThan(
939 std::numeric_limits<int>::max()); 1097 std::numeric_limits<int>::max());
940 } else { 1098 } else {
941 source_proxy_->RequestHigherFramerateThan( 1099 source_proxy_->RequestHigherFramerateThan(
942 adaptation_request.framerate_fps_); 1100 adaptation_request.framerate_fps_);
943 LOG(LS_INFO) << "Scaling up framerate."; 1101 LOG(LS_INFO) << "Scaling up framerate.";
944 } 1102 }
945 GetAdaptCounter().IncrementFramerate(reason, -1); 1103 GetAdaptCounter().DecrementFramerate(reason);
946 break; 1104 break;
947 case VideoSendStream::DegradationPreference::kDegradationDisabled: 1105 case VideoSendStream::DegradationPreference::kDegradationDisabled:
948 RTC_NOTREACHED(); 1106 RTC_NOTREACHED();
949 } 1107 }
950 1108
951 last_adaptation_request_.emplace(adaptation_request); 1109 last_adaptation_request_.emplace(adaptation_request);
952 1110
953 UpdateAdaptationStats(reason); 1111 UpdateAdaptationStats(reason);
954 1112
955 LOG(LS_INFO) << adapt_counter.ToString(); 1113 LOG(LS_INFO) << adapt_counter.ToString();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 } 1154 }
997 1155
998 const ViEEncoder::AdaptCounter& ViEEncoder::GetConstAdaptCounter() { 1156 const ViEEncoder::AdaptCounter& ViEEncoder::GetConstAdaptCounter() {
999 return adapt_counters_[degradation_preference_]; 1157 return adapt_counters_[degradation_preference_];
1000 } 1158 }
1001 1159
1002 // Class holding adaptation information. 1160 // Class holding adaptation information.
1003 ViEEncoder::AdaptCounter::AdaptCounter() { 1161 ViEEncoder::AdaptCounter::AdaptCounter() {
1004 fps_counters_.resize(kScaleReasonSize); 1162 fps_counters_.resize(kScaleReasonSize);
1005 resolution_counters_.resize(kScaleReasonSize); 1163 resolution_counters_.resize(kScaleReasonSize);
1164 RTC_DCHECK_EQ(fps_counters_.size(), 2) << "Update MoveCount()";
1165 RTC_DCHECK_EQ(resolution_counters_.size(), 2) << "Update MoveCount()";
1006 } 1166 }
1007 1167
1008 ViEEncoder::AdaptCounter::~AdaptCounter() {} 1168 ViEEncoder::AdaptCounter::~AdaptCounter() {}
1009 1169
1010 std::string ViEEncoder::AdaptCounter::ToString() const { 1170 std::string ViEEncoder::AdaptCounter::ToString() const {
1011 std::stringstream ss; 1171 std::stringstream ss;
1012 ss << "Downgrade counts: fps: {" << ToString(fps_counters_); 1172 ss << "Downgrade counts: fps: {" << ToString(fps_counters_);
1013 ss << "}, resolution: {" << ToString(resolution_counters_) << "}"; 1173 ss << "}, resolution: {" << ToString(resolution_counters_) << "}";
1014 return ss.str(); 1174 return ss.str();
1015 } 1175 }
1016 1176
1017 ViEEncoder::AdaptCounts ViEEncoder::AdaptCounter::Counts(int reason) const { 1177 ViEEncoder::AdaptCounts ViEEncoder::AdaptCounter::Counts(int reason) const {
1018 AdaptCounts counts; 1178 AdaptCounts counts;
1019 counts.fps = fps_counters_[reason]; 1179 counts.fps = fps_counters_[reason];
1020 counts.resolution = resolution_counters_[reason]; 1180 counts.resolution = resolution_counters_[reason];
1021 return counts; 1181 return counts;
1022 } 1182 }
1023 1183
1024 void ViEEncoder::AdaptCounter::IncrementFramerate(int reason, int delta) { 1184 void ViEEncoder::AdaptCounter::IncrementFramerate(int reason) {
1025 fps_counters_[reason] += delta; 1185 ++(fps_counters_[reason]);
1026 } 1186 }
1027 1187
1028 void ViEEncoder::AdaptCounter::IncrementResolution(int reason, int delta) { 1188 void ViEEncoder::AdaptCounter::IncrementResolution(int reason) {
1029 resolution_counters_[reason] += delta; 1189 ++(resolution_counters_[reason]);
1190 }
1191
1192 void ViEEncoder::AdaptCounter::DecrementFramerate(int reason) {
1193 if (fps_counters_[reason] == 0) {
1194 // Adapt up is in a different order, switch reason.
1195 // E.g. framerate adapt down: quality, framerate adapt up: cpu.
kthelgason 2017/05/19 08:34:14 Why is this the case? This seems very confusing.
åsapersson 2017/06/08 13:55:32 Updated comment.
1196 MoveCount(&resolution_counters_, reason);
1197 MoveCount(&fps_counters_, (reason + 1) % kScaleReasonSize);
1198 }
1199 --(fps_counters_[reason]);
1200 RTC_DCHECK_GE(fps_counters_[reason], 0);
1201 }
1202
1203 void ViEEncoder::AdaptCounter::DecrementResolution(int reason) {
1204 if (resolution_counters_[reason] == 0) {
1205 // Adapt up is in a different order, switch reason.
1206 // E.g. resolution adapt down: quality, resolution adapt up: cpu.
1207 MoveCount(&fps_counters_, reason);
1208 MoveCount(&resolution_counters_, (reason + 1) % kScaleReasonSize);
1209 }
1210 --(resolution_counters_[reason]);
1211 RTC_DCHECK_GE(resolution_counters_[reason], 0);
1030 } 1212 }
1031 1213
1032 int ViEEncoder::AdaptCounter::FramerateCount() const { 1214 int ViEEncoder::AdaptCounter::FramerateCount() const {
1033 return Count(fps_counters_); 1215 return Count(fps_counters_);
1034 } 1216 }
1035 1217
1036 int ViEEncoder::AdaptCounter::ResolutionCount() const { 1218 int ViEEncoder::AdaptCounter::ResolutionCount() const {
1037 return Count(resolution_counters_); 1219 return Count(resolution_counters_);
1038 } 1220 }
1039 1221
(...skipping 10 matching lines...) Expand all
1050 } 1232 }
1051 1233
1052 int ViEEncoder::AdaptCounter::TotalCount(int reason) const { 1234 int ViEEncoder::AdaptCounter::TotalCount(int reason) const {
1053 return FramerateCount(reason) + ResolutionCount(reason); 1235 return FramerateCount(reason) + ResolutionCount(reason);
1054 } 1236 }
1055 1237
1056 int ViEEncoder::AdaptCounter::Count(const std::vector<int>& counters) const { 1238 int ViEEncoder::AdaptCounter::Count(const std::vector<int>& counters) const {
1057 return std::accumulate(counters.begin(), counters.end(), 0); 1239 return std::accumulate(counters.begin(), counters.end(), 0);
1058 } 1240 }
1059 1241
1242 void ViEEncoder::AdaptCounter::MoveCount(std::vector<int>* counters,
1243 int from_reason) {
1244 int to_reason = (from_reason + 1) % kScaleReasonSize;
1245 ++((*counters)[to_reason]);
1246 --((*counters)[from_reason]);
1247 RTC_DCHECK_GE((*counters)[from_reason], 0);
1248 }
1249
1060 std::string ViEEncoder::AdaptCounter::ToString( 1250 std::string ViEEncoder::AdaptCounter::ToString(
1061 const std::vector<int>& counters) const { 1251 const std::vector<int>& counters) const {
1062 std::stringstream ss; 1252 std::stringstream ss;
1063 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { 1253 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) {
1064 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; 1254 ss << (reason ? " cpu" : "quality") << ":" << counters[reason];
1065 } 1255 }
1066 return ss.str(); 1256 return ss.str();
1067 } 1257 }
1068 1258
1069 } // namespace webrtc 1259 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698