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 */ 10 #ifndef VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ 11 #define VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ 12 13 #include <cstdint> 14 #include <memory> 15 #include <set> 16 17 namespace webrtc { 18 19 // Counts number of uniquely seen frames (aka pictures, aka temporal units) 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); 29 // Returns number of different `timestamp` passed to the UniqueCounter. GetUniqueSeen()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 // VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_ 45