mediasoup 3.28.0 → 3.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/node/lib/PipeTransportTypes.d.ts +6 -1
  3. package/node/lib/PipeTransportTypes.d.ts.map +1 -1
  4. package/node/lib/PlainTransportTypes.d.ts +6 -1
  5. package/node/lib/PlainTransportTypes.d.ts.map +1 -1
  6. package/node/lib/Router.d.ts +4 -4
  7. package/node/lib/Router.d.ts.map +1 -1
  8. package/node/lib/Router.js +10 -7
  9. package/node/lib/RouterTypes.d.ts +7 -1
  10. package/node/lib/RouterTypes.d.ts.map +1 -1
  11. package/node/lib/Transport.d.ts +2 -1
  12. package/node/lib/Transport.d.ts.map +1 -1
  13. package/node/lib/Transport.js +17 -6
  14. package/node/lib/TransportTypes.d.ts +12 -2
  15. package/node/lib/TransportTypes.d.ts.map +1 -1
  16. package/node/lib/WebRtcTransportTypes.d.ts +6 -1
  17. package/node/lib/WebRtcTransportTypes.d.ts.map +1 -1
  18. package/node/lib/fbs/transport/options.d.ts +6 -2
  19. package/node/lib/fbs/transport/options.d.ts.map +1 -1
  20. package/node/lib/fbs/transport/options.js +19 -7
  21. package/node/lib/fbs/transport/sctp-zero-checksum.d.ts +6 -0
  22. package/node/lib/fbs/transport/sctp-zero-checksum.d.ts.map +1 -0
  23. package/node/lib/fbs/transport/sctp-zero-checksum.js +11 -0
  24. package/node/lib/fbs/transport/stats.d.ts +2 -8
  25. package/node/lib/fbs/transport/stats.d.ts.map +1 -1
  26. package/node/lib/fbs/transport/stats.js +5 -29
  27. package/node/lib/fbs/transport.d.ts +1 -0
  28. package/node/lib/fbs/transport.d.ts.map +1 -1
  29. package/node/lib/fbs/transport.js +4 -2
  30. package/npm-scripts.mjs +35 -44
  31. package/package.json +10 -6
  32. package/worker/fbs/transport.fbs +9 -2
  33. package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +14 -1
  34. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +17 -4
  35. package/worker/include/RTC/BWE/AimdRateControl.hpp +9 -9
  36. package/worker/include/RTC/BWE/BweTypes.hpp +54 -17
  37. package/worker/include/RTC/BWE/DelayBasedBwe.hpp +3 -3
  38. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +2 -2
  39. package/worker/include/RTC/BWE/LossBasedController.hpp +4 -4
  40. package/worker/include/RTC/BWE/OveruseDetector.hpp +5 -4
  41. package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +1 -1
  42. package/worker/include/RTC/BWE/ProbeController.hpp +6 -6
  43. package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +2 -6
  44. package/worker/include/RTC/BWE/ProbingScheduler.hpp +3 -7
  45. package/worker/include/RTC/BWE/ReceiverTransportCongestionController.hpp +148 -0
  46. package/worker/include/RTC/BWE/RembGenerator.hpp +4 -3
  47. package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +1 -1
  48. package/worker/include/RTC/BWE/SenderTransportCongestionController.hpp +343 -0
  49. package/worker/include/RTC/BWE/TargetRateController.hpp +4 -1
  50. package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +5 -4
  51. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +3 -3
  52. package/worker/include/RTC/Consumer.hpp +8 -1
  53. package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +36 -10
  54. package/worker/include/RTC/RTP/RtpStream.hpp +21 -0
  55. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +1 -0
  56. package/worker/include/RTC/RTP/RtpStreamSend.hpp +122 -9
  57. package/worker/include/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp +12 -3
  58. package/worker/include/RTC/TransportCongestionControlClient.hpp +0 -5
  59. package/worker/include/RTC/TransportCongestionControlServer.hpp +0 -5
  60. package/worker/include/Utils.hpp +9 -2
  61. package/worker/meson.build +4 -0
  62. package/worker/src/RTC/BWE/AimdRateControl.cpp +22 -22
  63. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +16 -20
  64. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +1 -1
  65. package/worker/src/RTC/BWE/OveruseDetector.cpp +8 -8
  66. package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +2 -2
  67. package/worker/src/RTC/BWE/ProbeController.cpp +1 -1
  68. package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +1 -6
  69. package/worker/src/RTC/BWE/ProbingScheduler.cpp +2 -7
  70. package/worker/src/RTC/BWE/ReceiverTransportCongestionController.cpp +207 -0
  71. package/worker/src/RTC/BWE/RembGenerator.cpp +1 -1
  72. package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +1 -1
  73. package/worker/src/RTC/BWE/SenderTransportCongestionController.cpp +599 -0
  74. package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +2 -3
  75. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +5 -5
  76. package/worker/src/RTC/Consumer.cpp +3 -2
  77. package/worker/src/RTC/DataConsumer.cpp +2 -2
  78. package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +21 -8
  79. package/worker/src/RTC/RTP/RtpStream.cpp +0 -3
  80. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +57 -71
  81. package/worker/src/RTC/RTP/RtpStreamSend.cpp +428 -244
  82. package/worker/src/RTC/RTP/RtxStream.cpp +14 -19
  83. package/worker/src/RTC/SCTP/association/Association.cpp +3 -2
  84. package/worker/src/RTC/SCTP/association/StateCookie.cpp +26 -6
  85. package/worker/src/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.cpp +4 -3
  86. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +2 -1
  87. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +4 -2
  88. package/worker/src/RTC/Transport.cpp +49 -20
  89. package/worker/src/RTC/TransportCongestionControlClient.cpp +0 -66
  90. package/worker/src/RTC/TransportCongestionControlServer.cpp +0 -55
  91. package/worker/src/Utils/Crypto.cpp +114 -98
  92. package/worker/subprojects/catch2.wrap +6 -6
  93. package/worker/subprojects/openssl.wrap +11 -12
  94. package/worker/subprojects/packagefiles/ankerl-unordered-dense/meson.build +1 -1
  95. package/worker/subprojects/unordered-dense.wrap +4 -4
  96. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +5 -5
  97. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +26 -23
  98. package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +8 -8
  99. package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +4 -4
  100. package/worker/test/src/RTC/BWE/TestProbeController.cpp +35 -32
  101. package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +2 -17
  102. package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +1 -25
  103. package/worker/test/src/RTC/BWE/TestReceiverTransportCongestionController.cpp +346 -0
  104. package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +1 -1
  105. package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +9 -9
  106. package/worker/test/src/RTC/BWE/TestSenderTransportCongestionController.cpp +510 -0
  107. package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +16 -14
  108. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +6 -6
  109. package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +1 -2
  110. package/worker/test/src/RTC/RTCP/TestBye.cpp +1 -1
  111. package/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp +1 -1
  112. package/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp +1 -1
  113. package/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp +1 -1
  114. package/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp +1 -1
  115. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +1 -1
  116. package/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp +1 -1
  117. package/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp +1 -1
  118. package/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp +1 -1
  119. package/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp +1 -1
  120. package/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp +1 -1
  121. package/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp +1 -1
  122. package/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp +1 -1
  123. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp +1 -1
  124. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
  125. package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +1 -1
  126. package/worker/test/src/RTC/RTCP/TestReceiverReport.cpp +1 -1
  127. package/worker/test/src/RTC/RTCP/TestSenderReport.cpp +1 -1
  128. package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +60 -28
  129. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +1 -1
  130. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +746 -24
  131. package/worker/test/src/RTC/RTP/TestSharedPacket.cpp +1 -1
  132. package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +42 -0
  133. package/worker/test/src/RTC/SCTP/association/TestNegotiatedCapabilities.cpp +54 -5
  134. package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +80 -15
  135. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +410 -3
  136. package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +1 -1
  137. package/worker/test/src/RTC/SCTP/packet/parameters/TestZeroChecksumAcceptableParameter.cpp +37 -5
  138. package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +5 -4
  139. package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +1 -1
  140. package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
  141. package/worker/test/src/RTC/SCTP/rx/TestTraditionalReassemblyStreams.cpp +1 -1
  142. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +1 -1
  143. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +11 -10
  144. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +1 -1
  145. package/worker/test/src/RTC/TestNackGenerator.cpp +1 -1
  146. package/worker/test/src/RTC/TestPortManager.cpp +2 -2
  147. package/worker/test/src/RTC/TestRateCalculator.cpp +1 -1
  148. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +21 -15
  149. package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +13 -13
  150. package/worker/test/src/RTC/TestRtpEncodingParameters.cpp +1 -1
  151. package/worker/test/src/RTC/TestSubchannelsCodec.cpp +2 -2
  152. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +1 -1
  153. package/worker/test/src/RTC/TestTransportTuple.cpp +3 -2
  154. package/worker/test/src/Utils/TestCrypto.cpp +71 -2
  155. package/worker/test/src/Utils/TestTime.cpp +2 -2
@@ -0,0 +1,343 @@
1
+ #ifndef MS_RTC_BWE_SENDER_TRANSPORT_CONGESTION_CONTROLLER_HPP
2
+ #define MS_RTC_BWE_SENDER_TRANSPORT_CONGESTION_CONTROLLER_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "handles/TimerHandle.hpp"
6
+ #include "RTC/BWE/AlrDetector.hpp"
7
+ #include "RTC/BWE/BweTypes.hpp"
8
+ #include "RTC/BWE/DelayBasedBwe.hpp"
9
+ #include "RTC/BWE/FeedbackAdapter.hpp"
10
+ #include "RTC/BWE/ProbeBitrateEstimator.hpp"
11
+ #include "RTC/BWE/ProbeController.hpp"
12
+ #include "RTC/BWE/ProbingScheduler.hpp"
13
+ #include "RTC/BWE/RobustThroughputEstimator.hpp"
14
+ #include "RTC/BWE/SendPacketHistory.hpp"
15
+ #include "RTC/BWE/TargetRateController.hpp"
16
+ #include "RTC/Consts.hpp"
17
+ #include "RTC/RTCP/FeedbackRtpTransport.hpp"
18
+ #include "RTC/RTP/Packet.hpp"
19
+ #include "SharedInterface.hpp"
20
+ #include <vector>
21
+
22
+ namespace RTC
23
+ {
24
+ namespace BWE
25
+ {
26
+ /**
27
+ * Everything the sending side of a transport does about congestion, which
28
+ * amounts to deciding how much may be sent towards the remote endpoint.
29
+ *
30
+ * It owns the whole control loop and is, along with its receiving
31
+ * counterpart, the only part of the module that the transport deals with.
32
+ * What comes in is what leaves this endpoint and what the remote one reports
33
+ * back about it; what comes out is a target bitrate, for whoever shares it
34
+ * among the streams being sent, and the packets of a probe when the link has
35
+ * to be measured beyond what the media alone can tell.
36
+ */
37
+ class SenderTransportCongestionController : public ProbingScheduler::Listener,
38
+ public TimerHandleInterface::Listener
39
+ {
40
+ public:
41
+ class Listener
42
+ {
43
+ public:
44
+ virtual ~Listener() = default;
45
+
46
+ public:
47
+ /**
48
+ * The bitrate that may be sent towards the remote endpoint changed
49
+ * (bps).
50
+ */
51
+ virtual void OnSenderTransportCongestionControllerTargetBitrate(
52
+ SenderTransportCongestionController* senderTransportCongestionController,
53
+ int64_t targetBitrate) = 0;
54
+
55
+ /**
56
+ * A packet of a probe is ready to go out.
57
+ *
58
+ * @param sequenceNumber - The one given to the packet, which has to be
59
+ * given back through `OnRtpPacketSent()` once the packet has actually
60
+ * left, just like for a packet of media.
61
+ *
62
+ * @remarks
63
+ * - The packet must be sent before returning, since the next one is
64
+ * built over the very same instance.
65
+ */
66
+ virtual void OnSenderTransportCongestionControllerSendRtpProbePacket(
67
+ SenderTransportCongestionController* senderTransportCongestionController,
68
+ RTC::RTP::Packet* packet,
69
+ int64_t sequenceNumber) = 0;
70
+ };
71
+
72
+ /**
73
+ * What a packet about to be sent cannot tell about itself.
74
+ */
75
+ struct RtpPacketToBeSentOptions
76
+ {
77
+ /**
78
+ * Whether it belongs to an audio stream.
79
+ */
80
+ bool isAudio{ false };
81
+ /**
82
+ * Whether it is being sent again after having been reported lost.
83
+ */
84
+ bool isRetransmission{ false };
85
+ /**
86
+ * SSRC of the stream it retransmits, when it goes out over RTX.
87
+ */
88
+ std::optional<uint32_t> originalSsrc;
89
+ };
90
+
91
+ struct SenderTransportCongestionControllerOptions
92
+ {
93
+ /**
94
+ * Bitrate the control loop starts from, before anything has been
95
+ * measured (bps). It only means something until the first feedback
96
+ * arrives, which is why it is given once and never changed: starting
97
+ * over would mean throwing away what has been learnt since.
98
+ */
99
+ int64_t startBitrate{ 300000 };
100
+ /**
101
+ * Least that may ever be estimated (bps). It exists so that the loop
102
+ * cannot drive its own estimate to nothing, which would be
103
+ * unrecoverable: with nothing to hand out, nothing is sent, so there is
104
+ * nothing to measure and no way back up.
105
+ */
106
+ int64_t minBitrate{ RTC::Consts::BweMinBitrate };
107
+ /**
108
+ * Most that may ever be estimated (bps), or `Types::BitrateInfinite` to
109
+ * let the link decide.
110
+ */
111
+ int64_t maxBitrate{ Types::BitrateInfinite };
112
+ };
113
+
114
+ private:
115
+ /**
116
+ * What a call leaves to be done once it is over, so that nothing of this
117
+ * class is half way through anything by the time the listener is told and
118
+ * calls back in.
119
+ */
120
+ struct PendingUpdate
121
+ {
122
+ /**
123
+ * Bursts that were asked for, which are handed to the scheduler all at
124
+ * once.
125
+ */
126
+ std::vector<Types::ProbeClusterConfig> probeClusterConfigs;
127
+ /**
128
+ * Target the listener is to be told about, when something it reasons
129
+ * about turned out to have changed.
130
+ *
131
+ * @remarks
132
+ * - It is worked out where the call would have announced it, and only
133
+ * handed over at the end, since what is reconsidered along the way
134
+ * depends on the order the original does things in.
135
+ */
136
+ std::optional<int64_t> targetBitrateToNotify;
137
+ };
138
+
139
+ public:
140
+ SenderTransportCongestionController(
141
+ Listener* listener,
142
+ SharedInterface* shared,
143
+ SenderTransportCongestionControllerOptions options);
144
+
145
+ ~SenderTransportCongestionController() override = default;
146
+
147
+ SenderTransportCongestionController(const SenderTransportCongestionController&) = delete;
148
+ SenderTransportCongestionController& operator=(const SenderTransportCongestionController&) = delete;
149
+
150
+ /**
151
+ * Tell whether the transport can carry anything at all. Nothing is probed
152
+ * until it can, so forgetting this leaves the initial probing waiting
153
+ * forever.
154
+ */
155
+ void SetNetworkAvailable(bool networkAvailable);
156
+
157
+ /**
158
+ * Take note of a packet that is about to be sent, and write into it the
159
+ * transport wide sequence number and the abs-send-time that go on the
160
+ * wire with it.
161
+ *
162
+ * @returns The sequence number given to the packet, which has to be given
163
+ * back once the packet has actually left, or no value when the packet
164
+ * carries no room for it. A packet without that extension cannot be
165
+ * reported on, so nothing is taken note of and only its bytes count.
166
+ */
167
+ std::optional<int64_t> OnRtpPacketToBeSent(
168
+ RTC::RTP::Packet* packet, const RtpPacketToBeSentOptions& options);
169
+
170
+ /**
171
+ * Feed the confirmation that a packet left through the socket.
172
+ *
173
+ * @param sequenceNumber - What `OnRtpPacketToBeSent()` returned for it.
174
+ * @param size - Length of the packet (bytes), which is what is counted when
175
+ * there is no sequence number to look it up by.
176
+ */
177
+ void OnRtpPacketSent(std::optional<int64_t> sequenceNumber, size_t size, int64_t sentAtUs);
178
+
179
+ /**
180
+ * Feed a received transport wide cc feedback, which is what the delay
181
+ * based estimation is drawn from.
182
+ */
183
+ void ReceiveTransportWideCcFeedback(
184
+ const RTC::RTCP::FeedbackRtpTransportPacket* feedback, int64_t receivedAtUs);
185
+
186
+ /**
187
+ * Feed what the RTCP Receiver Reports of a received RTCP packet measured,
188
+ * added up over all the streams they report on, which is where the loss of
189
+ * what we send is taken from.
190
+ *
191
+ * @remarks
192
+ * - The loss may be negative, since a report gives back what a previous one
193
+ * was overcharged for.
194
+ */
195
+ void ReceiveRtcpReceiverReport(int64_t lostPackets, int64_t expectedPackets);
196
+
197
+ /**
198
+ * Feed a received REMB, which is what the remote endpoint says it is
199
+ * willing to receive.
200
+ */
201
+ void ReceiveEstimatedBitrate(int64_t bitrate);
202
+
203
+ /**
204
+ * Feed the round trip time towards the remote endpoint.
205
+ */
206
+ void OnRttUpdate(int64_t rttUs);
207
+
208
+ /**
209
+ * Bound what may be estimated (bps). The bitrate to start from is not
210
+ * among these, since it only applies before anything has been measured.
211
+ */
212
+ void SetBitrateLimits(int64_t minBitrate, int64_t maxBitrate);
213
+
214
+ /**
215
+ * Feed the total bitrate that the streams being sent would like to have
216
+ * (bps), which is what tells whether there is any point in probing higher.
217
+ */
218
+ void SetDesiredBitrate(int64_t desiredBitrate);
219
+
220
+ /**
221
+ * Size of the overhead that every packet carries below RTP (bytes), which
222
+ * the link bears along with the packets themselves.
223
+ */
224
+ void SetPacketOverhead(size_t packetOverhead);
225
+
226
+ /**
227
+ * Latest target bitrate (bps).
228
+ */
229
+ int64_t GetAvailableBitrate() const;
230
+
231
+ /* Pure virtual methods inherited from ProbingScheduler::Listener. */
232
+ public:
233
+ void OnProbingSchedulerSendRtpPacket(
234
+ ProbingScheduler* probingScheduler,
235
+ RTC::RTP::Packet* packet,
236
+ const Types::ProbeCluster& probeCluster) override;
237
+
238
+ /* Pure virtual methods inherited from RTC::TimerHandleInterface::Listener. */
239
+ public:
240
+ void OnTimer(TimerHandleInterface* timer) override;
241
+
242
+ private:
243
+ /**
244
+ * Take note of a packet about to be sent and write its two extensions,
245
+ * which is the same work for a packet of media and for one of a probe.
246
+ *
247
+ * @returns No value when the packet has no room for the transport wide
248
+ * sequence number, in which case nothing is taken note of.
249
+ */
250
+ std::optional<int64_t> AddRtpPacket(
251
+ RTC::RTP::Packet* packet,
252
+ const RtpPacketToBeSentOptions& options,
253
+ std::optional<Types::ProbeCluster> probeCluster);
254
+
255
+ /**
256
+ * Run everything that depends on time having passed rather than on
257
+ * anything having arrived, which is where the target may rise and where
258
+ * probes are decided.
259
+ */
260
+ void Process();
261
+
262
+ /**
263
+ * Take note of the bursts that were asked for, which go out once the call
264
+ * that asked for them is over.
265
+ */
266
+ void AddProbeClusters(const std::vector<Types::ProbeClusterConfig>& clusterConfigs);
267
+
268
+ /**
269
+ * Do everything the call leaves pending: hand the bursts to the scheduler
270
+ * and tell the listener about the target, but only when something it
271
+ * reasons about actually changed.
272
+ *
273
+ * @remarks
274
+ * - It is the last thing done by every entry point that may leave something
275
+ * pending, and the only place where anything of this leaves the class.
276
+ */
277
+ void ApplyPendingUpdate();
278
+
279
+ /**
280
+ * Reconsider the target and take note of it when the listener has to be
281
+ * told, which is what every path that may have moved it ends with.
282
+ */
283
+ void MayNotifyTargetBitrate(int64_t nowUs);
284
+
285
+ /**
286
+ * Bring the bounds into a range the pieces below accept and hand them
287
+ * down.
288
+ *
289
+ * @param applyStartBitrate - Whether the bitrate to start from is handed
290
+ * down along with them. It only is the first time, since doing it again
291
+ * would force the target back to it and throw away everything the delay
292
+ * based path has learnt since.
293
+ */
294
+ void ResetConstraints(int64_t nowUs, bool applyStartBitrate);
295
+
296
+ private:
297
+ // Passed by argument.
298
+ Listener* listener{ nullptr };
299
+ SharedInterface* shared{ nullptr };
300
+ // Allocated by this.
301
+ const std::unique_ptr<TimerHandleInterface> processTimer;
302
+ // Others.
303
+ SendPacketHistory sendPacketHistory;
304
+ FeedbackAdapter feedbackAdapter;
305
+ DelayBasedBwe delayBasedBwe;
306
+ RobustThroughputEstimator acknowledgedBitrateEstimator;
307
+ TargetRateController targetRateController;
308
+ AlrDetector alrDetector;
309
+ ProbeController probeController;
310
+ ProbeBitrateEstimator probeBitrateEstimator;
311
+ ProbingScheduler probingScheduler;
312
+ // What every packet carries below RTP (bytes), which is added to the size
313
+ // the rate control reasons about.
314
+ size_t packetOverhead{ 0 };
315
+ // Bounds in force, already brought into a range the pieces below accept.
316
+ // The one to start from is kept because a change of the other two has to
317
+ // be handed down along with it, and it is raised to the minimum where it
318
+ // is used rather than here, so that it stays what was asked for.
319
+ int64_t minBitrate{ 0 };
320
+ const int64_t startBitrate;
321
+ int64_t maxBitrate{ Types::BitrateInfinite };
322
+ // Whether anything has been sent and whether any transport-cc feedback has
323
+ // arrived, which tell apart a transport that is not being used from one
324
+ // whose remote endpoint does not report.
325
+ bool firstPacketSent{ false };
326
+ bool firstTransportFeedbackReceived{ false };
327
+ // Whether the sender was not filling the link when the latest feedback was
328
+ // handled, so that the instant it stopped being so can be told.
329
+ bool previouslyInAlr{ false };
330
+ // What the listener was last told about, which is what tells whether there
331
+ // is anything new to tell.
332
+ std::optional<int64_t> lastTargetBitrate;
333
+ uint8_t lastFractionLost{ 0 };
334
+ int64_t lastRttUs{ 0 };
335
+ LossBasedController::State lastLossBasedState{ LossBasedController::State::DELAY_BASED_ESTIMATE };
336
+ bool lastIsBandwidthLimited{ true };
337
+ // What the call being served leaves to be done once it is over.
338
+ PendingUpdate pendingUpdate;
339
+ };
340
+ } // namespace BWE
341
+ } // namespace RTC
342
+
343
+ #endif
@@ -62,6 +62,9 @@ namespace RTC
62
62
  /**
63
63
  * Round trip time over which the bitrate is dropped regardless of loss.
64
64
  * A round trip time this long means the queues of the network are full.
65
+ *
66
+ * @remarks
67
+ * - `Types::TimeUsInfinite` turns the backoff off.
65
68
  */
66
69
  int64_t maxRttUs{ 3 * 1000 * 1000 };
67
70
  /**
@@ -270,7 +273,7 @@ namespace RTC
270
273
  // the target as soon as it has enough observations.
271
274
  LossBasedController lossBasedController;
272
275
  LossBasedController::State lossBasedState{ LossBasedController::State::DELAY_BASED_ESTIMATE };
273
- struct RttBackoff rttBackoff;
276
+ RttBackoff rttBackoff;
274
277
  // Lowest target of the last second, as a sliding window minimum of
275
278
  // (instant in us, bitrate in bps) pairs.
276
279
  std::deque<std::pair<int64_t, int64_t>> minBitrateHistory;
@@ -38,10 +38,11 @@ namespace RTC
38
38
  /**
39
39
  * A feedback packet is ready for the remote sender.
40
40
  *
41
- * @param packet - Packet to send, only valid for the duration of this
42
- * call.
41
+ * @param packet - Packet to send. It belongs to the caller, so the
42
+ * listener must neither destroy it nor keep it around after this call
43
+ * returns.
43
44
  */
44
- virtual void OnTransportWideCcFeedbackGeneratorSendRtcpPacket(
45
+ virtual void OnTransportWideCcFeedbackGeneratorSendPacket(
45
46
  TransportWideCcFeedbackGenerator* transportWideCcFeedbackGenerator,
46
47
  RTC::RTCP::FeedbackRtpTransportPacket* packet) = 0;
47
48
  };
@@ -60,7 +61,7 @@ namespace RTC
60
61
  *
61
62
  * @param arrivalTimeUs - Instant the packet arrived.
62
63
  */
63
- void IncomingPacket(int64_t arrivalTimeUs, const RTC::RTP::Packet* packet);
64
+ void ReceiveRtpPacket(int64_t arrivalTimeUs, const RTC::RTP::Packet* packet);
64
65
 
65
66
  #ifdef MS_TEST
66
67
  public:
@@ -103,8 +103,8 @@ namespace RTC
103
103
  * @param sendDeltaUs - Time elapsed between the send times of both groups.
104
104
  * @param arrivalDeltaUs - Time elapsed between the arrival times of both
105
105
  * groups.
106
- * @param arrivalTimeUs - Arrival time of the latest group, in the remote
107
- * clock reference.
106
+ * @param arrivalTimeUs - Instant the latest group arrived at the remote
107
+ * endpoint, anchored to our own clock by the feedback adapter.
108
108
  */
109
109
  void Update(int64_t sendDeltaUs, int64_t arrivalDeltaUs, int64_t arrivalTimeUs);
110
110
 
@@ -149,7 +149,7 @@ namespace RTC
149
149
  double prevTrend{ 0 };
150
150
  std::optional<double> timeOverUsingUs;
151
151
  int overuseCounter{ 0 };
152
- std::optional<int64_t> lastThresholdUpdateAtUs;
152
+ std::optional<int64_t> lastSampleArrivalTimeUs;
153
153
  Types::BandwidthUsage state{ Types::BandwidthUsage::NORMAL };
154
154
  };
155
155
  } // namespace BWE
@@ -9,6 +9,7 @@
9
9
  #include "RTC/ConsumerTypes.hpp"
10
10
  #include "RTC/ProducerStreamManager.hpp"
11
11
  #include "RTC/RTCP/CompoundPacket.hpp"
12
+ #include "RTC/RTCP/Feedback.hpp"
12
13
  #include "RTC/RTCP/FeedbackRtpNack.hpp"
13
14
  #include "RTC/RTCP/ReceiverReport.hpp"
14
15
  #include "RTC/RTP/HeaderExtensionIds.hpp"
@@ -153,7 +154,13 @@ namespace RTC
153
154
  uint8_t GetWorstRemoteFractionLost(uint32_t mappedSsrc) const;
154
155
  void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
155
156
  void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc);
156
- void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report, int64_t receivedAtUs);
157
+ /**
158
+ * @returns What the link to the remote endpoint lost and what it was expected
159
+ * to deliver since the previous Receiver Report, or no value if this one
160
+ * measures no interval at all.
161
+ */
162
+ std::optional<RTC::RTP::RtpStreamSend::Loss> ReceiveRtcpReceiverReport(
163
+ RTC::RTCP::ReceiverReport* report, int64_t receivedAtUs);
157
164
  void ReceiveRtcpXrReceiverReferenceTime(
158
165
  RTC::RTCP::ReceiverReferenceTime* report, int64_t receivedAtUs);
159
166
  int64_t GetTransmissionRate(int64_t nowMs);
@@ -22,26 +22,47 @@ namespace RTC
22
22
  {
23
23
  void Reset();
24
24
 
25
- // Original packet.
25
+ /**
26
+ * Original packet.
27
+ */
26
28
  RTP::SharedPacket sharedPacket{ nullptr };
27
- // Payload descriptor encoder.
29
+ /**
30
+ * Payload descriptor encoder.
31
+ */
28
32
  std::unique_ptr<RTP::Codecs::PayloadDescriptor::Encoder> encoder{ nullptr };
29
- // Correct SSRC since original packet may not have the same.
33
+ /**
34
+ * Correct SSRC since original packet may not have the same.
35
+ */
30
36
  uint32_t ssrc{ 0 };
31
- // Correct sequence number since original packet may not have the same.
37
+ /**
38
+ * Correct sequence number since original packet may not have the same.
39
+ */
32
40
  uint16_t sequenceNumber{ 0 };
33
- // Correct timestamp since original packet may not have the same.
41
+ /**
42
+ * Correct timestamp since original packet may not have the same.
43
+ */
34
44
  uint32_t timestamp{ 0 };
35
- // Correct marker bit since original packet may not have the same.
45
+ /**
46
+ * Correct marker bit since original packet may not have the same.
47
+ */
36
48
  bool marker{ false };
37
- // Last time this packet was resent.
49
+ /**
50
+ * Time at which this packet was stored.
51
+ */
52
+ int64_t storedAtMs{ 0 };
53
+ /**
54
+ * Last time this packet was resent.
55
+ */
38
56
  int64_t resentAtMs{ 0 };
39
- // Number of times this packet was resent.
57
+ /**
58
+ * Number of times this packet was resent.
59
+ */
40
60
  uint8_t sentTimes{ 0 };
41
61
  };
42
62
 
43
63
  private:
44
- static Item* FillItem(Item* item, RTP::Packet* packet, const RTP::SharedPacket& sharedPacket);
64
+ static Item* FillItem(
65
+ Item* item, RTP::Packet* packet, const RTP::SharedPacket& sharedPacket, int64_t nowMs);
45
66
 
46
67
  public:
47
68
  RetransmissionBuffer(uint16_t maxItems, int64_t maxRetransmissionDelayMs, uint32_t clockRate);
@@ -49,8 +70,13 @@ namespace RTC
49
70
 
50
71
  void Dump(int indentation = 0) const;
51
72
  Item* Get(uint16_t seq) const;
52
- bool Insert(RTP::Packet* packet, const RTP::SharedPacket& sharedPacket);
73
+ bool Insert(RTP::Packet* packet, const RTP::SharedPacket& sharedPacket, int64_t nowMs);
53
74
  void Clear();
75
+ /**
76
+ * Whether the given stored item was stored longer than the maximum
77
+ * retransmission delay ago.
78
+ */
79
+ bool IsTooOld(const Item* item, int64_t nowMs) const;
54
80
 
55
81
  private:
56
82
  Item* GetOldest() const;
@@ -16,6 +16,22 @@ namespace RTC
16
16
  {
17
17
  class RtpStream
18
18
  {
19
+ public:
20
+ /**
21
+ * Largest jump forward in sequence number taken as a gap within the stream
22
+ * rather than as a restart of it.
23
+ */
24
+ static constexpr uint16_t MaxDropout{ 3000 };
25
+ /**
26
+ * How far back a sequence number may land for its packet to be taken as
27
+ * reordered rather than as a restart of the stream.
28
+ */
29
+ static constexpr uint16_t MaxMisorder{ 1500 };
30
+ /**
31
+ * Size of the RTP sequence number space, which is where it wraps around.
32
+ */
33
+ static constexpr uint32_t RtpSeqMod{ 1 << 16 };
34
+
19
35
  protected:
20
36
  class Listener
21
37
  {
@@ -171,6 +187,11 @@ namespace RTC
171
187
  return this->fractionLost;
172
188
  }
173
189
 
190
+ int32_t GetPacketsLost() const
191
+ {
192
+ return this->packetsLost;
193
+ }
194
+
174
195
  float GetLossPercentage() const
175
196
  {
176
197
  return static_cast<float>(this->fractionLost) * 100 / 256;
@@ -1,6 +1,7 @@
1
1
  #ifndef MS_RTC_RTP_RTP_STREAM_RECV_HPP
2
2
  #define MS_RTC_RTP_RTP_STREAM_RECV_HPP
3
3
 
4
+ #include "common.hpp"
4
5
  #include "handles/TimerHandleInterface.hpp"
5
6
  #include "RTC/NackGenerator.hpp"
6
7
  #include "RTC/RTCP/Packet.hpp"