| 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 |
| 11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 11 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
| 12 | 12 |
| 13 namespace webrtc { | 13 namespace webrtc { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 static const int kMinFps = 5; | 16 static const int kMinFps = 5; |
| 17 // Threshold constant used until first downscale (to permit fast rampup). | 17 // Threshold constant used until first downscale (to permit fast rampup). |
| 18 static const int kMeasureSecondsFastUpscale = 2; | 18 static const int kMeasureSecondsFastUpscale = 2; |
| 19 static const int kMeasureSecondsUpscale = 5; | 19 static const int kMeasureSecondsUpscale = 5; |
| 20 static const int kMeasureSecondsDownscale = 5; | 20 static const int kMeasureSecondsDownscale = 5; |
| 21 static const int kFramedropPercentThreshold = 60; | 21 static const int kFramedropPercentThreshold = 60; |
| 22 static const int kHdResolutionThreshold = 700 * 500; |
| 23 static const int kHdBitrateThresholdKbps = 500; |
| 22 // Min width/height to downscale to, set to not go below QVGA, but with some | 24 // Min width/height to downscale to, set to not go below QVGA, but with some |
| 23 // margin to permit "almost-QVGA" resolutions, such as QCIF. | 25 // margin to permit "almost-QVGA" resolutions, such as QCIF. |
| 24 static const int kMinDownscaleDimension = 140; | 26 static const int kMinDownscaleDimension = 140; |
| 25 // Initial resolutions corresponding to a bitrate. Aa bit above their actual | |
| 26 // values to permit near-VGA and near-QVGA resolutions to use the same | |
| 27 // mechanism. | |
| 28 static const int kVgaBitrateThresholdKbps = 500; | |
| 29 static const int kVgaNumPixels = 700 * 500; // 640x480 | |
| 30 static const int kQvgaBitrateThresholdKbps = 250; | |
| 31 static const int kQvgaNumPixels = 400 * 300; // 320x240 | |
| 32 } // namespace | 27 } // namespace |
| 33 | 28 |
| 34 // QP thresholds are chosen to be high enough to be hit in practice when quality | 29 // QP thresholds are chosen to be high enough to be hit in practice when quality |
| 35 // is good, but also low enough to not cause a flip-flop behavior (e.g. going up | 30 // is good, but also low enough to not cause a flip-flop behavior (e.g. going up |
| 36 // in resolution shouldn't give so bad quality that we should go back down). | 31 // in resolution shouldn't give so bad quality that we should go back down). |
| 37 | 32 |
| 38 const int QualityScaler::kLowVp8QpThreshold = 29; | 33 const int QualityScaler::kLowVp8QpThreshold = 29; |
| 39 const int QualityScaler::kBadVp8QpThreshold = 95; | 34 const int QualityScaler::kBadVp8QpThreshold = 95; |
| 40 | 35 |
| 41 const int QualityScaler::kLowH264QpThreshold = 22; | 36 const int QualityScaler::kLowH264QpThreshold = 22; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 ClearSamples(); | 47 ClearSamples(); |
| 53 low_qp_threshold_ = low_qp_threshold; | 48 low_qp_threshold_ = low_qp_threshold; |
| 54 high_qp_threshold_ = high_qp_threshold; | 49 high_qp_threshold_ = high_qp_threshold; |
| 55 downscale_shift_ = 0; | 50 downscale_shift_ = 0; |
| 56 // Use a faster window for upscaling initially (but be more graceful later). | 51 // Use a faster window for upscaling initially (but be more graceful later). |
| 57 // This enables faster initial rampups without risking strong up-down | 52 // This enables faster initial rampups without risking strong up-down |
| 58 // behavior later. | 53 // behavior later. |
| 59 measure_seconds_upscale_ = kMeasureSecondsFastUpscale; | 54 measure_seconds_upscale_ = kMeasureSecondsFastUpscale; |
| 60 const int init_width = width; | 55 const int init_width = width; |
| 61 const int init_height = height; | 56 const int init_height = height; |
| 62 if (initial_bitrate_kbps > 0) { | 57 // TODO(glaznev): Investigate using thresholds for other resolutions |
| 63 int init_num_pixels = width * height; | 58 // or threshold tables. |
| 64 if (initial_bitrate_kbps < kVgaBitrateThresholdKbps) | 59 if (initial_bitrate_kbps > 0 && |
| 65 init_num_pixels = kVgaNumPixels; | 60 initial_bitrate_kbps < kHdBitrateThresholdKbps) { |
| 66 if (initial_bitrate_kbps < kQvgaBitrateThresholdKbps) | 61 // Start scaling to roughly VGA. |
| 67 init_num_pixels = kQvgaNumPixels; | 62 while (width * height > kHdResolutionThreshold) { |
| 68 while (width * height > init_num_pixels) { | |
| 69 ++downscale_shift_; | 63 ++downscale_shift_; |
| 70 width /= 2; | 64 width /= 2; |
| 71 height /= 2; | 65 height /= 2; |
| 72 } | 66 } |
| 73 } | 67 } |
| 74 | 68 |
| 75 // Zero out width/height so they can be checked against inside | 69 // Zero out width/height so they can be checked against inside |
| 76 // UpdateTargetResolution. | 70 // UpdateTargetResolution. |
| 77 res_.width = res_.height = 0; | 71 res_.width = res_.height = 0; |
| 78 UpdateTargetResolution(init_width, init_height); | 72 UpdateTargetResolution(init_width, init_height); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (downscale_shift_ < 0) | 171 if (downscale_shift_ < 0) |
| 178 downscale_shift_ = 0; | 172 downscale_shift_ = 0; |
| 179 if (!up) { | 173 if (!up) { |
| 180 // First downscale hit, start using a slower threshold for going up. | 174 // First downscale hit, start using a slower threshold for going up. |
| 181 measure_seconds_upscale_ = kMeasureSecondsUpscale; | 175 measure_seconds_upscale_ = kMeasureSecondsUpscale; |
| 182 UpdateSampleCounts(); | 176 UpdateSampleCounts(); |
| 183 } | 177 } |
| 184 } | 178 } |
| 185 | 179 |
| 186 } // namespace webrtc | 180 } // namespace webrtc |
| OLD | NEW |