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 | |
kthelgason | 478681e | 2016-09-28 08:17:43 -0700 | [diff] [blame^] | 14 | #include "webrtc/common_types.h" |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 15 | #include "webrtc/common_video/include/i420_buffer_pool.h" |
kjellander@webrtc.org | b7ce964 | 2015-11-18 23:04:10 +0100 | [diff] [blame] | 16 | #include "webrtc/modules/video_coding/utility/moving_average.h" |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | class QualityScaler { |
| 20 | public: |
| 21 | struct Resolution { |
| 22 | int width; |
| 23 | int height; |
| 24 | }; |
| 25 | |
| 26 | QualityScaler(); |
kthelgason | 478681e | 2016-09-28 08:17:43 -0700 | [diff] [blame^] | 27 | void Init(VideoCodecType codec_type, |
| 28 | int initial_bitrate_kbps, |
| 29 | int width, |
| 30 | int height, |
| 31 | int fps); |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 32 | void Init(int low_qp_threshold, |
| 33 | int high_qp_threshold, |
Alex Glaznev | a9d0892 | 2016-02-19 15:24:06 -0800 | [diff] [blame] | 34 | int initial_bitrate_kbps, |
| 35 | int width, |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 36 | int height, |
| 37 | int fps); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 38 | void ReportFramerate(int framerate); |
jackychen | 98d8cf5 | 2015-05-21 11:12:02 -0700 | [diff] [blame] | 39 | void ReportQP(int qp); |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 40 | void ReportDroppedFrame(); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 41 | void OnEncodeFrame(int width, int height); |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 42 | Resolution GetScaledResolution() const; |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 43 | rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer( |
| 44 | const rtc::scoped_refptr<VideoFrameBuffer>& frame); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 45 | int downscale_shift() const { return downscale_shift_; } |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 46 | |
| 47 | private: |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 48 | void ClearSamples(); |
kthelgason | 194f40a | 2016-09-14 02:14:58 -0700 | [diff] [blame] | 49 | void ScaleUp(); |
| 50 | void ScaleDown(); |
| 51 | void UpdateTargetResolution(int width, int height); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 52 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 53 | I420BufferPool pool_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 54 | |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 55 | size_t num_samples_downscale_; |
| 56 | size_t num_samples_upscale_; |
kthelgason | 194f40a | 2016-09-14 02:14:58 -0700 | [diff] [blame] | 57 | bool fast_rampup_; |
| 58 | MovingAverage average_qp_; |
| 59 | MovingAverage framedrop_percent_; |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 60 | |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 61 | int low_qp_threshold_; |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 62 | int high_qp_threshold_; |
kthelgason | 194f40a | 2016-09-14 02:14:58 -0700 | [diff] [blame] | 63 | Resolution target_res_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 64 | |
| 65 | int downscale_shift_; |
kthelgason | 194f40a | 2016-09-14 02:14:58 -0700 | [diff] [blame] | 66 | int maximum_shift_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace webrtc |
| 70 | |
| 71 | #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |