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
@@ -0,0 +1,40 @@
1
+ #ifndef MS_SHARED_HPP
2
+ #define MS_SHARED_HPP
3
+
4
+ #include "SharedInterface.hpp"
5
+ #include "Channel/ChannelMessageRegistrator.hpp"
6
+ #include "Channel/ChannelNotifier.hpp"
7
+ #include "handles/BackoffTimerHandleInterface.hpp"
8
+ #include "handles/TimerHandleInterface.hpp"
9
+
10
+ class Shared : public SharedInterface
11
+ {
12
+ public:
13
+ explicit Shared(
14
+ Channel::ChannelMessageRegistrator* channelMessageRegistrator,
15
+ Channel::ChannelNotifier* channelNotifier);
16
+
17
+ ~Shared() override;
18
+
19
+ public:
20
+ Channel::ChannelMessageRegistratorInterface* GetChannelMessageRegistrator() const override
21
+ {
22
+ return this->channelMessageRegistrator.get();
23
+ }
24
+
25
+ Channel::ChannelNotifier* GetChannelNotifier() const override
26
+ {
27
+ return this->channelNotifier.get();
28
+ }
29
+
30
+ TimerHandleInterface* CreateTimer(TimerHandleInterface::Listener* listener) const override;
31
+
32
+ BackoffTimerHandleInterface* CreateBackoffTimer(
33
+ const BackoffTimerHandleInterface::BackoffTimerHandleOptions& options) const override;
34
+
35
+ private:
36
+ std::unique_ptr<Channel::ChannelMessageRegistrator> channelMessageRegistrator;
37
+ std::unique_ptr<Channel::ChannelNotifier> channelNotifier;
38
+ };
39
+
40
+ #endif
@@ -0,0 +1,44 @@
1
+ #ifndef MS_SHARED_INTERFACE_HPP
2
+ #define MS_SHARED_INTERFACE_HPP
3
+
4
+ #include "Channel/ChannelMessageRegistratorInterface.hpp"
5
+ // TODO: We should have a ChannelNotifierInterface class instead.
6
+ #include "Channel/ChannelNotifier.hpp"
7
+ #include "handles/BackoffTimerHandleInterface.hpp"
8
+ #include "handles/TimerHandleInterface.hpp"
9
+
10
+ class SharedInterface
11
+ {
12
+ public:
13
+ virtual ~SharedInterface() = default;
14
+
15
+ public:
16
+ /**
17
+ * @todo We should have a ChannelMessageRegistratorInterface class instead.
18
+ */
19
+ virtual Channel::ChannelMessageRegistratorInterface* GetChannelMessageRegistrator() const = 0;
20
+
21
+ /**
22
+ * @todo We should have a ChannelNotifierInterface class instead.
23
+ */
24
+ virtual Channel::ChannelNotifier* GetChannelNotifier() const = 0;
25
+
26
+ /**
27
+ * Creates a TimerHandle timer.
28
+ *
29
+ * @remarks
30
+ * - The caller is responsible for freeing it.
31
+ */
32
+ virtual TimerHandleInterface* CreateTimer(TimerHandleInterface::Listener* listener) const = 0;
33
+
34
+ /**
35
+ * Creates a BackoffTimerHandle timer.
36
+ *
37
+ * @remarks
38
+ * - The caller is responsible for freeing it.
39
+ */
40
+ virtual BackoffTimerHandleInterface* CreateBackoffTimer(
41
+ const BackoffTimerHandleInterface::BackoffTimerHandleOptions& options) const = 0;
42
+ };
43
+
44
+ #endif
@@ -212,6 +212,12 @@ namespace Utils
212
212
  return (size + 3) & ~static_cast<T>(0x03);
213
213
  }
214
214
 
215
+ template<typename T>
216
+ typename std::enable_if<std::is_unsigned<T>::value, T>::type static PadDownTo4Bytes(T size)
217
+ {
218
+ return size & ~static_cast<T>(0x03);
219
+ }
220
+
215
221
  template<typename T>
216
222
  typename std::enable_if<std::is_unsigned<T>::value, T>::type static PadTo8Bytes(T size)
217
223
  {
@@ -1,11 +1,11 @@
1
1
  #ifndef MS_WORKER_HPP
2
2
  #define MS_WORKER_HPP
3
3
 
4
+ #include "SharedInterface.hpp"
4
5
  #include "Channel/ChannelRequest.hpp"
5
6
  #include "Channel/ChannelSocket.hpp"
6
7
  #include "FBS/worker.h"
7
8
  #include "RTC/Router.hpp"
8
- #include "RTC/Shared.hpp"
9
9
  #include "RTC/WebRtcServer.hpp"
10
10
  #include "handles/SignalHandle.hpp"
11
11
  #include <flatbuffers/flatbuffer_builder.h>
@@ -17,7 +17,7 @@ class Worker : public Channel::ChannelSocket::Listener,
17
17
  public RTC::Router::Listener
18
18
  {
19
19
  public:
20
- explicit Worker(Channel::ChannelSocket* channel);
20
+ explicit Worker(Channel::ChannelSocket* channel, SharedInterface* shared);
21
21
  ~Worker() override;
22
22
 
23
23
  private:
@@ -53,7 +53,7 @@ private:
53
53
  Channel::ChannelSocket* channel{ nullptr };
54
54
  // Allocated by this.
55
55
  SignalHandle* signalHandle{ nullptr };
56
- RTC::Shared* shared{ nullptr };
56
+ SharedInterface* shared{ nullptr };
57
57
  absl::flat_hash_map<std::string, RTC::WebRtcServer*> mapWebRtcServers;
58
58
  absl::flat_hash_map<std::string, RTC::Router*> mapRouters;
59
59
  // Others.
@@ -1,7 +1,7 @@
1
1
  #ifndef MS_COMMON_HPP
2
2
  #define MS_COMMON_HPP
3
3
 
4
- #include <algorithm> // IWYU pragma: export std::transform(), std::find(), std::min(), std::max(), std::copy(), std::clamp()
4
+ #include <algorithm> // IWYU pragma: export std::transform(), std::find(), std::min(), std::max(), std::copy(), std::clamp(), std::ranges
5
5
  #include <cinttypes> // IWYU pragma: export PRIu64, etc
6
6
  #include <cstddef> // IWYU pragma: export size_t
7
7
  #include <cstdint> // IWYU pragma: export uint8_t, etc
@@ -2,68 +2,29 @@
2
2
  #define MS_BACKOFF_TIMER_HANDLE_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "handles/BackoffTimerHandleInterface.hpp"
5
6
  #include "handles/TimerHandle.hpp"
6
- #include <limits> // std::numeric_limits()
7
+ #include "handles/TimerHandleInterface.hpp"
7
8
 
8
- class BackoffTimerHandle : public TimerHandle::Listener
9
+ // Forward declaration.
10
+ class Shared;
11
+ // TODO: Temporal until we have MockBackoffTimerHandle.
12
+ namespace mocks
9
13
  {
10
- public:
11
- class Listener
12
- {
13
- public:
14
- virtual ~Listener() = default;
15
-
16
- public:
17
- /**
18
- * Invoked on timeout expiration. The parent can modify the base
19
- * timeout given as reference and affect the next timeout duration.
20
- *
21
- * @remarks
22
- * - If the caller deletes this BackoffTimer instance within the callback
23
- * it must signal it be setting `stop` to true.
24
- */
25
- virtual void OnTimer(BackoffTimerHandle* backoffTimer, uint64_t& baseTimeoutMs, bool& stop) = 0;
26
- };
14
+ class MockShared;
15
+ }
27
16
 
28
- public:
29
- enum class BackoffAlgorithm : uint8_t
30
- {
31
- // The base duration will be used for any restart.
32
- FIXED,
33
- // An exponential backoff is used for restarts, with a 2x multiplier,
34
- // meaning that every restart will use a duration that is twice as long as
35
- // the previous.
36
- EXPONENTIAL,
37
- };
17
+ class BackoffTimerHandle : public BackoffTimerHandleInterface, public TimerHandleInterface::Listener
18
+ {
19
+ // Only Shared class can invoke the constructor.
20
+ friend class Shared;
21
+ // TODO: Temporal until we have MockBackoffTimerHandle.
22
+ friend class mocks::MockShared;
38
23
 
39
- public:
40
- static constexpr uint64_t MaxTimeoutMs{ std::numeric_limits<uint64_t>::max() / 2 };
24
+ private:
25
+ explicit BackoffTimerHandle(const BackoffTimerHandleOptions& options);
41
26
 
42
27
  public:
43
- explicit BackoffTimerHandle(
44
- /**
45
- * Listener on which OnTimer() callback will be invoked.
46
- */
47
- Listener* listener,
48
- /**
49
- * Base timeout duration (ms).
50
- */
51
- uint64_t baseTimeoutMs,
52
- /**
53
- * Backoff algorithm.
54
- */
55
- BackoffAlgorithm backoffAlgorithm,
56
- /**
57
- * Maximum duration of the backoff timeout (ms). If no value is given, no
58
- * limit is set.
59
- */
60
- std::optional<uint64_t> maxBackoffTimeoutMs,
61
- /**
62
- * Maximum number of restarts. If no value is given, it will restart
63
- * forever until stopped.
64
- */
65
- std::optional<size_t> maxRestarts);
66
-
67
28
  BackoffTimerHandle& operator=(const BackoffTimerHandle&) = delete;
68
29
 
69
30
  BackoffTimerHandle(const BackoffTimerHandle&) = delete;
@@ -75,24 +36,24 @@ public:
75
36
  * Start the BackoffTimer (if it's stopped) or restart it (if already
76
37
  * running). It will reset the timeout count.
77
38
  */
78
- void Start();
39
+ void Start() override;
79
40
 
80
41
  /**
81
42
  * Stop the BackoffTimer. It will reset the timeout count.
82
43
  */
83
- void Stop();
44
+ void Stop() override;
84
45
 
85
46
  /**
86
47
  * Set the base timeout duration. It will be applied after the next timeout
87
48
  * and effective duration can be larger if backoff algorithm is exponential.
88
49
  */
89
- void SetBaseTimeoutMs(uint64_t baseTimeoutMs);
50
+ void SetBaseTimeoutMs(uint64_t baseTimeoutMs) override;
90
51
 
91
52
  /**
92
53
  * Whether the BackoffTimer is running. Useful to check if this BackoffTimer
93
54
  * will timeout again within the OnTimer() callback.
94
55
  */
95
- bool IsRunning() const
56
+ bool IsRunning() const override
96
57
  {
97
58
  return this->running;
98
59
  }
@@ -101,9 +62,10 @@ public:
101
62
  * Maximum number of restarts.
102
63
  *
103
64
  * @remarks
104
- * - If `maxRestarts` was not given in the constructor, this method returns 0.
65
+ * - If `maxRestarts` was not given in the constructor, this method returns
66
+ * `std::nullopt`.
105
67
  */
106
- std::optional<size_t> GetMaxRestarts() const
68
+ std::optional<size_t> GetMaxRestarts() const override
107
69
  {
108
70
  return this->maxRestarts;
109
71
  }
@@ -111,7 +73,7 @@ public:
111
73
  /**
112
74
  * Number of times the timer has expired.
113
75
  */
114
- size_t GetExpirationCount() const
76
+ size_t GetExpirationCount() const override
115
77
  {
116
78
  return this->expirationCount;
117
79
  }
@@ -119,13 +81,13 @@ public:
119
81
  private:
120
82
  uint64_t ComputeNextTimeoutMs() const;
121
83
 
122
- /* Pure virtual methods inherited from TimerHandle::Listener. */
84
+ /* Pure virtual methods inherited from TimerHandleInterface::Listener. */
123
85
  public:
124
- void OnTimer(TimerHandle* timer) override;
86
+ void OnTimer(TimerHandleInterface* timer) override;
125
87
 
126
88
  private:
127
89
  // Passed by argument.
128
- Listener* listener{ nullptr };
90
+ BackoffTimerHandleInterface::Listener* listener{ nullptr };
129
91
  uint64_t baseTimeoutMs{ 0 };
130
92
  BackoffAlgorithm backoffAlgorithm;
131
93
  std::optional<uint64_t> maxBackoffTimeoutMs;
@@ -0,0 +1,116 @@
1
+ #ifndef MS_BACKOFF_TIMER_HANDLE_INTERFACE_HPP
2
+ #define MS_BACKOFF_TIMER_HANDLE_INTERFACE_HPP
3
+
4
+ #include "common.hpp"
5
+ #include <limits> // std::numeric_limits()
6
+
7
+ class BackoffTimerHandleInterface
8
+ {
9
+ public:
10
+ class Listener
11
+ {
12
+ public:
13
+ virtual ~Listener() = default;
14
+
15
+ public:
16
+ /**
17
+ * Invoked on timeout expiration. The parent can modify the base
18
+ * timeout given as reference and affect the next timeout duration.
19
+ *
20
+ * @remarks
21
+ * - If the caller deletes this BackoffTimer instance within the callback
22
+ * it must signal it be setting `stop` to true.
23
+ */
24
+ virtual void OnTimer(
25
+ BackoffTimerHandleInterface* backoffTimer, uint64_t& baseTimeoutMs, bool& stop) = 0;
26
+ };
27
+
28
+ public:
29
+ enum class BackoffAlgorithm : uint8_t
30
+ {
31
+ // The base duration will be used for any restart.
32
+ FIXED,
33
+ // An exponential backoff is used for restarts, with a 2x multiplier,
34
+ // meaning that every restart will use a duration that is twice as long as
35
+ // the previous.
36
+ EXPONENTIAL,
37
+ };
38
+
39
+ public:
40
+ struct BackoffTimerHandleOptions
41
+ {
42
+ /**
43
+ * Listener on which OnTimer() callback will be invoked.
44
+ */
45
+ BackoffTimerHandleInterface::Listener* listener;
46
+ /**
47
+ * Base timeout duration (ms).
48
+ */
49
+ uint64_t baseTimeoutMs;
50
+ /**
51
+ * Backoff algorithm.
52
+ */
53
+ BackoffAlgorithm backoffAlgorithm;
54
+ /**
55
+ * Maximum duration of the backoff timeout (ms). If no value is given, no
56
+ * limit is set.
57
+ */
58
+ std::optional<uint64_t> maxBackoffTimeoutMs;
59
+ /**
60
+ * Maximum number of restarts. If no value is given, it will restart
61
+ * forever until stopped.
62
+ */
63
+ std::optional<size_t> maxRestarts;
64
+ };
65
+
66
+ public:
67
+ static constexpr uint64_t MaxTimeoutMs{ std::numeric_limits<uint64_t>::max() / 2 };
68
+
69
+ public:
70
+ BackoffTimerHandleInterface() = default;
71
+
72
+ BackoffTimerHandleInterface& operator=(const BackoffTimerHandleInterface&) = delete;
73
+
74
+ BackoffTimerHandleInterface(const BackoffTimerHandleInterface&) = delete;
75
+
76
+ virtual ~BackoffTimerHandleInterface() = default;
77
+
78
+ public:
79
+ /**
80
+ * Start the BackoffTimer (if it's stopped) or restart it (if already
81
+ * running). It will reset the timeout count.
82
+ */
83
+ virtual void Start() = 0;
84
+
85
+ /**
86
+ * Stop the BackoffTimer. It will reset the timeout count.
87
+ */
88
+ virtual void Stop() = 0;
89
+
90
+ /**
91
+ * Set the base timeout duration. It will be applied after the next timeout
92
+ * and effective duration can be larger if backoff algorithm is exponential.
93
+ */
94
+ virtual void SetBaseTimeoutMs(uint64_t baseTimeoutMs) = 0;
95
+
96
+ /**
97
+ * Whether the BackoffTimer is running. Useful to check if this BackoffTimer
98
+ * will timeout again within the OnTimer() callback.
99
+ */
100
+ virtual bool IsRunning() const = 0;
101
+
102
+ /**
103
+ * Maximum number of restarts.
104
+ *
105
+ * @remarks
106
+ * - If `maxRestarts` was not given in the constructor, this method returns 0.
107
+ */
108
+ virtual std::optional<size_t> GetMaxRestarts() const = 0;
109
+
110
+ /**
111
+ * Number of times the timer has expired.
112
+ */
113
+ virtual size_t GetExpirationCount() const = 0;
114
+ };
115
+
116
+ #endif
@@ -2,40 +2,56 @@
2
2
  #define MS_TIMER_HANDLE_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "handles/TimerHandleInterface.hpp"
5
6
  #include <uv.h>
6
7
 
7
- class TimerHandle
8
+ // Forward declaration.
9
+ class Shared;
10
+ class BackoffTimerHandle;
11
+ // TODO: Temporal until we have MockBackoffTimerHandle.
12
+ namespace mocks
8
13
  {
9
- public:
10
- class Listener
11
- {
12
- public:
13
- virtual ~Listener() = default;
14
+ class MockShared;
15
+ }
14
16
 
15
- public:
16
- virtual void OnTimer(TimerHandle* timer) = 0;
17
- };
17
+ class TimerHandle : public TimerHandleInterface
18
+ {
19
+ // Only Shared and BackoffTimerHandle classes can invoke the constructor.
20
+ friend class Shared;
21
+ friend class BackoffTimerHandle;
22
+ // TODO: Temporal until we have MockBackoffTimerHandle.
23
+ friend class mocks::MockShared;
24
+
25
+ private:
26
+ explicit TimerHandle(TimerHandleInterface::Listener* listener);
18
27
 
19
28
  public:
20
- explicit TimerHandle(Listener* listener);
21
29
  TimerHandle& operator=(const TimerHandle&) = delete;
22
- TimerHandle(const TimerHandle&) = delete;
23
- ~TimerHandle();
30
+
31
+ TimerHandle(const TimerHandle&) = delete;
32
+
33
+ ~TimerHandle() override;
24
34
 
25
35
  public:
26
- void Start(uint64_t timeout, uint64_t repeat = 0);
27
- void Stop();
28
- void Restart();
29
- void Restart(uint64_t timeout, uint64_t repeat = 0);
30
- uint64_t GetTimeout() const
36
+ void Start(uint64_t timeout, uint64_t repeat = 0) override;
37
+
38
+ void Stop() override;
39
+
40
+ void Restart() override;
41
+
42
+ void Restart(uint64_t timeout, uint64_t repeat = 0) override;
43
+
44
+ uint64_t GetTimeout() const override
31
45
  {
32
46
  return this->timeout;
33
47
  }
34
- uint64_t GetRepeat() const
48
+
49
+ uint64_t GetRepeat() const override
35
50
  {
36
51
  return this->repeat;
37
52
  }
38
- bool IsActive() const
53
+
54
+ bool IsActive() const override
39
55
  {
40
56
  return uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0;
41
57
  }
@@ -49,7 +65,7 @@ public:
49
65
 
50
66
  private:
51
67
  // Passed by argument.
52
- Listener* listener{ nullptr };
68
+ TimerHandleInterface::Listener* listener{ nullptr };
53
69
  // Allocated by this.
54
70
  uv_timer_t* uvHandle{ nullptr };
55
71
  // Others.
@@ -0,0 +1,43 @@
1
+ #ifndef MS_TIMER_HANDLE_INTERFACE_HPP
2
+ #define MS_TIMER_HANDLE_INTERFACE_HPP
3
+
4
+ #include "common.hpp"
5
+
6
+ class TimerHandleInterface
7
+ {
8
+ public:
9
+ class Listener
10
+ {
11
+ public:
12
+ virtual ~Listener() = default;
13
+
14
+ public:
15
+ virtual void OnTimer(TimerHandleInterface* timer) = 0;
16
+ };
17
+
18
+ public:
19
+ TimerHandleInterface() = default;
20
+
21
+ TimerHandleInterface& operator=(const TimerHandleInterface&) = delete;
22
+
23
+ TimerHandleInterface(const TimerHandleInterface&) = delete;
24
+
25
+ virtual ~TimerHandleInterface() = default;
26
+
27
+ public:
28
+ virtual void Start(uint64_t timeout, uint64_t repeat = 0) = 0;
29
+
30
+ virtual void Stop() = 0;
31
+
32
+ virtual void Restart() = 0;
33
+
34
+ virtual void Restart(uint64_t timeout, uint64_t repeat = 0) = 0;
35
+
36
+ virtual uint64_t GetTimeout() const = 0;
37
+
38
+ virtual uint64_t GetRepeat() const = 0;
39
+
40
+ virtual bool IsActive() const = 0;
41
+ };
42
+
43
+ #endif
@@ -33,6 +33,13 @@ if get_option('ms_build_tests')
33
33
  ]
34
34
  endif
35
35
 
36
+ if get_option('ms_build_fuzzer')
37
+ cpp_args += [
38
+ '-DMS_FUZZER',
39
+ '-DMS_LOG_STD'
40
+ ]
41
+ endif
42
+
36
43
  if get_option('ms_log_trace')
37
44
  cpp_args += [
38
45
  '-DMS_LOG_TRACE',
@@ -86,8 +93,8 @@ common_sources = [
86
93
  'src/Logger.cpp',
87
94
  'src/MediaSoupErrors.cpp',
88
95
  'src/Settings.cpp',
96
+ 'src/Shared.cpp',
89
97
  'src/Worker.cpp',
90
- 'src/ChannelMessageRegistrator.cpp',
91
98
  'src/Utils/BitStream.cpp',
92
99
  'src/Utils/Crypto.cpp',
93
100
  'src/Utils/File.cpp',
@@ -102,6 +109,7 @@ common_sources = [
102
109
  'src/handles/UnixStreamSocketHandle.cpp',
103
110
  'src/Channel/ChannelNotifier.cpp',
104
111
  'src/Channel/ChannelRequest.cpp',
112
+ 'src/Channel/ChannelMessageRegistrator.cpp',
105
113
  'src/Channel/ChannelNotification.cpp',
106
114
  'src/Channel/ChannelSocket.cpp',
107
115
  'src/RTC/ActiveSpeakerObserver.cpp',
@@ -129,7 +137,6 @@ common_sources = [
129
137
  'src/RTC/SenderBandwidthEstimator.cpp',
130
138
  'src/RTC/SeqManager.cpp',
131
139
  'src/RTC/Serializable.cpp',
132
- 'src/RTC/Shared.cpp',
133
140
  'src/RTC/SimpleConsumer.cpp',
134
141
  'src/RTC/SimulcastConsumer.cpp',
135
142
  'src/RTC/SrtpSession.cpp',
@@ -208,7 +215,9 @@ common_sources = [
208
215
  'src/RTC/SCTP/association/StreamResetHandler.cpp',
209
216
  'src/RTC/SCTP/association/TransmissionControlBlock.cpp',
210
217
  'src/RTC/SCTP/tx/RetransmissionErrorCounter.cpp',
218
+ 'src/RTC/SCTP/tx/RetransmissionQueue.cpp',
211
219
  'src/RTC/SCTP/tx/RetransmissionTimeout.cpp',
220
+ 'src/RTC/SCTP/tx/OutstandingData.cpp',
212
221
  'src/RTC/SCTP/packet/Packet.cpp',
213
222
  'src/RTC/SCTP/packet/TLV.cpp',
214
223
  'src/RTC/SCTP/packet/UserData.cpp',
@@ -485,6 +494,7 @@ test_sources = [
485
494
  'test/src/RTC/SCTP/common/TestUnwrappedSequenceNumber.cpp',
486
495
  'test/src/RTC/SCTP/tx/TestRetransmissionErrorCounter.cpp',
487
496
  'test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp',
497
+ 'test/src/RTC/SCTP/tx/TestOutstandingData.cpp',
488
498
  'test/src/RTC/SCTP/packet/TestPacket.cpp',
489
499
  'test/src/RTC/SCTP/packet/TestChunk.cpp',
490
500
  'test/src/RTC/SCTP/packet/TestParameter.cpp',
@@ -545,6 +555,8 @@ test_sources = [
545
555
  'test/src/Utils/TestNumber.cpp',
546
556
  'test/src/Utils/TestString.cpp',
547
557
  'test/src/Utils/TestTime.cpp',
558
+ 'mocks/src/MockShared.cpp',
559
+ 'mocks/src/Channel/MockChannelMessageRegistrator.cpp',
548
560
  ]
549
561
 
550
562
  mediasoup_worker_test = executable(
@@ -557,6 +569,7 @@ mediasoup_worker_test = executable(
557
569
  include_directories: include_directories(
558
570
  'include',
559
571
  'test/include',
572
+ 'mocks/include',
560
573
  ),
561
574
  cpp_args: cpp_args,
562
575
  )
@@ -577,6 +590,7 @@ mediasoup_worker_test_asan_address = executable(
577
590
  include_directories: include_directories(
578
591
  'include',
579
592
  'test/include',
593
+ 'mocks/include',
580
594
  ),
581
595
  cpp_args: cpp_args + [
582
596
  '-g',
@@ -605,6 +619,7 @@ mediasoup_worker_test_asan_undefined = executable(
605
619
  include_directories: include_directories(
606
620
  'include',
607
621
  'test/include',
622
+ 'mocks/include',
608
623
  ),
609
624
  cpp_args: cpp_args + [
610
625
  '-g',
@@ -665,7 +680,9 @@ fuzzer_sources = common_sources + [
665
680
  'fuzzer/src/RTC/RTCP/FuzzerSenderReport.cpp',
666
681
  'fuzzer/src/RTC/RTCP/FuzzerXr.cpp',
667
682
  'fuzzer/src/RTC/SCTP/association/FuzzerStateCookie.cpp',
668
- 'fuzzer/src/RTC/SCTP/packet/FuzzerPacket.cpp'
683
+ 'fuzzer/src/RTC/SCTP/packet/FuzzerPacket.cpp',
684
+ 'mocks/src/MockShared.cpp',
685
+ 'mocks/src/Channel/MockChannelMessageRegistrator.cpp',
669
686
  ]
670
687
 
671
688
  executable(
@@ -678,9 +695,9 @@ executable(
678
695
  include_directories: include_directories(
679
696
  'include',
680
697
  'fuzzer/include',
698
+ 'mocks/include',
681
699
  ),
682
700
  cpp_args: cpp_args + [
683
- '-DMS_LOG_STD',
684
701
  '-g',
685
702
  '-O3',
686
703
  '-fno-omit-frame-pointer',
@@ -1,7 +1,8 @@
1
- option('ms_build_tests', type: 'boolean', value: false, description: 'Whether to build mediasoup worker tests')
2
1
  option('ms_log_trace', type: 'boolean', value: false, description: 'Logs the current method/function if current log level is "debug"')
3
2
  option('ms_log_file_line', type: 'boolean', value: false, description: 'Logging macros print more verbose information, including current file and line')
4
3
  option('ms_rtc_logger_rtp', type: 'boolean', value: false, description: 'Prints a line with information for each processed RTP packet')
5
4
  option('ms_dump_rtp_payload_descriptor', type: 'boolean', value: false, description: 'RTC::RTP::Packet::Dump() method also dumps payload descriptor details')
6
5
  option('ms_dump_rtp_shared_packet_memory_usage', type: 'boolean', value: false, description: 'prints information about total memory allocated by RTC::RTP::SharedPacket instances')
7
6
  option('ms_disable_liburing', type: 'boolean', value: false, description: 'When set to true, disables liburing integration despite current host supports it')
7
+ option('ms_build_tests', type: 'boolean', value: false, description: 'Must be enabled when building mediasoup worker tests')
8
+ option('ms_build_fuzzer', type: 'boolean', value: false, description: 'Must be enabled when building mediasoup worker fuzzer')