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

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

Issue 1160403004: Add default downscale threshold to QualityScaler. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: requested tests Created 5 years, 6 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/include/quality_scaler.h" 10 #include "webrtc/modules/video_coding/utility/include/quality_scaler.h"
11 11
12 namespace webrtc { 12 namespace webrtc {
13 13
14 static const int kMinFps = 10; 14 static const int kMinFps = 10;
15 static const int kMeasureSeconds = 5; 15 static const int kMeasureSeconds = 5;
16 static const int kFramedropPercentThreshold = 60; 16 static const int kFramedropPercentThreshold = 60;
17 17
18 const int QualityScaler::kDefaultLowQpDenominator = 3;
19 // Note that this is the same for width and height to permit 120x90 in both
20 // portrait and landscape mode.
21 const int QualityScaler::kDefaultMinDownscaleDimension = 90;
22
18 QualityScaler::QualityScaler() 23 QualityScaler::QualityScaler()
19 : num_samples_(0), low_qp_threshold_(-1), downscale_shift_(0), 24 : num_samples_(0),
20 min_width_(0), min_height_(0) { 25 low_qp_threshold_(-1),
26 downscale_shift_(0),
27 min_width_(kDefaultMinDownscaleDimension),
28 min_height_(kDefaultMinDownscaleDimension) {
21 } 29 }
22 30
23 void QualityScaler::Init(int low_qp_threshold) { 31 void QualityScaler::Init(int low_qp_threshold) {
24 ClearSamples(); 32 ClearSamples();
25 low_qp_threshold_ = low_qp_threshold; 33 low_qp_threshold_ = low_qp_threshold;
26 } 34 }
27 35
28 void QualityScaler::SetMinResolution(int min_width, int min_height) { 36 void QualityScaler::SetMinResolution(int min_width, int min_height) {
29 min_width_ = min_width; 37 min_width_ = min_width;
30 min_height_ = min_height; 38 min_height_ = min_height;
(...skipping 30 matching lines...) Expand all
61 if (framedrop_percent_.GetAverage(num_samples_, &avg_drop) && 69 if (framedrop_percent_.GetAverage(num_samples_, &avg_drop) &&
62 avg_drop >= kFramedropPercentThreshold) { 70 avg_drop >= kFramedropPercentThreshold) {
63 AdjustScale(false); 71 AdjustScale(false);
64 } else if (average_qp_.GetAverage(num_samples_, &avg_qp) && 72 } else if (average_qp_.GetAverage(num_samples_, &avg_qp) &&
65 avg_qp <= low_qp_threshold_) { 73 avg_qp <= low_qp_threshold_) {
66 AdjustScale(true); 74 AdjustScale(true);
67 } 75 }
68 76
69 assert(downscale_shift_ >= 0); 77 assert(downscale_shift_ >= 0);
70 for (int shift = downscale_shift_; 78 for (int shift = downscale_shift_;
71 shift > 0 && res.width > 1 && res.height > 1; 79 shift > 0 && (res.width >> 1 >= min_width_) &&
80 (res.height >> 1 >= min_height_);
72 --shift) { 81 --shift) {
73 res.width >>= 1; 82 res.width >>= 1;
74 res.height >>= 1; 83 res.height >>= 1;
75 } 84 }
76 85
77 // Set this limitation for VP8 HW encoder to avoid crash.
78 if (min_width_ > 0 && res.width * res.height < min_width_ * min_height_) {
79 res.width = min_width_;
80 res.height = min_height_;
81 }
82
83 return res; 86 return res;
84 } 87 }
85 88
86 const VideoFrame& QualityScaler::GetScaledFrame(const VideoFrame& frame) { 89 const VideoFrame& QualityScaler::GetScaledFrame(const VideoFrame& frame) {
87 Resolution res = GetScaledResolution(frame); 90 Resolution res = GetScaledResolution(frame);
88 if (res.width == frame.width()) 91 if (res.width == frame.width())
89 return frame; 92 return frame;
90 93
91 scaler_.Set(frame.width(), 94 scaler_.Set(frame.width(),
92 frame.height(), 95 frame.height(),
(...skipping 18 matching lines...) Expand all
111 } 114 }
112 115
113 void QualityScaler::AdjustScale(bool up) { 116 void QualityScaler::AdjustScale(bool up) {
114 downscale_shift_ += up ? -1 : 1; 117 downscale_shift_ += up ? -1 : 1;
115 if (downscale_shift_ < 0) 118 if (downscale_shift_ < 0)
116 downscale_shift_ = 0; 119 downscale_shift_ = 0;
117 ClearSamples(); 120 ClearSamples();
118 } 121 }
119 122
120 } // namespace webrtc 123 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698