Danil Chapovalov | 09860e0 | 2019-10-30 13:12:24 | [diff] [blame] | 1 | /* |
| 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 Brandt | fbf66dd | 2022-05-23 07:53:32 | [diff] [blame] | 10 | #ifndef VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ |
| 11 | #define VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ |
Danil Chapovalov | 09860e0 | 2019-10-30 13:12:24 | [diff] [blame] | 12 | |
| 13 | #include <cstdint> |
| 14 | #include <memory> |
| 15 | #include <set> |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
Rasmus Brandt | fbf66dd | 2022-05-23 07:53:32 | [diff] [blame] | 19 | // Counts number of uniquely seen frames (aka pictures, aka temporal units) |
Danil Chapovalov | 09860e0 | 2019-10-30 13:12:24 | [diff] [blame] | 20 | // identified by their rtp timestamp. |
| 21 | class 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 Titov | dcd7fc7 | 2021-08-09 11:02:57 | [diff] [blame] | 29 | // Returns number of different `timestamp` passed to the UniqueCounter. |
Danil Chapovalov | 09860e0 | 2019-10-30 13:12:24 | [diff] [blame] | 30 | 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 Brandt | fbf66dd | 2022-05-23 07:53:32 | [diff] [blame] | 44 | #endif // VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ |