#include "media/formats/mp2t/timestamp_unroller.h"
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "base/test/perf_test_suite.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media::mp2t {
static std::vector<int64_t> TruncateTimestamps(
const std::vector<int64_t>& timestamps) {
const int nbits = 33;
int64_t truncate_mask = (INT64_C(1) << nbits) - 1;
std::vector<int64_t> truncated_timestamps(timestamps.size());
for (size_t k = 0; k < timestamps.size(); k++)
truncated_timestamps[k] = timestamps[k] & truncate_mask;
return truncated_timestamps;
}
static void RunUnrollTest(const std::vector<int64_t>& timestamps) {
std::vector<int64_t> truncated_timestamps = TruncateTimestamps(timestamps);
TimestampUnroller timestamp_unroller;
for (size_t k = 0; k < timestamps.size(); k++) {
int64_t unrolled_timestamp =
timestamp_unroller.GetUnrolledTimestamp(truncated_timestamps[k]);
EXPECT_EQ(timestamps[k], unrolled_timestamp);
}
}
TEST(TimestampUnrollerTest, SingleStream) {
const std::vector<int64_t> timestamps_vector = {
INT64_C(0x0000000000000000),
INT64_C(-190),
INT64_C(0x00000000aaaaa9ed),
INT64_C(0x0000000155555498),
INT64_C(0x00000001ffffff43),
INT64_C(0x00000002aaaaa9ee),
INT64_C(0x0000000355555499),
INT64_C(0x00000003ffffff44),
};
RunUnrollTest(timestamps_vector);
}
}