| 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 #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 = 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 static const int kHdResolutionThreshold = 700 * 500; | 
 |   18 static const int kHdBitrateThresholdKbps = 500; | 
|   17  |   19  | 
|   18 const int QualityScaler::kDefaultLowQpDenominator = 3; |   20 const int QualityScaler::kDefaultLowQpDenominator = 3; | 
|   19 // Note that this is the same for width and height to permit 120x90 in both |   21 // Note that this is the same for width and height to permit 120x90 in both | 
|   20 // portrait and landscape mode. |   22 // portrait and landscape mode. | 
|   21 const int QualityScaler::kDefaultMinDownscaleDimension = 90; |   23 const int QualityScaler::kDefaultMinDownscaleDimension = 90; | 
|   22  |   24  | 
|   23 QualityScaler::QualityScaler() |   25 QualityScaler::QualityScaler() | 
|   24     : num_samples_(0), |   26     : num_samples_(0), | 
|   25       low_qp_threshold_(-1), |   27       low_qp_threshold_(-1), | 
|   26       downscale_shift_(0), |   28       downscale_shift_(0), | 
|   27       framerate_down_(false), |   29       framerate_down_(false), | 
|   28       min_width_(kDefaultMinDownscaleDimension), |   30       min_width_(kDefaultMinDownscaleDimension), | 
|   29       min_height_(kDefaultMinDownscaleDimension) {} |   31       min_height_(kDefaultMinDownscaleDimension) {} | 
|   30  |   32  | 
|   31 void QualityScaler::Init(int low_qp_threshold, |   33 void QualityScaler::Init(int low_qp_threshold, | 
|   32                          int high_qp_threshold, |   34                          int high_qp_threshold, | 
|   33                          bool use_framerate_reduction) { |   35                          bool use_framerate_reduction, | 
 |   36                          int initial_bitrate_kbps, | 
 |   37                          int width, | 
 |   38                          int height) { | 
|   34   ClearSamples(); |   39   ClearSamples(); | 
|   35   low_qp_threshold_ = low_qp_threshold; |   40   low_qp_threshold_ = low_qp_threshold; | 
|   36   high_qp_threshold_ = high_qp_threshold; |   41   high_qp_threshold_ = high_qp_threshold; | 
|   37   use_framerate_reduction_ = use_framerate_reduction; |   42   use_framerate_reduction_ = use_framerate_reduction; | 
 |   43   // TODO(glaznev): Investigate using thresholds for other resolutions | 
 |   44   // or threshold tables. | 
 |   45   if (initial_bitrate_kbps > 0 && | 
 |   46       initial_bitrate_kbps < kHdBitrateThresholdKbps) { | 
 |   47     // Start scaling to roughly VGA. | 
 |   48     while (width * height > kHdResolutionThreshold) { | 
 |   49       ++downscale_shift_; | 
 |   50       width /= 2; | 
 |   51       height /= 2; | 
 |   52     } | 
 |   53   } | 
 |   54   res_.width = width; | 
 |   55   res_.height = height; | 
|   38   target_framerate_ = -1; |   56   target_framerate_ = -1; | 
|   39 } |   57 } | 
|   40  |   58  | 
|   41 void QualityScaler::SetMinResolution(int min_width, int min_height) { |   59 void QualityScaler::SetMinResolution(int min_width, int min_height) { | 
|   42   min_width_ = min_width; |   60   min_width_ = min_width; | 
|   43   min_height_ = min_height; |   61   min_height_ = min_height; | 
|   44 } |   62 } | 
|   45  |   63  | 
|   46 // Report framerate(fps) to estimate # of samples. |   64 // Report framerate(fps) to estimate # of samples. | 
|   47 void QualityScaler::ReportFramerate(int framerate) { |   65 void QualityScaler::ReportFramerate(int framerate) { | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  141 } |  159 } | 
|  142  |  160  | 
|  143 void QualityScaler::AdjustScale(bool up) { |  161 void QualityScaler::AdjustScale(bool up) { | 
|  144   downscale_shift_ += up ? -1 : 1; |  162   downscale_shift_ += up ? -1 : 1; | 
|  145   if (downscale_shift_ < 0) |  163   if (downscale_shift_ < 0) | 
|  146     downscale_shift_ = 0; |  164     downscale_shift_ = 0; | 
|  147   ClearSamples(); |  165   ClearSamples(); | 
|  148 } |  166 } | 
|  149  |  167  | 
|  150 }  // namespace webrtc |  168 }  // namespace webrtc | 
| OLD | NEW |