blob: 371ffd419f39487f40debce938654b4d3bfb2cbf [file] [log] [blame]
Åsa Persson062acd92021-08-16 09:33:13 +02001/*
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
18namespace webrtc {
19
20// Determines which frames that should be dropped based on input framerate and
21// requested framerate.
22class FramerateController {
23 public:
24 FramerateController();
Åsa Persson59947d22021-08-26 12:04:27 +020025 explicit FramerateController(double max_framerate);
Åsa Persson062acd92021-08-16 09:33:13 +020026 ~FramerateController();
27
28 // Sets max framerate (default is maxdouble).
29 void SetMaxFramerate(double max_framerate);
Åsa Persson59947d22021-08-26 12:04:27 +020030 double GetMaxFramerate() const;
Åsa Persson062acd92021-08-16 09:33:13 +020031
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 Persson59947d22021-08-26 12:04:27 +020037 void KeepFrame(int64_t in_timestamp_ns);
38
Åsa Persson062acd92021-08-16 09:33:13 +020039 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_