11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
27PROMEKI_NAMESPACE_BEGIN
38struct RtcpSchedulerWriterStream {
53 RtpSession *session =
nullptr;
58 const Atomic<int64_t> *packetsSent =
nullptr;
64 const Atomic<int64_t> *senderOctets =
nullptr;
82struct RtcpSchedulerReaderStream {
96 RtpSession *session =
nullptr;
103 const RtpSeqTracker *seqTracker =
nullptr;
114 const Atomic<int64_t> *lastPacketArrivalNs =
nullptr;
122 bool *wireSilenceEosSignaled =
nullptr;
149struct RtcpSchedulerContext {
154 int intervalMs = 5000;
163 int64_t wireSilenceTimeoutMs = 0;
170 List<RtcpSchedulerWriterStream> writers;
177 List<RtcpSchedulerReaderStream> readers;
193 Function<void(RtcpSchedulerReaderStream &, int64_t gapNs)>
249class RtcpScheduler :
public Thread {
255 static constexpr unsigned int kStartupPollMs = 50;
262 static constexpr int kDefaultIntervalMs = 5000;
272 explicit RtcpScheduler(RtcpSchedulerContext ctx,
273 const String &name = String(
"rtp-rtcp"));
277 ~RtcpScheduler()
override;
279 RtcpScheduler(
const RtcpScheduler &) =
delete;
280 RtcpScheduler &operator=(
const RtcpScheduler &) =
delete;
293 bool isStopRequested()
const {
return _stopRequested.value(); }
306 void emitByeForAll();
328 void checkWireSilence(RtcpSchedulerReaderStream &s);
329 bool allStreamsHaveEmitted()
const;
330 void cvSleep(
unsigned int ms);
332 static void emitForStream(RtcpSchedulerWriterStream &s);
333 static void emitRrForStream(RtcpSchedulerReaderStream &s);
334 static void emitByeForWriter(RtcpSchedulerWriterStream &s);
335 static void emitByeForReader(RtcpSchedulerReaderStream &s);
337 RtcpSchedulerContext _ctx;
339 Atomic<bool> _stopRequested;