| 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 | 10 |
| 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
| 12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
| 13 | 13 |
| 14 #include "webrtc/common_video/libyuv/include/scaler.h" | 14 #include "webrtc/common_video/include/i420_buffer_pool.h" |
| 15 #include "webrtc/modules/video_coding/utility/moving_average.h" | 15 #include "webrtc/modules/video_coding/utility/moving_average.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 class QualityScaler { | 18 class QualityScaler { |
| 19 public: | 19 public: |
| 20 struct Resolution { | 20 struct Resolution { |
| 21 int width; | 21 int width; |
| 22 int height; | 22 int height; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 QualityScaler(); | 25 QualityScaler(); |
| 26 void Init(int low_qp_threshold, | 26 void Init(int low_qp_threshold, |
| 27 int high_qp_threshold, | 27 int high_qp_threshold, |
| 28 int initial_bitrate_kbps, | 28 int initial_bitrate_kbps, |
| 29 int width, | 29 int width, |
| 30 int height, | 30 int height, |
| 31 int fps); | 31 int fps); |
| 32 void ReportFramerate(int framerate); | 32 void ReportFramerate(int framerate); |
| 33 void ReportQP(int qp); | 33 void ReportQP(int qp); |
| 34 void ReportDroppedFrame(); | 34 void ReportDroppedFrame(); |
| 35 void OnEncodeFrame(const VideoFrame& frame); | 35 void OnEncodeFrame(int width, int height); |
| 36 Resolution GetScaledResolution() const; | 36 Resolution GetScaledResolution() const; |
| 37 const VideoFrame& GetScaledFrame(const VideoFrame& frame); | 37 rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer( |
| 38 const rtc::scoped_refptr<VideoFrameBuffer>& frame); |
| 38 int downscale_shift() const { return downscale_shift_; } | 39 int downscale_shift() const { return downscale_shift_; } |
| 39 | 40 |
| 40 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the | 41 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the |
| 41 // bitstream range of [0, 127] and not the user-level range of [0,63]. | 42 // bitstream range of [0, 127] and not the user-level range of [0,63]. |
| 42 static const int kLowVp8QpThreshold; | 43 static const int kLowVp8QpThreshold; |
| 43 static const int kBadVp8QpThreshold; | 44 static const int kBadVp8QpThreshold; |
| 44 | 45 |
| 45 // H264 QP is in the range [0, 51]. | 46 // H264 QP is in the range [0, 51]. |
| 46 static const int kLowH264QpThreshold; | 47 static const int kLowH264QpThreshold; |
| 47 static const int kBadH264QpThreshold; | 48 static const int kBadH264QpThreshold; |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 void AdjustScale(bool up); | 51 void AdjustScale(bool up); |
| 51 void UpdateTargetResolution(int frame_width, int frame_height); | 52 void UpdateTargetResolution(int frame_width, int frame_height); |
| 52 void ClearSamples(); | 53 void ClearSamples(); |
| 53 void UpdateSampleCounts(); | 54 void UpdateSampleCounts(); |
| 54 | 55 |
| 55 Scaler scaler_; | 56 I420BufferPool pool_; |
| 56 VideoFrame scaled_frame_; | |
| 57 | 57 |
| 58 size_t num_samples_downscale_; | 58 size_t num_samples_downscale_; |
| 59 size_t num_samples_upscale_; | 59 size_t num_samples_upscale_; |
| 60 int measure_seconds_upscale_; | 60 int measure_seconds_upscale_; |
| 61 MovingAverage<int> average_qp_upscale_; | 61 MovingAverage<int> average_qp_upscale_; |
| 62 MovingAverage<int> average_qp_downscale_; | 62 MovingAverage<int> average_qp_downscale_; |
| 63 | 63 |
| 64 int framerate_; | 64 int framerate_; |
| 65 int low_qp_threshold_; | 65 int low_qp_threshold_; |
| 66 int high_qp_threshold_; | 66 int high_qp_threshold_; |
| 67 MovingAverage<int> framedrop_percent_; | 67 MovingAverage<int> framedrop_percent_; |
| 68 Resolution res_; | 68 Resolution res_; |
| 69 | 69 |
| 70 int downscale_shift_; | 70 int downscale_shift_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 } // namespace webrtc | 73 } // namespace webrtc |
| 74 | 74 |
| 75 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ | 75 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
| OLD | NEW |