diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /Audio/AudioStreamClock.hpp | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
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 |
