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
@@ -33,7 +33,7 @@ namespace RTC
33
33
  * This constructor is used when the WebRtcTransport doesn't use a WebRtcServer.
34
34
  */
35
35
  WebRtcTransport::WebRtcTransport(
36
- RTC::Shared* shared,
36
+ SharedInterface* shared,
37
37
  const std::string& id,
38
38
  RTC::Transport::Listener* listener,
39
39
  const FBS::WebRtcTransport::WebRtcTransportOptions* options)
@@ -226,13 +226,17 @@ namespace RTC
226
226
 
227
227
  // Create a ICE server.
228
228
  this->iceServer = new RTC::ICE::IceServer(
229
- this, Utils::Crypto::GetRandomString(32), Utils::Crypto::GetRandomString(32), iceConsentTimeout);
229
+ this,
230
+ this->shared,
231
+ Utils::Crypto::GetRandomString(32),
232
+ Utils::Crypto::GetRandomString(32),
233
+ iceConsentTimeout);
230
234
 
231
235
  // Create a DTLS transport.
232
- this->dtlsTransport = new RTC::DtlsTransport(this);
236
+ this->dtlsTransport = new RTC::DtlsTransport(this, this->shared);
233
237
 
234
238
  // NOTE: This may throw.
235
- this->shared->channelMessageRegistrator->RegisterHandler(
239
+ this->shared->GetChannelMessageRegistrator()->RegisterHandler(
236
240
  this->id,
237
241
  /*channelRequestHandler*/ this,
238
242
  /*channelNotificationHandler*/ this);
@@ -273,7 +277,7 @@ namespace RTC
273
277
  * This constructor is used when the WebRtcTransport uses a WebRtcServer.
274
278
  */
275
279
  WebRtcTransport::WebRtcTransport(
276
- RTC::Shared* shared,
280
+ SharedInterface* shared,
277
281
  const std::string& id,
278
282
  RTC::Transport::Listener* listener,
279
283
  WebRtcTransportListener* webRtcTransportListener,
@@ -296,16 +300,20 @@ namespace RTC
296
300
 
297
301
  // Create a ICE server.
298
302
  this->iceServer = new RTC::ICE::IceServer(
299
- this, Utils::Crypto::GetRandomString(32), Utils::Crypto::GetRandomString(32), iceConsentTimeout);
303
+ this,
304
+ this->shared,
305
+ Utils::Crypto::GetRandomString(32),
306
+ Utils::Crypto::GetRandomString(32),
307
+ iceConsentTimeout);
300
308
 
301
309
  // Create a DTLS transport.
302
- this->dtlsTransport = new RTC::DtlsTransport(this);
310
+ this->dtlsTransport = new RTC::DtlsTransport(this, this->shared);
303
311
 
304
312
  // Notify the webRtcTransportListener.
305
313
  this->webRtcTransportListener->OnWebRtcTransportCreated(this);
306
314
 
307
315
  // NOTE: This may throw.
308
- this->shared->channelMessageRegistrator->RegisterHandler(
316
+ this->shared->GetChannelMessageRegistrator()->RegisterHandler(
309
317
  this->id,
310
318
  /*channelRequestHandler*/ this,
311
319
  /*channelNotificationHandler*/ this);
@@ -333,7 +341,7 @@ namespace RTC
333
341
  // parent's destructor. See comment in Transport::OnSctpAssociationSendData().
334
342
  Destroying();
335
343
 
336
- this->shared->channelMessageRegistrator->UnregisterHandler(this->id);
344
+ this->shared->GetChannelMessageRegistrator()->UnregisterHandler(this->id);
337
345
 
338
346
  // Must delete the DTLS transport first since it will generate a DTLS alert
339
347
  // to be sent.
@@ -1221,12 +1229,12 @@ namespace RTC
1221
1229
 
1222
1230
  // Notify the Node WebRtcTransport.
1223
1231
  auto tuple = this->iceServer->GetSelectedTuple()->FillBuffer(
1224
- this->shared->channelNotifier->GetBufferBuilder());
1232
+ this->shared->GetChannelNotifier()->GetBufferBuilder());
1225
1233
 
1226
1234
  auto notification = FBS::WebRtcTransport::CreateIceSelectedTupleChangeNotification(
1227
- this->shared->channelNotifier->GetBufferBuilder(), tuple);
1235
+ this->shared->GetChannelNotifier()->GetBufferBuilder(), tuple);
1228
1236
 
1229
- this->shared->channelNotifier->Emit(
1237
+ this->shared->GetChannelNotifier()->Emit(
1230
1238
  this->id,
1231
1239
  FBS::Notification::Event::WEBRTCTRANSPORT_ICE_SELECTED_TUPLE_CHANGE,
1232
1240
  FBS::Notification::Body::WebRtcTransport_IceSelectedTupleChangeNotification,
@@ -1241,9 +1249,10 @@ namespace RTC
1241
1249
 
1242
1250
  // Notify the Node WebRtcTransport.
1243
1251
  auto iceStateChangeOffset = FBS::WebRtcTransport::CreateIceStateChangeNotification(
1244
- this->shared->channelNotifier->GetBufferBuilder(), FBS::WebRtcTransport::IceState::CONNECTED);
1252
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1253
+ FBS::WebRtcTransport::IceState::CONNECTED);
1245
1254
 
1246
- this->shared->channelNotifier->Emit(
1255
+ this->shared->GetChannelNotifier()->Emit(
1247
1256
  this->id,
1248
1257
  FBS::Notification::Event::WEBRTCTRANSPORT_ICE_STATE_CHANGE,
1249
1258
  FBS::Notification::Body::WebRtcTransport_IceStateChangeNotification,
@@ -1267,9 +1276,10 @@ namespace RTC
1267
1276
 
1268
1277
  // Notify the Node WebRtcTransport.
1269
1278
  auto iceStateChangeOffset = FBS::WebRtcTransport::CreateIceStateChangeNotification(
1270
- this->shared->channelNotifier->GetBufferBuilder(), FBS::WebRtcTransport::IceState::COMPLETED);
1279
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1280
+ FBS::WebRtcTransport::IceState::COMPLETED);
1271
1281
 
1272
- this->shared->channelNotifier->Emit(
1282
+ this->shared->GetChannelNotifier()->Emit(
1273
1283
  this->id,
1274
1284
  FBS::Notification::Event::WEBRTCTRANSPORT_ICE_STATE_CHANGE,
1275
1285
  FBS::Notification::Body::WebRtcTransport_IceStateChangeNotification,
@@ -1293,10 +1303,10 @@ namespace RTC
1293
1303
 
1294
1304
  // Notify the Node WebRtcTransport.
1295
1305
  auto iceStateChangeOffset = FBS::WebRtcTransport::CreateIceStateChangeNotification(
1296
- this->shared->channelNotifier->GetBufferBuilder(),
1306
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1297
1307
  FBS::WebRtcTransport::IceState::DISCONNECTED);
1298
1308
 
1299
- this->shared->channelNotifier->Emit(
1309
+ this->shared->GetChannelNotifier()->Emit(
1300
1310
  this->id,
1301
1311
  FBS::Notification::Event::WEBRTCTRANSPORT_ICE_STATE_CHANGE,
1302
1312
  FBS::Notification::Body::WebRtcTransport_IceStateChangeNotification,
@@ -1317,9 +1327,10 @@ namespace RTC
1317
1327
 
1318
1328
  // Notify the Node WebRtcTransport.
1319
1329
  auto dtlsStateChangeOffset = FBS::WebRtcTransport::CreateDtlsStateChangeNotification(
1320
- this->shared->channelNotifier->GetBufferBuilder(), FBS::WebRtcTransport::DtlsState::CONNECTING);
1330
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1331
+ FBS::WebRtcTransport::DtlsState::CONNECTING);
1321
1332
 
1322
- this->shared->channelNotifier->Emit(
1333
+ this->shared->GetChannelNotifier()->Emit(
1323
1334
  this->id,
1324
1335
  FBS::Notification::Event::WEBRTCTRANSPORT_DTLS_STATE_CHANGE,
1325
1336
  FBS::Notification::Body::WebRtcTransport_DtlsStateChangeNotification,
@@ -1363,11 +1374,11 @@ namespace RTC
1363
1374
 
1364
1375
  // Notify the Node WebRtcTransport.
1365
1376
  auto dtlsStateChangeOffset = FBS::WebRtcTransport::CreateDtlsStateChangeNotificationDirect(
1366
- this->shared->channelNotifier->GetBufferBuilder(),
1377
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1367
1378
  FBS::WebRtcTransport::DtlsState::CONNECTED,
1368
1379
  remoteCert.c_str());
1369
1380
 
1370
- this->shared->channelNotifier->Emit(
1381
+ this->shared->GetChannelNotifier()->Emit(
1371
1382
  this->id,
1372
1383
  FBS::Notification::Event::WEBRTCTRANSPORT_DTLS_STATE_CHANGE,
1373
1384
  FBS::Notification::Body::WebRtcTransport_DtlsStateChangeNotification,
@@ -1393,9 +1404,10 @@ namespace RTC
1393
1404
 
1394
1405
  // Notify the Node WebRtcTransport.
1395
1406
  auto dtlsStateChangeOffset = FBS::WebRtcTransport::CreateDtlsStateChangeNotification(
1396
- this->shared->channelNotifier->GetBufferBuilder(), FBS::WebRtcTransport::DtlsState::FAILED);
1407
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1408
+ FBS::WebRtcTransport::DtlsState::FAILED);
1397
1409
 
1398
- this->shared->channelNotifier->Emit(
1410
+ this->shared->GetChannelNotifier()->Emit(
1399
1411
  this->id,
1400
1412
  FBS::Notification::Event::WEBRTCTRANSPORT_DTLS_STATE_CHANGE,
1401
1413
  FBS::Notification::Body::WebRtcTransport_DtlsStateChangeNotification,
@@ -1410,9 +1422,10 @@ namespace RTC
1410
1422
 
1411
1423
  // Notify the Node WebRtcTransport.
1412
1424
  auto dtlsStateChangeOffset = FBS::WebRtcTransport::CreateDtlsStateChangeNotification(
1413
- this->shared->channelNotifier->GetBufferBuilder(), FBS::WebRtcTransport::DtlsState::CLOSED);
1425
+ this->shared->GetChannelNotifier()->GetBufferBuilder(),
1426
+ FBS::WebRtcTransport::DtlsState::CLOSED);
1414
1427
 
1415
- this->shared->channelNotifier->Emit(
1428
+ this->shared->GetChannelNotifier()->Emit(
1416
1429
  this->id,
1417
1430
  FBS::Notification::Event::WEBRTCTRANSPORT_DTLS_STATE_CHANGE,
1418
1431
  FBS::Notification::Body::WebRtcTransport_DtlsStateChangeNotification,
@@ -0,0 +1,35 @@
1
+ #define MS_CLASS "Shared"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "Shared.hpp"
5
+ #include "Logger.hpp"
6
+ #include "handles/BackoffTimerHandle.hpp"
7
+ #include "handles/TimerHandle.hpp"
8
+
9
+ Shared::Shared(
10
+ Channel::ChannelMessageRegistrator* channelMessageRegistrator,
11
+ Channel::ChannelNotifier* channelNotifier)
12
+ : channelMessageRegistrator(channelMessageRegistrator), channelNotifier(channelNotifier)
13
+ {
14
+ MS_TRACE();
15
+ }
16
+
17
+ Shared::~Shared()
18
+ {
19
+ MS_TRACE();
20
+ }
21
+
22
+ TimerHandleInterface* Shared::CreateTimer(TimerHandleInterface::Listener* listener) const
23
+ {
24
+ MS_TRACE();
25
+
26
+ return new TimerHandle(listener);
27
+ }
28
+
29
+ BackoffTimerHandleInterface* Shared::CreateBackoffTimer(
30
+ const BackoffTimerHandleInterface::BackoffTimerHandleOptions& options) const
31
+ {
32
+ MS_TRACE();
33
+
34
+ return new BackoffTimerHandle(options);
35
+ }
@@ -2,7 +2,6 @@
2
2
  // #define MS_LOG_DEV_LEVEL 3
3
3
 
4
4
  #include "Worker.hpp"
5
- #include "ChannelMessageRegistrator.hpp"
6
5
  #ifdef MS_LIBURING_SUPPORTED
7
6
  #include "DepLibUring.hpp"
8
7
  #endif
@@ -12,13 +11,13 @@
12
11
  #include "Logger.hpp"
13
12
  #include "MediaSoupErrors.hpp"
14
13
  #include "Settings.hpp"
15
- #include "Channel/ChannelNotifier.hpp"
16
14
  #include "FBS/response.h"
17
15
  #include "FBS/worker.h"
18
16
 
19
17
  /* Instance methods. */
20
18
 
21
- Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel)
19
+ Worker::Worker(::Channel::ChannelSocket* channel, SharedInterface* shared)
20
+ : channel(channel), shared(shared)
22
21
  {
23
22
  MS_TRACE();
24
23
 
@@ -28,11 +27,6 @@ Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel)
28
27
  // Set the SignalHandle.
29
28
  this->signalHandle = new SignalHandle(this);
30
29
 
31
- // Set up the RTC::Shared singleton.
32
- this->shared = new RTC::Shared(
33
- /*channelMessageRegistrator*/ new ChannelMessageRegistrator(),
34
- /*channelNotifier*/ new Channel::ChannelNotifier(this->channel));
35
-
36
30
  #ifdef MS_EXECUTABLE
37
31
  {
38
32
  // Add signals to handle.
@@ -45,7 +39,7 @@ Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel)
45
39
  if (!Settings::configuration.useBuiltInSctpStack)
46
40
  {
47
41
  // Create the Checker instance in DepUsrSCTP.
48
- DepUsrSCTP::CreateChecker();
42
+ DepUsrSCTP::CreateChecker(this->shared);
49
43
  }
50
44
 
51
45
  #ifdef MS_LIBURING_SUPPORTED
@@ -57,7 +51,7 @@ Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel)
57
51
  #endif
58
52
 
59
53
  // Tell the Node process that we are running.
60
- this->shared->channelNotifier->Emit(
54
+ this->shared->GetChannelNotifier()->Emit(
61
55
  std::to_string(Logger::pid), FBS::Notification::Event::WORKER_RUNNING);
62
56
 
63
57
  MS_DEBUG_DEV("starting libuv loop");
@@ -107,9 +101,6 @@ void Worker::Close()
107
101
  }
108
102
  this->mapWebRtcServers.clear();
109
103
 
110
- // Delete the RTC::Shared singleton.
111
- delete this->shared;
112
-
113
104
  // TODO: Remove once we only use built-in SCTP stack.
114
105
  if (!Settings::configuration.useBuiltInSctpStack)
115
106
  {
@@ -155,7 +146,7 @@ flatbuffers::Offset<FBS::Worker::DumpResponse> Worker::FillBuffer(
155
146
  }
156
147
 
157
148
  // Add channelMessageHandlers.
158
- auto channelMessageHandlers = this->shared->channelMessageRegistrator->FillBuffer(builder);
149
+ auto channelMessageHandlers = this->shared->GetChannelMessageRegistrator()->FillBuffer(builder);
159
150
 
160
151
  #ifdef MS_LIBURING_SUPPORTED
161
152
  if (DepLibUring::IsEnabled())
@@ -437,7 +428,7 @@ void Worker::HandleRequest(Channel::ChannelRequest* request)
437
428
  try
438
429
  {
439
430
  auto* handler =
440
- this->shared->channelMessageRegistrator->GetChannelRequestHandler(request->handlerId);
431
+ this->shared->GetChannelMessageRegistrator()->GetChannelRequestHandler(request->handlerId);
441
432
 
442
433
  if (handler == nullptr)
443
434
  {
@@ -486,7 +477,7 @@ void Worker::HandleNotification(Channel::ChannelNotification* notification)
486
477
  {
487
478
  try
488
479
  {
489
- auto* handler = this->shared->channelMessageRegistrator->GetChannelNotificationHandler(
480
+ auto* handler = this->shared->GetChannelMessageRegistrator()->GetChannelNotificationHandler(
490
481
  notification->handlerId);
491
482
 
492
483
  if (handler == nullptr)
@@ -513,7 +504,8 @@ void Worker::OnChannelClosed(Channel::ChannelSocket* /*socket*/)
513
504
  {
514
505
  MS_TRACE_STD();
515
506
 
516
- // Only needed for executable, library user can close channel earlier and it is fine.
507
+ // Only needed for executable, library user can close channel earlier and it
508
+ // is fine.
517
509
  #ifdef MS_EXECUTABLE
518
510
  // If the pipe is remotely closed it may mean that mediasoup Node process
519
511
  // abruptly died (SIGKILL?) so we must die.
@@ -537,11 +529,6 @@ void Worker::OnSignal(SignalHandle* /*signalHandle*/, int signum)
537
529
  case SIGINT:
538
530
  case SIGTERM:
539
531
  {
540
- if (this->closed)
541
- {
542
- return;
543
- }
544
-
545
532
  MS_DEBUG_DEV("%s signal received, closing myself", signum == SIGINT ? "INT" : "TERM");
546
533
 
547
534
  Close();
@@ -551,7 +538,7 @@ void Worker::OnSignal(SignalHandle* /*signalHandle*/, int signum)
551
538
 
552
539
  default:
553
540
  {
554
- MS_WARN_DEV("received a non handled signal [signum:%d]", signum);
541
+ MS_WARN_DEV("ignoring received non handled signal [signum:%d]", signum);
555
542
  }
556
543
  }
557
544
  }
@@ -8,17 +8,12 @@
8
8
 
9
9
  /* Instance methods. */
10
10
 
11
- BackoffTimerHandle::BackoffTimerHandle(
12
- Listener* listener,
13
- uint64_t baseTimeoutMs,
14
- BackoffAlgorithm backoffAlgorithm,
15
- std::optional<uint64_t> maxBackoffTimeoutMs,
16
- std::optional<size_t> maxRestarts)
17
- : listener(listener),
18
- baseTimeoutMs(baseTimeoutMs),
19
- backoffAlgorithm(backoffAlgorithm),
20
- maxBackoffTimeoutMs(maxBackoffTimeoutMs),
21
- maxRestarts(maxRestarts)
11
+ BackoffTimerHandle::BackoffTimerHandle(const BackoffTimerHandleOptions& options)
12
+ : listener(options.listener),
13
+ baseTimeoutMs(options.baseTimeoutMs),
14
+ backoffAlgorithm(options.backoffAlgorithm),
15
+ maxBackoffTimeoutMs(options.maxBackoffTimeoutMs),
16
+ maxRestarts(options.maxRestarts)
22
17
  {
23
18
  MS_TRACE();
24
19
 
@@ -60,12 +55,12 @@ void BackoffTimerHandle::SetBaseTimeoutMs(uint64_t baseTimeoutMs)
60
55
  {
61
56
  MS_TRACE();
62
57
 
63
- if (baseTimeoutMs > BackoffTimerHandle::MaxTimeoutMs)
58
+ if (baseTimeoutMs > BackoffTimerHandleInterface::MaxTimeoutMs)
64
59
  {
65
60
  MS_THROW_ERROR(
66
61
  "base timeout (%" PRIu64 " ms) cannot be greater than %" PRIu64 " ms",
67
62
  baseTimeoutMs,
68
- BackoffTimerHandle::MaxTimeoutMs);
63
+ BackoffTimerHandleInterface::MaxTimeoutMs);
69
64
  }
70
65
 
71
66
  this->baseTimeoutMs = baseTimeoutMs;
@@ -88,7 +83,7 @@ uint64_t BackoffTimerHandle::ComputeNextTimeoutMs() const
88
83
  {
89
84
  auto timeoutMs = this->baseTimeoutMs;
90
85
 
91
- while (expirationCount > 0 && timeoutMs < BackoffTimerHandle::MaxTimeoutMs)
86
+ while (expirationCount > 0 && timeoutMs < BackoffTimerHandleInterface::MaxTimeoutMs)
92
87
  {
93
88
  timeoutMs *= 2;
94
89
  --expirationCount;
@@ -99,14 +94,14 @@ uint64_t BackoffTimerHandle::ComputeNextTimeoutMs() const
99
94
  }
100
95
  }
101
96
 
102
- return std::min<uint64_t>(timeoutMs, BackoffTimerHandle::MaxTimeoutMs);
97
+ return std::min<uint64_t>(timeoutMs, BackoffTimerHandleInterface::MaxTimeoutMs);
103
98
  }
104
99
 
105
100
  NO_DEFAULT_GCC();
106
101
  }
107
102
  }
108
103
 
109
- void BackoffTimerHandle::OnTimer(TimerHandle* timer)
104
+ void BackoffTimerHandle::OnTimer(TimerHandleInterface* /*timer*/)
110
105
  {
111
106
  MS_TRACE();
112
107
 
@@ -8,19 +8,20 @@
8
8
 
9
9
  /* Static methods for UV callbacks. */
10
10
 
11
- inline static void onTimer(uv_timer_t* handle)
11
+ static void onTimer(uv_timer_t* handle)
12
12
  {
13
13
  static_cast<TimerHandle*>(handle->data)->OnUvTimer();
14
14
  }
15
15
 
16
- inline static void onCloseTimer(uv_handle_t* handle)
16
+ static void onCloseTimer(uv_handle_t* handle)
17
17
  {
18
18
  delete reinterpret_cast<uv_timer_t*>(handle);
19
19
  }
20
20
 
21
21
  /* Instance methods. */
22
22
 
23
- TimerHandle::TimerHandle(Listener* listener) : listener(listener), uvHandle(new uv_timer_t)
23
+ TimerHandle::TimerHandle(TimerHandleInterface::Listener* listener)
24
+ : listener(listener), uvHandle(new uv_timer_t)
24
25
  {
25
26
  MS_TRACE();
26
27
 
@@ -174,7 +175,7 @@ void TimerHandle::InternalClose()
174
175
  uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onCloseTimer));
175
176
  }
176
177
 
177
- inline void TimerHandle::OnUvTimer()
178
+ void TimerHandle::OnUvTimer()
178
179
  {
179
180
  MS_TRACE();
180
181
 
@@ -1,6 +1,7 @@
1
1
  #define MS_CLASS "mediasoup-worker"
2
2
  // #define MS_LOG_DEV_LEVEL 3
3
3
 
4
+ #include "lib.hpp"
4
5
  #include "common.hpp"
5
6
  #include "DepLibSRTP.hpp"
6
7
  #ifdef MS_LIBURING_SUPPORTED
@@ -14,8 +15,11 @@
14
15
  #include "Logger.hpp"
15
16
  #include "MediaSoupErrors.hpp"
16
17
  #include "Settings.hpp"
18
+ #include "Shared.hpp"
17
19
  #include "Utils.hpp"
18
20
  #include "Worker.hpp"
21
+ #include "Channel/ChannelMessageRegistrator.hpp"
22
+ #include "Channel/ChannelNotifier.hpp"
19
23
  #include "Channel/ChannelSocket.hpp"
20
24
  #include "RTC/DtlsTransport.hpp"
21
25
  #include "RTC/SrtpSession.hpp"
@@ -82,6 +86,11 @@ extern "C" int mediasoup_worker_run(
82
86
  }
83
87
  #endif
84
88
 
89
+ // Create a Shared singleton.
90
+ std::unique_ptr<Shared> shared{ new Shared(
91
+ /*channelMessageRegistrator*/ new Channel::ChannelMessageRegistrator(),
92
+ /*channelNotifier*/ new Channel::ChannelNotifier(channel.get())) };
93
+
85
94
  // Initialize the Logger.
86
95
  Logger::ClassInit(channel.get());
87
96
 
@@ -163,8 +172,12 @@ extern "C" int mediasoup_worker_run(
163
172
  // Ignore some signals.
164
173
  ignoreSignals();
165
174
 
175
+ MS_DEBUG_TAG(info, "creating Worker instance");
176
+
166
177
  // Run the Worker.
167
- const Worker worker(channel.get());
178
+ const Worker worker(channel.get(), shared.get());
179
+
180
+ MS_DEBUG_TAG(info, "Worker instance terminated");
168
181
 
169
182
  // Free static stuff.
170
183
  DepLibSRTP::ClassDestroy();
package/worker/tasks.py CHANGED
@@ -496,7 +496,7 @@ def test_asan_undefined(ctx):
496
496
  );
497
497
 
498
498
 
499
- @task(pre=[call(setup, meson_args=MESON_ARGS + ' -Db_sanitize=address -Db_lundef=false'), flatc])
499
+ @task(pre=[call(setup, meson_args=MESON_ARGS + ' -Dms_build_fuzzer=true -Db_sanitize=address -Db_lundef=false'), flatc])
500
500
  def fuzzer(ctx):
501
501
  """
502
502
  Build the mediasoup-worker-fuzzer binary (which uses libFuzzer)
@@ -65,6 +65,7 @@ namespace iceCommon
65
65
  REQUIRE(packet->GetBufferLength() == bufferLength); \
66
66
  REQUIRE(packet->GetLength() != 0); \
67
67
  REQUIRE(packet->GetLength() == length); \
68
+ REQUIRE(packet->GetAvailableLength() == packet->GetBufferLength() - packet->GetLength()); \
68
69
  REQUIRE(packet->GetClass() == klass); \
69
70
  REQUIRE(packet->GetMethod() == method); \
70
71
  REQUIRE(packet->HasAttribute(RTC::ICE::StunPacket::AttributeType::USERNAME) == hasUsername); \
@@ -55,6 +55,7 @@ namespace rtpCommon
55
55
  REQUIRE(packet->GetBufferLength() == bufferLength); \
56
56
  REQUIRE(packet->GetLength() != 0); \
57
57
  REQUIRE(packet->GetLength() == length); \
58
+ REQUIRE(packet->GetAvailableLength() == packet->GetBufferLength() - packet->GetLength()); \
58
59
  REQUIRE(static_cast<unsigned>(packet->GetVersion()) == 2); \
59
60
  REQUIRE(static_cast<unsigned>(packet->GetPayloadType()) == payloadType); \
60
61
  REQUIRE(packet->HasMarker() == hasMarker); \
@@ -49,6 +49,7 @@ namespace sctpCommon
49
49
  REQUIRE(packet->GetBufferLength() == bufferLength); \
50
50
  REQUIRE(packet->GetLength() != 0); \
51
51
  REQUIRE(packet->GetLength() == length); \
52
+ REQUIRE(packet->GetAvailableLength() == packet->GetBufferLength() - packet->GetLength()); \
52
53
  REQUIRE(Utils::Byte::IsPaddedTo4Bytes(packet->GetLength()) == true); \
53
54
  REQUIRE(packet->GetSourcePort() == sourcePort); \
54
55
  REQUIRE(packet->GetDestinationPort() == destinationPort); \
@@ -92,6 +93,7 @@ namespace sctpCommon
92
93
  REQUIRE(chunk->GetBufferLength() == bufferLength); \
93
94
  REQUIRE(chunk->GetLength() != 0); \
94
95
  REQUIRE(chunk->GetLength() == length); \
96
+ REQUIRE(chunk->GetAvailableLength() == chunk->GetBufferLength() - chunk->GetLength()); \
95
97
  REQUIRE(Utils::Byte::IsPaddedTo4Bytes(chunk->GetLength()) == true); \
96
98
  REQUIRE(chunk->GetType() == chunkType); \
97
99
  REQUIRE(chunk->HasUnknownType() == unknownType); \
@@ -152,6 +154,8 @@ namespace sctpCommon
152
154
  REQUIRE(parameter->GetBufferLength() == bufferLength); \
153
155
  REQUIRE(parameter->GetLength() != 0); \
154
156
  REQUIRE(parameter->GetLength() == length); \
157
+ REQUIRE( \
158
+ parameter->GetAvailableLength() == parameter->GetBufferLength() - parameter->GetLength()); \
155
159
  REQUIRE(Utils::Byte::IsPaddedTo4Bytes(parameter->GetLength()) == true); \
156
160
  REQUIRE(parameter->GetType() == parameterType); \
157
161
  REQUIRE(parameter->HasUnknownType() == unknownType); \
@@ -189,6 +193,8 @@ namespace sctpCommon
189
193
  REQUIRE(errorCause->GetBufferLength() == bufferLength); \
190
194
  REQUIRE(errorCause->GetLength() != 0); \
191
195
  REQUIRE(errorCause->GetLength() == length); \
196
+ REQUIRE( \
197
+ errorCause->GetAvailableLength() == errorCause->GetBufferLength() - errorCause->GetLength()); \
192
198
  REQUIRE(Utils::Byte::IsPaddedTo4Bytes(errorCause->GetLength()) == true); \
193
199
  REQUIRE(errorCause->GetCode() == causeCode); \
194
200
  REQUIRE(errorCause->HasUnknownCode() == unknownCode); \
@@ -1,5 +1,6 @@
1
1
  #include "common.hpp"
2
2
  #include "DepLibUV.hpp"
3
+ #include "mocks/include/MockShared.hpp"
3
4
  #include "RTC/RTP/Packet.hpp"
4
5
  #include "RTC/RTP/RtpStream.hpp"
5
6
  #include "RTC/RTP/RtpStreamRecv.hpp"
@@ -118,8 +119,10 @@ SCENARIO("RtpStreamRecv", "[rtp][rtpstream][rtpstreamrecv]")
118
119
  std::vector<uint16_t> nackedSeqNumbers;
119
120
  };
120
121
 
122
+ mocks::MockShared shared;
123
+
121
124
  // clang-format off
122
- uint8_t buffer[] =
125
+ alignas(4) uint8_t buffer[] =
123
126
  {
124
127
  0x80, 0x01, 0x00, 0x01,
125
128
  0x00, 0x00, 0x00, 0x04,
@@ -148,7 +151,8 @@ SCENARIO("RtpStreamRecv", "[rtp][rtpstream][rtpstreamrecv]")
148
151
  SECTION("NACK one packet")
149
152
  {
150
153
  RtpStreamRecvListener listener;
151
- RTC::RTP::RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
154
+ RTC::RTP::RtpStreamRecv rtpStream(
155
+ std::addressof(listener), std::addressof(shared), params, SendNackDelay, UseRtpInactivityCheck);
152
156
 
153
157
  packet->SetSequenceNumber(1);
154
158
  rtpStream.ReceivePacket(packet.get());
@@ -177,7 +181,8 @@ SCENARIO("RtpStreamRecv", "[rtp][rtpstream][rtpstreamrecv]")
177
181
  SECTION("receive RTX before corresponding RTP")
178
182
  {
179
183
  RtpStreamRecvListener listener;
180
- RTC::RTP::RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
184
+ RTC::RTP::RtpStreamRecv rtpStream(
185
+ std::addressof(listener), std::addressof(shared), params, SendNackDelay, UseRtpInactivityCheck);
181
186
 
182
187
  packet->SetSequenceNumber(1);
183
188
  rtpStream.ReceivePacket(packet.get());
@@ -210,7 +215,8 @@ SCENARIO("RtpStreamRecv", "[rtp][rtpstream][rtpstreamrecv]")
210
215
  SECTION("wrapping sequence numbers")
211
216
  {
212
217
  RtpStreamRecvListener listener;
213
- RTC::RTP::RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
218
+ RTC::RTP::RtpStreamRecv rtpStream(
219
+ std::addressof(listener), std::addressof(shared), params, SendNackDelay, UseRtpInactivityCheck);
214
220
 
215
221
  packet->SetSequenceNumber(0xfffe);
216
222
  rtpStream.ReceivePacket(packet.get());
@@ -230,7 +236,8 @@ SCENARIO("RtpStreamRecv", "[rtp][rtpstream][rtpstreamrecv]")
230
236
  SECTION("require key frame")
231
237
  {
232
238
  RtpStreamRecvListener listener;
233
- RTC::RTP::RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck);
239
+ RTC::RTP::RtpStreamRecv rtpStream(
240
+ std::addressof(listener), std::addressof(shared), params, SendNackDelay, UseRtpInactivityCheck);
234
241
 
235
242
  packet->SetSequenceNumber(1);
236
243
  rtpStream.ReceivePacket(packet.get());