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

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: 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 static const int kMinFps = 5; 14 static const int kMinFps = 5;
15 static const int kMeasureSecondsDownscale = 3; 15 static const int kMeasureSecondsDownscale = 3;
16 // Threshold constant used until first downscale (to permit fast rampup). 16 // Threshold constant used until first downscale (to permit fast rampup).
17 static const int kMeasureSecondsFastUpscale = 2; 17 static const int kMeasureSecondsFastUpscale = 2;
18 static const int kMeasureSecondsUpscale = 5; 18 static const int kMeasureSecondsUpscale = 5;
19 static const int kFramedropPercentThreshold = 60; 19 static const int kFramedropPercentThreshold = 60;
20 static const int kHdResolutionThreshold = 700 * 500; 20 static const int kHdResolutionThreshold = 700 * 500;
21 static const int kHdBitrateThresholdKbps = 500; 21 static const int kHdBitrateThresholdKbps = 500;
22 22
23 // Min x/y dimensions downscale to, set to not go below QVGA, but with some
danilchap 2016/04/13 13:56:35 Min width/height
pbos-webrtc 2016/04/13 14:00:08 Done.
24 // margin to permit "almost-QVGA" resolutions.
25 static const int kMinDownscaleDimension = 160;
26
23 const int QualityScaler::kDefaultLowQpDenominator = 3; 27 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 28
28 QualityScaler::QualityScaler() 29 QualityScaler::QualityScaler()
29 : low_qp_threshold_(-1), 30 : low_qp_threshold_(-1), framerate_down_(false) {}
30 framerate_down_(false),
31 min_width_(kDefaultMinDownscaleDimension),
32 min_height_(kDefaultMinDownscaleDimension) {}
33 31
34 void QualityScaler::Init(int low_qp_threshold, 32 void QualityScaler::Init(int low_qp_threshold,
35 int high_qp_threshold, 33 int high_qp_threshold,
36 bool use_framerate_reduction, 34 bool use_framerate_reduction,
37 int initial_bitrate_kbps, 35 int initial_bitrate_kbps,
38 int width, 36 int width,
39 int height, 37 int height,
40 int fps) { 38 int fps) {
41 ClearSamples(); 39 ClearSamples();
42 low_qp_threshold_ = low_qp_threshold; 40 low_qp_threshold_ = low_qp_threshold;
(...skipping 15 matching lines...) Expand all
58 ++downscale_shift_; 56 ++downscale_shift_;
59 width /= 2; 57 width /= 2;
60 height /= 2; 58 height /= 2;
61 } 59 }
62 } 60 }
63 UpdateTargetResolution(init_width, init_height); 61 UpdateTargetResolution(init_width, init_height);
64 ReportFramerate(fps); 62 ReportFramerate(fps);
65 target_framerate_ = -1; 63 target_framerate_ = -1;
66 } 64 }
67 65
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. 66 // Report framerate(fps) to estimate # of samples.
74 void QualityScaler::ReportFramerate(int framerate) { 67 void QualityScaler::ReportFramerate(int framerate) {
75 framerate_ = framerate; 68 framerate_ = framerate;
76 UpdateSampleCounts(); 69 UpdateSampleCounts();
77 } 70 }
78 71
79 void QualityScaler::ReportQP(int qp) { 72 void QualityScaler::ReportQP(int qp) {
80 framedrop_percent_.AddSample(0); 73 framedrop_percent_.AddSample(0);
81 average_qp_downscale_.AddSample(qp); 74 average_qp_downscale_.AddSample(qp);
82 average_qp_upscale_.AddSample(qp); 75 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()); 144 scaled_frame_.set_render_time_ms(frame.render_time_ms());
152 145
153 return scaled_frame_; 146 return scaled_frame_;
154 } 147 }
155 148
156 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) { 149 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) {
157 assert(downscale_shift_ >= 0); 150 assert(downscale_shift_ >= 0);
158 res_.width = frame_width; 151 res_.width = frame_width;
159 res_.height = frame_height; 152 res_.height = frame_height;
160 for (int shift = downscale_shift_; 153 for (int shift = downscale_shift_;
161 shift > 0 && (res_.width / 2 >= min_width_) && 154 shift > 0 && (res_.width / 2 >= kMinDownscaleDimension) &&
162 (res_.height / 2 >= min_height_); 155 (res_.height / 2 >= kMinDownscaleDimension);
163 --shift) { 156 --shift) {
164 res_.width /= 2; 157 res_.width /= 2;
165 res_.height /= 2; 158 res_.height /= 2;
166 } 159 }
167 } 160 }
168 161
169 void QualityScaler::ClearSamples() { 162 void QualityScaler::ClearSamples() {
170 framedrop_percent_.Reset(); 163 framedrop_percent_.Reset();
171 average_qp_downscale_.Reset(); 164 average_qp_downscale_.Reset();
172 average_qp_upscale_.Reset(); 165 average_qp_upscale_.Reset();
(...skipping 12 matching lines...) Expand all
185 downscale_shift_ = 0; 178 downscale_shift_ = 0;
186 if (!up) { 179 if (!up) {
187 // Hit first downscale, start using a slower threshold for going up. 180 // Hit first downscale, start using a slower threshold for going up.
188 measure_seconds_upscale_ = kMeasureSecondsUpscale; 181 measure_seconds_upscale_ = kMeasureSecondsUpscale;
189 UpdateSampleCounts(); 182 UpdateSampleCounts();
190 } 183 }
191 ClearSamples(); 184 ClearSamples();
192 } 185 }
193 186
194 } // namespace webrtc 187 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698