framerate_controller.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  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. #ifndef MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_
  11. #define MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_
  12. #include <stdint.h>
  13. #include "absl/types/optional.h"
  14. #include "rtc_base/rate_statistics.h"
  15. namespace webrtc {
  16. class FramerateController {
  17. public:
  18. explicit FramerateController(float target_framerate_fps);
  19. void SetTargetRate(float target_framerate_fps);
  20. float GetTargetRate();
  21. // Advices user to drop next frame in order to reach target framerate.
  22. bool DropFrame(uint32_t timestamp_ms) const;
  23. void AddFrame(uint32_t timestamp_ms);
  24. void Reset();
  25. private:
  26. absl::optional<float> Rate(uint32_t timestamp_ms) const;
  27. absl::optional<float> target_framerate_fps_;
  28. absl::optional<uint32_t> last_timestamp_ms_;
  29. uint32_t min_frame_interval_ms_;
  30. RateStatistics framerate_estimator_;
  31. };
  32. } // namespace webrtc
  33. #endif // MODULES_VIDEO_CODING_UTILITY_FRAMERATE_CONTROLLER_H_