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
@@ -2,16 +2,19 @@
2
2
  #define MS_RTC_SCTP_TRANSMISSION_CONTROL_BLOCK_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "SharedInterface.hpp"
5
6
  #include "RTC/SCTP/association/HeartbeatHandler.hpp"
6
7
  #include "RTC/SCTP/association/NegotiatedCapabilities.hpp"
7
8
  #include "RTC/SCTP/association/PacketSender.hpp"
9
+ #include "RTC/SCTP/association/StreamResetHandler.hpp"
8
10
  #include "RTC/SCTP/association/TCBContext.hpp"
9
11
  #include "RTC/SCTP/packet/Packet.hpp"
10
12
  #include "RTC/SCTP/public/AssociationListener.hpp"
11
13
  #include "RTC/SCTP/public/SctpOptions.hpp"
12
14
  #include "RTC/SCTP/tx/RetransmissionErrorCounter.hpp"
15
+ #include "RTC/SCTP/tx/RetransmissionQueue.hpp"
13
16
  #include "RTC/SCTP/tx/RetransmissionTimeout.hpp"
14
- #include "handles/BackoffTimerHandle.hpp"
17
+ #include "handles/BackoffTimerHandleInterface.hpp"
15
18
  #include <string_view>
16
19
  #include <vector>
17
20
 
@@ -25,12 +28,17 @@ namespace RTC
25
28
  *
26
29
  * @see https://datatracker.ietf.org/doc/html/rfc9260#section-14
27
30
  */
28
- class TransmissionControlBlock : public TCBContext, public BackoffTimerHandle::Listener
31
+ class TransmissionControlBlock : public TCBContext,
32
+ public RetransmissionQueue::Listener,
33
+ public BackoffTimerHandleInterface::Listener
29
34
  {
30
35
  public:
31
36
  TransmissionControlBlock(
32
37
  AssociationListener& associationListener,
33
38
  const SctpOptions& sctpOptions,
39
+ SharedInterface* shared,
40
+ // TODO: SCTP: Implement it.
41
+ // SendQueue& sendQueue,
34
42
  PacketSender& packetSender,
35
43
  uint32_t localVerificationTag,
36
44
  uint32_t remoteVerificationTag,
@@ -128,7 +136,12 @@ namespace RTC
128
136
  * @remarks
129
137
  * - Implements TCBContext interface.
130
138
  */
131
- void ObserveRtt(uint64_t rtt) override;
139
+ void ObserveRttMs(uint64_t rttMs) override;
140
+
141
+ size_t GetCwnd() const
142
+ {
143
+ return this->retransmissionQueue.GetCwnd();
144
+ }
132
145
 
133
146
  /**
134
147
  * @remarks
@@ -158,13 +171,46 @@ namespace RTC
158
171
  */
159
172
  void Send(Packet* packet) override;
160
173
 
174
+ // TODO: SCTP: Implement it.
175
+ // DataTracker& GetDataTracker()
176
+ // {
177
+ // return this->dataTracker;
178
+ // }
179
+
180
+ // TODO: SCTP: Implement it.
181
+ // ReassemblyQueue& GetReassemblyQueue()
182
+ // {
183
+ // return this->reassemblyQueue;
184
+ // }
185
+
186
+ RetransmissionQueue& GetRetransmissionQueue()
187
+ {
188
+ return this->retransmissionQueue;
189
+ }
190
+
191
+ StreamResetHandler& GetStreamResetHandler()
192
+ {
193
+ return this->streamResetHandler;
194
+ }
195
+
161
196
  HeartbeatHandler& GetHeartbeatHandler()
162
197
  {
163
198
  return this->heartbeatHandler;
164
199
  }
165
200
 
201
+ /**
202
+ * Will be set while the Association is in COOKIE_ECHOED state. In this
203
+ * state, there can only be a single Packet outstanding, and it must
204
+ * contain the COOKIE_ECHO Chunk as the first Chunk in that Packet, until
205
+ * the COOKIE_ACK has been received, which will make the socket call
206
+ * `ClearRemoteStateCookie()`.
207
+ */
166
208
  void SetRemoteStateCookie(std::vector<uint8_t> remoteStateCookie);
167
209
 
210
+ /**
211
+ * Called when the COOKIE_ACK Chunk has been received, to allow further
212
+ * Packets to be sent.
213
+ */
168
214
  void ClearRemoteStateCookie();
169
215
 
170
216
  bool HasRemoteStateCookie() const
@@ -172,8 +218,21 @@ namespace RTC
172
218
  return this->remoteStateCookie.has_value();
173
219
  }
174
220
 
221
+ /**
222
+ * Sends a SACK Chunk, if there is a need to.
223
+ */
175
224
  void MaySendSackChunk();
176
225
 
226
+ /**
227
+ * Sends a FORWARD-TSN or I-FORWARD-TSN Chunk if it is needed and allowed
228
+ * (rate-limited).
229
+ */
230
+ void MaybeSendForwardTsnChunk(Packet* packet, uint64_t nowMs);
231
+
232
+ void MaySendFastRetransmit();
233
+
234
+ // TODO: SCTP: Mamy more methods.
235
+
177
236
  /**
178
237
  * @remarks
179
238
  * - Implements TCBContext interface.
@@ -206,13 +265,20 @@ namespace RTC
206
265
 
207
266
  void OnDelayedAckTimer(uint64_t& baseTimeoutMs, bool& stop);
208
267
 
209
- /* Pure virtual methods inherited from BackoffTimerHandle::Listener. */
268
+ /* Pure virtual methods inherited from RetransmissionQueue::Listener. */
269
+ public:
270
+ void OnRetransmissionQueueNewRttMs(uint64_t newRttMs) override;
271
+ void OnRetransmissionQueueClearRetransmissionCounter() override;
272
+ ;
273
+
274
+ /* Pure virtual methods inherited from BackoffTimerHandleInterface::Listener. */
210
275
  public:
211
- void OnTimer(BackoffTimerHandle* backoffTimer, uint64_t& baseTimeoutMs, bool& stop) override;
276
+ void OnTimer(BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop) override;
212
277
 
213
278
  private:
214
279
  AssociationListener& associationListener;
215
280
  const SctpOptions sctpOptions;
281
+ SharedInterface* shared;
216
282
  PacketSender& packetSender;
217
283
  uint32_t localVerificationTag{ 0 };
218
284
  uint32_t remoteVerificationTag{ 0 };
@@ -224,17 +290,24 @@ namespace RTC
224
290
  NegotiatedCapabilities negotiatedCapabilities;
225
291
  std::function<bool()> isAssociationEstablished;
226
292
  // The data retransmission timer.
227
- const std::unique_ptr<BackoffTimerHandle> t3RtxTimer;
293
+ const std::unique_ptr<BackoffTimerHandleInterface> t3RtxTimer;
228
294
  // Delayed ack timer, which triggers when acks should be sent (when
229
295
  // delayed).
230
- const std::unique_ptr<BackoffTimerHandle> delayedAckTimer;
296
+ const std::unique_ptr<BackoffTimerHandleInterface> delayedAckTimer;
231
297
  RetransmissionTimeout rto;
232
298
  RetransmissionErrorCounter txErrorCounter;
299
+ // TODO: SCTP: Implement.
300
+ // DataTracker dataTracker;
301
+ // TODO: SCTP: Implement.
302
+ // ReassemblyQueue reassemblyQueue;
303
+ // TODO: SCTP: Implement.
304
+ RetransmissionQueue retransmissionQueue;
305
+ StreamResetHandler streamResetHandler;
233
306
  HeartbeatHandler heartbeatHandler;
234
307
  // Rate limiting of FORWARD_TSN. Next can be sent at or after this
235
308
  // timestamp.
236
309
  // TODO: SCTP: Uncomment.
237
- // uint64_t limitForwardTsnUntilMs{ 0 };
310
+ uint64_t limitForwardTsnUntilMs{ 0 };
238
311
  // Only valid when state is State::COOKIE_ECHOED. In this state, the
239
312
  // Association must wait for COOKIE_ACK to continue sending any packets (not
240
313
  // including a COOKIE_ECHO). So if this state cookie is present, the
@@ -2,6 +2,7 @@
2
2
  #define MS_RTC_SCTP_USER_DATA_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include <ostream>
5
6
  #include <vector>
6
7
 
7
8
  namespace RTC
@@ -39,6 +40,15 @@ namespace RTC
39
40
  // Disable copy assignment.
40
41
  UserData& operator=(const UserData&) = delete;
41
42
 
43
+ bool operator==(const UserData& other) const
44
+ {
45
+ return (
46
+ this->streamId == other.streamId && this->ssn == other.ssn && this->mid == other.mid &&
47
+ this->fsn == other.fsn && this->ppid == other.ppid && this->payload == other.payload &&
48
+ this->isBeginning == other.isBeginning && this->isEnd == other.isEnd &&
49
+ this->isUnordered == other.isUnordered);
50
+ }
51
+
42
52
  ~UserData();
43
53
 
44
54
  public:
@@ -91,6 +101,20 @@ namespace RTC
91
101
  return this->payload.size();
92
102
  }
93
103
 
104
+ UserData Clone() const
105
+ {
106
+ return UserData(
107
+ this->streamId,
108
+ this->ssn,
109
+ this->mid,
110
+ this->fsn,
111
+ this->ppid,
112
+ this->payload,
113
+ this->isBeginning,
114
+ this->isEnd,
115
+ this->isUnordered);
116
+ }
117
+
94
118
  /**
95
119
  * Useful to extract the payload and its ownership when destructing the
96
120
  * Message.
@@ -135,6 +159,18 @@ namespace RTC
135
159
  bool isEnd{ false };
136
160
  bool isUnordered{ false };
137
161
  };
162
+
163
+ /**
164
+ * For Catch2 to print it nicely.
165
+ */
166
+ inline std::ostream& operator<<(std::ostream& os, const UserData& d)
167
+ {
168
+ return os << "{streamId:" << d.GetStreamId() << ", ssn:" << d.GetStreamSequenceNumber()
169
+ << ", mid:" << d.GetMessageId() << ", fsn:" << d.GetFragmentSequenceNumber()
170
+ << ", ppid:" << d.GetPayloadProtocolId() << ", payloadLen:" << d.GetPayloadLength()
171
+ << ", B:" << d.IsBeginning() << ", E:" << d.IsEnd() << ", U:" << d.IsUnordered()
172
+ << "}";
173
+ }
138
174
  } // namespace SCTP
139
175
  } // namespace RTC
140
176
 
@@ -114,7 +114,7 @@ namespace RTC
114
114
 
115
115
  std::vector<AnyForwardTsnChunk::SkippedStream> GetSkippedStreams() const final;
116
116
 
117
- void AddStream(uint16_t stream, uint16_t streamSequence);
117
+ void AddStream(uint16_t streamId, uint16_t streamSequence);
118
118
 
119
119
  protected:
120
120
  ForwardTsnChunk* SoftClone(const uint8_t* buffer) const final;
@@ -126,7 +126,7 @@ namespace RTC
126
126
 
127
127
  std::vector<AnyForwardTsnChunk::SkippedStream> GetSkippedStreams() const final;
128
128
 
129
- void AddStream(uint16_t stream, bool uFlag, uint32_t messageIdentifier);
129
+ void AddStream(uint16_t streamId, bool uFlag, uint32_t messageIdentifier);
130
130
 
131
131
  protected:
132
132
  IForwardTsnChunk* SoftClone(const uint8_t* buffer) const final;
@@ -2,6 +2,7 @@
2
2
  #define MS_RTC_SCTP_OPTIONS_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "Utils.hpp"
5
6
  #include "RTC/Consts.hpp"
6
7
  #include "RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp"
7
8
 
@@ -44,7 +45,7 @@ namespace RTC
44
45
  * Maximum size of an SCTP Packet. It doesn't include any overhead of
45
46
  * DTLS, TURN, UDP or IP headers.
46
47
  */
47
- size_t mtu{ RTC::Consts::MaxSafeMtuSizeForSctp };
48
+ size_t mtu{ Utils::Byte::PadDownTo4Bytes(RTC::Consts::MaxSafeMtuSizeForSctp) };
48
49
 
49
50
  /**
50
51
  * The largest allowed message payload to be sent. Messages will be rejected