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 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 14 | #include "webrtc/common_video/include/i420_buffer_pool.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: |
| 20 | struct Resolution { |
| 21 | int width; |
| 22 | int height; |
| 23 | }; |
| 24 | |
| 25 | QualityScaler(); |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 26 | void Init(int low_qp_threshold, |
| 27 | int high_qp_threshold, |
Alex Glaznev | a9d0892 | 2016-02-19 15:24:06 -0800 | [diff] [blame] | 28 | int initial_bitrate_kbps, |
| 29 | int width, |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 30 | int height, |
| 31 | int fps); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 32 | void ReportFramerate(int framerate); |
jackychen | 98d8cf5 | 2015-05-21 11:12:02 -0700 | [diff] [blame] | 33 | void ReportQP(int qp); |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 34 | void ReportDroppedFrame(); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 35 | void OnEncodeFrame(int width, int height); |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 36 | Resolution GetScaledResolution() const; |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 37 | rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer( |
| 38 | const rtc::scoped_refptr<VideoFrameBuffer>& frame); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 39 | int downscale_shift() const { return downscale_shift_; } |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 40 | |
pbos | 1f53452 | 2016-05-13 11:05:35 -0700 | [diff] [blame] | 41 | // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the |
| 42 | // bitstream range of [0, 127] and not the user-level range of [0,63]. |
| 43 | static const int kLowVp8QpThreshold; |
| 44 | static const int kBadVp8QpThreshold; |
| 45 | |
| 46 | // H264 QP is in the range [0, 51]. |
| 47 | static const int kLowH264QpThreshold; |
| 48 | static const int kBadH264QpThreshold; |
| 49 | |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 50 | private: |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 51 | void AdjustScale(bool up); |
Peter Boström | 01bcbd0 | 2016-03-22 21:44:29 +0100 | [diff] [blame] | 52 | void UpdateTargetResolution(int frame_width, int frame_height); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 53 | void ClearSamples(); |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 54 | void UpdateSampleCounts(); |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 55 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 56 | I420BufferPool pool_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 57 | |
pbos | cbac40d | 2016-04-13 02:51:02 -0700 | [diff] [blame] | 58 | size_t num_samples_downscale_; |
| 59 | size_t num_samples_upscale_; |
| 60 | int measure_seconds_upscale_; |
| 61 | MovingAverage<int> average_qp_upscale_; |
| 62 | MovingAverage<int> average_qp_downscale_; |
| 63 | |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 64 | int framerate_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 65 | int low_qp_threshold_; |
Peter Boström | 1741770 | 2015-09-25 17:03:26 +0200 | [diff] [blame] | 66 | int high_qp_threshold_; |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 67 | MovingAverage<int> framedrop_percent_; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 68 | Resolution res_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 69 | |
| 70 | int downscale_shift_; |
pbos@webrtc.org | a0d7827 | 2014-09-12 11:51:47 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace webrtc |
| 74 | |
| 75 | #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |