blob: 5dfb758bce1f208ce274e3c4a7ae494285647e7c [file] [log] [blame]
Danil Chapovalov09860e02019-10-30 13:12:241/*
2 * Copyright (c) 2019 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 */
Rasmus Brandtfbf66dd2022-05-23 07:53:3210#ifndef VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_
11#define VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_
Danil Chapovalov09860e02019-10-30 13:12:2412
13#include <cstdint>
14#include <memory>
15#include <set>
16
17namespace webrtc {
18
Rasmus Brandtfbf66dd2022-05-23 07:53:3219// Counts number of uniquely seen frames (aka pictures, aka temporal units)
Danil Chapovalov09860e02019-10-30 13:12:2420// identified by their rtp timestamp.
21class UniqueTimestampCounter {
22 public:
23 UniqueTimestampCounter();
24 UniqueTimestampCounter(const UniqueTimestampCounter&) = delete;
25 UniqueTimestampCounter& operator=(const UniqueTimestampCounter&) = delete;
26 ~UniqueTimestampCounter() = default;
27
28 void Add(uint32_t timestamp);
Artem Titovdcd7fc72021-08-09 11:02:5729 // Returns number of different `timestamp` passed to the UniqueCounter.
Danil Chapovalov09860e02019-10-30 13:12:2430 int GetUniqueSeen() const { return unique_seen_; }
31
32 private:
33 int unique_seen_ = 0;
34 // Stores several last seen unique values for quick search.
35 std::set<uint32_t> search_index_;
36 // The same unique values in the circular buffer in the insertion order.
37 std::unique_ptr<uint32_t[]> latest_;
38 // Last inserted value for optimization purpose.
39 int64_t last_ = -1;
40};
41
42} // namespace webrtc
43
Rasmus Brandtfbf66dd2022-05-23 07:53:3244#endif // VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_