pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
| 13 | |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 14 | #include "webrtc/common_video/libyuv/include/scaler.h" |
kjellander@webrtc.org | b7ce964 | 2015-11-18 23:04:10 +0100 | [diff] [blame] | 15 | #include "webrtc/modules/video_coding/utility/moving_average.h" |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | class QualityScaler { |
| 19 | public: |
Peter Boström | 6a688f5 | 2015-06-22 08:02:58 +0200 | [diff] [blame] | 20 | static const int kDefaultLowQpDenominator; |
| 21 | static const int kDefaultMinDownscaleDimension; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 22 | struct Resolution { |
| 23 | int width; |
| 24 | int height; |
| 25 | }; |
| 26 | |
| 27 | QualityScaler(); |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 28 | void Init(int low_qp_threshold, |
| 29 | int high_qp_threshold, |
Alex Glaznev | a9d0892 | 2016-02-19 15:24:06 -0800 | [diff] [blame^] | 30 | bool use_framerate_reduction, |
| 31 | int initial_bitrate_kbps, |
| 32 | int width, |
| 33 | int height); |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 34 | void SetMinResolution(int min_width, int min_height); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 35 | void ReportFramerate(int framerate); |
jackychen | 98d8cf5 | 2015-05-21 11:12:02 -0700 | [diff] [blame] | 36 | void ReportQP(int qp); |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 37 | void ReportDroppedFrame(); |
| 38 | void Reset(int framerate, int bitrate, int width, int height); |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 39 | void OnEncodeFrame(const VideoFrame& frame); |
| 40 | Resolution GetScaledResolution() const; |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 41 | const VideoFrame& GetScaledFrame(const VideoFrame& frame); |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 42 | int GetTargetFramerate() const; |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 43 | int downscale_shift() const { return downscale_shift_; } |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 46 | void AdjustScale(bool up); |
| 47 | void ClearSamples(); |
| 48 | |
| 49 | Scaler scaler_; |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 50 | VideoFrame scaled_frame_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 51 | |
| 52 | size_t num_samples_; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 53 | int framerate_; |
| 54 | int target_framerate_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 55 | int low_qp_threshold_; |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 56 | int high_qp_threshold_; |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 57 | MovingAverage<int> framedrop_percent_; |
jackychen | 98d8cf5 | 2015-05-21 11:12:02 -0700 | [diff] [blame] | 58 | MovingAverage<int> average_qp_; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 59 | Resolution res_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 60 | |
| 61 | int downscale_shift_; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 62 | int framerate_down_; |
| 63 | bool use_framerate_reduction_; |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 64 | int min_width_; |
| 65 | int min_height_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace webrtc |
| 69 | |
| 70 | #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |