mediasoup 3.19.21 → 3.19.22

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 (130) hide show
  1. package/node/lib/Worker.d.ts +1 -0
  2. package/node/lib/Worker.d.ts.map +1 -1
  3. package/node/lib/Worker.js +14 -0
  4. package/package.json +4 -2
  5. package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +9 -3
  6. package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +9 -1
  7. package/worker/include/Channel/ChannelMessageRegistrator.hpp +39 -0
  8. package/worker/include/Channel/ChannelMessageRegistratorInterface.hpp +32 -0
  9. package/worker/include/Channel/ChannelSocket.hpp +1 -1
  10. package/worker/include/DepUsrSCTP.hpp +8 -7
  11. package/worker/include/RTC/ActiveSpeakerObserver.hpp +7 -7
  12. package/worker/include/RTC/AudioLevelObserver.hpp +7 -7
  13. package/worker/include/RTC/Consumer.hpp +3 -3
  14. package/worker/include/RTC/DataConsumer.hpp +3 -3
  15. package/worker/include/RTC/DataProducer.hpp +3 -3
  16. package/worker/include/RTC/DirectTransport.hpp +2 -2
  17. package/worker/include/RTC/DtlsTransport.hpp +8 -6
  18. package/worker/include/RTC/ICE/IceServer.hpp +8 -5
  19. package/worker/include/RTC/KeyFrameRequestManager.hpp +15 -12
  20. package/worker/include/RTC/NackGenerator.hpp +7 -6
  21. package/worker/include/RTC/PipeConsumer.hpp +1 -2
  22. package/worker/include/RTC/PipeTransport.hpp +2 -2
  23. package/worker/include/RTC/PlainTransport.hpp +2 -2
  24. package/worker/include/RTC/Producer.hpp +3 -3
  25. package/worker/include/RTC/RTP/RtpStream.hpp +7 -1
  26. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +6 -5
  27. package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -1
  28. package/worker/include/RTC/Router.hpp +3 -3
  29. package/worker/include/RTC/RtpObserver.hpp +3 -3
  30. package/worker/include/RTC/SCTP/TODO_SCTP.md +18 -6
  31. package/worker/include/RTC/SCTP/association/Association.hpp +11 -8
  32. package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +9 -6
  33. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +37 -23
  34. package/worker/include/RTC/SCTP/association/TCBContext.hpp +3 -2
  35. package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +81 -8
  36. package/worker/include/RTC/SCTP/packet/UserData.hpp +36 -0
  37. package/worker/include/RTC/SCTP/packet/chunks/ForwardTsnChunk.hpp +1 -1
  38. package/worker/include/RTC/SCTP/packet/chunks/IForwardTsnChunk.hpp +1 -1
  39. package/worker/include/RTC/SCTP/public/SctpOptions.hpp +2 -1
  40. package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +604 -0
  41. package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +336 -0
  42. package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +5 -4
  43. package/worker/include/RTC/Serializable.hpp +8 -0
  44. package/worker/include/RTC/SimpleConsumer.hpp +1 -2
  45. package/worker/include/RTC/SimulcastConsumer.hpp +1 -2
  46. package/worker/include/RTC/SvcConsumer.hpp +1 -2
  47. package/worker/include/RTC/Transport.hpp +8 -8
  48. package/worker/include/RTC/TransportCongestionControlClient.hpp +8 -5
  49. package/worker/include/RTC/TransportCongestionControlServer.hpp +8 -5
  50. package/worker/include/RTC/WebRtcServer.hpp +3 -3
  51. package/worker/include/RTC/WebRtcTransport.hpp +3 -3
  52. package/worker/include/Shared.hpp +40 -0
  53. package/worker/include/SharedInterface.hpp +44 -0
  54. package/worker/include/Utils.hpp +6 -0
  55. package/worker/include/Worker.hpp +3 -3
  56. package/worker/include/common.hpp +1 -1
  57. package/worker/include/handles/BackoffTimerHandle.hpp +27 -65
  58. package/worker/include/handles/BackoffTimerHandleInterface.hpp +116 -0
  59. package/worker/include/handles/TimerHandle.hpp +36 -20
  60. package/worker/include/handles/TimerHandleInterface.hpp +43 -0
  61. package/worker/meson.build +21 -4
  62. package/worker/meson_options.txt +2 -1
  63. package/worker/mocks/include/Channel/MockChannelMessageRegistrator.hpp +45 -0
  64. package/worker/mocks/include/MockShared.hpp +43 -0
  65. package/worker/mocks/src/Channel/MockChannelMessageRegistrator.cpp +128 -0
  66. package/worker/mocks/src/MockShared.cpp +26 -0
  67. package/worker/scripts/clang-scripts.mjs +4 -1
  68. package/worker/src/Channel/ChannelMessageRegistrator.cpp +125 -0
  69. package/worker/src/Channel/ChannelSocket.cpp +1 -1
  70. package/worker/src/DepUsrSCTP.cpp +10 -4
  71. package/worker/src/RTC/ActiveSpeakerObserver.cpp +7 -7
  72. package/worker/src/RTC/AudioLevelObserver.cpp +12 -10
  73. package/worker/src/RTC/Consumer.cpp +23 -20
  74. package/worker/src/RTC/DataConsumer.cpp +11 -11
  75. package/worker/src/RTC/DataProducer.cpp +3 -3
  76. package/worker/src/RTC/DirectTransport.cpp +16 -16
  77. package/worker/src/RTC/DtlsTransport.cpp +4 -4
  78. package/worker/src/RTC/ICE/IceServer.cpp +4 -3
  79. package/worker/src/RTC/KeyFrameRequestManager.cpp +15 -15
  80. package/worker/src/RTC/NackGenerator.cpp +3 -3
  81. package/worker/src/RTC/PipeConsumer.cpp +5 -4
  82. package/worker/src/RTC/PipeTransport.cpp +3 -3
  83. package/worker/src/RTC/PlainTransport.cpp +10 -9
  84. package/worker/src/RTC/Producer.cpp +30 -28
  85. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +1 -2
  86. package/worker/src/RTC/RTP/RtpStream.cpp +9 -2
  87. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +5 -4
  88. package/worker/src/RTC/RTP/RtpStreamSend.cpp +5 -2
  89. package/worker/src/RTC/Router.cpp +3 -3
  90. package/worker/src/RTC/RtpObserver.cpp +2 -1
  91. package/worker/src/RTC/SCTP/association/Association.cpp +94 -114
  92. package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +27 -21
  93. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +52 -55
  94. package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +144 -25
  95. package/worker/src/RTC/SCTP/packet/chunks/ForwardTsnChunk.cpp +2 -2
  96. package/worker/src/RTC/SCTP/packet/chunks/IForwardTsnChunk.cpp +2 -2
  97. package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +905 -0
  98. package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +799 -0
  99. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +1 -1
  100. package/worker/src/RTC/SctpAssociation.cpp +1 -1
  101. package/worker/src/RTC/SimpleConsumer.cpp +8 -7
  102. package/worker/src/RTC/SimulcastConsumer.cpp +11 -10
  103. package/worker/src/RTC/SvcConsumer.cpp +11 -10
  104. package/worker/src/RTC/Transport.cpp +36 -26
  105. package/worker/src/RTC/TransportCongestionControlClient.cpp +4 -2
  106. package/worker/src/RTC/TransportCongestionControlServer.cpp +4 -3
  107. package/worker/src/RTC/WebRtcServer.cpp +5 -4
  108. package/worker/src/RTC/WebRtcTransport.cpp +39 -26
  109. package/worker/src/Shared.cpp +35 -0
  110. package/worker/src/Worker.cpp +10 -23
  111. package/worker/src/handles/BackoffTimerHandle.cpp +11 -16
  112. package/worker/src/handles/TimerHandle.cpp +5 -4
  113. package/worker/src/lib.cpp +14 -1
  114. package/worker/tasks.py +1 -1
  115. package/worker/test/include/RTC/ICE/iceCommon.hpp +1 -0
  116. package/worker/test/include/RTC/RTP/rtpCommon.hpp +1 -0
  117. package/worker/test/include/RTC/SCTP/sctpCommon.hpp +6 -0
  118. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +12 -5
  119. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +34 -23
  120. package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +1196 -0
  121. package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +33 -33
  122. package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +14 -6
  123. package/worker/test/src/RTC/TestNackGenerator.cpp +6 -2
  124. package/worker/test/src/RTC/TestSimpleConsumer.cpp +6 -10
  125. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +9 -2
  126. package/worker/test/src/Utils/TestByte.cpp +98 -0
  127. package/worker/include/ChannelMessageRegistrator.hpp +0 -30
  128. package/worker/include/RTC/Shared.hpp +0 -23
  129. package/worker/src/ChannelMessageRegistrator.cpp +0 -119
  130. package/worker/src/RTC/Shared.cpp +0 -23
@@ -6,6 +6,9 @@
6
6
  #include "DepLibUV.hpp"
7
7
  #include "Logger.hpp"
8
8
  #include "RTC/Consts.hpp"
9
+ #include "RTC/SCTP/packet/chunks/DataChunk.hpp"
10
+ #include "RTC/SCTP/packet/chunks/IDataChunk.hpp"
11
+ #include "handles/BackoffTimerHandle.hpp"
9
12
  #include <cmath> // std::min()
10
13
  #include <string>
11
14
 
@@ -22,7 +25,10 @@ namespace RTC
22
25
  TransmissionControlBlock::TransmissionControlBlock(
23
26
  AssociationListener& associationListener,
24
27
  const SctpOptions& sctpOptions,
28
+ SharedInterface* shared,
25
29
  PacketSender& packetSender,
30
+ // TODO: SCTP: Implement it.
31
+ // SendQueue& sendQueue,
26
32
  uint32_t localVerificationTag,
27
33
  uint32_t remoteVerificationTag,
28
34
  uint32_t localInitialTsn,
@@ -33,6 +39,9 @@ namespace RTC
33
39
  std::function<bool()> isAssociationEstablished)
34
40
  : associationListener(associationListener),
35
41
  sctpOptions(sctpOptions),
42
+ shared(shared),
43
+ // TODO: SCTP: Implement it.
44
+ // sendQueue(sendQueue),
36
45
  packetSender(packetSender),
37
46
  localVerificationTag(localVerificationTag),
38
47
  remoteVerificationTag(remoteVerificationTag),
@@ -42,23 +51,46 @@ namespace RTC
42
51
  tieTag(tieTag),
43
52
  negotiatedCapabilities(negotiatedCapabilities),
44
53
  isAssociationEstablished(std::move(isAssociationEstablished)),
45
- t3RtxTimer(
46
- std::make_unique<BackoffTimerHandle>(
47
- /*listener*/ this,
48
- /*baseTimeoutMs*/ sctpOptions.initialRtoMs,
49
- /*backoffAlgorithm*/ BackoffTimerHandle::BackoffAlgorithm::EXPONENTIAL,
50
- /*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
51
- /*maxRestarts*/ std::nullopt)),
52
- delayedAckTimer(
53
- std::make_unique<BackoffTimerHandle>(
54
- /*listener*/ this,
55
- /*baseTimeoutMs*/ sctpOptions.delayedAckMaxTimeoutMs,
56
- /*backoffAlgorithm*/ BackoffTimerHandle::BackoffAlgorithm::EXPONENTIAL,
57
- /*maxBackoffTimeoutMs*/ std::nullopt,
58
- /*maxRestarts*/ 0)),
54
+ t3RtxTimer(this->shared->CreateBackoffTimer(
55
+ BackoffTimerHandleInterface::BackoffTimerHandleOptions{
56
+ .listener = this,
57
+ .baseTimeoutMs = sctpOptions.initialRtoMs,
58
+ .backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
59
+ .maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
60
+ .maxRestarts = std::nullopt })),
61
+ delayedAckTimer(this->shared->CreateBackoffTimer(
62
+ BackoffTimerHandleInterface::BackoffTimerHandleOptions{
63
+ .listener = this,
64
+ .baseTimeoutMs = sctpOptions.delayedAckMaxTimeoutMs,
65
+ .backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
66
+ .maxBackoffTimeoutMs = std::nullopt,
67
+ .maxRestarts = 0 })),
59
68
  rto(sctpOptions),
60
69
  txErrorCounter(sctpOptions),
61
- heartbeatHandler(this->associationListener, sctpOptions, this)
70
+ // TODO: SCTP: Implement.
71
+ // dataTracker(),
72
+ // TODO: SCTP: Implement.
73
+ // reassemblyQueue(),
74
+ retransmissionQueue(
75
+ this,
76
+ this->associationListener,
77
+ localInitialTsn,
78
+ remoteAdvertisedReceiverWindowCredit,
79
+ // TODO: SCTP: Implement
80
+ // this->sendQueue,
81
+ this->t3RtxTimer.get(),
82
+ sctpOptions,
83
+ negotiatedCapabilities.partialReliability,
84
+ negotiatedCapabilities.messageInterleaving),
85
+ streamResetHandler(
86
+ this->associationListener,
87
+ this->shared,
88
+ this,
89
+ // TODO: SCTP: Implement.
90
+ // std::addressof(this->dataTracker),
91
+ // std::addressof(this->reassemblyQueue),
92
+ std::addressof(this->retransmissionQueue)),
93
+ heartbeatHandler(this->associationListener, sctpOptions, this->shared, this)
62
94
  {
63
95
  MS_TRACE();
64
96
  }
@@ -93,7 +125,7 @@ namespace RTC
93
125
  MS_DUMP_CLEAN(indentation, "</SCTP::TransmissionControlBlock>");
94
126
  }
95
127
 
96
- void TransmissionControlBlock::ObserveRtt(uint64_t rtt)
128
+ void TransmissionControlBlock::ObserveRttMs(uint64_t rttMs)
97
129
  {
98
130
  MS_TRACE();
99
131
 
@@ -101,11 +133,11 @@ namespace RTC
101
133
  const auto prevRtoMs = this->rto.GetRtoMs();
102
134
  #endif
103
135
 
104
- this->rto.ObserveRtt(rtt);
136
+ this->rto.ObserveRttMs(rttMs);
105
137
 
106
138
  MS_DEBUG_DEV(
107
139
  "new rtt:%" PRIu64 ", previous rto:%" PRIu64 ", new rto:%" PRIu64 ", srtt:%" PRIu64,
108
- rtt,
140
+ rttMs,
109
141
  prevRtoMs,
110
142
  this->rto.GetRtoMs(),
111
143
  this->rto.GetSrttMs());
@@ -182,6 +214,80 @@ namespace RTC
182
214
  // Send(packet.get());
183
215
  }
184
216
 
217
+ void TransmissionControlBlock::MaybeSendForwardTsnChunk(Packet* packet, uint64_t nowMs)
218
+ {
219
+ MS_TRACE();
220
+
221
+ if (nowMs >= this->limitForwardTsnUntilMs && this->retransmissionQueue.ShouldSendForwardTsn(nowMs))
222
+ {
223
+ if (this->negotiatedCapabilities.messageInterleaving)
224
+ {
225
+ this->retransmissionQueue.CreateIForwardTsn(packet);
226
+ }
227
+ else
228
+ {
229
+ this->retransmissionQueue.CreateForwardTsn(packet);
230
+ }
231
+
232
+ // https://datatracker.ietf.org/doc/html/rfc3758
233
+ //
234
+ // "IMPLEMENTATION NOTE: An implementation may wish to limit the number
235
+ // of duplicate FORWARD TSN chunks it sends by ... waiting a full RTT
236
+ // before sending a duplicate FORWARD TSN."
237
+ // "Any delay applied to the sending of FORWARD TSN chunk SHOULD NOT
238
+ // exceed 200ms and MUST NOT exceed 500ms".
239
+ this->limitForwardTsnUntilMs = nowMs + std::min(uint64_t{ 200 }, this->rto.GetSrttMs());
240
+ }
241
+ }
242
+
243
+ void TransmissionControlBlock::MaySendFastRetransmit()
244
+ {
245
+ MS_TRACE();
246
+
247
+ if (!this->retransmissionQueue.HasDataToBeFastRetransmitted())
248
+ {
249
+ return;
250
+ }
251
+
252
+ // https://datatracker.ietf.org/doc/html/rfc9260#section-7.2.4
253
+ //
254
+ // "Determine how many of the earliest (i.e., lowest TSN) DATA chunks
255
+ // marked for retransmission will fit into a single packet, subject to
256
+ // constraint of the path MTU of the destination transport address to
257
+ // which the packet is being sent. Call this value K. Retransmit those
258
+ // K DATA chunks in a single packet. When a Fast Retransmit is being
259
+ // performed, the sender SHOULD ignore the value of cwnd and SHOULD NOT
260
+ // delay retransmission for this single packet."
261
+
262
+ auto packet = CreatePacket();
263
+ const auto result =
264
+ this->retransmissionQueue.GetChunksForFastRetransmit(packet->GetAvailableLength());
265
+
266
+ for (const auto& [tsn, data] : result)
267
+ {
268
+ if (this->negotiatedCapabilities.messageInterleaving)
269
+ {
270
+ auto* iDataChunk = packet->BuildChunkInPlace<IDataChunk>();
271
+
272
+ iDataChunk->SetTsn(tsn);
273
+ // TODO: SCTP: Implement.
274
+ // iDataChunk->SetUserData(data);
275
+ iDataChunk->Consolidate();
276
+ }
277
+ else
278
+ {
279
+ auto* dataChunk = packet->BuildChunkInPlace<DataChunk>();
280
+
281
+ dataChunk->SetTsn(tsn);
282
+ // TODO: SCTP: Implement.
283
+ // dataChunk->SetUserData(data);
284
+ dataChunk->Consolidate();
285
+ }
286
+ }
287
+
288
+ Send(packet.get());
289
+ }
290
+
185
291
  void TransmissionControlBlock::OnT3RtxTimer(uint64_t& /*baseTimeoutMs*/, bool& /*stop*/)
186
292
  {
187
293
  MS_TRACE();
@@ -190,7 +296,7 @@ namespace RTC
190
296
 
191
297
  MS_DEBUG_TAG(
192
298
  sctp,
193
- "T3-rtx timer has expired %zu/%s]",
299
+ "T3-rtx timer has expired [%zu/%s]",
194
300
  this->t3RtxTimer->GetExpirationCount(),
195
301
  maxRestarts ? std::to_string(maxRestarts.value()).c_str() : "Infinite");
196
302
 
@@ -204,13 +310,12 @@ namespace RTC
204
310
  {
205
311
  if (IncrementTxErrorCounter("t3-rtx expired"))
206
312
  {
207
- // TODO: SCTP: Implement
208
- // this->retransmissionQueue.HandleT3RtxTimerExpiry();
313
+ this->retransmissionQueue.HandleT3RtxTimerExpiry();
209
314
 
210
- // const uint64_t now = DepLibUV::GetTimeMs();
315
+ // const uint64_t nowMs = DepLibUV::GetTimeMs();
211
316
 
212
317
  // TODO: SCTP: Implement
213
- // SendBufferedPackets(now);
318
+ // SendBufferedPackets(nowMs);
214
319
  }
215
320
  }
216
321
  }
@@ -223,7 +328,7 @@ namespace RTC
223
328
 
224
329
  MS_DEBUG_TAG(
225
330
  sctp,
226
- "delayer ack timer has expired %zu/%s]",
331
+ "delayer ack timer has expired [%zu/%s]",
227
332
  this->delayedAckTimer->GetExpirationCount(),
228
333
  maxRestarts ? std::to_string(maxRestarts.value()).c_str() : "Infinite");
229
334
 
@@ -234,7 +339,7 @@ namespace RTC
234
339
  }
235
340
 
236
341
  void TransmissionControlBlock::OnTimer(
237
- BackoffTimerHandle* backoffTimer, uint64_t& baseTimeoutMs, bool& stop)
342
+ BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop)
238
343
  {
239
344
  MS_TRACE();
240
345
 
@@ -247,5 +352,19 @@ namespace RTC
247
352
  OnDelayedAckTimer(baseTimeoutMs, stop);
248
353
  }
249
354
  }
355
+
356
+ void TransmissionControlBlock::OnRetransmissionQueueNewRttMs(uint64_t newRttMs)
357
+ {
358
+ MS_TRACE();
359
+
360
+ ObserveRttMs(newRttMs);
361
+ }
362
+
363
+ void TransmissionControlBlock::OnRetransmissionQueueClearRetransmissionCounter()
364
+ {
365
+ MS_TRACE();
366
+
367
+ this->txErrorCounter.Clear();
368
+ }
250
369
  } // namespace SCTP
251
370
  } // namespace RTC
@@ -161,7 +161,7 @@ namespace RTC
161
161
  return skippedStreams;
162
162
  }
163
163
 
164
- void ForwardTsnChunk::AddStream(uint16_t stream, uint16_t streamSequence)
164
+ void ForwardTsnChunk::AddStream(uint16_t streamId, uint16_t streamSequence)
165
165
  {
166
166
  MS_TRACE();
167
167
 
@@ -172,7 +172,7 @@ namespace RTC
172
172
 
173
173
  // Add the new stream and stream sequence.
174
174
  Utils::Byte::Set2Bytes(
175
- GetVariableLengthValuePointer(), previousVariableLengthValueLength, stream);
175
+ GetVariableLengthValuePointer(), previousVariableLengthValueLength, streamId);
176
176
  Utils::Byte::Set2Bytes(
177
177
  GetVariableLengthValuePointer(), previousVariableLengthValueLength + 2, streamSequence);
178
178
  }
@@ -162,7 +162,7 @@ namespace RTC
162
162
  return skippedStreams;
163
163
  }
164
164
 
165
- void IForwardTsnChunk::AddStream(uint16_t stream, bool uFlag, uint32_t messageIdentifier)
165
+ void IForwardTsnChunk::AddStream(uint16_t streamId, bool uFlag, uint32_t messageIdentifier)
166
166
  {
167
167
  MS_TRACE();
168
168
 
@@ -173,7 +173,7 @@ namespace RTC
173
173
 
174
174
  // Add the new stream, flag U and message identifier.
175
175
  Utils::Byte::Set2Bytes(
176
- GetVariableLengthValuePointer(), previousVariableLengthValueLength, stream);
176
+ GetVariableLengthValuePointer(), previousVariableLengthValueLength, streamId);
177
177
  Utils::Byte::Set2Bytes(
178
178
  GetVariableLengthValuePointer(), previousVariableLengthValueLength + 2, uFlag);
179
179
  Utils::Byte::Set4Bytes(