[Unwrap] Prepare SequenceNumberUnwrapper for migrations
This is in prep for the migration of all unwrappers to
SequenceNumberUnwrapper as a standard implementation.
This moves the SeqNumUnwapper to its own header and adds 2 methods to
SeqNumUnwrapper which are defined by other unwrappers:
* PeekUnwrap
* Reset
It also adds two implementations for RtpTimestamps and
RtpSequenceNumbers.
Bug: webrtc:13982
Change-Id: I5baefb2de1db92fe1bb600760bd63b71e9310eb5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288742
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39030}
diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn
index d65f641..0424b55 100644
--- a/api/video/BUILD.gn
+++ b/api/video/BUILD.gn
@@ -185,6 +185,7 @@
"../../modules/video_coding:packet_buffer",
"../../modules/video_coding:video_coding",
"../../rtc_base:logging",
+ "../../rtc_base:rtc_numerics",
]
absl_deps = [
diff --git a/api/video/rtp_video_frame_assembler.cc b/api/video/rtp_video_frame_assembler.cc
index 81c0838..b748534 100644
--- a/api/video/rtp_video_frame_assembler.cc
+++ b/api/video/rtp_video_frame_assembler.cc
@@ -32,6 +32,7 @@
#include "modules/video_coding/packet_buffer.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
#include "rtc_base/logging.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
namespace {
diff --git a/logging/rtc_event_log/rtc_event_log_parser.cc b/logging/rtc_event_log/rtc_event_log_parser.cc
index 7e471dd..b37d29d 100644
--- a/logging/rtc_event_log/rtc_event_log_parser.cc
+++ b/logging/rtc_event_log/rtc_event_log_parser.cc
@@ -42,7 +42,7 @@
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/protobuf_utils.h"
#include "rtc_base/system/file_wrapper.h"
diff --git a/modules/remote_bitrate_estimator/remote_estimator_proxy.h b/modules/remote_bitrate_estimator/remote_estimator_proxy.h
index 7b0a8a6..54257ea 100644
--- a/modules/remote_bitrate_estimator/remote_estimator_proxy.h
+++ b/modules/remote_bitrate_estimator/remote_estimator_proxy.h
@@ -26,7 +26,7 @@
#include "modules/remote_bitrate_estimator/packet_arrival_map.h"
#include "modules/rtp_rtcp/source/rtcp_packet.h"
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc
index 4d8786c..2713171 100644
--- a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc
+++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc
@@ -33,7 +33,7 @@
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "third_party/libaom/source/libaom/aom/aom_codec.h"
#include "third_party/libaom/source/libaom/aom/aom_encoder.h"
#include "third_party/libaom/source/libaom/aom/aomcx.h"
diff --git a/modules/video_coding/h264_packet_buffer.h b/modules/video_coding/h264_packet_buffer.h
index 1671fdd..a72c240 100644
--- a/modules/video_coding/h264_packet_buffer.h
+++ b/modules/video_coding/h264_packet_buffer.h
@@ -18,7 +18,7 @@
#include "absl/base/attributes.h"
#include "absl/types/optional.h"
#include "modules/video_coding/packet_buffer.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
diff --git a/modules/video_coding/packet_buffer_unittest.cc b/modules/video_coding/packet_buffer_unittest.cc
index 49afa14..b147977 100644
--- a/modules/video_coding/packet_buffer_unittest.cc
+++ b/modules/video_coding/packet_buffer_unittest.cc
@@ -18,6 +18,7 @@
#include "api/array_view.h"
#include "common_video/h264/h264_common.h"
#include "modules/video_coding/frame_object.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/random.h"
#include "test/field_trial.h"
#include "test/gmock.h"
diff --git a/modules/video_coding/rtp_frame_id_only_ref_finder.h b/modules/video_coding/rtp_frame_id_only_ref_finder.h
index 1df4870..5c0bdc8 100644
--- a/modules/video_coding/rtp_frame_id_only_ref_finder.h
+++ b/modules/video_coding/rtp_frame_id_only_ref_finder.h
@@ -16,7 +16,7 @@
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/frame_object.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
diff --git a/modules/video_coding/rtp_seq_num_only_ref_finder.h b/modules/video_coding/rtp_seq_num_only_ref_finder.h
index ef3c022..c05655b 100644
--- a/modules/video_coding/rtp_seq_num_only_ref_finder.h
+++ b/modules/video_coding/rtp_seq_num_only_ref_finder.h
@@ -20,7 +20,7 @@
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/frame_object.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
diff --git a/modules/video_coding/rtp_vp8_ref_finder.h b/modules/video_coding/rtp_vp8_ref_finder.h
index 1ae45cd..26df658 100644
--- a/modules/video_coding/rtp_vp8_ref_finder.h
+++ b/modules/video_coding/rtp_vp8_ref_finder.h
@@ -19,7 +19,7 @@
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/frame_object.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
diff --git a/modules/video_coding/rtp_vp9_ref_finder.h b/modules/video_coding/rtp_vp9_ref_finder.h
index 2971f68..ea5e319 100644
--- a/modules/video_coding/rtp_vp9_ref_finder.h
+++ b/modules/video_coding/rtp_vp9_ref_finder.h
@@ -19,7 +19,7 @@
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/frame_object.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
namespace webrtc {
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 5d4cdb3..07dec5d 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -775,6 +775,7 @@
"numerics/moving_percentile_filter.h",
"numerics/percentile_filter.h",
"numerics/running_statistics.h",
+ "numerics/sequence_number_unwrapper.h",
"numerics/sequence_number_util.h",
]
deps = [
@@ -1696,6 +1697,7 @@
"numerics/moving_percentile_filter_unittest.cc",
"numerics/percentile_filter_unittest.cc",
"numerics/running_statistics_unittest.cc",
+ "numerics/sequence_number_unwrapper_unittest.cc",
"numerics/sequence_number_util_unittest.cc",
"numerics/sequence_numbers_conformance_test.cc",
]
diff --git a/rtc_base/numerics/sequence_number_unwrapper.h b/rtc_base/numerics/sequence_number_unwrapper.h
new file mode 100644
index 0000000..d741b5c
--- /dev/null
+++ b/rtc_base/numerics/sequence_number_unwrapper.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2022 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 RTC_BASE_NUMERICS_SEQUENCE_NUMBER_UNWRAPPER_H_
+#define RTC_BASE_NUMERICS_SEQUENCE_NUMBER_UNWRAPPER_H_
+
+#include <stdint.h>
+
+#include <limits>
+
+#include "absl/types/optional.h"
+#include "rtc_base/numerics/sequence_number_util.h"
+
+namespace webrtc {
+
+// A sequence number unwrapper where the first unwrapped value equals the
+// first value being unwrapped.
+template <typename T, T M = 0>
+class SeqNumUnwrapper {
+ static_assert(
+ std::is_unsigned<T>::value &&
+ std::numeric_limits<T>::max() < std::numeric_limits<int64_t>::max(),
+ "Type unwrapped must be an unsigned integer smaller than int64_t.");
+
+ public:
+ // Unwraps `value` and updates the internal state of the unwrapper.
+ int64_t Unwrap(T value) {
+ if (!last_value_) {
+ last_unwrapped_ = {value};
+ } else {
+ last_unwrapped_ += Delta(*last_value_, value);
+ }
+
+ last_value_ = value;
+ return last_unwrapped_;
+ }
+
+ // Returns the `value` without updating the internal state of the unwrapper.
+ int64_t PeekUnwrap(T value) const {
+ if (!last_value_) {
+ return value;
+ }
+ return last_unwrapped_ + Delta(*last_value_, value);
+ }
+
+ // Resets the unwrapper to its initial state. Unwrapped sequence numbers will
+ // being at 0 after resetting.
+ void Reset() {
+ last_unwrapped_ = 0;
+ last_value_.reset();
+ }
+
+ private:
+ static int64_t Delta(T last_value, T new_value) {
+ constexpr int64_t kBackwardAdjustment =
+ M == 0 ? int64_t{std::numeric_limits<T>::max()} + 1 : M;
+ int64_t result = ForwardDiff<T, M>(last_value, new_value);
+ if (!AheadOrAt<T, M>(new_value, last_value)) {
+ result -= kBackwardAdjustment;
+ }
+ return result;
+ }
+
+ int64_t last_unwrapped_ = 0;
+ absl::optional<T> last_value_;
+};
+
+using RtpTimestampUnwrapper = SeqNumUnwrapper<uint32_t>;
+using RtpSequenceNumberUnwrapper = SeqNumUnwrapper<uint16_t>;
+
+} // namespace webrtc
+
+#endif // RTC_BASE_NUMERICS_SEQUENCE_NUMBER_UNWRAPPER_H_
diff --git a/rtc_base/numerics/sequence_number_unwrapper_unittest.cc b/rtc_base/numerics/sequence_number_unwrapper_unittest.cc
new file mode 100644
index 0000000..fcd903b
--- /dev/null
+++ b/rtc_base/numerics/sequence_number_unwrapper_unittest.cc
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2022 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 "rtc_base/numerics/sequence_number_unwrapper.h"
+
+#include <cstdint>
+
+#include "test/gtest.h"
+
+namespace webrtc {
+
+TEST(SeqNumUnwrapper, PreserveStartValue) {
+ SeqNumUnwrapper<uint8_t> unwrapper;
+ EXPECT_EQ(123, unwrapper.Unwrap(123));
+}
+
+TEST(SeqNumUnwrapper, ForwardWrap) {
+ SeqNumUnwrapper<uint8_t> unwrapper;
+ EXPECT_EQ(255, unwrapper.Unwrap(255));
+ EXPECT_EQ(256, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) {
+ SeqNumUnwrapper<uint8_t, 33> unwrapper;
+ EXPECT_EQ(30, unwrapper.Unwrap(30));
+ EXPECT_EQ(36, unwrapper.Unwrap(3));
+}
+
+TEST(SeqNumUnwrapper, BackWardWrap) {
+ SeqNumUnwrapper<uint8_t> unwrapper;
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+ EXPECT_EQ(-2, unwrapper.Unwrap(254));
+}
+
+TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) {
+ SeqNumUnwrapper<uint8_t, 33> unwrapper;
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+ EXPECT_EQ(-2, unwrapper.Unwrap(31));
+}
+
+TEST(SeqNumUnwrapper, Unwrap) {
+ SeqNumUnwrapper<uint16_t> unwrapper;
+ const uint16_t kMax = std::numeric_limits<uint16_t>::max();
+ const uint16_t kMaxDist = kMax / 2 + 1;
+
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
+ EXPECT_EQ(kMax + 1, unwrapper.Unwrap(0));
+ EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
+ EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, UnwrapOddDivisor) {
+ SeqNumUnwrapper<uint8_t, 11> unwrapper;
+
+ EXPECT_EQ(10, unwrapper.Unwrap(10));
+ EXPECT_EQ(11, unwrapper.Unwrap(0));
+ EXPECT_EQ(16, unwrapper.Unwrap(5));
+ EXPECT_EQ(21, unwrapper.Unwrap(10));
+ EXPECT_EQ(22, unwrapper.Unwrap(0));
+ EXPECT_EQ(17, unwrapper.Unwrap(6));
+ EXPECT_EQ(12, unwrapper.Unwrap(1));
+ EXPECT_EQ(7, unwrapper.Unwrap(7));
+ EXPECT_EQ(2, unwrapper.Unwrap(2));
+ EXPECT_EQ(0, unwrapper.Unwrap(0));
+}
+
+TEST(SeqNumUnwrapper, ManyForwardWraps) {
+ const int kLargeNumber = 4711;
+ const int kMaxStep = kLargeNumber / 2;
+ const int kNumWraps = 100;
+ SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
+
+ uint16_t next_unwrap = 0;
+ int64_t expected = 0;
+ for (int i = 0; i < kNumWraps * 2 + 1; ++i) {
+ EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
+ expected += kMaxStep;
+ next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber;
+ }
+}
+
+TEST(SeqNumUnwrapper, ManyBackwardWraps) {
+ const int kLargeNumber = 4711;
+ const int kMaxStep = kLargeNumber / 2;
+ const int kNumWraps = 100;
+ SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
+
+ uint16_t next_unwrap = 0;
+ int64_t expected = 0;
+ for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) {
+ EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
+ expected -= kMaxStep;
+ next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber;
+ }
+}
+
+TEST(SeqNumUnwrapper, Reset) {
+ const uint16_t kMax = std::numeric_limits<uint16_t>::max();
+ const uint16_t kMaxStep = kMax / 2;
+ SeqNumUnwrapper<uint16_t> unwrapper;
+ EXPECT_EQ(10, unwrapper.Unwrap(10));
+ EXPECT_EQ(kMaxStep + 10, unwrapper.Unwrap(kMaxStep + 10));
+
+ EXPECT_EQ(kMax + 3, unwrapper.PeekUnwrap(2));
+ unwrapper.Reset();
+ // After Reset() the range is reset back to the start.
+ EXPECT_EQ(2, unwrapper.PeekUnwrap(2));
+}
+
+TEST(SeqNumUnwrapper, PeekUnwrap) {
+ const uint16_t kMax = std::numeric_limits<uint16_t>::max();
+ const uint16_t kMaxStep = kMax / 2;
+ const uint16_t kMaxDist = kMaxStep + 1;
+ SeqNumUnwrapper<uint16_t> unwrapper;
+ // No previous unwraps, so PeekUnwrap(x) == x.
+ EXPECT_EQ(10, unwrapper.PeekUnwrap(10));
+ EXPECT_EQ(kMaxDist + 10, unwrapper.PeekUnwrap(kMaxDist + 10));
+
+ EXPECT_EQ(10, unwrapper.Unwrap(10));
+ EXPECT_EQ(12, unwrapper.PeekUnwrap(12));
+ // State should not have updated, so kMaxDist + 12 should be negative.
+ EXPECT_EQ(-kMaxDist + 12, unwrapper.Unwrap(kMaxDist + 12));
+
+ // Test PeekUnwrap after around.
+ unwrapper.Reset();
+ EXPECT_EQ(kMaxStep, unwrapper.Unwrap(kMaxStep));
+ EXPECT_EQ(2 * kMaxStep, unwrapper.Unwrap(2 * kMaxStep));
+ EXPECT_EQ(kMax + 1, unwrapper.PeekUnwrap(0));
+ // Wrap back to last range.
+ EXPECT_EQ(kMax - 3, unwrapper.PeekUnwrap(kMax - 3));
+}
+
+} // namespace webrtc
diff --git a/rtc_base/numerics/sequence_number_util.h b/rtc_base/numerics/sequence_number_util.h
index d68c064..702b82f 100644
--- a/rtc_base/numerics/sequence_number_util.h
+++ b/rtc_base/numerics/sequence_number_util.h
@@ -16,8 +16,6 @@
#include <limits>
#include <type_traits>
-#include "absl/types/optional.h"
-#include "rtc_base/checks.h"
#include "rtc_base/numerics/mod_ops.h"
namespace webrtc {
@@ -82,38 +80,6 @@
bool operator()(T a, T b) const { return AheadOf<T, M>(b, a); }
};
-// A sequence number unwrapper where the first unwrapped value equals the
-// first value being unwrapped.
-template <typename T, T M = 0>
-class SeqNumUnwrapper {
- static_assert(
- std::is_unsigned<T>::value &&
- std::numeric_limits<T>::max() < std::numeric_limits<int64_t>::max(),
- "Type unwrapped must be an unsigned integer smaller than int64_t.");
-
- public:
- int64_t Unwrap(T value) {
- if (!last_value_) {
- last_unwrapped_ = {value};
- } else {
- last_unwrapped_ += ForwardDiff<T, M>(*last_value_, value);
-
- if (!AheadOrAt<T, M>(value, *last_value_)) {
- constexpr int64_t kBackwardAdjustment =
- M == 0 ? int64_t{std::numeric_limits<T>::max()} + 1 : M;
- last_unwrapped_ -= kBackwardAdjustment;
- }
- }
-
- last_value_ = value;
- return last_unwrapped_;
- }
-
- private:
- int64_t last_unwrapped_ = 0;
- absl::optional<T> last_value_;
-};
-
} // namespace webrtc
#endif // RTC_BASE_NUMERICS_SEQUENCE_NUMBER_UTIL_H_
diff --git a/rtc_base/numerics/sequence_number_util_unittest.cc b/rtc_base/numerics/sequence_number_util_unittest.cc
index d7fa0b1..d44127b 100644
--- a/rtc_base/numerics/sequence_number_util_unittest.cc
+++ b/rtc_base/numerics/sequence_number_util_unittest.cc
@@ -212,95 +212,4 @@
}
}
-TEST(SeqNumUnwrapper, PreserveStartValue) {
- SeqNumUnwrapper<uint8_t> unwrapper;
- EXPECT_EQ(123, unwrapper.Unwrap(123));
-}
-
-TEST(SeqNumUnwrapper, ForwardWrap) {
- SeqNumUnwrapper<uint8_t> unwrapper;
- EXPECT_EQ(255, unwrapper.Unwrap(255));
- EXPECT_EQ(256, unwrapper.Unwrap(0));
-}
-
-TEST(SeqNumUnwrapper, ForwardWrapWithDivisor) {
- SeqNumUnwrapper<uint8_t, 33> unwrapper;
- EXPECT_EQ(30, unwrapper.Unwrap(30));
- EXPECT_EQ(36, unwrapper.Unwrap(3));
-}
-
-TEST(SeqNumUnwrapper, BackWardWrap) {
- SeqNumUnwrapper<uint8_t> unwrapper;
- EXPECT_EQ(0, unwrapper.Unwrap(0));
- EXPECT_EQ(-2, unwrapper.Unwrap(254));
-}
-
-TEST(SeqNumUnwrapper, BackWardWrapWithDivisor) {
- SeqNumUnwrapper<uint8_t, 33> unwrapper;
- EXPECT_EQ(0, unwrapper.Unwrap(0));
- EXPECT_EQ(-2, unwrapper.Unwrap(31));
-}
-
-TEST(SeqNumUnwrapper, Unwrap) {
- SeqNumUnwrapper<uint16_t> unwrapper;
- const uint16_t kMax = std::numeric_limits<uint16_t>::max();
- const uint16_t kMaxDist = kMax / 2 + 1;
-
- EXPECT_EQ(0, unwrapper.Unwrap(0));
- EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
- EXPECT_EQ(0, unwrapper.Unwrap(0));
-
- EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
- EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
- EXPECT_EQ(kMax + 1, unwrapper.Unwrap(0));
- EXPECT_EQ(kMax, unwrapper.Unwrap(kMax));
- EXPECT_EQ(kMaxDist, unwrapper.Unwrap(kMaxDist));
- EXPECT_EQ(0, unwrapper.Unwrap(0));
-}
-
-TEST(SeqNumUnwrapper, UnwrapOddDivisor) {
- SeqNumUnwrapper<uint8_t, 11> unwrapper;
-
- EXPECT_EQ(10, unwrapper.Unwrap(10));
- EXPECT_EQ(11, unwrapper.Unwrap(0));
- EXPECT_EQ(16, unwrapper.Unwrap(5));
- EXPECT_EQ(21, unwrapper.Unwrap(10));
- EXPECT_EQ(22, unwrapper.Unwrap(0));
- EXPECT_EQ(17, unwrapper.Unwrap(6));
- EXPECT_EQ(12, unwrapper.Unwrap(1));
- EXPECT_EQ(7, unwrapper.Unwrap(7));
- EXPECT_EQ(2, unwrapper.Unwrap(2));
- EXPECT_EQ(0, unwrapper.Unwrap(0));
-}
-
-TEST(SeqNumUnwrapper, ManyForwardWraps) {
- const int kLargeNumber = 4711;
- const int kMaxStep = kLargeNumber / 2;
- const int kNumWraps = 100;
- SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
-
- uint16_t next_unwrap = 0;
- int64_t expected = 0;
- for (int i = 0; i < kNumWraps * 2 + 1; ++i) {
- EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
- expected += kMaxStep;
- next_unwrap = (next_unwrap + kMaxStep) % kLargeNumber;
- }
-}
-
-TEST(SeqNumUnwrapper, ManyBackwardWraps) {
- const int kLargeNumber = 4711;
- const int kMaxStep = kLargeNumber / 2;
- const int kNumWraps = 100;
- SeqNumUnwrapper<uint16_t, kLargeNumber> unwrapper;
-
- uint16_t next_unwrap = 0;
- int64_t expected = 0;
- for (uint16_t i = 0; i < kNumWraps * 2 + 1; ++i) {
- EXPECT_EQ(expected, unwrapper.Unwrap(next_unwrap));
- expected -= kMaxStep;
- next_unwrap = (next_unwrap + kMaxStep + 1) % kLargeNumber;
- }
-}
-
} // namespace webrtc
diff --git a/rtc_base/numerics/sequence_numbers_conformance_test.cc b/rtc_base/numerics/sequence_numbers_conformance_test.cc
index 8c5bc62..62f7eb7 100644
--- a/rtc_base/numerics/sequence_numbers_conformance_test.cc
+++ b/rtc_base/numerics/sequence_numbers_conformance_test.cc
@@ -14,7 +14,7 @@
#include "modules/include/module_common_types_public.h"
#include "net/dcsctp/common/sequence_numbers.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/strong_alias.h"
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
@@ -26,7 +26,7 @@
using ::testing::Test;
using dcsctp::UnwrappedSequenceNumber;
-using Wrapped = webrtc::StrongAlias<class WrappedTag, uint32_t>;
+using Wrapped = StrongAlias<class WrappedTag, uint32_t>;
using TestSequence = UnwrappedSequenceNumber<Wrapped>;
template <typename T>
@@ -84,9 +84,9 @@
TYPED_TEST_P(UnwrapperConformanceFixture, NegativeUnwrap) {
using UnwrapperT = decltype(this->ref_unwrapper_);
- // webrtc::TimestampUnwrapper known to not handle negative numbers.
+ // TimestampUnwrapper known to not handle negative numbers.
// rtc::TimestampWrapAroundHandler does not wrap around correctly.
- if constexpr (std::is_same<UnwrapperT, webrtc::TimestampUnwrapper>() ||
+ if constexpr (std::is_same<UnwrapperT, TimestampUnwrapper>() ||
std::is_same<UnwrapperT, rtc::TimestampWrapAroundHandler>()) {
return;
}
@@ -134,10 +134,10 @@
TYPED_TEST_P(UnwrapperConformanceFixture, MultipleNegativeWrapArounds) {
using UnwrapperT = decltype(this->ref_unwrapper_);
- // webrtc::TimestampUnwrapper known to not handle negative numbers.
- // webrtc::SequenceNumberUnwrapper can only wrap negative once.
+ // TimestampUnwrapper known to not handle negative numbers.
+ // SequenceNumberUnwrapper can only wrap negative once.
// rtc::TimestampWrapAroundHandler does not wrap around correctly.
- if constexpr (std::is_same<UnwrapperT, webrtc::TimestampUnwrapper>() ||
+ if constexpr (std::is_same<UnwrapperT, TimestampUnwrapper>() ||
std::is_same<UnwrapperT,
UnwrapperHelper<TestSequence::Unwrapper>>() ||
std::is_same<UnwrapperT, rtc::TimestampWrapAroundHandler>()) {
@@ -164,11 +164,11 @@
constexpr int64_t k15BitMax = (int64_t{1} << 15) - 1;
using UnwrapperTypes = ::testing::Types<
FixtureParams<rtc::TimestampWrapAroundHandler>,
- FixtureParams<webrtc::TimestampUnwrapper>,
- FixtureParams<webrtc::SeqNumUnwrapper<uint32_t>>,
+ FixtureParams<TimestampUnwrapper>,
+ FixtureParams<RtpTimestampUnwrapper>,
FixtureParams<UnwrapperHelper<TestSequence::Unwrapper>>,
// SeqNumUnwrapper supports arbitrary limits.
- FixtureParams<webrtc::SeqNumUnwrapper<uint32_t, k15BitMax + 1>, k15BitMax>>;
+ FixtureParams<SeqNumUnwrapper<uint32_t, k15BitMax + 1>, k15BitMax>>;
class TestNames {
public:
@@ -177,15 +177,13 @@
if constexpr (std::is_same<typename T::Unwrapper,
rtc::TimestampWrapAroundHandler>())
return "TimestampWrapAroundHandler";
- if constexpr (std::is_same<typename T::Unwrapper,
- webrtc::TimestampUnwrapper>())
+ if constexpr (std::is_same<typename T::Unwrapper, TimestampUnwrapper>())
return "TimestampUnwrapper";
if constexpr (std::is_same<typename T::Unwrapper,
- webrtc::SeqNumUnwrapper<uint32_t>>())
+ SeqNumUnwrapper<uint32_t>>())
return "SeqNumUnwrapper";
- if constexpr (std::is_same<
- typename T::Unwrapper,
- webrtc::SeqNumUnwrapper<uint32_t, k15BitMax + 1>>())
+ if constexpr (std::is_same<typename T::Unwrapper,
+ SeqNumUnwrapper<uint32_t, k15BitMax + 1>>())
return "SeqNumUnwrapper15bit";
if constexpr (std::is_same<typename T::Unwrapper,
UnwrapperHelper<TestSequence::Unwrapper>>())
diff --git a/rtc_tools/rtc_event_log_visualizer/alerts.cc b/rtc_tools/rtc_event_log_visualizer/alerts.cc
index 9ef5e9a..a9f50cd 100644
--- a/rtc_tools/rtc_event_log_visualizer/alerts.cc
+++ b/rtc_tools/rtc_event_log_visualizer/alerts.cc
@@ -20,7 +20,7 @@
#include "logging/rtc_event_log/rtc_event_processor.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/strings/string_builder.h"
namespace webrtc {
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.cc b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
index ddd65cb..6b9449f 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.cc
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
@@ -49,7 +49,7 @@
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/rate_statistics.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_tools/rtc_event_log_visualizer/log_simulation.h"
diff --git a/test/fuzzers/frame_buffer_fuzzer.cc b/test/fuzzers/frame_buffer_fuzzer.cc
index ea00993..e58d5e9 100644
--- a/test/fuzzers/frame_buffer_fuzzer.cc
+++ b/test/fuzzers/frame_buffer_fuzzer.cc
@@ -11,7 +11,7 @@
#include "api/array_view.h"
#include "api/video/encoded_frame.h"
#include "api/video/frame_buffer.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "test/fuzzers/fuzz_data_helper.h"
#include "test/scoped_key_value_config.h"
diff --git a/video/rtp_video_stream_receiver2.h b/video/rtp_video_stream_receiver2.h
index 782fa52..862db6c 100644
--- a/video/rtp_video_stream_receiver2.h
+++ b/video/rtp_video_stream_receiver2.h
@@ -43,7 +43,7 @@
#include "modules/video_coding/packet_buffer.h"
#include "modules/video_coding/rtp_frame_reference_finder.h"
#include "rtc_base/experiments/field_trial_parser.h"
-#include "rtc_base/numerics/sequence_number_util.h"
+#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/thread_annotations.h"
#include "video/buffered_frame_decryptor.h"