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

Side by Side Diff: webrtc/modules/video_coding/utility/quality_scaler.cc

Issue 1867643003: Make QualityScaler not downscale below QVGA. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: update test Created 4 years, 8 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
OLDNEW
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 #include "webrtc/modules/video_coding/utility/quality_scaler.h" 10 #include "webrtc/modules/video_coding/utility/quality_scaler.h"
11 11
12 namespace webrtc { 12 namespace webrtc {
13 13
14 namespace {
14 static const int kMinFps = 5; 15 static const int kMinFps = 5;
15 static const int kMeasureSecondsDownscale = 3; 16 static const int kMeasureSecondsDownscale = 3;
16 // Threshold constant used until first downscale (to permit fast rampup). 17 // Threshold constant used until first downscale (to permit fast rampup).
17 static const int kMeasureSecondsFastUpscale = 2; 18 static const int kMeasureSecondsFastUpscale = 2;
18 static const int kMeasureSecondsUpscale = 5; 19 static const int kMeasureSecondsUpscale = 5;
19 static const int kFramedropPercentThreshold = 60; 20 static const int kFramedropPercentThreshold = 60;
20 static const int kHdResolutionThreshold = 700 * 500; 21 static const int kHdResolutionThreshold = 700 * 500;
21 static const int kHdBitrateThresholdKbps = 500; 22 static const int kHdBitrateThresholdKbps = 500;
23 // Min width/height to downscale to, set to not go below QVGA, but with some
24 // margin to permit "almost-QVGA" resolutions, such as QCIF.
25 static const int kMinDownscaleDimension = 140;
26 } // namespace
22 27
23 const int QualityScaler::kDefaultLowQpDenominator = 3; 28 const int QualityScaler::kDefaultLowQpDenominator = 3;
24 // Note that this is the same for width and height to permit 120x90 in both
25 // portrait and landscape mode.
26 const int QualityScaler::kDefaultMinDownscaleDimension = 90;
27 29
28 QualityScaler::QualityScaler() 30 QualityScaler::QualityScaler()
29 : low_qp_threshold_(-1), 31 : low_qp_threshold_(-1), framerate_down_(false) {}
30 framerate_down_(false),
31 min_width_(kDefaultMinDownscaleDimension),
32 min_height_(kDefaultMinDownscaleDimension) {}
33 32
34 void QualityScaler::Init(int low_qp_threshold, 33 void QualityScaler::Init(int low_qp_threshold,
35 int high_qp_threshold, 34 int high_qp_threshold,
36 bool use_framerate_reduction, 35 bool use_framerate_reduction,
37 int initial_bitrate_kbps, 36 int initial_bitrate_kbps,
38 int width, 37 int width,
39 int height, 38 int height,
40 int fps) { 39 int fps) {
41 ClearSamples(); 40 ClearSamples();
42 low_qp_threshold_ = low_qp_threshold; 41 low_qp_threshold_ = low_qp_threshold;
(...skipping 15 matching lines...) Expand all
58 ++downscale_shift_; 57 ++downscale_shift_;
59 width /= 2; 58 width /= 2;
60 height /= 2; 59 height /= 2;
61 } 60 }
62 } 61 }
63 UpdateTargetResolution(init_width, init_height); 62 UpdateTargetResolution(init_width, init_height);
64 ReportFramerate(fps); 63 ReportFramerate(fps);
65 target_framerate_ = -1; 64 target_framerate_ = -1;
66 } 65 }
67 66
68 void QualityScaler::SetMinResolution(int min_width, int min_height) {
69 min_width_ = min_width;
70 min_height_ = min_height;
71 }
72
73 // Report framerate(fps) to estimate # of samples. 67 // Report framerate(fps) to estimate # of samples.
74 void QualityScaler::ReportFramerate(int framerate) { 68 void QualityScaler::ReportFramerate(int framerate) {
75 framerate_ = framerate; 69 framerate_ = framerate;
76 UpdateSampleCounts(); 70 UpdateSampleCounts();
77 } 71 }
78 72
79 void QualityScaler::ReportQP(int qp) { 73 void QualityScaler::ReportQP(int qp) {
80 framedrop_percent_.AddSample(0); 74 framedrop_percent_.AddSample(0);
81 average_qp_downscale_.AddSample(qp); 75 average_qp_downscale_.AddSample(qp);
82 average_qp_upscale_.AddSample(qp); 76 average_qp_upscale_.AddSample(qp);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 scaled_frame_.set_render_time_ms(frame.render_time_ms()); 145 scaled_frame_.set_render_time_ms(frame.render_time_ms());
152 146
153 return scaled_frame_; 147 return scaled_frame_;
154 } 148 }
155 149
156 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) { 150 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) {
157 assert(downscale_shift_ >= 0); 151 assert(downscale_shift_ >= 0);
158 res_.width = frame_width; 152 res_.width = frame_width;
159 res_.height = frame_height; 153 res_.height = frame_height;
160 for (int shift = downscale_shift_; 154 for (int shift = downscale_shift_;
161 shift > 0 && (res_.width / 2 >= min_width_) && 155 shift > 0 && (res_.width / 2 >= kMinDownscaleDimension) &&
162 (res_.height / 2 >= min_height_); 156 (res_.height / 2 >= kMinDownscaleDimension);
163 --shift) { 157 --shift) {
164 res_.width /= 2; 158 res_.width /= 2;
165 res_.height /= 2; 159 res_.height /= 2;
166 } 160 }
167 } 161 }
168 162
169 void QualityScaler::ClearSamples() { 163 void QualityScaler::ClearSamples() {
170 framedrop_percent_.Reset(); 164 framedrop_percent_.Reset();
171 average_qp_downscale_.Reset(); 165 average_qp_downscale_.Reset();
172 average_qp_upscale_.Reset(); 166 average_qp_upscale_.Reset();
(...skipping 12 matching lines...) Expand all
185 downscale_shift_ = 0; 179 downscale_shift_ = 0;
186 if (!up) { 180 if (!up) {
187 // Hit first downscale, start using a slower threshold for going up. 181 // Hit first downscale, start using a slower threshold for going up.
188 measure_seconds_upscale_ = kMeasureSecondsUpscale; 182 measure_seconds_upscale_ = kMeasureSecondsUpscale;
189 UpdateSampleCounts(); 183 UpdateSampleCounts();
190 } 184 }
191 ClearSamples(); 185 ClearSamples();
192 } 186 }
193 187
194 } // namespace webrtc 188 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/utility/quality_scaler.h ('k') | webrtc/modules/video_coding/utility/quality_scaler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698