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 | |
| 14 | #include <list> |
| 15 | |
| 16 | #include "webrtc/common_video/libyuv/include/scaler.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | class QualityScaler { |
| 20 | public: |
| 21 | struct Resolution { |
| 22 | int width; |
| 23 | int height; |
| 24 | }; |
| 25 | |
| 26 | QualityScaler(); |
| 27 | void Init(int max_qp); |
| 28 | |
| 29 | void ReportFramerate(int framerate); |
| 30 | void ReportEncodedFrame(int qp); |
| 31 | void ReportDroppedFrame(); |
| 32 | |
| 33 | Resolution GetScaledResolution(const I420VideoFrame& frame); |
| 34 | const I420VideoFrame& GetScaledFrame(const I420VideoFrame& frame); |
| 35 | |
| 36 | private: |
| 37 | class MovingAverage { |
| 38 | public: |
| 39 | MovingAverage(); |
| 40 | void AddSample(int sample); |
| 41 | bool GetAverage(size_t num_samples, int* average); |
| 42 | void Reset(); |
| 43 | |
| 44 | private: |
| 45 | int sum_; |
| 46 | std::list<int> samples_; |
| 47 | }; |
| 48 | |
| 49 | void AdjustScale(bool up); |
| 50 | void ClearSamples(); |
| 51 | |
| 52 | Scaler scaler_; |
| 53 | I420VideoFrame scaled_frame_; |
| 54 | |
| 55 | size_t num_samples_; |
| 56 | int low_qp_threshold_; |
| 57 | MovingAverage average_qp_; |
| 58 | MovingAverage framedrop_percent_; |
| 59 | |
| 60 | int downscale_shift_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace webrtc |
| 64 | |
| 65 | #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |