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

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

Issue 1971693003: Clamp number of downscales in QualityScaler. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: zero out initial resolution Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 if (initial_bitrate_kbps < kVgaBitrateThresholdKbps) 53 if (initial_bitrate_kbps < kVgaBitrateThresholdKbps)
54 init_num_pixels = kVgaNumPixels; 54 init_num_pixels = kVgaNumPixels;
55 if (initial_bitrate_kbps < kQvgaBitrateThresholdKbps) 55 if (initial_bitrate_kbps < kQvgaBitrateThresholdKbps)
56 init_num_pixels = kQvgaNumPixels; 56 init_num_pixels = kQvgaNumPixels;
57 while (width * height > init_num_pixels) { 57 while (width * height > init_num_pixels) {
58 ++downscale_shift_; 58 ++downscale_shift_;
59 width /= 2; 59 width /= 2;
60 height /= 2; 60 height /= 2;
61 } 61 }
62 } 62 }
63
64 // Zero out width/height so they can be checked against inside
65 // UpdateTargetResolution.
66 res_.width = res_.height = 0;
63 UpdateTargetResolution(init_width, init_height); 67 UpdateTargetResolution(init_width, init_height);
64 ReportFramerate(fps); 68 ReportFramerate(fps);
65 } 69 }
66 70
67 // Report framerate(fps) to estimate # of samples. 71 // Report framerate(fps) to estimate # of samples.
68 void QualityScaler::ReportFramerate(int framerate) { 72 void QualityScaler::ReportFramerate(int framerate) {
69 framerate_ = framerate; 73 framerate_ = framerate;
70 UpdateSampleCounts(); 74 UpdateSampleCounts();
71 } 75 }
72 76
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 scaled_frame_.set_ntp_time_ms(frame.ntp_time_ms()); 128 scaled_frame_.set_ntp_time_ms(frame.ntp_time_ms());
125 scaled_frame_.set_timestamp(frame.timestamp()); 129 scaled_frame_.set_timestamp(frame.timestamp());
126 scaled_frame_.set_render_time_ms(frame.render_time_ms()); 130 scaled_frame_.set_render_time_ms(frame.render_time_ms());
127 scaled_frame_.set_rotation(frame.rotation()); 131 scaled_frame_.set_rotation(frame.rotation());
128 132
129 return scaled_frame_; 133 return scaled_frame_;
130 } 134 }
131 135
132 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) { 136 void QualityScaler::UpdateTargetResolution(int frame_width, int frame_height) {
133 assert(downscale_shift_ >= 0); 137 assert(downscale_shift_ >= 0);
138 int shifts_performed = 0;
139 for (int shift = downscale_shift_;
140 shift > 0 && (frame_width / 2 >= kMinDownscaleDimension) &&
141 (frame_height / 2 >= kMinDownscaleDimension);
142 --shift, ++shifts_performed) {
143 frame_width /= 2;
144 frame_height /= 2;
145 }
146 // Clamp to number of shifts actually performed to not be stuck trying to
147 // scale way beyond QVGA.
148 downscale_shift_ = shifts_performed;
149 if (res_.width == frame_width && res_.height == frame_height) {
150 // No reset done/needed, using same resolution.
151 return;
152 }
134 res_.width = frame_width; 153 res_.width = frame_width;
135 res_.height = frame_height; 154 res_.height = frame_height;
136 for (int shift = downscale_shift_; 155 ClearSamples();
137 shift > 0 && (res_.width / 2 >= kMinDownscaleDimension) &&
138 (res_.height / 2 >= kMinDownscaleDimension);
139 --shift) {
140 res_.width /= 2;
141 res_.height /= 2;
142 }
143 } 156 }
144 157
145 void QualityScaler::ClearSamples() { 158 void QualityScaler::ClearSamples() {
146 framedrop_percent_.Reset(); 159 framedrop_percent_.Reset();
147 average_qp_downscale_.Reset(); 160 average_qp_downscale_.Reset();
148 average_qp_upscale_.Reset(); 161 average_qp_upscale_.Reset();
149 } 162 }
150 163
151 void QualityScaler::UpdateSampleCounts() { 164 void QualityScaler::UpdateSampleCounts() {
152 num_samples_downscale_ = static_cast<size_t>( 165 num_samples_downscale_ = static_cast<size_t>(
153 kMeasureSecondsDownscale * (framerate_ < kMinFps ? kMinFps : framerate_)); 166 kMeasureSecondsDownscale * (framerate_ < kMinFps ? kMinFps : framerate_));
154 num_samples_upscale_ = static_cast<size_t>( 167 num_samples_upscale_ = static_cast<size_t>(
155 measure_seconds_upscale_ * (framerate_ < kMinFps ? kMinFps : framerate_)); 168 measure_seconds_upscale_ * (framerate_ < kMinFps ? kMinFps : framerate_));
156 } 169 }
157 170
158 void QualityScaler::AdjustScale(bool up) { 171 void QualityScaler::AdjustScale(bool up) {
159 downscale_shift_ += up ? -1 : 1; 172 downscale_shift_ += up ? -1 : 1;
160 if (downscale_shift_ < 0) 173 if (downscale_shift_ < 0)
161 downscale_shift_ = 0; 174 downscale_shift_ = 0;
162 if (!up) { 175 if (!up) {
163 // Hit first downscale, start using a slower threshold for going up. 176 // First downscale hit, start using a slower threshold for going up.
164 measure_seconds_upscale_ = kMeasureSecondsUpscale; 177 measure_seconds_upscale_ = kMeasureSecondsUpscale;
165 UpdateSampleCounts(); 178 UpdateSampleCounts();
166 } 179 }
167 ClearSamples();
168 } 180 }
169 181
170 } // namespace webrtc 182 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698