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_types.h" | 14 #include "webrtc/common_types.h" |
15 #include "webrtc/video_frame.h" | |
16 #include "webrtc/base/sequenced_task_checker.h" | |
15 #include "webrtc/common_video/include/i420_buffer_pool.h" | 17 #include "webrtc/common_video/include/i420_buffer_pool.h" |
16 #include "webrtc/modules/video_coding/utility/moving_average.h" | 18 #include "webrtc/modules/video_coding/utility/moving_average.h" |
17 | 19 |
18 namespace webrtc { | 20 namespace webrtc { |
21 | |
22 // An interface for a class that receives scale up/down requests. | |
23 class ScalingInterface { | |
kthelgason
2016/10/06 14:34:13
It may make sense to place this somewhere else. So
| |
24 public: | |
25 // Called as soon as an overuse is detected. | |
26 virtual void ScaleUp() = 0; | |
27 // Called periodically when the system is not overused any longer. | |
28 virtual void ScaleDown() = 0; | |
29 | |
30 protected: | |
31 virtual ~ScalingInterface() {} | |
32 }; | |
33 | |
19 class QualityScaler { | 34 class QualityScaler { |
20 public: | 35 public: |
21 struct Resolution { | 36 struct Resolution { |
22 int width; | 37 int width; |
23 int height; | 38 int height; |
24 }; | 39 }; |
25 | 40 |
26 QualityScaler(); | 41 QualityScaler(); |
27 void Init(VideoCodecType codec_type, | 42 virtual ~QualityScaler(); |
28 int initial_bitrate_kbps, | 43 void Init(ScalingInterface* obeserver_, VideoCodecType codec_type, int fps); |
29 int width, | 44 void Init(ScalingInterface* obeserver_, |
30 int height, | 45 int low_qp_threshold, |
46 int high_qp_threshold, | |
31 int fps); | 47 int fps); |
32 void Init(int low_qp_threshold, | 48 void Stop(); |
33 int high_qp_threshold, | |
34 int initial_bitrate_kbps, | |
35 int width, | |
36 int height, | |
37 int fps); | |
38 void ReportFramerate(int framerate); | 49 void ReportFramerate(int framerate); |
50 void ReportDroppedFrame(); | |
39 void ReportQP(int qp); | 51 void ReportQP(int qp); |
40 void ReportDroppedFrame(); | 52 void CheckQP(); |
41 void OnEncodeFrame(int width, int height); | 53 // This method declared virtual to help with testing. |
42 Resolution GetScaledResolution() const; | 54 virtual int64_t GetTimeoutMs(); |
43 rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer( | |
44 const rtc::scoped_refptr<VideoFrameBuffer>& frame); | |
45 int downscale_shift() const { return downscale_shift_; } | |
46 | 55 |
47 private: | 56 private: |
57 class CheckQPTask; | |
48 void ClearSamples(); | 58 void ClearSamples(); |
49 void ScaleUp(); | 59 void ReportQPLow(); |
50 void ScaleDown(); | 60 void ReportQPHigh(); |
51 void UpdateTargetResolution(int width, int height); | |
52 | 61 |
53 I420BufferPool pool_; | 62 ScalingInterface* observer_; |
63 CheckQPTask* check_qp_task_; | |
64 rtc::SequencedTaskChecker task_checker_; | |
54 | 65 |
55 size_t num_samples_downscale_; | |
56 size_t num_samples_upscale_; | |
57 bool fast_rampup_; | 66 bool fast_rampup_; |
67 int64_t measure_interval_; | |
58 MovingAverage average_qp_; | 68 MovingAverage average_qp_; |
59 MovingAverage framedrop_percent_; | 69 MovingAverage framedrop_percent_; |
60 | 70 |
61 int low_qp_threshold_; | 71 int low_qp_threshold_; |
62 int high_qp_threshold_; | 72 int high_qp_threshold_; |
63 Resolution target_res_; | |
64 | |
65 int downscale_shift_; | |
66 int maximum_shift_; | |
67 }; | 73 }; |
68 | 74 |
69 } // namespace webrtc | 75 } // namespace webrtc |
70 | 76 |
71 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ | 77 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ |
OLD | NEW |