Erik Språng | 7ca375c | 2019-02-06 16:20:17 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019 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 VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_ |
| 12 | #define VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_ |
| 13 | |
| 14 | #include <deque> |
| 15 | |
| 16 | #include "absl/types/optional.h" |
| 17 | #include "api/units/data_rate.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | class EncoderOvershootDetector { |
| 22 | public: |
| 23 | explicit EncoderOvershootDetector(int64_t window_size_ms); |
| 24 | ~EncoderOvershootDetector(); |
| 25 | |
| 26 | void SetTargetRate(DataRate target_bitrate, |
| 27 | double target_framerate_fps, |
| 28 | int64_t time_ms); |
| 29 | void OnEncodedFrame(size_t bytes, int64_t time_ms); |
| 30 | absl::optional<double> GetUtilizationFactor(int64_t time_ms); |
| 31 | void Reset(); |
| 32 | |
| 33 | private: |
| 34 | int64_t IdealFrameSizeBits() const; |
| 35 | void LeakBits(int64_t time_ms); |
| 36 | |
| 37 | const int64_t window_size_ms_; |
| 38 | int64_t time_last_update_ms_; |
| 39 | struct BitrateUpdate { |
| 40 | BitrateUpdate(double utilization_factor, int64_t update_time_ms) |
| 41 | : utilization_factor(utilization_factor), |
| 42 | update_time_ms(update_time_ms) {} |
| 43 | double utilization_factor; |
| 44 | int64_t update_time_ms; |
| 45 | }; |
| 46 | std::deque<BitrateUpdate> utilization_factors_; |
| 47 | double sum_utilization_factors_; |
| 48 | DataRate target_bitrate_; |
| 49 | double target_framerate_fps_; |
| 50 | int64_t buffer_level_bits_; |
| 51 | }; |
| 52 | |
| 53 | } // namespace webrtc |
| 54 | |
| 55 | #endif // VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_ |