libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
rtcpscheduler.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 <cstdint>
14#include <functional>
15#include <promeki/function.h>
16#include <promeki/atomic.h>
17#include <promeki/list.h>
18#include <promeki/mutex.h>
19#include <promeki/namespace.h>
20#include <promeki/rtcppacket.h>
22#include <promeki/rtpsession.h>
23#include <promeki/string.h>
24#include <promeki/thread.h>
26
27PROMEKI_NAMESPACE_BEGIN
28
38struct RtcpSchedulerWriterStream {
43 bool active = false;
44
48 String mediaType;
49
53 RtpSession *session = nullptr;
54
58 const Atomic<int64_t> *packetsSent = nullptr;
59
64 const Atomic<int64_t> *senderOctets = nullptr;
65};
66
82struct RtcpSchedulerReaderStream {
86 bool active = false;
87
91 String mediaType;
92
96 RtpSession *session = nullptr;
97
103 const RtpSeqTracker *seqTracker = nullptr;
104
114 const Atomic<int64_t> *lastPacketArrivalNs = nullptr;
115
122 bool *wireSilenceEosSignaled = nullptr;
123};
124
149struct RtcpSchedulerContext {
154 int intervalMs = 5000;
155
163 int64_t wireSilenceTimeoutMs = 0;
164
170 List<RtcpSchedulerWriterStream> writers;
171
177 List<RtcpSchedulerReaderStream> readers;
178
193 Function<void(RtcpSchedulerReaderStream &, int64_t gapNs)>
194 onWireSilenceEos;
195};
196
249class RtcpScheduler : public Thread {
250 public:
255 static constexpr unsigned int kStartupPollMs = 50;
256
262 static constexpr int kDefaultIntervalMs = 5000;
263
272 explicit RtcpScheduler(RtcpSchedulerContext ctx,
273 const String &name = String("rtp-rtcp"));
274
277 ~RtcpScheduler() override;
278
279 RtcpScheduler(const RtcpScheduler &) = delete;
280 RtcpScheduler &operator=(const RtcpScheduler &) = delete;
281
289 void requestStop();
290
293 bool isStopRequested() const { return _stopRequested.value(); }
294
306 void emitByeForAll();
307
319 void runOnce();
320
321 protected:
324 void run() override;
325
326 private:
327 void emitOnce();
328 void checkWireSilence(RtcpSchedulerReaderStream &s);
329 bool allStreamsHaveEmitted() const;
330 void cvSleep(unsigned int ms);
331
332 static void emitForStream(RtcpSchedulerWriterStream &s);
333 static void emitRrForStream(RtcpSchedulerReaderStream &s);
334 static void emitByeForWriter(RtcpSchedulerWriterStream &s);
335 static void emitByeForReader(RtcpSchedulerReaderStream &s);
336
337 RtcpSchedulerContext _ctx;
338 int _intervalMs;
339 Atomic<bool> _stopRequested;
340 Mutex _mutex;
341 WaitCondition _cv;
342};
343
344PROMEKI_NAMESPACE_END
345
346#endif // PROMEKI_ENABLE_NETWORK