Nagram/TMessagesProj/jni/voip/webrtc/video/unique_timestamp_counter.h

45 lines
1.5 KiB
C
Raw Normal View History

2020-08-14 16:58:22 +00:00
/*
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
2023-02-18 21:24:25 +00:00
#ifndef VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_
#define VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_
2020-08-14 16:58:22 +00:00
#include <cstdint>
#include <memory>
#include <set>
namespace webrtc {
2023-02-18 21:24:25 +00:00
// Counts number of uniquely seen frames (aka pictures, aka temporal units)
2020-08-14 16:58:22 +00:00
// identified by their rtp timestamp.
class UniqueTimestampCounter {
public:
UniqueTimestampCounter();
UniqueTimestampCounter(const UniqueTimestampCounter&) = delete;
UniqueTimestampCounter& operator=(const UniqueTimestampCounter&) = delete;
~UniqueTimestampCounter() = default;
void Add(uint32_t timestamp);
2022-03-11 16:49:54 +00:00
// Returns number of different `timestamp` passed to the UniqueCounter.
2020-08-14 16:58:22 +00:00
int GetUniqueSeen() const { return unique_seen_; }
private:
int unique_seen_ = 0;
// Stores several last seen unique values for quick search.
std::set<uint32_t> search_index_;
// The same unique values in the circular buffer in the insertion order.
std::unique_ptr<uint32_t[]> latest_;
// Last inserted value for optimization purpose.
int64_t last_ = -1;
};
} // namespace webrtc
2023-02-18 21:24:25 +00:00
#endif // VIDEO_UNIQUE_TIMESTAMP_COUNTER_H_