blob: 4b6a6ad85cedab044594b371b770a71e84413c05 [file] [log] [blame]
Sergey Silkinae3144c2018-08-29 01:05:26 +02001/*
2 * Copyright (c) 2018 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 MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_
12#define MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_
13
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
15
Sergey Silkinae3144c2018-08-29 01:05:26 +020016#include "absl/types/optional.h"
17#include "rtc_base/rate_statistics.h"
18
19namespace webrtc {
20
21class FramerateController {
22 public:
23 explicit FramerateController(float target_framerate_fps);
24
25 void SetTargetRate(float target_framerate_fps);
26 float GetTargetRate();
27
28 // Advices user to drop next frame in order to reach target framerate.
29 bool DropFrame(uint32_t timestamp_ms) const;
30
31 void AddFrame(uint32_t timestamp_ms);
32
33 void Reset();
34
35 private:
36 absl::optional<float> Rate(uint32_t timestamp_ms) const;
37
38 absl::optional<float> target_framerate_fps_;
39 absl::optional<uint32_t> last_timestamp_ms_;
40 uint32_t min_frame_interval_ms_;
41 RateStatistics framerate_estimator_;
42};
43
44} // namespace webrtc
45
46#endif // MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_