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 21 matching lines...) Expand all Loading... |
32 static const int kMeasureMs = 2000; | 32 static const int kMeasureMs = 2000; |
33 static const float kSamplePeriodScaleFactor = 2.5; | 33 static const float kSamplePeriodScaleFactor = 2.5; |
34 static const int kFramedropPercentThreshold = 60; | 34 static const int kFramedropPercentThreshold = 60; |
35 // QP scaling threshold defaults: | 35 // QP scaling threshold defaults: |
36 static const int kLowH264QpThreshold = 24; | 36 static const int kLowH264QpThreshold = 24; |
37 static const int kHighH264QpThreshold = 37; | 37 static const int kHighH264QpThreshold = 37; |
38 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the | 38 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the |
39 // bitstream range of [0, 127] and not the user-level range of [0,63]. | 39 // bitstream range of [0, 127] and not the user-level range of [0,63]. |
40 static const int kLowVp8QpThreshold = 29; | 40 static const int kLowVp8QpThreshold = 29; |
41 static const int kHighVp8QpThreshold = 95; | 41 static const int kHighVp8QpThreshold = 95; |
42 const ScalingObserverInterface::ScaleReason scale_reason_ = | |
43 ScalingObserverInterface::ScaleReason::kQuality; | |
44 | 42 |
45 static VideoEncoder::QpThresholds CodecTypeToDefaultThresholds( | 43 static VideoEncoder::QpThresholds CodecTypeToDefaultThresholds( |
46 VideoCodecType codec_type) { | 44 VideoCodecType codec_type) { |
47 int low = -1; | 45 int low = -1; |
48 int high = -1; | 46 int high = -1; |
49 switch (codec_type) { | 47 switch (codec_type) { |
50 case kVideoCodecH264: | 48 case kVideoCodecH264: |
51 low = kLowH264QpThreshold; | 49 low = kLowH264QpThreshold; |
52 high = kHighH264QpThreshold; | 50 high = kHighH264QpThreshold; |
53 break; | 51 break; |
(...skipping 30 matching lines...) Expand all Loading... |
84 rtc::TaskQueue::Current()->PostDelayedTask( | 82 rtc::TaskQueue::Current()->PostDelayedTask( |
85 std::unique_ptr<rtc::QueuedTask>(this), scaler_->GetSamplingPeriodMs()); | 83 std::unique_ptr<rtc::QueuedTask>(this), scaler_->GetSamplingPeriodMs()); |
86 return false; // Retain the task in order to reuse it. | 84 return false; // Retain the task in order to reuse it. |
87 } | 85 } |
88 | 86 |
89 QualityScaler* const scaler_; | 87 QualityScaler* const scaler_; |
90 bool stop_ = false; | 88 bool stop_ = false; |
91 rtc::SequencedTaskChecker task_checker_; | 89 rtc::SequencedTaskChecker task_checker_; |
92 }; | 90 }; |
93 | 91 |
94 QualityScaler::QualityScaler(ScalingObserverInterface* observer, | 92 QualityScaler::QualityScaler(AdaptationObserverInterface* observer, |
95 VideoCodecType codec_type) | 93 VideoCodecType codec_type) |
96 : QualityScaler(observer, CodecTypeToDefaultThresholds(codec_type)) {} | 94 : QualityScaler(observer, CodecTypeToDefaultThresholds(codec_type)) {} |
97 | 95 |
98 QualityScaler::QualityScaler(ScalingObserverInterface* observer, | 96 QualityScaler::QualityScaler(AdaptationObserverInterface* observer, |
99 VideoEncoder::QpThresholds thresholds) | 97 VideoEncoder::QpThresholds thresholds) |
100 : QualityScaler(observer, thresholds, kMeasureMs) {} | 98 : QualityScaler(observer, thresholds, kMeasureMs) {} |
101 | 99 |
102 // Protected ctor, should not be called directly. | 100 // Protected ctor, should not be called directly. |
103 QualityScaler::QualityScaler(ScalingObserverInterface* observer, | 101 QualityScaler::QualityScaler(AdaptationObserverInterface* observer, |
104 VideoEncoder::QpThresholds thresholds, | 102 VideoEncoder::QpThresholds thresholds, |
105 int64_t sampling_period) | 103 int64_t sampling_period) |
106 : check_qp_task_(nullptr), | 104 : check_qp_task_(nullptr), |
107 observer_(observer), | 105 observer_(observer), |
108 sampling_period_ms_(sampling_period), | 106 sampling_period_ms_(sampling_period), |
109 fast_rampup_(true), | 107 fast_rampup_(true), |
110 // Arbitrarily choose size based on 30 fps for 5 seconds. | 108 // Arbitrarily choose size based on 30 fps for 5 seconds. |
111 average_qp_(5 * 30), | 109 average_qp_(5 * 30), |
112 framedrop_percent_(5 * 30), | 110 framedrop_percent_(5 * 30), |
113 thresholds_(thresholds) { | 111 thresholds_(thresholds) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // QP has been low. We want to try a higher resolution. | 158 // QP has been low. We want to try a higher resolution. |
161 ReportQPLow(); | 159 ReportQPLow(); |
162 return; | 160 return; |
163 } | 161 } |
164 } | 162 } |
165 | 163 |
166 void QualityScaler::ReportQPLow() { | 164 void QualityScaler::ReportQPLow() { |
167 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 165 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
168 LOG(LS_INFO) << "QP has been low, asking for higher resolution."; | 166 LOG(LS_INFO) << "QP has been low, asking for higher resolution."; |
169 ClearSamples(); | 167 ClearSamples(); |
170 observer_->ScaleUp(scale_reason_); | 168 observer_->AdaptUp(AdaptationObserverInterface::AdaptReason::kQuality); |
171 } | 169 } |
172 | 170 |
173 void QualityScaler::ReportQPHigh() { | 171 void QualityScaler::ReportQPHigh() { |
174 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 172 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
175 LOG(LS_INFO) << "QP has been high , asking for lower resolution."; | 173 LOG(LS_INFO) << "QP has been high , asking for lower resolution."; |
176 ClearSamples(); | 174 ClearSamples(); |
177 observer_->ScaleDown(scale_reason_); | 175 observer_->AdaptDown(AdaptationObserverInterface::AdaptReason::kQuality); |
178 // If we've scaled down, wait longer before scaling up again. | 176 // If we've scaled down, wait longer before scaling up again. |
179 if (fast_rampup_) { | 177 if (fast_rampup_) { |
180 fast_rampup_ = false; | 178 fast_rampup_ = false; |
181 } | 179 } |
182 } | 180 } |
183 | 181 |
184 void QualityScaler::ClearSamples() { | 182 void QualityScaler::ClearSamples() { |
185 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); | 183 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_); |
186 framedrop_percent_.Reset(); | 184 framedrop_percent_.Reset(); |
187 average_qp_.Reset(); | 185 average_qp_.Reset(); |
188 } | 186 } |
189 } // namespace webrtc | 187 } // namespace webrtc |
OLD | NEW |