unique_timestamp_counter.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
  11. #define MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
  12. #include <cstdint>
  13. #include <memory>
  14. #include <set>
  15. namespace webrtc {
  16. // Counts number of uniquly seen frames (aka pictures, aka temporal units)
  17. // identified by their rtp timestamp.
  18. class UniqueTimestampCounter {
  19. public:
  20. UniqueTimestampCounter();
  21. UniqueTimestampCounter(const UniqueTimestampCounter&) = delete;
  22. UniqueTimestampCounter& operator=(const UniqueTimestampCounter&) = delete;
  23. ~UniqueTimestampCounter() = default;
  24. void Add(uint32_t timestamp);
  25. // Returns number of different |timestamp| passed to the UniqueCounter.
  26. int GetUniqueSeen() const { return unique_seen_; }
  27. private:
  28. int unique_seen_ = 0;
  29. // Stores several last seen unique values for quick search.
  30. std::set<uint32_t> search_index_;
  31. // The same unique values in the circular buffer in the insertion order.
  32. std::unique_ptr<uint32_t[]> latest_;
  33. // Last inserted value for optimization purpose.
  34. int64_t last_ = -1;
  35. };
  36. } // namespace webrtc
  37. #endif // MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_