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/TxAudioQueue.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/TxAudioQueue.hpp')
| -rw-r--r-- | Audio/TxAudioQueue.hpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Audio/TxAudioQueue.hpp b/Audio/TxAudioQueue.hpp new file mode 100644 index 00000000..8e1a4710 --- /dev/null +++ b/Audio/TxAudioQueue.hpp @@ -0,0 +1,93 @@ +#ifndef TX_AUDIO_QUEUE_HPP_ +#define TX_AUDIO_QUEUE_HPP_ + +#include <memory> + +#include <QMetaType> +#include <QVector> +#include <QtGlobal> + +struct TxAudioQueueEpoch +{ + constexpr TxAudioQueueEpoch () noexcept : value_ {0} {} + explicit constexpr TxAudioQueueEpoch (qint64 value) noexcept : value_ {value} {} + + static constexpr TxAudioQueueEpoch invalid () noexcept {return TxAudioQueueEpoch {};} + constexpr bool isValid () const noexcept {return value_ > 0;} + constexpr qint64 value () const noexcept {return value_;} + +private: + qint64 value_; +}; + +inline constexpr bool operator == (TxAudioQueueEpoch lhs, + TxAudioQueueEpoch rhs) noexcept +{ + return lhs.value () == rhs.value (); +} + +inline constexpr bool operator != (TxAudioQueueEpoch lhs, + TxAudioQueueEpoch rhs) noexcept +{ + return !(lhs == rhs); +} + +struct TxAudioQueueProgress +{ + TxAudioQueueEpoch epoch {}; + qint64 queued_samples {0}; + qint64 served_samples {0}; + qint64 total_samples {0}; +}; + +struct TxAudioQueueDrainState +{ + bool ready {false}; + TxAudioQueueEpoch epoch {}; + qint64 total_at_drain {0}; +}; + +struct TxAudioQueueEnqueueResult +{ + bool accepted {false}; + TxAudioQueueProgress progress {}; +}; + +class TxAudioQueue +{ +public: + // One serialized producer owns clear/enqueue; one consumer owns reset/pull/drain. + static constexpr qint64 defaultCapacity () noexcept {return 60 * 48000;} + + TxAudioQueue (); + explicit TxAudioQueue (qint64 capacity_samples); + ~TxAudioQueue (); + + TxAudioQueue (TxAudioQueue const&) = delete; + TxAudioQueue& operator = (TxAudioQueue const&) = delete; + + TxAudioQueueEnqueueResult enqueue (QVector<qint16> const& samples, + TxAudioQueueEpoch epoch); + TxAudioQueueEnqueueResult enqueue (qint16 const * samples, qint64 count, + TxAudioQueueEpoch epoch); + void clear (TxAudioQueueEpoch epoch); + void applyPendingReset () noexcept; + + qint16 pullSample (qint64 drain_guard) noexcept; + TxAudioQueueDrainState takeDrainReady () noexcept; + + // A concurrent clear may produce progress with an invalid epoch. + TxAudioQueueProgress progress () const noexcept; + qint64 capacity () const noexcept; + +private: + class Impl; + std::unique_ptr<Impl> impl_; +}; + +Q_DECLARE_METATYPE (TxAudioQueueEpoch) +Q_DECLARE_METATYPE (TxAudioQueueProgress) +Q_DECLARE_METATYPE (TxAudioQueueDrainState) +Q_DECLARE_METATYPE (TxAudioQueueEnqueueResult) + +#endif |
