Shaka Packager SDK
Loading...
Searching...
No Matches
timestamp_util.h
1// Copyright 2025 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_MEDIA_BASE_TIMESTAMP_UTIL_H_
8#define PACKAGER_MEDIA_BASE_TIMESTAMP_UTIL_H_
9
10#include <cstdint>
11
12namespace shaka {
13namespace media {
14
15// MPEG-2 TS PTS/DTS are 33-bit values that wrap around at 2^33
16constexpr int64_t kPtsWrapAround =
17 (1LL << 33); // 8589934592 (~26.5 hours @ 90kHz)
18constexpr int64_t kPtsHalfWrapAround =
19 (1LL << 32); // 4294967296 (~13.25 hours @ 90kHz)
20
38int64_t SignedPtsDiff(int64_t a, int64_t b);
39
46bool PtsIsBefore(int64_t a, int64_t b);
47
54bool PtsIsBeforeOrEqual(int64_t a, int64_t b);
55
71 public:
72 PtsUnwrapper() = default;
73
78 int64_t Unwrap(int64_t wrapped_pts);
79
81 void Reset();
82
85 bool IsInitialized() const { return initialized_; }
86
87 private:
88 bool initialized_ = false;
89 int64_t last_wrapped_ = 0;
90 int64_t unwrapped_offset_ = 0;
91};
92
93} // namespace media
94} // namespace shaka
95
96#endif // PACKAGER_MEDIA_BASE_TIMESTAMP_UTIL_H_
int64_t Unwrap(int64_t wrapped_pts)
void Reset()
Resets the unwrapper state (for stream discontinuities).
All the methods that are virtual are virtual for mocking.