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
@@ -1,31 +1,44 @@
1
1
  #ifndef MS_RTC_RTP_RTP_STREAM_SEND_HPP
2
2
  #define MS_RTC_RTP_RTP_STREAM_SEND_HPP
3
3
 
4
- #include "RTC/RTCP/FeedbackPs.hpp"
4
+ #include "common.hpp"
5
+ #include "FBS/rtpStream.h"
6
+ #include "Utils/UnwrappedSequenceNumber.hpp"
7
+ #include "handles/TimerHandleInterface.hpp"
8
+ #include "RTC/RTCP/Feedback.hpp"
5
9
  #include "RTC/RTCP/FeedbackRtpNack.hpp"
10
+ #include "RTC/RTCP/ReceiverReport.hpp"
6
11
  #include "RTC/RTCP/Sdes.hpp"
12
+ #include "RTC/RTCP/SenderReport.hpp"
7
13
  #include "RTC/RTCP/XrDelaySinceLastRr.hpp"
8
14
  #include "RTC/RTCP/XrReceiverReferenceTime.hpp"
15
+ #include "RTC/RTP/Packet.hpp"
9
16
  #include "RTC/RTP/RetransmissionBuffer.hpp"
10
17
  #include "RTC/RTP/RtpStream.hpp"
11
18
  #include "RTC/RTP/SharedPacket.hpp"
12
19
  #include "RTC/RateCalculator.hpp"
20
+ #include "SharedInterface.hpp"
21
+ #include <flatbuffers/flatbuffer_builder.h>
22
+ #include <ankerl/unordered_dense.h>
23
+ #include <deque>
24
+ #include <set>
25
+ #include <string>
13
26
 
14
27
  namespace RTC
15
28
  {
16
29
  namespace RTP
17
30
  {
18
- class RtpStreamSend : public RTP::RtpStream
31
+ class RtpStreamSend : public RTP::RtpStream, public TimerHandleInterface::Listener
19
32
  {
20
33
  public:
21
34
  /**
22
35
  * Maximum retransmission buffer size for video (ms).
23
36
  */
24
- static constexpr int64_t MaxRetransmissionDelayForVideoMs{ 2000 };
37
+ static constexpr int64_t MaxRetransmissionDelayForVideoMs{ 4000 };
25
38
  /**
26
39
  * Maximum retransmission buffer size for audio (ms).
27
40
  */
28
- static constexpr int64_t MaxRetransmissionDelayForAudioMs{ 1000 };
41
+ static constexpr int64_t MaxRetransmissionDelayForAudioMs{ 2000 };
29
42
  /**
30
43
  * How old the last packet sent may be for a Sender Report to still be generated
31
44
  * (ms).
@@ -36,6 +49,40 @@ namespace RTC
36
49
  * a stream that has really stopped sending.
37
50
  */
38
51
  static constexpr int64_t MaxSenderReportReferenceAgeMs{ 2000 };
52
+ /**
53
+ * How many sequence numbers that were never sent are remembered.
54
+ *
55
+ * @remarks
56
+ * - Only a Receiver Report drains them and a remote endpoint may stop
57
+ * reporting, so this bounds what a stream whose reports never arrive can
58
+ * hold on to.
59
+ * - What it has to cover is the sequence numbers skipped between two
60
+ * Receiver Reports. Taking the 5 seconds that RFC 3550 gives as a report
61
+ * interval and the 520 packets per second of a 5 Mbps video stream, this
62
+ * is close to four seconds of such a stream skipped whole.
63
+ */
64
+ static constexpr size_t MaxUnsentSeqNumbers{ 2000 };
65
+
66
+ public:
67
+ /**
68
+ * How many packets the remote endpoint missed and how many it should have
69
+ * got, over the time between the previous Receiver Report and this one,
70
+ * counting only what this link is answerable for.
71
+ */
72
+ struct Loss
73
+ {
74
+ /**
75
+ * Packets lost. It may be negative, since a hole that a previous report
76
+ * already counted and that a late packet has filled in since gives back
77
+ * what that report was charged for.
78
+ */
79
+ int64_t lostPackets;
80
+ /**
81
+ * Packets expected, which is what the sequence numbers of the interval
82
+ * covered once the ones that were never sent are taken out of it.
83
+ */
84
+ int64_t expectedPackets;
85
+ };
39
86
 
40
87
  public:
41
88
  enum class ReceivePacketResult : uint8_t
@@ -92,7 +139,13 @@ namespace RTC
92
139
 
93
140
  void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType);
94
141
 
95
- void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report, int64_t receivedAtUs);
142
+ /**
143
+ * @returns What this link lost and what it was expected to deliver since
144
+ * the previous Receiver Report, or no value if this one measures no
145
+ * interval at all.
146
+ */
147
+ std::optional<Loss> ReceiveRtcpReceiverReport(
148
+ RTC::RTCP::ReceiverReport* report, int64_t receivedAtUs);
96
149
 
97
150
  void ReceiveRtcpXrReceiverReferenceTime(
98
151
  RTC::RTCP::ReceiverReferenceTime* report, int64_t receivedAtUs);
@@ -119,17 +172,50 @@ namespace RTC
119
172
  int64_t GetLayerBitrate(int64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override;
120
173
 
121
174
  private:
122
- void FillRetransmissionContainer(uint16_t seq, uint16_t bitmask);
175
+ void RetransmitPendingPackets();
123
176
 
124
- void UpdateScore(RTC::RTCP::ReceiverReport* report);
177
+ /**
178
+ * @param loss What the latest Receiver Report measured, or no value if it
179
+ * measured nothing.
180
+ */
181
+ void UpdateScore(const std::optional<Loss>& loss);
182
+
183
+ /**
184
+ * Take note of the sequence numbers that the packet just accepted leaves
185
+ * behind for good, or forget one that it fills in late.
186
+ */
187
+ void UpdateUnsentSeqNumbers(uint16_t seq);
188
+
189
+ /**
190
+ * Work out how much of what the Receiver Report reports as lost really was
191
+ * lost on the way to the remote endpoint, and take note of it.
192
+ *
193
+ * @returns What this link lost and what it was expected to deliver since
194
+ * the previous Receiver Report, or no value if this one measures no
195
+ * interval at all.
196
+ *
197
+ * @remarks
198
+ * - What it takes note of in `fractionLost` and `packetsLost` is held at
199
+ * zero and at the packets expected, since neither may go backwards. What
200
+ * it returns is not, so that whoever adds up several of them gets the
201
+ * negative ones back.
202
+ */
203
+ std::optional<Loss> UpdateSendLoss(RTC::RTCP::ReceiverReport* report);
204
+
205
+ /**
206
+ * Forget everything measured over a numbering that is not in use anymore.
207
+ */
208
+ void ResetSendLoss();
125
209
 
126
210
  /* Pure virtual methods inherited from RTP::RtpStream. */
127
211
  public:
128
212
  void UserOnSequenceNumberReset() override;
129
213
 
214
+ /* Pure virtual methods inherited from TimerHandleInterface::Listener. */
215
+ public:
216
+ void OnTimer(TimerHandleInterface* timer) override;
217
+
130
218
  private:
131
- // Packets lost at last interval for score calculation.
132
- int32_t lostPriorScore{ 0 };
133
219
  // Packets sent at last interval for score calculation.
134
220
  // NOTE: As wide as the counter it snapshots, which does not wrap, so that
135
221
  // the difference against it stays exact however long the stream runs.
@@ -138,8 +224,35 @@ namespace RTC
138
224
  uint16_t rtxSeq{ 0 };
139
225
  RTC::RtpDataCounter transmissionCounter;
140
226
  RTP::RetransmissionBuffer* retransmissionBuffer{ nullptr };
227
+ // Sequence numbers requested by received NACKs and not retransmitted yet,
228
+ // in the order they were requested.
229
+ std::deque<uint16_t> pendingRetransmissionsQueue;
230
+ // Same sequence numbers as in pendingRetransmissionsQueue, to tell whether
231
+ // a requested one is already pending.
232
+ ankerl::unordered_dense::set<uint16_t> pendingRetransmissionsSet;
233
+ // Timer to retransmit the pending retransmissions spaced in time. Only
234
+ // created if NACK is enabled.
235
+ const std::unique_ptr<TimerHandleInterface> retransmissionTimer;
141
236
  // Timing data of the most recent Receiver Reference Time received.
142
237
  std::optional<ReceiverReferenceTime> lastReceiverReferenceTime;
238
+ // Unwraps the sequence numbers of what is sent, so that comparing them
239
+ // against the ones a Receiver Report names needs no wrapping arithmetic.
240
+ Utils::UnwrappedSequenceNumber<uint16_t>::Unwrapper seqUnwrapper;
241
+ // Sequence numbers that were skipped and will never be sent, which is what
242
+ // the uplink of the Producer lost, unwrapped.
243
+ std::set<int64_t> unsentSeqs;
244
+ // Highest sequence number sent so far, unwrapped.
245
+ std::optional<int64_t> highestSentSeq;
246
+ // Highest sequence number the previous Receiver Report had seen, unwrapped
247
+ // into our own numbering, which is where the interval of the next one
248
+ // starts. Seeded one below the first sequence number sent, so that the
249
+ // first report measures from that one onwards.
250
+ std::optional<int64_t> lastRrSeq;
251
+ // What the previous Receiver Report reported as lost in total. Left without
252
+ // a value when the numbering is reset, since the remote endpoint counts
253
+ // over the whole session and does not reset along with us, so the next
254
+ // report can only be taken as a new mark.
255
+ std::optional<int32_t> lastRrTotalLost{ 0 };
143
256
  };
144
257
  } // namespace RTP
145
258
  } // namespace RTC
@@ -37,12 +37,20 @@ namespace RTC
37
37
  public:
38
38
  /**
39
39
  * Zero Checksum Alternate Error Detection Method.
40
+ *
41
+ * @remarks
42
+ * - `TRUSTED_NETWORK` is not assigned by IANA. It's a mediasoup specific
43
+ * method meant to be used between mediasoup endpoints only, when the
44
+ * network path between them is trusted (such as localhost). Its value
45
+ * is taken from the top of the range to minimize the chances of
46
+ * colliding with a method assigned by IANA in the future.
40
47
  */
41
48
  // NOLINTNEXTLINE(performance-enum-size)
42
49
  enum class AlternateErrorDetectionMethod : uint32_t
43
50
  {
44
- NONE = 0x0000,
45
- SCTP_OVER_DTLS = 0x0001,
51
+ NONE = 0x00000000,
52
+ SCTP_OVER_DTLS = 0x00000001,
53
+ TRUSTED_NETWORK = 0xFFFFFFFE,
46
54
  };
47
55
 
48
56
  public:
@@ -100,7 +108,8 @@ namespace RTC
100
108
 
101
109
  if (
102
110
  method == static_cast<uint32_t>(AlternateErrorDetectionMethod::NONE) ||
103
- method == static_cast<uint32_t>(AlternateErrorDetectionMethod::SCTP_OVER_DTLS))
111
+ method == static_cast<uint32_t>(AlternateErrorDetectionMethod::SCTP_OVER_DTLS) ||
112
+ method == static_cast<uint32_t>(AlternateErrorDetectionMethod::TRUSTED_NETWORK))
104
113
  {
105
114
  return static_cast<AlternateErrorDetectionMethod>(method);
106
115
  }
@@ -14,7 +14,6 @@
14
14
  #include <libwebrtc/api/transport/network_types.h>
15
15
  #include <libwebrtc/call/rtp_transport_controller_send.h>
16
16
  #include <libwebrtc/modules/pacing/packet_router.h>
17
- #include <deque>
18
17
 
19
18
  namespace RTC
20
19
  {
@@ -87,12 +86,10 @@ namespace RTC
87
86
  return this->bitrates;
88
87
  }
89
88
  int64_t GetAvailableBitrate() const;
90
- double GetPacketLoss() const;
91
89
  void RescheduleNextAvailableBitrateEvent();
92
90
 
93
91
  private:
94
92
  void MayEmitAvailableBitrateEvent(int64_t previousAvailableBitrate);
95
- void UpdatePacketLoss(double packetLoss);
96
93
  void ApplyBitrateUpdates();
97
94
 
98
95
  void InitializeController();
@@ -133,8 +130,6 @@ namespace RTC
133
130
  bool availableBitrateEventCalled{ false };
134
131
  int64_t lastAvailableBitrateEventAtMs{ 0 };
135
132
  RTC::TrendCalculator desiredBitrateTrend;
136
- std::deque<double> packetLossHistory;
137
- double packetLoss{ 0 };
138
133
  };
139
134
  } // namespace RTC
140
135
 
@@ -10,7 +10,6 @@
10
10
  #include "RTC/SeqManager.hpp"
11
11
  #include "SharedInterface.hpp"
12
12
  #include <libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h>
13
- #include <deque>
14
13
 
15
14
  namespace RTC
16
15
  {
@@ -54,7 +53,6 @@ namespace RTC
54
53
  return 0;
55
54
  }
56
55
  }
57
- double GetPacketLoss() const;
58
56
  void IncomingPacket(int64_t nowUs, const RTC::RTP::Packet* packet);
59
57
  void SetMaxIncomingBitrate(int64_t bitrate);
60
58
  void FillAndSendTransportCcFeedback();
@@ -64,7 +62,6 @@ namespace RTC
64
62
  bool SendTransportCcFeedback();
65
63
  void MayDropOldPacketArrivalTimes(uint16_t seqNum, int64_t nowUs);
66
64
  void MaySendLimitationRembFeedback(int64_t nowMs);
67
- void UpdatePacketLoss(double packetLoss);
68
65
  void ResetTransportCcFeedback(uint8_t feedbackPacketCount);
69
66
 
70
67
  /* Pure virtual methods inherited from webrtc::RemoteBitrateEstimator::Listener. */
@@ -95,8 +92,6 @@ namespace RTC
95
92
  int64_t maxIncomingBitrate{ 0 };
96
93
  int64_t limitationRembSentAtMs{ 0 };
97
94
  uint8_t unlimitedRembCounter{ 0 };
98
- std::deque<double> packetLossHistory;
99
- double packetLoss{ 0 };
100
95
  // Whether any packet with transport wide sequence number was received.
101
96
  bool transportWideSeqNumberReceived{ false };
102
97
  uint16_t transportCcFeedbackWideSeqNumStart{ 0 };
@@ -4,6 +4,7 @@
4
4
  #include "common.hpp"
5
5
  #include "RTC/Consts.hpp"
6
6
  #include <openssl/evp.h>
7
+ #include <array>
7
8
  #include <cassert>
8
9
  #include <cmath>
9
10
  #include <cstring> // std::memcmp(), std::memcpy()
@@ -275,8 +276,14 @@ namespace Utils
275
276
  static thread_local EVP_MAC* mac;
276
277
  static thread_local EVP_MAC_CTX* hmacSha1Ctx;
277
278
  static thread_local uint8_t hmacSha1Buffer[];
278
- static const uint32_t Crc32Table[256];
279
- static const uint32_t Crc32cTable[256];
279
+ // Number of input bytes consumed per iteration of the slice-by-8 loop.
280
+ static constexpr size_t CrcSlices{ 8u };
281
+ using CrcTables = std::array<std::array<uint32_t, 256>, CrcSlices>;
282
+ static const CrcTables crc32Tables;
283
+ static const CrcTables crc32cTables;
284
+ static constexpr CrcTables generateCrcTables(uint32_t polynomial) noexcept;
285
+ static uint32_t ReadLe32(const uint8_t* data);
286
+ static uint32_t ComputeCrc(const CrcTables& tables, const uint8_t* data, size_t size);
280
287
  };
281
288
 
282
289
  class String
@@ -193,7 +193,9 @@ common_sources = [
193
193
  'src/RTC/BWE/ProbeController.cpp',
194
194
  'src/RTC/BWE/ProbePacketGenerator.cpp',
195
195
  'src/RTC/BWE/ProbingScheduler.cpp',
196
+ 'src/RTC/BWE/ReceiverTransportCongestionController.cpp',
196
197
  'src/RTC/BWE/RembGenerator.cpp',
198
+ 'src/RTC/BWE/SenderTransportCongestionController.cpp',
197
199
  'src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp',
198
200
  'src/RTC/BWE/RobustThroughputEstimator.cpp',
199
201
  'src/RTC/BWE/SendPacketHistory.cpp',
@@ -515,7 +517,9 @@ test_sources = [
515
517
  'test/src/RTC/BWE/TestProbeController.cpp',
516
518
  'test/src/RTC/BWE/TestProbePacketGenerator.cpp',
517
519
  'test/src/RTC/BWE/TestProbingScheduler.cpp',
520
+ 'test/src/RTC/BWE/TestReceiverTransportCongestionController.cpp',
518
521
  'test/src/RTC/BWE/TestRembGenerator.cpp',
522
+ 'test/src/RTC/BWE/TestSenderTransportCongestionController.cpp',
519
523
  'test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp',
520
524
  'test/src/RTC/BWE/TestRobustThroughputEstimator.cpp',
521
525
  'test/src/RTC/BWE/TestSendPacketHistory.cpp',
@@ -72,7 +72,7 @@ namespace RTC
72
72
  MS_TRACE();
73
73
  }
74
74
 
75
- int64_t AimdRateControl::Update(const Types::RateControlInput& input, int64_t atTimeUs)
75
+ int64_t AimdRateControl::Update(const Types::RateControlInput& input, int64_t nowUs)
76
76
  {
77
77
  MS_TRACE();
78
78
 
@@ -84,11 +84,11 @@ namespace RTC
84
84
  {
85
85
  if (input.estimatedThroughput.has_value())
86
86
  {
87
- this->timeFirstThroughputEstimateUs = atTimeUs;
87
+ this->timeFirstThroughputEstimateUs = nowUs;
88
88
  }
89
89
  }
90
90
  else if (
91
- atTimeUs - this->timeFirstThroughputEstimateUs.value() > InitializationTimeUs &&
91
+ nowUs - this->timeFirstThroughputEstimateUs.value() > InitializationTimeUs &&
92
92
  input.estimatedThroughput.has_value())
93
93
  {
94
94
  this->currentBitrate = input.estimatedThroughput.value();
@@ -96,18 +96,18 @@ namespace RTC
96
96
  }
97
97
  }
98
98
 
99
- ChangeBitrate(input, atTimeUs);
99
+ ChangeBitrate(input, nowUs);
100
100
 
101
101
  return this->currentBitrate;
102
102
  }
103
103
 
104
- void AimdRateControl::SetEstimate(int64_t bitrate, int64_t atTimeUs)
104
+ void AimdRateControl::SetEstimate(int64_t bitrate, int64_t nowUs)
105
105
  {
106
106
  MS_TRACE();
107
107
 
108
108
  this->bitrateIsInitialized = true;
109
109
  this->currentBitrate = ClampBitrate(bitrate);
110
- this->timeLastBitrateChangeUs = atTimeUs;
110
+ this->timeLastBitrateChangeUs = nowUs;
111
111
  }
112
112
 
113
113
  void AimdRateControl::SetStartBitrate(int64_t startBitrate)
@@ -149,7 +149,7 @@ namespace RTC
149
149
  this->networkEstimate = estimate;
150
150
  }
151
151
 
152
- bool AimdRateControl::IsTimeToReduceFurther(int64_t atTimeUs, int64_t estimatedThroughput) const
152
+ bool AimdRateControl::IsTimeToReduceFurther(int64_t nowUs, int64_t estimatedThroughput) const
153
153
  {
154
154
  MS_TRACE();
155
155
 
@@ -162,7 +162,7 @@ namespace RTC
162
162
  return true;
163
163
  }
164
164
 
165
- if (atTimeUs - this->timeLastBitrateChangeUs.value() >= bitrateReductionIntervalUs)
165
+ if (nowUs - this->timeLastBitrateChangeUs.value() >= bitrateReductionIntervalUs)
166
166
  {
167
167
  return true;
168
168
  }
@@ -177,11 +177,11 @@ namespace RTC
177
177
  return false;
178
178
  }
179
179
 
180
- bool AimdRateControl::IsInitialTimeToReduceFurther(int64_t atTimeUs) const
180
+ bool AimdRateControl::IsInitialTimeToReduceFurther(int64_t nowUs) const
181
181
  {
182
182
  MS_TRACE();
183
183
 
184
- return IsValidEstimate() && IsTimeToReduceFurther(atTimeUs, (GetLatestEstimate() / 2) - 1);
184
+ return IsValidEstimate() && IsTimeToReduceFurther(nowUs, (GetLatestEstimate() / 2) - 1);
185
185
  }
186
186
 
187
187
  double AimdRateControl::GetNearMaxIncreaseRateBpsPerSecond() const
@@ -217,7 +217,7 @@ namespace RTC
217
217
  return std::clamp(intervalUs, MinFeedbackIntervalUs, MaxFeedbackIntervalUs);
218
218
  }
219
219
 
220
- void AimdRateControl::ChangeBitrate(const Types::RateControlInput& input, int64_t atTimeUs)
220
+ void AimdRateControl::ChangeBitrate(const Types::RateControlInput& input, int64_t nowUs)
221
221
  {
222
222
  MS_TRACE();
223
223
 
@@ -238,7 +238,7 @@ namespace RTC
238
238
  return;
239
239
  }
240
240
 
241
- ChangeState(input, atTimeUs);
241
+ ChangeState(input, nowUs);
242
242
 
243
243
  switch (this->rateControlState)
244
244
  {
@@ -288,7 +288,7 @@ namespace RTC
288
288
  "there is a link capacity estimate but the bitrate was never changed");
289
289
 
290
290
  const int64_t additiveIncrease =
291
- AdditiveRateIncrease(atTimeUs, this->timeLastBitrateChangeUs.value());
291
+ AdditiveRateIncrease(nowUs, this->timeLastBitrateChangeUs.value());
292
292
 
293
293
  increasedBitrate = this->currentBitrate + additiveIncrease;
294
294
  }
@@ -297,7 +297,7 @@ namespace RTC
297
297
  // Without an estimate of the link capacity, ramp up faster to
298
298
  // discover it.
299
299
  const int64_t multiplicativeIncrease = MultiplicativeRateIncrease(
300
- atTimeUs, this->timeLastBitrateChangeUs, this->currentBitrate);
300
+ nowUs, this->timeLastBitrateChangeUs, this->currentBitrate);
301
301
 
302
302
  increasedBitrate = this->currentBitrate + multiplicativeIncrease;
303
303
  }
@@ -305,7 +305,7 @@ namespace RTC
305
305
  newBitrate = std::min(increasedBitrate, increaseLimit);
306
306
  }
307
307
 
308
- this->timeLastBitrateChangeUs = atTimeUs;
308
+ this->timeLastBitrateChangeUs = nowUs;
309
309
 
310
310
  break;
311
311
  }
@@ -352,7 +352,7 @@ namespace RTC
352
352
 
353
353
  // Stay on hold until the queues of the network are drained.
354
354
  this->rateControlState = RateControlState::HOLD;
355
- this->timeLastBitrateChangeUs = atTimeUs;
355
+ this->timeLastBitrateChangeUs = nowUs;
356
356
 
357
357
  break;
358
358
  }
@@ -363,7 +363,7 @@ namespace RTC
363
363
  this->currentBitrate = ClampBitrate(newBitrate.value_or(this->currentBitrate));
364
364
  }
365
365
 
366
- void AimdRateControl::ChangeState(const Types::RateControlInput& input, int64_t atTimeUs)
366
+ void AimdRateControl::ChangeState(const Types::RateControlInput& input, int64_t nowUs)
367
367
  {
368
368
  MS_TRACE();
369
369
 
@@ -373,7 +373,7 @@ namespace RTC
373
373
  {
374
374
  if (this->rateControlState == RateControlState::HOLD)
375
375
  {
376
- this->timeLastBitrateChangeUs = atTimeUs;
376
+ this->timeLastBitrateChangeUs = nowUs;
377
377
  this->rateControlState = RateControlState::INCREASE;
378
378
  }
379
379
 
@@ -436,7 +436,7 @@ namespace RTC
436
436
  }
437
437
 
438
438
  int64_t AimdRateControl::MultiplicativeRateIncrease(
439
- int64_t atTimeUs, std::optional<int64_t> lastTimeUs, int64_t currentBitrate) const
439
+ int64_t nowUs, std::optional<int64_t> lastTimeUs, int64_t currentBitrate) const
440
440
  {
441
441
  MS_TRACE();
442
442
 
@@ -445,7 +445,7 @@ namespace RTC
445
445
  if (lastTimeUs.has_value())
446
446
  {
447
447
  const double timeSinceLastUpdateSeconds =
448
- static_cast<double>(atTimeUs - lastTimeUs.value()) / 1000000.0;
448
+ static_cast<double>(nowUs - lastTimeUs.value()) / 1000000.0;
449
449
 
450
450
  alpha = std::pow(alpha, std::min(timeSinceLastUpdateSeconds, 1.0));
451
451
  }
@@ -455,11 +455,11 @@ namespace RTC
455
455
  MinMultiplicativeIncrease);
456
456
  }
457
457
 
458
- int64_t AimdRateControl::AdditiveRateIncrease(int64_t atTimeUs, int64_t lastTimeUs) const
458
+ int64_t AimdRateControl::AdditiveRateIncrease(int64_t nowUs, int64_t lastTimeUs) const
459
459
  {
460
460
  MS_TRACE();
461
461
 
462
- const double timePeriodSeconds = static_cast<double>(atTimeUs - lastTimeUs) / 1000000.0;
462
+ const double timePeriodSeconds = static_cast<double>(nowUs - lastTimeUs) / 1000000.0;
463
463
 
464
464
  return static_cast<int64_t>(GetNearMaxIncreaseRateBpsPerSecond() * timePeriodSeconds);
465
465
  }
@@ -78,7 +78,7 @@ namespace RTC
78
78
  ackedBitrate, probeBitrate, recoveredFromOveruse, feedback.feedbackTimeUs);
79
79
  }
80
80
 
81
- void DelayBasedBwe::IncomingPacketFeedback(const Types::PacketResult& packetResult, int64_t atTimeUs)
81
+ void DelayBasedBwe::IncomingPacketFeedback(const Types::PacketResult& packetResult, int64_t nowUs)
82
82
  {
83
83
  MS_TRACE();
84
84
 
@@ -91,7 +91,7 @@ namespace RTC
91
91
 
92
92
  // Reset if the stream has timed out, since nothing measured before such a
93
93
  // silence still describes this link.
94
- if (!this->lastSeenPacketUs.has_value() || atTimeUs - this->lastSeenPacketUs.value() > StreamTimeOutUs)
94
+ if (!this->lastSeenPacketUs.has_value() || nowUs - this->lastSeenPacketUs.value() > StreamTimeOutUs)
95
95
  {
96
96
  this->videoInterArrivalDelta.emplace(SendTimeGroupLengthUs);
97
97
  this->audioInterArrivalDelta.emplace(SendTimeGroupLengthUs);
@@ -101,7 +101,7 @@ namespace RTC
101
101
  this->activeDelayDetector = std::addressof(this->videoDelayDetector.value());
102
102
  }
103
103
 
104
- this->lastSeenPacketUs = atTimeUs;
104
+ this->lastSeenPacketUs = nowUs;
105
105
 
106
106
  // As an alternative to ignoring small packets, audio and video can be given
107
107
  // a delay detector of their own.
@@ -148,16 +148,14 @@ namespace RTC
148
148
  : this->videoInterArrivalDelta.value();
149
149
 
150
150
  const auto deltas = interArrivalForPacket.ComputeDeltas(
151
- packetResult.sentPacket.sendTimeUs, receiveTimeUs, atTimeUs, packetResult.sentPacket.size);
151
+ packetResult.sentPacket.sendTimeUs, receiveTimeUs, nowUs, packetResult.sentPacket.size);
152
152
 
153
153
  if (deltas.has_value())
154
154
  {
155
+ const auto& deltasValue = deltas.value();
156
+
155
157
  delayDetectorForPacket->Update(
156
- // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
157
- deltas.value().sendDeltaUs,
158
- // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
159
- deltas.value().arrivalDeltaUs,
160
- receiveTimeUs);
158
+ deltasValue.sendDeltaUs, deltasValue.arrivalDeltaUs, receiveTimeUs);
161
159
  }
162
160
  }
163
161
 
@@ -165,7 +163,7 @@ namespace RTC
165
163
  std::optional<int64_t> ackedBitrate,
166
164
  std::optional<int64_t> probeBitrate,
167
165
  bool recoveredFromOveruse,
168
- int64_t atTimeUs)
166
+ int64_t nowUs)
169
167
  {
170
168
  MS_TRACE();
171
169
 
@@ -173,19 +171,17 @@ namespace RTC
173
171
 
174
172
  if (this->activeDelayDetector->GetState() == Types::BandwidthUsage::OVERUSING)
175
173
  {
176
- if (
177
- ackedBitrate.has_value() &&
178
- this->rateControl.IsTimeToReduceFurther(atTimeUs, ackedBitrate.value()))
174
+ if (ackedBitrate.has_value() && this->rateControl.IsTimeToReduceFurther(nowUs, ackedBitrate.value()))
179
175
  {
180
- result.updated = UpdateEstimate(atTimeUs, ackedBitrate, result.targetBitrate);
176
+ result.updated = UpdateEstimate(nowUs, ackedBitrate, result.targetBitrate);
181
177
  }
182
178
  else if (
183
179
  !ackedBitrate.has_value() && this->rateControl.IsValidEstimate() &&
184
- this->rateControl.IsInitialTimeToReduceFurther(atTimeUs))
180
+ this->rateControl.IsInitialTimeToReduceFurther(nowUs))
185
181
  {
186
182
  // Overusing before any throughput has been measured, so halve the
187
183
  // bitrate instead of aiming at a measurement we don't have.
188
- this->rateControl.SetEstimate(this->rateControl.GetLatestEstimate() / 2, atTimeUs);
184
+ this->rateControl.SetEstimate(this->rateControl.GetLatestEstimate() / 2, nowUs);
189
185
 
190
186
  result.updated = true;
191
187
  result.probe = false;
@@ -199,13 +195,13 @@ namespace RTC
199
195
  result.probe = true;
200
196
  result.updated = true;
201
197
 
202
- this->rateControl.SetEstimate(probeBitrate.value(), atTimeUs);
198
+ this->rateControl.SetEstimate(probeBitrate.value(), nowUs);
203
199
 
204
200
  result.targetBitrate = this->rateControl.GetLatestEstimate();
205
201
  }
206
202
  else
207
203
  {
208
- result.updated = UpdateEstimate(atTimeUs, ackedBitrate, result.targetBitrate);
204
+ result.updated = UpdateEstimate(nowUs, ackedBitrate, result.targetBitrate);
209
205
  result.recoveredFromOveruse = recoveredFromOveruse;
210
206
  }
211
207
  }
@@ -224,14 +220,14 @@ namespace RTC
224
220
  }
225
221
 
226
222
  bool DelayBasedBwe::UpdateEstimate(
227
- int64_t atTimeUs, std::optional<int64_t> ackedBitrate, int64_t& targetBitrate)
223
+ int64_t nowUs, std::optional<int64_t> ackedBitrate, int64_t& targetBitrate)
228
224
  {
229
225
  MS_TRACE();
230
226
 
231
227
  const Types::RateControlInput input{ .bandwidthUsage = this->activeDelayDetector->GetState(),
232
228
  .estimatedThroughput = ackedBitrate };
233
229
 
234
- targetBitrate = this->rateControl.Update(input, atTimeUs);
230
+ targetBitrate = this->rateControl.Update(input, nowUs);
235
231
 
236
232
  return this->rateControl.IsValidEstimate();
237
233
  }
@@ -16,7 +16,7 @@ namespace RTC
16
16
  MS_TRACE();
17
17
  }
18
18
 
19
- std::optional<Types::TransportPacketsFeedback> FeedbackAdapter::ProcessTransportFeedback(
19
+ std::optional<Types::TransportPacketsFeedback> FeedbackAdapter::ProcessTransportWideCcFeedback(
20
20
  const RTCP::FeedbackRtpTransportPacket* feedback, int64_t receivedAtUs)
21
21
  {
22
22
  MS_TRACE();