libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
rtpaudiotxthread.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 <cstddef>
14#include <cstdint>
15#include <promeki/atomic.h>
16#include <promeki/audiodesc.h>
17#include <promeki/buffer.h>
18#include <promeki/cadence.h>
19#include <promeki/namespace.h>
21#include <promeki/queue.h>
22#include <promeki/rtppayload.h>
23#include <promeki/rtpsession.h>
24#include <promeki/rtptxthread.h>
25#include <promeki/string.h>
26
27PROMEKI_NAMESPACE_BEGIN
28
54struct RtpAudioTxContext {
61 AudioDesc storageDesc;
62
66 size_t packetSamples = 0;
67
72 size_t packetBytes = 0;
73
77 int packetTimeUs = 0;
78
84 RtpSession *session = nullptr;
85
89 RtpPayload *payload = nullptr;
90
95 uint32_t clockRate = 0;
96
100 Atomic<int64_t> *packetsSent = nullptr;
101
104 Atomic<int64_t> *bytesSent = nullptr;
105
109 Atomic<int64_t> *senderOctets = nullptr;
110
115 Atomic<int64_t> *silencePacketsEmitted = nullptr;
116
120 Atomic<int64_t> *silenceSamplesEmitted = nullptr;
121
132 uint32_t initialRtpTs = 0;
133};
134
174class RtpAudioTxThread : public RtpTxThread {
175 public:
182 static constexpr int64_t HeadroomUs = 1'000'000;
183
187 static constexpr size_t MinDepth = 8;
188
196 static constexpr int64_t StallReanchorMultiplier = 16;
197
206 explicit RtpAudioTxThread(RtpAudioTxContext ctx,
207 const String &name = String("RtpAudTx"));
208
211 ~RtpAudioTxThread() override;
212
213 RtpAudioTxThread(const RtpAudioTxThread &) = delete;
214 RtpAudioTxThread &operator=(const RtpAudioTxThread &) = delete;
215
222 Queue<Buffer> &packetQueue() { return _packetQueue; }
223
225 const Queue<Buffer> &packetQueue() const { return _packetQueue; }
226
232 uint32_t rtpTsCursor() const { return _rtpTs; }
233
258 bool runOnceForTest();
259
260 protected:
261 void onShutdown() override { _packetQueue.cancelWaiters(); }
262 void run() override;
263
264 private:
269 bool emitOne(const Buffer &silenceBuf);
270
273 Buffer silenceBuffer();
274
275 RtpAudioTxContext _ctx;
276 Queue<Buffer> _packetQueue;
277 uint32_t _rtpTs = 0;
278 Buffer _silenceBuf;
279 bool _silenceBuilt = false;
280};
281
282PROMEKI_NAMESPACE_END
283
284#endif // PROMEKI_ENABLE_NETWORK