diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /Audio/AudioStreamClock.hpp | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg'
with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'Audio/AudioStreamClock.hpp')
| -rw-r--r-- | Audio/AudioStreamClock.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Audio/AudioStreamClock.hpp b/Audio/AudioStreamClock.hpp new file mode 100644 index 00000000..65e5b1e1 --- /dev/null +++ b/Audio/AudioStreamClock.hpp @@ -0,0 +1,59 @@ +// -*- Mode: C++ -*- +#ifndef AUDIO_STREAM_CLOCK_HPP__ +#define AUDIO_STREAM_CLOCK_HPP__ + +#include <QtGlobal> + +#include "Audio/AudioStreamDescriptor.hpp" + +class AudioStreamClock +{ +public: + enum class Reference + { + ArrivalWallClock, + CaptureAnchor + }; + + void setDescriptor (AudioStreamDescriptor descriptor) noexcept + { + descriptor_ = descriptor; + captured_frames_ = 0; + } + + Reference reference () const noexcept + { + return descriptor_.isValid () + && descriptor_.clock_domain + == AudioStreamDescriptor::ClockDomain::SystemClock + && descriptor_.timing_evidence + == AudioStreamDescriptor::TimingEvidence::CaptureTimeAnchored + && descriptor_.capture_anchor_utc_ms > 0 + ? Reference::CaptureAnchor : Reference::ArrivalWallClock; + } + + qint64 timestamp (qint64 arrival_utc_ms) const noexcept + { + if (Reference::CaptureAnchor != reference ()) + { + return arrival_utc_ms; + } + + return descriptor_.capture_anchor_utc_ms + + captured_frames_ * 1000 / descriptor_.sample_rate_hz; + } + + void advance (qint64 frames) noexcept + { + if (Reference::CaptureAnchor == reference () && frames > 0) + { + captured_frames_ += frames; + } + } + +private: + AudioStreamDescriptor descriptor_; + qint64 captured_frames_ {0}; +}; + +#endif |
