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 11 #include "modules/video_coding/unique_timestamp_counter.h" 12 13 #include <cstdint> 14 #include <memory> 15 #include <set> 16 17 namespace webrtc { 18 namespace { 19 20 constexpr int kMaxHistory = 1000; 21 22 } // namespace 23 UniqueTimestampCounter()24UniqueTimestampCounter::UniqueTimestampCounter() 25 : latest_(std::make_unique<uint32_t[]>(kMaxHistory)) {} 26 Add(uint32_t value)27void UniqueTimestampCounter::Add(uint32_t value) { 28 if (value == last_ || !search_index_.insert(value).second) { 29 // Already known. 30 return; 31 } 32 int index = unique_seen_ % kMaxHistory; 33 if (unique_seen_ >= kMaxHistory) { 34 search_index_.erase(latest_[index]); 35 } 36 latest_[index] = value; 37 last_ = value; 38 ++unique_seen_; 39 } 40 41 } // namespace webrtc 42