OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 observer_(observer), | 105 observer_(observer), |
106 sampling_period_ms_(sampling_period), | 106 sampling_period_ms_(sampling_period), |
107 fast_rampup_(true), | 107 fast_rampup_(true), |
108 // Arbitrarily choose size based on 30 fps for 5 seconds. | 108 // Arbitrarily choose size based on 30 fps for 5 seconds. |
109 average_qp_(5 * 30), | 109 average_qp_(5 * 30), |
110 framedrop_percent_(5 * 30), | 110 framedrop_percent_(5 * 30), |
111 thresholds_(thresholds) { | 111 thresholds_(thresholds) { |
112 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 112 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
113 RTC_DCHECK(observer_ != nullptr); | 113 RTC_DCHECK(observer_ != nullptr); |
114 check_qp_task_ = new CheckQPTask(this); | 114 check_qp_task_ = new CheckQPTask(this); |
| 115 LOG(LS_INFO) << "QP thresholds: low: " << thresholds_.low |
| 116 << ", high: " << thresholds_.high; |
115 } | 117 } |
116 | 118 |
117 QualityScaler::~QualityScaler() { | 119 QualityScaler::~QualityScaler() { |
118 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 120 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
119 check_qp_task_->Stop(); | 121 check_qp_task_->Stop(); |
120 } | 122 } |
121 | 123 |
122 int64_t QualityScaler::GetSamplingPeriodMs() const { | 124 int64_t QualityScaler::GetSamplingPeriodMs() const { |
123 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 125 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
124 return fast_rampup_ ? sampling_period_ms_ | 126 return fast_rampup_ ? sampling_period_ms_ |
125 : (sampling_period_ms_ * kSamplePeriodScaleFactor); | 127 : (sampling_period_ms_ * kSamplePeriodScaleFactor); |
126 } | 128 } |
127 | 129 |
128 void QualityScaler::ReportDroppedFrame() { | 130 void QualityScaler::ReportDroppedFrame() { |
129 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 131 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
130 framedrop_percent_.AddSample(100); | 132 framedrop_percent_.AddSample(100); |
131 } | 133 } |
132 | 134 |
133 void QualityScaler::ReportQP(int qp) { | 135 void QualityScaler::ReportQP(int qp) { |
134 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 136 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
135 framedrop_percent_.AddSample(0); | 137 framedrop_percent_.AddSample(0); |
136 average_qp_.AddSample(qp); | 138 average_qp_.AddSample(qp); |
137 } | 139 } |
138 | 140 |
139 void QualityScaler::CheckQP() { | 141 void QualityScaler::CheckQP() { |
140 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 142 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
141 // Should be set through InitEncode -> Should be set by now. | 143 // Should be set through InitEncode -> Should be set by now. |
142 RTC_DCHECK_GE(thresholds_.low, 0); | 144 RTC_DCHECK_GE(thresholds_.low, 0); |
143 LOG(LS_INFO) << "Checking if average QP exceeds threshold"; | |
144 // Check if we should scale down due to high frame drop. | 145 // Check if we should scale down due to high frame drop. |
145 const rtc::Optional<int> drop_rate = framedrop_percent_.GetAverage(); | 146 const rtc::Optional<int> drop_rate = framedrop_percent_.GetAverage(); |
146 if (drop_rate && *drop_rate >= kFramedropPercentThreshold) { | 147 if (drop_rate && *drop_rate >= kFramedropPercentThreshold) { |
147 ReportQPHigh(); | 148 ReportQPHigh(); |
148 return; | 149 return; |
149 } | 150 } |
150 | 151 |
151 // Check if we should scale up or down based on QP. | 152 // Check if we should scale up or down based on QP. |
152 const rtc::Optional<int> avg_qp = average_qp_.GetAverage(); | 153 const rtc::Optional<int> avg_qp = average_qp_.GetAverage(); |
153 if (avg_qp && *avg_qp > thresholds_.high) { | 154 if (avg_qp) { |
154 ReportQPHigh(); | 155 LOG(LS_INFO) << "Checking average QP " << *avg_qp; |
155 return; | 156 if (*avg_qp > thresholds_.high) { |
156 } | 157 ReportQPHigh(); |
157 if (avg_qp && *avg_qp <= thresholds_.low) { | 158 return; |
158 // QP has been low. We want to try a higher resolution. | 159 } |
159 ReportQPLow(); | 160 if (*avg_qp <= thresholds_.low) { |
160 return; | 161 // QP has been low. We want to try a higher resolution. |
| 162 ReportQPLow(); |
| 163 return; |
| 164 } |
161 } | 165 } |
162 } | 166 } |
163 | 167 |
164 void QualityScaler::ReportQPLow() { | 168 void QualityScaler::ReportQPLow() { |
165 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 169 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
166 LOG(LS_INFO) << "QP has been low, asking for higher resolution."; | |
167 ClearSamples(); | 170 ClearSamples(); |
168 observer_->AdaptUp(AdaptationObserverInterface::AdaptReason::kQuality); | 171 observer_->AdaptUp(AdaptationObserverInterface::AdaptReason::kQuality); |
169 } | 172 } |
170 | 173 |
171 void QualityScaler::ReportQPHigh() { | 174 void QualityScaler::ReportQPHigh() { |
172 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 175 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
173 LOG(LS_INFO) << "QP has been high , asking for lower resolution."; | |
174 ClearSamples(); | 176 ClearSamples(); |
175 observer_->AdaptDown(AdaptationObserverInterface::AdaptReason::kQuality); | 177 observer_->AdaptDown(AdaptationObserverInterface::AdaptReason::kQuality); |
176 // If we've scaled down, wait longer before scaling up again. | 178 // If we've scaled down, wait longer before scaling up again. |
177 if (fast_rampup_) { | 179 if (fast_rampup_) { |
178 fast_rampup_ = false; | 180 fast_rampup_ = false; |
179 } | 181 } |
180 } | 182 } |
181 | 183 |
182 void QualityScaler::ClearSamples() { | 184 void QualityScaler::ClearSamples() { |
183 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 185 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
184 framedrop_percent_.Reset(); | 186 framedrop_percent_.Reset(); |
185 average_qp_.Reset(); | 187 average_qp_.Reset(); |
186 } | 188 } |
187 } // namespace webrtc | 189 } // namespace webrtc |
OLD | NEW |