diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/common_video/frame_rate_estimator.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/common_video/frame_rate_estimator.h')
-rw-r--r-- | third_party/libwebrtc/common_video/frame_rate_estimator.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/third_party/libwebrtc/common_video/frame_rate_estimator.h b/third_party/libwebrtc/common_video/frame_rate_estimator.h new file mode 100644 index 0000000000..95219a534d --- /dev/null +++ b/third_party/libwebrtc/common_video/frame_rate_estimator.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef COMMON_VIDEO_FRAME_RATE_ESTIMATOR_H_ +#define COMMON_VIDEO_FRAME_RATE_ESTIMATOR_H_ + +#include <deque> + +#include "absl/types/optional.h" +#include "api/units/time_delta.h" +#include "api/units/timestamp.h" + +namespace webrtc { + +// Class used to estimate a frame-rate using inter-frame intervals. +// Some notes on usage: +// This class is intended to accurately estimate the frame rate during a +// continuous stream. Unlike a traditional rate estimator that looks at number +// of data points within a time window, if the input stops this implementation +// will not smoothly fall down towards 0. This is done so that the estimated +// fps is not affected by edge conditions like if we sample just before or just +// after the next frame. +// To avoid problems if a stream is stopped and restarted (where estimated fps +// could look too low), users of this class should explicitly call Reset() on +// restart. +// Also note that this class is not thread safe, it's up to the user to guard +// against concurrent access. +class FrameRateEstimator { + public: + explicit FrameRateEstimator(TimeDelta averaging_window); + + // Insert a frame, potentially culling old frames that falls outside the + // averaging window. + void OnFrame(Timestamp time); + + // Get the current average FPS, based on the frames currently in the window. + absl::optional<double> GetAverageFps() const; + + // Move the window so it ends at `now`, and return the new fps estimate. + absl::optional<double> GetAverageFps(Timestamp now); + + // Completely clear the averaging window. + void Reset(); + + private: + void CullOld(Timestamp now); + const TimeDelta averaging_window_; + std::deque<Timestamp> frame_times_; +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_FRAME_RATE_ESTIMATOR_H_ |