blob: 8a08d1db65c1bf1d69ae0a3ed0b6de2125e76319 [file] [log] [blame]
Danil Chapovalov09860e02019-10-30 14:12:24 +01001/*
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 */
10#ifndef MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
11#define MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
12
13#include <cstdint>
14#include <memory>
15#include <set>
16
17namespace webrtc {
18
19// Counts number of uniquly seen frames (aka pictures, aka temporal units)
20// 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);
29 // Returns number of different |timestamp| passed to the UniqueCounter.
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
44#endif // MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_