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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | | |
|
sprang_webrtc
2017/06/13 11:58:29
I think there could be a case for 24fps for 720p a
åsapersson
2017/06/13 12:40:04
Agree, these are initial limits.
| |
| 78 // <=640x480: | 15fps | max | | |
| 79 // <=480x270: | 10fps | 15fps | | |
| 80 // <=320x240: | 7fps | 10fps | | |
| 81 // ---------------------------------------------------------- | |
| 82 // kbps: 0 60 130 500 | | |
| 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(); | |
|
sprang_webrtc
2017/06/13 11:58:29
nit: please use brackets for if/else statements
åsapersson
2017/06/13 12:40:05
Done.
| |
| 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 Loading... | |
| 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: |
| 257 break; | |
| 214 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 258 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 215 wants.max_framerate_fps = std::numeric_limits<int>::max(); | 259 wants.max_framerate_fps = std::numeric_limits<int>::max(); |
| 216 break; | 260 break; |
| 217 case VideoSendStream::DegradationPreference::kMaintainResolution: | 261 case VideoSendStream::DegradationPreference::kMaintainResolution: |
| 218 wants.max_pixel_count = std::numeric_limits<int>::max(); | 262 wants.max_pixel_count = std::numeric_limits<int>::max(); |
| 219 wants.target_pixel_count.reset(); | 263 wants.target_pixel_count.reset(); |
| 220 break; | 264 break; |
| 221 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 265 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 222 wants.max_pixel_count = std::numeric_limits<int>::max(); | 266 wants.max_pixel_count = std::numeric_limits<int>::max(); |
| 223 wants.target_pixel_count.reset(); | 267 wants.target_pixel_count.reset(); |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 stats_proxy_->GetStats().input_frame_rate, | 843 stats_proxy_->GetStats().input_frame_rate, |
| 800 AdaptationRequest::Mode::kAdaptDown}; | 844 AdaptationRequest::Mode::kAdaptDown}; |
| 801 | 845 |
| 802 bool downgrade_requested = | 846 bool downgrade_requested = |
| 803 last_adaptation_request_ && | 847 last_adaptation_request_ && |
| 804 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; | 848 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; |
| 805 | 849 |
| 806 int max_downgrades = 0; | 850 int max_downgrades = 0; |
| 807 switch (degradation_preference_) { | 851 switch (degradation_preference_) { |
| 808 case VideoSendStream::DegradationPreference::kBalanced: | 852 case VideoSendStream::DegradationPreference::kBalanced: |
| 853 max_downgrades = kMaxCpuResolutionDowngrades; | |
| 854 break; | |
| 809 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 855 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 810 max_downgrades = kMaxCpuResolutionDowngrades; | 856 max_downgrades = kMaxCpuResolutionDowngrades; |
| 811 if (downgrade_requested && | 857 if (downgrade_requested && |
| 812 adaptation_request.input_pixel_count_ >= | 858 adaptation_request.input_pixel_count_ >= |
| 813 last_adaptation_request_->input_pixel_count_) { | 859 last_adaptation_request_->input_pixel_count_) { |
| 814 // Don't request lower resolution if the current resolution is not | 860 // 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. | 861 // lower than the last time we asked for the resolution to be lowered. |
| 816 return; | 862 return; |
| 817 } | 863 } |
| 818 break; | 864 break; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 833 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 879 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 834 return; | 880 return; |
| 835 } | 881 } |
| 836 | 882 |
| 837 if (reason == kCpu) { | 883 if (reason == kCpu) { |
| 838 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades) | 884 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades) |
| 839 return; | 885 return; |
| 840 } | 886 } |
| 841 | 887 |
| 842 switch (degradation_preference_) { | 888 switch (degradation_preference_) { |
| 843 case VideoSendStream::DegradationPreference::kBalanced: | 889 case VideoSendStream::DegradationPreference::kBalanced: { |
| 890 // Try scale down framerate, if lower. | |
| 891 int max_fps = MaxFpsForBitrateAndResolution( | |
| 892 last_observed_bitrate_bps_, last_frame_info_->pixel_count()); | |
| 893 if (source_proxy_->RestrictFramerate(max_fps)) { | |
| 894 GetAdaptCounter().IncrementFramerate(reason); | |
| 895 break; | |
| 896 } | |
| 897 // Scale down resolution. | |
| 898 FALLTHROUGH(); | |
| 899 } | |
| 844 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 900 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 845 // Scale down resolution. | 901 // Scale down resolution. |
| 846 if (!source_proxy_->RequestResolutionLowerThan( | 902 if (!source_proxy_->RequestResolutionLowerThan( |
| 847 adaptation_request.input_pixel_count_)) { | 903 adaptation_request.input_pixel_count_)) { |
| 848 return; | 904 return; |
| 849 } | 905 } |
| 850 GetAdaptCounter().IncrementResolution(reason, 1); | 906 GetAdaptCounter().IncrementResolution(reason); |
| 851 break; | 907 break; |
| 852 case VideoSendStream::DegradationPreference::kMaintainResolution: | 908 case VideoSendStream::DegradationPreference::kMaintainResolution: |
| 853 // Scale down framerate. | 909 // Scale down framerate. |
| 854 if (!source_proxy_->RequestFramerateLowerThan( | 910 if (!source_proxy_->RequestFramerateLowerThan( |
| 855 adaptation_request.framerate_fps_)) { | 911 adaptation_request.framerate_fps_)) { |
| 856 return; | 912 return; |
| 857 } | 913 } |
| 858 GetAdaptCounter().IncrementFramerate(reason, 1); | 914 GetAdaptCounter().IncrementFramerate(reason); |
| 859 break; | 915 break; |
| 860 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 916 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 861 RTC_NOTREACHED(); | 917 RTC_NOTREACHED(); |
| 862 } | 918 } |
| 863 | 919 |
| 864 last_adaptation_request_.emplace(adaptation_request); | 920 last_adaptation_request_.emplace(adaptation_request); |
| 865 | 921 |
| 866 UpdateAdaptationStats(reason); | 922 UpdateAdaptationStats(reason); |
| 867 | 923 |
| 868 LOG(LS_INFO) << GetConstAdaptCounter().ToString(); | 924 LOG(LS_INFO) << GetConstAdaptCounter().ToString(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 879 | 935 |
| 880 AdaptationRequest adaptation_request = { | 936 AdaptationRequest adaptation_request = { |
| 881 last_frame_info_->pixel_count(), | 937 last_frame_info_->pixel_count(), |
| 882 stats_proxy_->GetStats().input_frame_rate, | 938 stats_proxy_->GetStats().input_frame_rate, |
| 883 AdaptationRequest::Mode::kAdaptUp}; | 939 AdaptationRequest::Mode::kAdaptUp}; |
| 884 | 940 |
| 885 bool adapt_up_requested = | 941 bool adapt_up_requested = |
| 886 last_adaptation_request_ && | 942 last_adaptation_request_ && |
| 887 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; | 943 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; |
| 888 | 944 |
| 889 switch (degradation_preference_) { | 945 if (degradation_preference_ == |
| 890 case VideoSendStream::DegradationPreference::kBalanced: | 946 VideoSendStream::DegradationPreference::kMaintainFramerate) { |
| 891 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 947 if (adapt_up_requested && |
| 892 if (adapt_up_requested && | 948 adaptation_request.input_pixel_count_ <= |
| 893 adaptation_request.input_pixel_count_ <= | 949 last_adaptation_request_->input_pixel_count_) { |
| 894 last_adaptation_request_->input_pixel_count_) { | 950 // Don't request higher resolution if the current resolution is not |
| 895 // Don't request higher resolution if the current resolution is not | 951 // 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. | |
| 897 return; | |
| 898 } | |
| 899 break; | |
| 900 case VideoSendStream::DegradationPreference::kMaintainResolution: | |
| 901 // TODO(sprang): Don't request higher framerate if we are already at | |
| 902 // max requested fps? | |
| 903 break; | |
| 904 case VideoSendStream::DegradationPreference::kDegradationDisabled: | |
| 905 return; | 952 return; |
| 953 } | |
| 906 } | 954 } |
| 907 | 955 |
| 908 switch (degradation_preference_) { | 956 switch (degradation_preference_) { |
| 909 case VideoSendStream::DegradationPreference::kBalanced: | 957 case VideoSendStream::DegradationPreference::kBalanced: { |
| 958 // Try scale up framerate, if higher. | |
| 959 int fps = MaxFps(last_frame_info_->pixel_count()); | |
| 960 if (source_proxy_->IncreaseFramerate(fps)) { | |
| 961 GetAdaptCounter().DecrementFramerate(reason); | |
| 962 break; | |
| 963 } | |
| 964 // Scale up resolution. | |
| 965 FALLTHROUGH(); | |
| 966 } | |
| 910 case VideoSendStream::DegradationPreference::kMaintainFramerate: { | 967 case VideoSendStream::DegradationPreference::kMaintainFramerate: { |
| 911 // Scale up resolution. | 968 // Scale up resolution. |
| 912 int pixel_count = adaptation_request.input_pixel_count_; | 969 int pixel_count = adaptation_request.input_pixel_count_; |
| 913 if (adapt_counter.ResolutionCount() == 1) { | 970 if (adapt_counter.ResolutionCount() == 1) { |
| 914 LOG(LS_INFO) << "Removing resolution down-scaling setting."; | 971 LOG(LS_INFO) << "Removing resolution down-scaling setting."; |
| 915 pixel_count = std::numeric_limits<int>::max(); | 972 pixel_count = std::numeric_limits<int>::max(); |
| 916 } | 973 } |
| 917 if (!source_proxy_->RequestHigherResolutionThan(pixel_count)) | 974 if (!source_proxy_->RequestHigherResolutionThan(pixel_count)) |
| 918 return; | 975 return; |
| 919 GetAdaptCounter().IncrementResolution(reason, -1); | 976 GetAdaptCounter().DecrementResolution(reason); |
| 920 break; | 977 break; |
| 921 } | 978 } |
| 922 case VideoSendStream::DegradationPreference::kMaintainResolution: { | 979 case VideoSendStream::DegradationPreference::kMaintainResolution: { |
| 923 // Scale up framerate. | 980 // Scale up framerate. |
| 924 int fps = adaptation_request.framerate_fps_; | 981 int fps = adaptation_request.framerate_fps_; |
| 925 if (adapt_counter.FramerateCount() == 1) { | 982 if (adapt_counter.FramerateCount() == 1) { |
| 926 LOG(LS_INFO) << "Removing framerate down-scaling setting."; | 983 LOG(LS_INFO) << "Removing framerate down-scaling setting."; |
| 927 fps = std::numeric_limits<int>::max(); | 984 fps = std::numeric_limits<int>::max(); |
| 928 } | 985 } |
| 929 if (!source_proxy_->RequestHigherFramerateThan(fps)) | 986 if (!source_proxy_->RequestHigherFramerateThan(fps)) |
| 930 return; | 987 return; |
| 931 GetAdaptCounter().IncrementFramerate(reason, -1); | 988 GetAdaptCounter().DecrementFramerate(reason); |
| 932 break; | 989 break; |
| 933 } | 990 } |
| 934 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 991 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 935 RTC_NOTREACHED(); | 992 return; |
| 936 } | 993 } |
| 937 | 994 |
| 938 last_adaptation_request_.emplace(adaptation_request); | 995 last_adaptation_request_.emplace(adaptation_request); |
| 939 | 996 |
| 940 UpdateAdaptationStats(reason); | 997 UpdateAdaptationStats(reason); |
| 941 | 998 |
| 942 LOG(LS_INFO) << adapt_counter.ToString(); | 999 LOG(LS_INFO) << adapt_counter.ToString(); |
| 943 } | 1000 } |
| 944 | 1001 |
| 945 void ViEEncoder::UpdateAdaptationStats(AdaptReason reason) { | 1002 void ViEEncoder::UpdateAdaptationStats(AdaptReason reason) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 } | 1040 } |
| 984 | 1041 |
| 985 const ViEEncoder::AdaptCounter& ViEEncoder::GetConstAdaptCounter() { | 1042 const ViEEncoder::AdaptCounter& ViEEncoder::GetConstAdaptCounter() { |
| 986 return adapt_counters_[degradation_preference_]; | 1043 return adapt_counters_[degradation_preference_]; |
| 987 } | 1044 } |
| 988 | 1045 |
| 989 // Class holding adaptation information. | 1046 // Class holding adaptation information. |
| 990 ViEEncoder::AdaptCounter::AdaptCounter() { | 1047 ViEEncoder::AdaptCounter::AdaptCounter() { |
| 991 fps_counters_.resize(kScaleReasonSize); | 1048 fps_counters_.resize(kScaleReasonSize); |
| 992 resolution_counters_.resize(kScaleReasonSize); | 1049 resolution_counters_.resize(kScaleReasonSize); |
| 1050 static_assert(kScaleReasonSize == 2, "Update MoveCount."); | |
| 993 } | 1051 } |
| 994 | 1052 |
| 995 ViEEncoder::AdaptCounter::~AdaptCounter() {} | 1053 ViEEncoder::AdaptCounter::~AdaptCounter() {} |
| 996 | 1054 |
| 997 std::string ViEEncoder::AdaptCounter::ToString() const { | 1055 std::string ViEEncoder::AdaptCounter::ToString() const { |
| 998 std::stringstream ss; | 1056 std::stringstream ss; |
| 999 ss << "Downgrade counts: fps: {" << ToString(fps_counters_); | 1057 ss << "Downgrade counts: fps: {" << ToString(fps_counters_); |
| 1000 ss << "}, resolution: {" << ToString(resolution_counters_) << "}"; | 1058 ss << "}, resolution: {" << ToString(resolution_counters_) << "}"; |
| 1001 return ss.str(); | 1059 return ss.str(); |
| 1002 } | 1060 } |
| 1003 | 1061 |
| 1004 ViEEncoder::AdaptCounts ViEEncoder::AdaptCounter::Counts(int reason) const { | 1062 ViEEncoder::AdaptCounts ViEEncoder::AdaptCounter::Counts(int reason) const { |
| 1005 AdaptCounts counts; | 1063 AdaptCounts counts; |
| 1006 counts.fps = fps_counters_[reason]; | 1064 counts.fps = fps_counters_[reason]; |
| 1007 counts.resolution = resolution_counters_[reason]; | 1065 counts.resolution = resolution_counters_[reason]; |
| 1008 return counts; | 1066 return counts; |
| 1009 } | 1067 } |
| 1010 | 1068 |
| 1011 void ViEEncoder::AdaptCounter::IncrementFramerate(int reason, int delta) { | 1069 void ViEEncoder::AdaptCounter::IncrementFramerate(int reason) { |
| 1012 fps_counters_[reason] += delta; | 1070 ++(fps_counters_[reason]); |
| 1013 } | 1071 } |
| 1014 | 1072 |
| 1015 void ViEEncoder::AdaptCounter::IncrementResolution(int reason, int delta) { | 1073 void ViEEncoder::AdaptCounter::IncrementResolution(int reason) { |
| 1016 resolution_counters_[reason] += delta; | 1074 ++(resolution_counters_[reason]); |
| 1075 } | |
| 1076 | |
| 1077 void ViEEncoder::AdaptCounter::DecrementFramerate(int reason) { | |
| 1078 if (fps_counters_[reason] == 0) { | |
| 1079 // Balanced mode: Adapt up is in a different order, switch reason. | |
| 1080 // E.g. framerate adapt down: quality (2), framerate adapt up: cpu (3). | |
| 1081 // 1. Down resolution (cpu): res={quality:0,cpu:1}, fps={quality:0,cpu:0} | |
| 1082 // 2. Down fps (quality): res={quality:0,cpu:1}, fps={quality:1,cpu:0} | |
| 1083 // 3. Up fps (cpu): res={quality:1,cpu:0}, fps={quality:0,cpu:0} | |
| 1084 // 4. Up resolution (quality): res={quality:0,cpu:0}, fps={quality:0,cpu:0} | |
| 1085 RTC_DCHECK_GT(TotalCount(reason), 0) << "No downgrade for reason."; | |
| 1086 RTC_DCHECK_GT(FramerateCount(), 0) << "Framerate not downgraded."; | |
| 1087 MoveCount(&resolution_counters_, reason); | |
| 1088 MoveCount(&fps_counters_, (reason + 1) % kScaleReasonSize); | |
| 1089 } | |
| 1090 --(fps_counters_[reason]); | |
| 1091 RTC_DCHECK_GE(fps_counters_[reason], 0); | |
| 1092 } | |
| 1093 | |
| 1094 void ViEEncoder::AdaptCounter::DecrementResolution(int reason) { | |
| 1095 if (resolution_counters_[reason] == 0) { | |
| 1096 // Balanced mode: Adapt up is in a different order, switch reason. | |
| 1097 RTC_DCHECK_GT(TotalCount(reason), 0) << "No downgrade for reason."; | |
| 1098 RTC_DCHECK_GT(ResolutionCount(), 0) << "Resolution not downgraded."; | |
| 1099 MoveCount(&fps_counters_, reason); | |
| 1100 MoveCount(&resolution_counters_, (reason + 1) % kScaleReasonSize); | |
| 1101 } | |
| 1102 --(resolution_counters_[reason]); | |
| 1103 RTC_DCHECK_GE(resolution_counters_[reason], 0); | |
| 1017 } | 1104 } |
| 1018 | 1105 |
| 1019 int ViEEncoder::AdaptCounter::FramerateCount() const { | 1106 int ViEEncoder::AdaptCounter::FramerateCount() const { |
| 1020 return Count(fps_counters_); | 1107 return Count(fps_counters_); |
| 1021 } | 1108 } |
| 1022 | 1109 |
| 1023 int ViEEncoder::AdaptCounter::ResolutionCount() const { | 1110 int ViEEncoder::AdaptCounter::ResolutionCount() const { |
| 1024 return Count(resolution_counters_); | 1111 return Count(resolution_counters_); |
| 1025 } | 1112 } |
| 1026 | 1113 |
| 1027 int ViEEncoder::AdaptCounter::TotalCount() const { | |
| 1028 return FramerateCount() + ResolutionCount(); | |
| 1029 } | |
| 1030 | |
| 1031 int ViEEncoder::AdaptCounter::FramerateCount(int reason) const { | 1114 int ViEEncoder::AdaptCounter::FramerateCount(int reason) const { |
| 1032 return fps_counters_[reason]; | 1115 return fps_counters_[reason]; |
| 1033 } | 1116 } |
| 1034 | 1117 |
| 1035 int ViEEncoder::AdaptCounter::ResolutionCount(int reason) const { | 1118 int ViEEncoder::AdaptCounter::ResolutionCount(int reason) const { |
| 1036 return resolution_counters_[reason]; | 1119 return resolution_counters_[reason]; |
| 1037 } | 1120 } |
| 1038 | 1121 |
| 1039 int ViEEncoder::AdaptCounter::TotalCount(int reason) const { | 1122 int ViEEncoder::AdaptCounter::TotalCount(int reason) const { |
| 1040 return FramerateCount(reason) + ResolutionCount(reason); | 1123 return FramerateCount(reason) + ResolutionCount(reason); |
| 1041 } | 1124 } |
| 1042 | 1125 |
| 1043 int ViEEncoder::AdaptCounter::Count(const std::vector<int>& counters) const { | 1126 int ViEEncoder::AdaptCounter::Count(const std::vector<int>& counters) const { |
| 1044 return std::accumulate(counters.begin(), counters.end(), 0); | 1127 return std::accumulate(counters.begin(), counters.end(), 0); |
| 1045 } | 1128 } |
| 1046 | 1129 |
| 1130 void ViEEncoder::AdaptCounter::MoveCount(std::vector<int>* counters, | |
| 1131 int from_reason) { | |
| 1132 int to_reason = (from_reason + 1) % kScaleReasonSize; | |
| 1133 ++((*counters)[to_reason]); | |
| 1134 --((*counters)[from_reason]); | |
| 1135 } | |
| 1136 | |
| 1047 std::string ViEEncoder::AdaptCounter::ToString( | 1137 std::string ViEEncoder::AdaptCounter::ToString( |
| 1048 const std::vector<int>& counters) const { | 1138 const std::vector<int>& counters) const { |
| 1049 std::stringstream ss; | 1139 std::stringstream ss; |
| 1050 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { | 1140 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { |
| 1051 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; | 1141 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; |
| 1052 } | 1142 } |
| 1053 return ss.str(); | 1143 return ss.str(); |
| 1054 } | 1144 } |
| 1055 | 1145 |
| 1056 } // namespace webrtc | 1146 } // namespace webrtc |
| OLD | NEW |