xref: /aosp_15_r20/external/webrtc/common_video/framerate_controller.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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();
25   explicit FramerateController(double max_framerate);
26   ~FramerateController();
27 
28   // Sets max framerate (default is maxdouble).
29   void SetMaxFramerate(double max_framerate);
30   double GetMaxFramerate() const;
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 
37   void KeepFrame(int64_t in_timestamp_ns);
38 
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_
47