libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
ndiclock.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
11#include <promeki/config.h>
12
13#if PROMEKI_ENABLE_NDI
14
15#include <promeki/atomic.h>
16#include <promeki/clock.h>
17#include <promeki/clockdomain.h>
18#include <promeki/framerate.h>
19#include <promeki/mutex.h>
21
22PROMEKI_NAMESPACE_BEGIN
23
70class NdiClock : public Clock {
71 public:
78 static const ClockDomain &domain();
79
91 explicit NdiClock(const FrameRate &frameRate = FrameRate());
92
93 ~NdiClock() override;
94
105 void setLatestTimestamp(int64_t ndiTimestampTicks);
106
114 void setFrameRate(const FrameRate &frameRate);
115
116 int64_t resolutionNs() const override;
117 ClockJitter jitter() const override;
118
119 protected:
120 Result<int64_t> raw() const override;
121 Error sleepUntilNs(int64_t targetNs) const override;
122
123 private:
124 // Atomic backing the fast-path raw() / setLatestTimestamp pair.
125 // Stored in nanoseconds so raw() does not multiply on every
126 // call — a hot path for downstream timing math.
127 mutable Atomic<int64_t> _lastTimestampNs{0};
128 Atomic<bool> _hasTimestamp{false};
129 Atomic<bool> _shutdown{false};
130
131 // Wait condition for sleepUntilNs. Signalled on every
132 // setLatestTimestamp so the longest-waiter can wake
133 // and recheck. The mutex guards _frameRate too.
134 mutable Mutex _waitMutex;
135 mutable WaitCondition _waitCond;
136 FrameRate _frameRate;
137};
138
139PROMEKI_NAMESPACE_END
140
141#endif // PROMEKI_ENABLE_NDI