Åsa Persson | 062acd9 | 2021-08-16 09:33:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 COMMON_VIDEO_FRAMERATE_CONTROLLER_H_ |
| 12 | #define COMMON_VIDEO_FRAMERATE_CONTROLLER_H_ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | |
| 16 | #include "absl/types/optional.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Determines which frames that should be dropped based on input framerate and |
| 21 | // requested framerate. |
| 22 | class FramerateController { |
| 23 | public: |
| 24 | FramerateController(); |
Åsa Persson | 59947d2 | 2021-08-26 12:04:27 +0200 | [diff] [blame] | 25 | explicit FramerateController(double max_framerate); |
Åsa Persson | 062acd9 | 2021-08-16 09:33:13 +0200 | [diff] [blame] | 26 | ~FramerateController(); |
| 27 | |
| 28 | // Sets max framerate (default is maxdouble). |
| 29 | void SetMaxFramerate(double max_framerate); |
Åsa Persson | 59947d2 | 2021-08-26 12:04:27 +0200 | [diff] [blame] | 30 | double GetMaxFramerate() const; |
Åsa Persson | 062acd9 | 2021-08-16 09:33:13 +0200 | [diff] [blame] | 31 | |
| 32 | // Returns true if the frame should be dropped, false otherwise. |
| 33 | bool ShouldDropFrame(int64_t in_timestamp_ns); |
| 34 | |
| 35 | void Reset(); |
| 36 | |
Åsa Persson | 59947d2 | 2021-08-26 12:04:27 +0200 | [diff] [blame] | 37 | void KeepFrame(int64_t in_timestamp_ns); |
| 38 | |
Åsa Persson | 062acd9 | 2021-08-16 09:33:13 +0200 | [diff] [blame] | 39 | private: |
| 40 | double max_framerate_; |
| 41 | absl::optional<int64_t> next_frame_timestamp_ns_; |
| 42 | }; |
| 43 | |
| 44 | } // namespace webrtc |
| 45 | |
| 46 | #endif // COMMON_VIDEO_FRAMERATE_CONTROLLER_H_ |