Move UniqueTimestampCounter to video/
This helper class currently lives in `modules/video_coding`, but it's only users are in `video/`. Thus, it makes sense to move the class to `video/`. Bug: webrtc:14116 Change-Id: I0d3f8961bc8f5fe80f3100dbbd309b206020e6d5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262963 Reviewed-by: Åsa Persson <asapersson@webrtc.org> Commit-Queue: Rasmus Brandt <brandtr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36973}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
fbfe6f08a4
commit
fbf66ddddf
@ -268,8 +268,6 @@ rtc_library("video_coding") {
|
||||
"rtp_vp9_ref_finder.h",
|
||||
"timestamp_map.cc",
|
||||
"timestamp_map.h",
|
||||
"unique_timestamp_counter.cc",
|
||||
"unique_timestamp_counter.h",
|
||||
"video_codec_initializer.cc",
|
||||
"video_receiver2.cc",
|
||||
"video_receiver2.h",
|
||||
@ -1176,7 +1174,6 @@ if (rtc_include_tests) {
|
||||
"test/stream_generator.h",
|
||||
"timestamp_map_unittest.cc",
|
||||
"timing_unittest.cc",
|
||||
"unique_timestamp_counter_unittest.cc",
|
||||
"utility/bandwidth_quality_scaler_unittest.cc",
|
||||
"utility/decoded_frames_history_unittest.cc",
|
||||
"utility/frame_dropper_unittest.cc",
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "modules/video_coding/unique_timestamp_counter.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
constexpr int kMaxHistory = 1000;
|
||||
|
||||
} // namespace
|
||||
|
||||
UniqueTimestampCounter::UniqueTimestampCounter()
|
||||
: latest_(std::make_unique<uint32_t[]>(kMaxHistory)) {}
|
||||
|
||||
void UniqueTimestampCounter::Add(uint32_t value) {
|
||||
if (value == last_ || !search_index_.insert(value).second) {
|
||||
// Already known.
|
||||
return;
|
||||
}
|
||||
int index = unique_seen_ % kMaxHistory;
|
||||
if (unique_seen_ >= kMaxHistory) {
|
||||
search_index_.erase(latest_[index]);
|
||||
}
|
||||
latest_[index] = value;
|
||||
last_ = value;
|
||||
++unique_seen_;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
|
||||
#define MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Counts number of uniquly seen frames (aka pictures, aka temporal units)
|
||||
// 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);
|
||||
// Returns number of different `timestamp` passed to the UniqueCounter.
|
||||
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
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_UNIQUE_TIMESTAMP_COUNTER_H_
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "modules/video_coding/unique_timestamp_counter.h"
|
||||
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
TEST(UniqueTimestampCounterTest, InitiallyZero) {
|
||||
UniqueTimestampCounter counter;
|
||||
EXPECT_EQ(counter.GetUniqueSeen(), 0);
|
||||
}
|
||||
|
||||
TEST(UniqueTimestampCounterTest, CountsUniqueValues) {
|
||||
UniqueTimestampCounter counter;
|
||||
counter.Add(100);
|
||||
counter.Add(100);
|
||||
counter.Add(200);
|
||||
counter.Add(150);
|
||||
counter.Add(100);
|
||||
EXPECT_EQ(counter.GetUniqueSeen(), 3);
|
||||
}
|
||||
|
||||
TEST(UniqueTimestampCounterTest, ForgetsOldValuesAfter1000NewValues) {
|
||||
const int kNumValues = 1500;
|
||||
const int kMaxHistory = 1000;
|
||||
const uint32_t value = 0xFFFFFFF0;
|
||||
UniqueTimestampCounter counter;
|
||||
for (int i = 0; i < kNumValues; ++i) {
|
||||
counter.Add(value + 10 * i);
|
||||
}
|
||||
ASSERT_EQ(counter.GetUniqueSeen(), kNumValues);
|
||||
// Slightly old values not affect number of seen unique values.
|
||||
for (int i = kNumValues - kMaxHistory; i < kNumValues; ++i) {
|
||||
counter.Add(value + 10 * i);
|
||||
}
|
||||
EXPECT_EQ(counter.GetUniqueSeen(), kNumValues);
|
||||
// Very old value will be treated as unique.
|
||||
counter.Add(value);
|
||||
EXPECT_EQ(counter.GetUniqueSeen(), kNumValues + 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
Reference in New Issue
Block a user