libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
rtpmediaclock.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <cstdint>
14#include <promeki/clockdomain.h>
15#include <promeki/duration.h>
16#include <promeki/framerate.h>
17#include <promeki/namespace.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
81class RtpMediaClock {
82 public:
91 RtpMediaClock() = default;
92
109 static RtpMediaClock frameZeroAnchored(uint32_t mediaClockHz, const FrameRate &rate);
110
131 static RtpMediaClock ptpAnchored(uint32_t mediaClockHz, const FrameRate &rate,
132 int64_t anchorUtcNs);
133
135 bool isValid() const { return _mediaClockHz > 0 && _frameRate.isValid(); }
136
138 uint32_t mediaClockHz() const { return _mediaClockHz; }
139
141 const FrameRate &frameRate() const { return _frameRate; }
142
144 int64_t anchorUtcNs() const { return _anchorUtcNs; }
145
147 uint32_t anchorRtpTs() const { return _anchorRtpTs; }
148
150 int64_t anchorFrameIndex() const { return _anchorFrameIndex; }
151
153 bool hasPtpAnchor() const { return _anchorUtcNs > 0; }
154
156 const Duration &trOffset() const { return _trOffset; }
157
164 void setTrOffset(const Duration &d) { _trOffset = d; }
165
183 uint32_t rtpTsForFrame(int64_t frameIndex) const;
184
200 int64_t tvdUtcNs(int64_t frameIndex) const;
201
219 int64_t tvdUtcNsForRtpTs(uint32_t rtpTs) const;
220
240 uint32_t mediaClkDirectOffset() const;
241
242 private:
243 explicit RtpMediaClock(uint32_t mediaClockHz, const FrameRate &rate)
244 : _mediaClockHz(mediaClockHz), _frameRate(rate) {}
245
246 uint32_t _mediaClockHz = 0;
247 FrameRate _frameRate;
248 int64_t _anchorFrameIndex = 0;
249 int64_t _anchorUtcNs = 0;
250 uint32_t _anchorRtpTs = 0;
251 // Default-constructed Duration is Invalid (INT64_MIN);
252 // explicit zero is the documented "no offset" value
253 // for ST 2110-10 §7.4 — every reader treats Invalid
254 // as zero as a belt-and-braces guard but the in-class
255 // initialiser is the primary fix.
256 Duration _trOffset = Duration::zero();
257};
258
259PROMEKI_NAMESPACE_END
260
261#endif // PROMEKI_ENABLE_NETWORK