mediasoup 3.27.0 → 3.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/node/lib/Consumer.d.ts.map +1 -1
  3. package/node/lib/Consumer.js +4 -51
  4. package/node/lib/Producer.d.ts.map +1 -1
  5. package/node/lib/Producer.js +4 -8
  6. package/node/lib/ProducerTypes.d.ts +4 -2
  7. package/node/lib/ProducerTypes.d.ts.map +1 -1
  8. package/node/lib/Router.d.ts.map +1 -1
  9. package/node/lib/Router.js +4 -0
  10. package/node/lib/Transport.d.ts.map +1 -1
  11. package/node/lib/Transport.js +7 -10
  12. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts +3 -4
  13. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.d.ts.map +1 -1
  14. package/node/lib/fbs/rtp-parameters/rtp-header-extension-uri.js +3 -4
  15. package/node/lib/ortc.d.ts +0 -2
  16. package/node/lib/ortc.d.ts.map +1 -1
  17. package/node/lib/ortc.js +11 -21
  18. package/node/lib/rtpMappingFbsUtils.d.ts +6 -0
  19. package/node/lib/rtpMappingFbsUtils.d.ts.map +1 -0
  20. package/node/lib/rtpMappingFbsUtils.js +65 -0
  21. package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
  22. package/node/lib/rtpParametersFbsUtils.js +0 -6
  23. package/node/lib/rtpParametersTypes.d.ts +1 -1
  24. package/node/lib/rtpParametersTypes.d.ts.map +1 -1
  25. package/node/lib/rtpStreamFbsUtils.d.ts +4 -0
  26. package/node/lib/rtpStreamFbsUtils.d.ts.map +1 -0
  27. package/node/lib/rtpStreamFbsUtils.js +51 -0
  28. package/node/lib/supportedRtpCapabilities.d.ts.map +1 -1
  29. package/node/lib/supportedRtpCapabilities.js +6 -13
  30. package/node/lib/test/test-Consumer.js +1 -13
  31. package/node/lib/test/test-DataConsumer.js +9 -0
  32. package/node/lib/test/test-DataProducer.js +38 -0
  33. package/node/lib/test/test-PipeTransport.js +27 -29
  34. package/node/lib/test/test-Producer.js +97 -0
  35. package/node/lib/test/test-ortc.js +34 -14
  36. package/package.json +10 -10
  37. package/worker/fbs/FBS/meson.build +25 -0
  38. package/worker/fbs/meson.build +15 -18
  39. package/worker/fbs/rtpParameters.fbs +0 -1
  40. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  41. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +16 -2
  42. package/worker/include/DepLibUV.hpp +13 -0
  43. package/worker/include/RTC/BWE/AlrDetector.hpp +97 -0
  44. package/worker/include/RTC/BWE/BitrateProber.hpp +217 -0
  45. package/worker/include/RTC/BWE/BitrateUtils.hpp +39 -0
  46. package/worker/include/RTC/BWE/BweTypes.hpp +171 -3
  47. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +0 -14
  48. package/worker/include/RTC/BWE/InterArrival.hpp +117 -0
  49. package/worker/include/RTC/BWE/IntervalBudget.hpp +81 -0
  50. package/worker/include/RTC/BWE/LossBasedController.hpp +625 -0
  51. package/worker/include/RTC/BWE/OveruseDetector.hpp +71 -0
  52. package/worker/include/RTC/BWE/OveruseEstimator.hpp +115 -0
  53. package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +84 -0
  54. package/worker/include/RTC/BWE/ProbeController.hpp +379 -0
  55. package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +130 -0
  56. package/worker/include/RTC/BWE/ProbingScheduler.hpp +187 -0
  57. package/worker/include/RTC/BWE/RembGenerator.hpp +96 -0
  58. package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +237 -0
  59. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +26 -0
  60. package/worker/include/RTC/BWE/SendPacketHistory.hpp +161 -25
  61. package/worker/include/RTC/BWE/TargetRateController.hpp +306 -0
  62. package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +146 -0
  63. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +73 -16
  64. package/worker/include/RTC/Consts.hpp +70 -0
  65. package/worker/include/RTC/DataConsumer.hpp +3 -5
  66. package/worker/include/RTC/DirectTransport.hpp +4 -5
  67. package/worker/include/RTC/PipeTransport.hpp +4 -5
  68. package/worker/include/RTC/PlainTransport.hpp +4 -5
  69. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +6 -7
  70. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +3 -1
  71. package/worker/include/RTC/RTP/Codecs/Tools.hpp +1 -1
  72. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +0 -1
  73. package/worker/include/RTC/RTP/Packet.hpp +16 -4
  74. package/worker/include/RTC/RTP/ProbationGenerator.hpp +0 -8
  75. package/worker/include/RTC/RTP/RtpStream.hpp +12 -9
  76. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +22 -4
  77. package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -2
  78. package/worker/include/RTC/RTP/RtxStream.hpp +10 -4
  79. package/worker/include/RTC/RateCalculator.hpp +103 -24
  80. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +33 -3
  81. package/worker/include/RTC/{RtcLogger.hpp → RtcLogger/RtpPacket.hpp} +5 -3
  82. package/worker/include/RTC/RtcLogger/SendBurst.hpp +88 -0
  83. package/worker/include/RTC/RtpDictionaries.hpp +3 -4
  84. package/worker/include/RTC/SCTP/association/Association.hpp +1 -1
  85. package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +36 -0
  86. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +0 -1
  87. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +9 -9
  88. package/worker/include/RTC/SCTP/rx/DataTracker.hpp +1 -1
  89. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +11 -1
  90. package/worker/include/RTC/SctpDictionaries.hpp +2 -2
  91. package/worker/include/RTC/TcpConnection.hpp +2 -1
  92. package/worker/include/RTC/Transport.hpp +23 -8
  93. package/worker/include/RTC/TransportTuple.hpp +61 -6
  94. package/worker/include/RTC/WebRtcTransport.hpp +4 -5
  95. package/worker/include/Shared.hpp +5 -0
  96. package/worker/include/SharedInterface.hpp +10 -0
  97. package/worker/include/Utils.hpp +72 -3
  98. package/worker/include/common.hpp +12 -4
  99. package/worker/include/handles/SendCallbacks.hpp +34 -0
  100. package/worker/include/handles/TcpConnectionHandle.hpp +4 -12
  101. package/worker/include/handles/UdpSocketHandle.hpp +4 -8
  102. package/worker/meson.build +45 -1
  103. package/worker/meson_options.txt +1 -0
  104. package/worker/mocks/include/MockShared.hpp +16 -2
  105. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +1 -1
  106. package/worker/scripts/package-lock.json +6 -6
  107. package/worker/src/RTC/BWE/AimdRateControl.cpp +4 -5
  108. package/worker/src/RTC/BWE/AlrDetector.cpp +80 -0
  109. package/worker/src/RTC/BWE/BitrateProber.cpp +256 -0
  110. package/worker/src/RTC/BWE/BitrateUtils.cpp +54 -0
  111. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +2 -2
  112. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +20 -37
  113. package/worker/src/RTC/BWE/InterArrival.cpp +216 -0
  114. package/worker/src/RTC/BWE/IntervalBudget.cpp +93 -0
  115. package/worker/src/RTC/BWE/LossBasedController.cpp +1194 -0
  116. package/worker/src/RTC/BWE/OveruseDetector.cpp +128 -0
  117. package/worker/src/RTC/BWE/OveruseEstimator.cpp +166 -0
  118. package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +222 -0
  119. package/worker/src/RTC/BWE/ProbeController.cpp +645 -0
  120. package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +140 -0
  121. package/worker/src/RTC/BWE/ProbingScheduler.cpp +196 -0
  122. package/worker/src/RTC/BWE/RembGenerator.cpp +169 -0
  123. package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +497 -0
  124. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +47 -0
  125. package/worker/src/RTC/BWE/SendPacketHistory.cpp +173 -50
  126. package/worker/src/RTC/BWE/TargetRateController.cpp +433 -0
  127. package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +377 -0
  128. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +102 -5
  129. package/worker/src/RTC/Consumer.cpp +7 -5
  130. package/worker/src/RTC/DataConsumer.cpp +8 -10
  131. package/worker/src/RTC/DirectTransport.cpp +14 -8
  132. package/worker/src/RTC/DtlsTransport.cpp +8 -8
  133. package/worker/src/RTC/ICE/IceCandidate.cpp +4 -4
  134. package/worker/src/RTC/ICE/IceServer.cpp +1 -1
  135. package/worker/src/RTC/PipeTransport.cpp +13 -8
  136. package/worker/src/RTC/PlainTransport.cpp +13 -8
  137. package/worker/src/RTC/Producer.cpp +14 -31
  138. package/worker/src/RTC/RTCP/Bye.cpp +1 -1
  139. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +18 -0
  140. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +2 -2
  141. package/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +2 -1
  142. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +2 -2
  143. package/worker/src/RTC/RTCP/Sdes.cpp +1 -1
  144. package/worker/src/RTC/RTP/Codecs/DependencyDescriptor.cpp +2 -1
  145. package/worker/src/RTC/RTP/Packet.cpp +26 -11
  146. package/worker/src/RTC/RTP/ProbationGenerator.cpp +5 -6
  147. package/worker/src/RTC/RTP/RtpStream.cpp +1 -1
  148. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +69 -48
  149. package/worker/src/RTC/RTP/RtpStreamSend.cpp +31 -31
  150. package/worker/src/RTC/RTP/RtxStream.cpp +22 -7
  151. package/worker/src/RTC/RateCalculator.cpp +133 -28
  152. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +56 -1
  153. package/worker/src/RTC/{RtcLogger.cpp → RtcLogger/RtpPacket.cpp} +2 -2
  154. package/worker/src/RTC/RtcLogger/SendBurst.cpp +124 -0
  155. package/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +2 -12
  156. package/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +1 -1
  157. package/worker/src/RTC/SCTP/association/Association.cpp +16 -2
  158. package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +106 -1
  159. package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
  160. package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +3 -3
  161. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +2 -1
  162. package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +4 -4
  163. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +4 -4
  164. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +6 -10
  165. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +2 -2
  166. package/worker/src/RTC/SrtpSession.cpp +2 -2
  167. package/worker/src/RTC/SvcProducerStreamManager.cpp +2 -2
  168. package/worker/src/RTC/TcpConnection.cpp +2 -2
  169. package/worker/src/RTC/Transport.cpp +112 -75
  170. package/worker/src/RTC/TransportTuple.cpp +4 -4
  171. package/worker/src/RTC/WebRtcServer.cpp +4 -3
  172. package/worker/src/RTC/WebRtcTransport.cpp +20 -13
  173. package/worker/src/Utils/BitStream.cpp +24 -0
  174. package/worker/src/handles/BackoffTimerHandle.cpp +1 -1
  175. package/worker/src/handles/TcpConnectionHandle.cpp +13 -23
  176. package/worker/src/handles/UdpSocketHandle.cpp +14 -21
  177. package/worker/tasks.py +43 -18
  178. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +68 -14
  179. package/worker/test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp +125 -0
  180. package/worker/test/src/RTC/BWE/TestAlrDetector.cpp +110 -0
  181. package/worker/test/src/RTC/BWE/TestBitrateProber.cpp +418 -0
  182. package/worker/test/src/RTC/BWE/TestBitrateUtils.cpp +61 -0
  183. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +4 -4
  184. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +53 -37
  185. package/worker/test/src/RTC/BWE/TestInterArrival.cpp +643 -0
  186. package/worker/test/src/RTC/BWE/TestIntervalBudget.cpp +130 -0
  187. package/worker/test/src/RTC/BWE/TestLossBasedController.cpp +1199 -0
  188. package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +519 -0
  189. package/worker/test/src/RTC/BWE/TestProbeBitrateEstimator.cpp +266 -0
  190. package/worker/test/src/RTC/BWE/TestProbeController.cpp +1682 -0
  191. package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +265 -0
  192. package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +260 -0
  193. package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +285 -0
  194. package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +414 -0
  195. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +296 -77
  196. package/worker/test/src/RTC/BWE/TestTargetRateController.cpp +337 -0
  197. package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +578 -0
  198. package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +45 -0
  199. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +133 -29
  200. package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +625 -0
  201. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +19 -0
  202. package/worker/test/src/RTC/RTP/TestPacket.cpp +58 -4
  203. package/worker/test/src/RTC/RTP/TestProbationGenerator.cpp +3 -2
  204. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +50 -0
  205. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +59 -0
  206. package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +111 -0
  207. package/worker/test/src/RTC/TestRateCalculator.cpp +322 -60
  208. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +95 -7
  209. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +34 -16
  210. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +31 -13
  211. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +37 -19
  212. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +10 -10
  213. package/worker/test/src/Utils/TestTime.cpp +120 -21
@@ -26,30 +26,76 @@ namespace RTC
26
26
  */
27
27
  class TrendlineEstimator
28
28
  {
29
+ public:
30
+ /**
31
+ * @remarks
32
+ * - Every constraint documented below is checked by the constructor and
33
+ * aborts when it doesn't hold. These options are set from C++ alone,
34
+ * never from the network nor from the API, so breaking one of them is a
35
+ * programming error.
36
+ */
37
+ struct TrendlineEstimatorOptions
38
+ {
39
+ /**
40
+ * Number of samples of the least squares regression window. A shorter
41
+ * window reacts sooner at the cost of being noisier.
42
+ *
43
+ * @remarks
44
+ * - It must be at least 2, since a line cannot be fitted to a single
45
+ * point.
46
+ */
47
+ size_t windowSize{ 20 };
48
+ /**
49
+ * Whether the samples of the window are kept sorted by arrival time.
50
+ * Feedback should already give them in order, so this is a safety net
51
+ * against a source that doesn't.
52
+ */
53
+ bool enableSort{ false };
54
+ /**
55
+ * Whether the slope is capped by the one that the least delayed packets
56
+ * of both ends of the window describe, which keeps a burst of delayed
57
+ * packets in the middle from being read as a growing queue.
58
+ */
59
+ bool enableCap{ false };
60
+ /**
61
+ * How many packets of the beginning of the window that cap looks at.
62
+ *
63
+ * @remarks
64
+ * - While `enableCap` is set it must be at least 1, and the two ends
65
+ * together must fit in `windowSize`, since the cap looks at both of
66
+ * them without them overlapping.
67
+ */
68
+ size_t beginningPackets{ 7 };
69
+ /**
70
+ * How many packets of the end of the window that cap looks at.
71
+ *
72
+ * @remarks
73
+ * - The same constraints as `beginningPackets`.
74
+ */
75
+ size_t endPackets{ 7 };
76
+ /**
77
+ * Slack added to that cap, so that a slope barely above it is not
78
+ * capped.
79
+ */
80
+ double capUncertainty{ 0.0 };
81
+ };
82
+
29
83
  private:
30
84
  struct PacketTiming
31
85
  {
32
86
  double arrivalTimeUs;
33
87
  double smoothedDelayUs;
88
+ /**
89
+ * Accumulated delay before it's smoothed, which is what the slope cap
90
+ * looks at.
91
+ */
92
+ double rawDelayUs;
34
93
  };
35
94
 
36
95
  public:
37
- /**
38
- * Number of samples of the least squares regression window used unless
39
- * another one is given.
40
- */
41
- static constexpr size_t DefaultWindowSize{ 20 };
96
+ TrendlineEstimator();
42
97
 
43
- public:
44
- /**
45
- * @param windowSize - Number of samples of the least squares regression
46
- * window. A shorter window reacts sooner at the cost of being noisier.
47
- *
48
- * @remarks
49
- * - `windowSize` must be at least 2, since a line cannot be fitted to a
50
- * single point.
51
- */
52
- explicit TrendlineEstimator(size_t windowSize = DefaultWindowSize);
98
+ explicit TrendlineEstimator(TrendlineEstimatorOptions options);
53
99
 
54
100
  /**
55
101
  * Feed the deltas between two consecutive groups of packets.
@@ -77,12 +123,23 @@ namespace RTC
77
123
  */
78
124
  std::optional<double> GetLinearFitSlope() const;
79
125
 
126
+ /**
127
+ * Highest slope that the least delayed samples of both ends of the window
128
+ * describe, or no value if they are too close in time to tell.
129
+ *
130
+ * @remarks
131
+ * - A burst of delayed packets in the middle of the window tilts the
132
+ * fitted line even though the queue never grew, and this is what keeps
133
+ * that from being read as overuse.
134
+ */
135
+ std::optional<double> GetSlopeCap() const;
136
+
80
137
  void Detect(double trend, double sendDeltaUs, int64_t arrivalTimeUs);
81
138
 
82
139
  void UpdateThreshold(double modifiedTrend, int64_t arrivalTimeUs);
83
140
 
84
141
  private:
85
- const size_t windowSize;
142
+ const TrendlineEstimatorOptions options;
86
143
  int numOfDeltas{ 0 };
87
144
  std::optional<int64_t> firstArrivalTimeUs;
88
145
  double accumulatedDelayUs{ 0 };
@@ -2,11 +2,39 @@
2
2
  #define MS_RTC_CONSTS_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include <string_view>
5
6
 
6
7
  namespace RTC
7
8
  {
8
9
  namespace Consts
9
10
  {
11
+ /**
12
+ * Bytes an IPv4 header takes, without options.
13
+ */
14
+ constexpr size_t Ipv4HeaderSize{ 20 };
15
+
16
+ /**
17
+ * Bytes an IPv6 header takes, without extension headers.
18
+ */
19
+ constexpr size_t Ipv6HeaderSize{ 40 };
20
+
21
+ /**
22
+ * Bytes a UDP header takes.
23
+ */
24
+ constexpr size_t UdpHeaderSize{ 8 };
25
+
26
+ /**
27
+ * Bytes a TCP header takes, without options.
28
+ */
29
+ constexpr size_t TcpHeaderSize{ 20 };
30
+
31
+ /**
32
+ * Bytes of the length field that frames every packet sent over TCP.
33
+ *
34
+ * @see https://datatracker.ietf.org/doc/html/rfc4571
35
+ */
36
+ constexpr size_t TcpFramingSize{ 2 };
37
+
10
38
  /**
11
39
  * Max MTU size.
12
40
  */
@@ -39,6 +67,48 @@ namespace RTC
39
67
  */
40
68
  constexpr uint8_t MidRtpExtensionMaxLength{ 8 };
41
69
 
70
+ /**
71
+ * SSRC of the RTP stream the probing packets are sent on.
72
+ *
73
+ * @remarks
74
+ * - The receiver negotiates a stream with this very SSRC, so it cannot be
75
+ * changed without changing the client as well.
76
+ */
77
+ constexpr uint32_t BweProbeRtpSsrc{ 1234 };
78
+
79
+ /**
80
+ * Codec payload type of the RTP stream the probing packets are sent on.
81
+ *
82
+ * @remarks
83
+ * - The receiver negotiates a stream with this very payload type, so it
84
+ * cannot be changed without changing the client as well.
85
+ */
86
+ constexpr uint8_t BweProbeRtpPayloadType{ 127 };
87
+
88
+ /**
89
+ * MID of the RTP stream the probing packets are sent on, which is how the
90
+ * receiver tells it apart.
91
+ *
92
+ * @remarks
93
+ * - The receiver negotiates a stream with this very MID, so it cannot be
94
+ * changed without changing the client as well.
95
+ */
96
+ constexpr std::string_view BweProbeRtpMid{ "probator" };
97
+
98
+ static_assert(
99
+ BweProbeRtpMid.size() <= MidRtpExtensionMaxLength,
100
+ "the MID of the probing stream does not fit in a MID RTP header extension");
101
+
102
+ /**
103
+ * Lowest bitrate the bandwidth estimation ever produces (bps), so 5 kbps.
104
+ */
105
+ constexpr int64_t BweMinBitrate{ 5000 };
106
+
107
+ /**
108
+ * Highest bitrate the bandwidth estimation ever deals in (bps), so 1 Gbps.
109
+ */
110
+ constexpr int64_t BweMaxBitrate{ 1000000000 };
111
+
42
112
  /**
43
113
  * Largest safe SCTP packet. Starting from the minimum guaranteed MTU value
44
114
  * of 1280 for IPv6 (which may not support fragmentation), take off 85
@@ -4,6 +4,7 @@
4
4
  #include "common.hpp"
5
5
  #include "Channel/ChannelRequest.hpp"
6
6
  #include "Channel/ChannelSocket.hpp"
7
+ #include "handles/SendCallbacks.hpp"
7
8
  #include "RTC/SCTP/public/Message.hpp"
8
9
  #include "RTC/SctpDictionaries.hpp"
9
10
  #include "SharedInterface.hpp"
@@ -14,9 +15,6 @@ namespace RTC
14
15
  {
15
16
  class DataConsumer : public Channel::ChannelSocket::RequestHandler
16
17
  {
17
- protected:
18
- using onQueuedCallback = const std::function<void(bool queued, bool sctpSendBufferFull)>;
19
-
20
18
  public:
21
19
  class Listener
22
20
  {
@@ -25,7 +23,7 @@ namespace RTC
25
23
 
26
24
  public:
27
25
  virtual void OnDataConsumerSendMessage(
28
- RTC::DataConsumer* dataConsumer, RTC::SCTP::Message message, onQueuedCallback* cb) = 0;
26
+ RTC::DataConsumer* dataConsumer, RTC::SCTP::Message message, onMessageQueuedCallback cb) = 0;
29
27
  virtual void OnDataConsumerNeedBufferedAmount(
30
28
  const RTC::DataConsumer* dataConsumer, uint32_t& bufferedAmount) const = 0;
31
29
  virtual void OnDataConsumerNeedBufferedAmountLowThreshold(
@@ -110,7 +108,7 @@ namespace RTC
110
108
  std::vector<uint16_t>& subchannels,
111
109
  std::optional<uint16_t> requiredSubchannel,
112
110
  std::optional<uint16_t> ignoredSubchannel,
113
- const onQueuedCallback* cb = nullptr);
111
+ onMessageQueuedCallback cb = {});
114
112
 
115
113
  /* Methods inherited from Channel::ChannelSocket::RequestHandler. */
116
114
  public:
@@ -1,6 +1,7 @@
1
1
  #ifndef MS_RTC_DIRECT_TRANSPORT_HPP
2
2
  #define MS_RTC_DIRECT_TRANSPORT_HPP
3
3
 
4
+ #include "handles/SendCallbacks.hpp"
4
5
  #include "RTC/Transport.hpp"
5
6
  #include "SharedInterface.hpp"
6
7
 
@@ -24,16 +25,14 @@ namespace RTC
24
25
 
25
26
  private:
26
27
  bool IsConnected() const override;
27
- void SendRtpPacket(
28
- RTC::Consumer* consumer,
29
- RTC::RTP::Packet* packet,
30
- RTC::Transport::onSendCallback* cb = nullptr) override;
28
+ size_t GetPacketOverhead() const override;
29
+ void SendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet, onSendCallback cb = {}) override;
31
30
  void SendRtcpPacket(RTC::RTCP::Packet* packet) override;
32
31
  void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet) override;
33
32
  void SendMessage(
34
33
  RTC::DataConsumer* dataConsumer,
35
34
  RTC::SCTP::Message message,
36
- onQueuedCallback* cb = nullptr) override;
35
+ onMessageQueuedCallback cb = {}) override;
37
36
  bool SendData(const uint8_t* data, size_t len) override;
38
37
  void RecvStreamClosed(uint32_t ssrc) override;
39
38
  void SendStreamClosed(uint32_t ssrc) override;
@@ -2,6 +2,7 @@
2
2
  #define MS_RTC_PIPE_TRANSPORT_HPP
3
3
 
4
4
  #include "FBS/pipeTransport.h"
5
+ #include "handles/SendCallbacks.hpp"
5
6
  #include "RTC/SrtpSession.hpp"
6
7
  #include "RTC/Transport.hpp"
7
8
  #include "RTC/TransportTuple.hpp"
@@ -45,17 +46,15 @@ namespace RTC
45
46
  {
46
47
  return true;
47
48
  }
49
+ size_t GetPacketOverhead() const override;
48
50
  bool HasSrtp() const;
49
- void SendRtpPacket(
50
- RTC::Consumer* consumer,
51
- RTC::RTP::Packet* packet,
52
- RTC::Transport::onSendCallback* cb = nullptr) override;
51
+ void SendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet, onSendCallback cb = {}) override;
53
52
  void SendRtcpPacket(RTC::RTCP::Packet* packet) override;
54
53
  void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet) override;
55
54
  void SendMessage(
56
55
  RTC::DataConsumer* dataConsumer,
57
56
  RTC::SCTP::Message message,
58
- onQueuedCallback* cb = nullptr) override;
57
+ onMessageQueuedCallback cb = {}) override;
59
58
  bool SendData(const uint8_t* data, size_t len) override;
60
59
  void RecvStreamClosed(uint32_t ssrc) override;
61
60
  void SendStreamClosed(uint32_t ssrc) override;
@@ -2,6 +2,7 @@
2
2
  #define MS_RTC_PLAIN_TRANSPORT_HPP
3
3
 
4
4
  #include "FBS/plainTransport.h"
5
+ #include "handles/SendCallbacks.hpp"
5
6
  #include "RTC/SrtpSession.hpp"
6
7
  #include "RTC/Transport.hpp"
7
8
  #include "RTC/TransportTuple.hpp"
@@ -33,18 +34,16 @@ namespace RTC
33
34
 
34
35
  private:
35
36
  bool IsConnected() const override;
37
+ size_t GetPacketOverhead() const override;
36
38
  bool HasSrtp() const;
37
39
  bool IsSrtpReady() const;
38
- void SendRtpPacket(
39
- RTC::Consumer* consumer,
40
- RTC::RTP::Packet* packet,
41
- RTC::Transport::onSendCallback* cb = nullptr) override;
40
+ void SendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet, onSendCallback cb = {}) override;
42
41
  void SendRtcpPacket(RTC::RTCP::Packet* packet) override;
43
42
  void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet) override;
44
43
  void SendMessage(
45
44
  RTC::DataConsumer* dataConsumer,
46
45
  RTC::SCTP::Message message,
47
- onQueuedCallback* cb = nullptr) override;
46
+ onMessageQueuedCallback cb = {}) override;
48
47
  bool SendData(const uint8_t* data, size_t len) override;
49
48
  void RecvStreamClosed(uint32_t ssrc) override;
50
49
  void SendStreamClosed(uint32_t ssrc) override;
@@ -33,8 +33,10 @@ namespace RTC
33
33
  {
34
34
  public:
35
35
  // 'R' 'E' 'M' 'B'.
36
- static const uint32_t UniqueIdentifier{ 0x52454D42 };
37
- static const size_t UniqueIdentifierSize{ 4 };
36
+ static constexpr uint32_t UniqueIdentifier{ 0x52454D42 };
37
+ static constexpr size_t UniqueIdentifierSize{ 4 };
38
+ // Most SSRCs that fit, since the field that counts them is a single byte.
39
+ static constexpr size_t MaxNumberOfSsrcs{ 0xFF };
38
40
 
39
41
  public:
40
42
  static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len);
@@ -56,15 +58,12 @@ namespace RTC
56
58
  {
57
59
  this->bitrate = bitrate;
58
60
  }
59
- void SetSsrcs(const std::vector<uint32_t>& ssrcs)
60
- {
61
- this->ssrcs = ssrcs;
62
- }
61
+ void SetSsrcs(const std::vector<uint32_t>& ssrcs);
63
62
  int64_t GetBitrate() const
64
63
  {
65
64
  return this->bitrate;
66
65
  }
67
- const std::vector<uint32_t>& GetSsrcs()
66
+ const std::vector<uint32_t>& GetSsrcs() const
68
67
  {
69
68
  return this->ssrcs;
70
69
  }
@@ -3,6 +3,8 @@
3
3
 
4
4
  #include "common.hpp"
5
5
  #include "RTC/RTCP/Feedback.hpp"
6
+ #include "Utils.hpp"
7
+ #include <cstdlib> // std::abs()
6
8
  #include <vector>
7
9
 
8
10
  /* RTP extensions for Transport-wide Congestion Control
@@ -324,7 +326,7 @@ namespace RTC
324
326
  size += this->deltasAndChunksSize;
325
327
 
326
328
  // 32 bits padding.
327
- size += (-size) & 3;
329
+ size = Utils::Byte::PadTo4Bytes(size);
328
330
 
329
331
  return size;
330
332
  }
@@ -186,7 +186,7 @@ namespace RTC
186
186
  return true;
187
187
  }
188
188
 
189
- NO_DEFAULT_GCC();
189
+ NO_DEFAULT();
190
190
  }
191
191
  }
192
192
 
@@ -20,7 +20,6 @@ namespace RTC
20
20
  uint8_t ssrcAudioLevel{ 0 };
21
21
  uint8_t dependencyDescriptor{ 0 };
22
22
  uint8_t videoOrientation{ 0 };
23
- uint8_t timeOffset{ 0 };
24
23
  uint8_t absCaptureTime{ 0 };
25
24
  uint8_t playoutDelay{ 0 };
26
25
  uint8_t mediasoupPacketId{ 0 };
@@ -10,7 +10,7 @@
10
10
  #include "RTC/Serializable.hpp"
11
11
  #include "Utils.hpp"
12
12
  #ifdef MS_RTC_LOGGER_RTP
13
- #include "RTC/RtcLogger.hpp"
13
+ #include "RTC/RtcLogger/RtpPacket.hpp"
14
14
  #endif
15
15
  #include <flatbuffers/flatbuffers.h>
16
16
  #include <array>
@@ -527,10 +527,11 @@ namespace RTC
527
527
 
528
528
  /**
529
529
  * @remarks
530
- * - `sentAtUs` is converted internally to the 3 bytes ABS Send Time format,
531
- * unlike `ReadAbsSendTime()`, which exposes the raw extension value.
530
+ * - `absSendTime` is the raw 3 bytes unsigned integer the extension
531
+ * carries, the same one `ReadAbsSendTime()` gives back. An instant is
532
+ * turned into it with `Utils::Time::TimeUsToAbsSendTime()`.
532
533
  */
533
- bool UpdateAbsSendTime(int64_t sentAtUs) const;
534
+ bool UpdateAbsSendTime(uint32_t absSendTime) const;
534
535
 
535
536
  bool ReadTransportWideCc01(uint16_t& wideSeqNumber) const;
536
537
 
@@ -549,6 +550,17 @@ namespace RTC
549
550
 
550
551
  bool ReadAbsCaptureTime(uint64_t& absCaptureTimestamp, int64_t& estimatedCaptureClockOffset) const;
551
552
 
553
+ /**
554
+ * @remarks
555
+ * - `absCaptureTimestamp` is the raw 8 bytes unsigned integer the extension
556
+ * carries, the same one `ReadAbsCaptureTime()` gives back, which is a
557
+ * capture instant in NTP format. An instant is turned into it with
558
+ * `Utils::Time::TimeUsToNtp()`.
559
+ * - The estimated capture clock offset the extension carries when it is 16
560
+ * bytes long is left untouched.
561
+ */
562
+ bool UpdateAbsCaptureTime(uint64_t absCaptureTimestamp) const;
563
+
552
564
  bool ReadPlayoutDelay(uint16_t& minDelay, uint16_t& maxDelay) const;
553
565
 
554
566
  bool ReadMediasoupPacketId(uint32_t& mediasoupPacketId) const;
@@ -15,14 +15,6 @@ namespace RTC
15
15
  * Maximum length of a probation RTP packet.
16
16
  */
17
17
  static constexpr size_t ProbationPacketMaxLength{ 1400 };
18
- /**
19
- * SSRC of the probation RTP stream.
20
- */
21
- static const uint32_t Ssrc{ 1234 };
22
- /**
23
- * Codec payload type of the probation RTP stream.
24
- */
25
- static const uint8_t PayloadType{ 127 };
26
18
 
27
19
  public:
28
20
  explicit ProbationGenerator();
@@ -259,17 +259,20 @@ namespace RTC
259
259
  // Jitter in RTP timestamp units. As per spec it's kept as floating value
260
260
  // although it's exposed as integer in the stats.
261
261
  float jitter{ 0 };
262
- size_t packetsDiscarded{ 0 };
263
- size_t packetsRetransmitted{ 0 };
264
- size_t packetsRepaired{ 0 };
265
- size_t nackCount{ 0 };
266
- size_t nackPacketCount{ 0 };
267
- size_t pliCount{ 0 };
268
- size_t firCount{ 0 };
262
+ // NOTE: These counters are never reset and nothing bounds them, so they are
263
+ // as wide as the stats fields they end up in rather than as wide as a
264
+ // pointer.
265
+ uint64_t packetsDiscarded{ 0 };
266
+ uint64_t packetsRetransmitted{ 0 };
267
+ uint64_t packetsRepaired{ 0 };
268
+ uint64_t nackCount{ 0 };
269
+ uint64_t nackPacketCount{ 0 };
270
+ uint64_t pliCount{ 0 };
271
+ uint64_t firCount{ 0 };
269
272
  // Packets repaired at last interval for score calculation.
270
- size_t repairedPriorScore{ 0 };
273
+ uint64_t repairedPriorScore{ 0 };
271
274
  // Packets retransmitted at last interval for score calculation.
272
- size_t retransmittedPriorScore{ 0 };
275
+ uint64_t retransmittedPriorScore{ 0 };
273
276
  // Correspondence between wall clock and RTP timeline given by the last Sender
274
277
  // Report.
275
278
  std::optional<RTP::RtpStream::SenderReportMapping> lastSenderReportMapping;
@@ -77,9 +77,9 @@ namespace RTC
77
77
 
78
78
  int64_t GetLayerBitrate(int64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer);
79
79
 
80
- size_t GetPacketCount() const;
80
+ uint64_t GetPacketCount() const;
81
81
 
82
- size_t GetBytes() const;
82
+ uint64_t GetBytes() const;
83
83
 
84
84
  private:
85
85
  std::vector<std::vector<RTC::RtpDataCounter>> spatialLayerCounters;
@@ -227,6 +227,20 @@ namespace RTC
227
227
  */
228
228
  std::optional<int64_t> GetRemoteCaptureAtUsFromAbsCaptureTime(uint32_t ts) const;
229
229
 
230
+ /**
231
+ * Whether the 'abs-capture-time' RTP header extension has ever been received
232
+ * on this stream.
233
+ *
234
+ * @remarks
235
+ * - It is not the same as being able to tell a capture instant from it, which
236
+ * also depends on how far the wanted RTP timestamp falls from the one it
237
+ * referred to.
238
+ */
239
+ bool HasAbsCaptureTime() const
240
+ {
241
+ return this->lastAbsCaptureTime.has_value();
242
+ }
243
+
230
244
  /**
231
245
  * Capture instant of the given RTP timestamp, expressed in the remote sender's
232
246
  * wall clock, interpolated from the last received RTCP Sender Report.
@@ -306,13 +320,17 @@ namespace RTC
306
320
  bool useRtpInactivityCheck{ false };
307
321
  // Others.
308
322
  // Packets expected at last interval.
323
+ // NOTE: As wide as GetExpectedPackets(), which wraps with the sequence
324
+ // number, so that the difference against it is taken in its own width.
309
325
  uint32_t expectedPrior{ 0 };
310
326
  // Packets expected at last interval for score calculation.
311
327
  uint32_t expectedPriorScore{ 0 };
312
328
  // Packets received at last interval.
313
- uint32_t receivedPrior{ 0 };
329
+ // NOTE: As wide as the counter it snapshots, which does not wrap, so that
330
+ // the difference against it stays exact however long the stream runs.
331
+ uint64_t receivedPrior{ 0 };
314
332
  // Packets received at last interval for score calculation.
315
- uint32_t receivedPriorScore{ 0 };
333
+ uint64_t receivedPriorScore{ 0 };
316
334
  // Timing data of the most recent Sender Report received.
317
335
  std::optional<SenderReportTiming> lastSenderReportTiming;
318
336
  // Most recent `abs-capture-time` RTP header extension received.
@@ -109,7 +109,7 @@ namespace RTC
109
109
 
110
110
  int64_t GetBitrate(int64_t nowMs) override
111
111
  {
112
- return this->transmissionCounter.GetBitrate(nowMs);
112
+ return this->transmissionCounter.GetBitrate(nowMs).value_or(0);
113
113
  }
114
114
 
115
115
  int64_t GetBitrate(int64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override;
@@ -131,7 +131,9 @@ namespace RTC
131
131
  // Packets lost at last interval for score calculation.
132
132
  int32_t lostPriorScore{ 0 };
133
133
  // Packets sent at last interval for score calculation.
134
- uint32_t sentPriorScore{ 0 };
134
+ // NOTE: As wide as the counter it snapshots, which does not wrap, so that
135
+ // the difference against it stays exact however long the stream runs.
136
+ uint64_t sentPriorScore{ 0 };
135
137
  std::string mid;
136
138
  uint16_t rtxSeq{ 0 };
137
139
  RTC::RtpDataCounter transmissionCounter;
@@ -96,7 +96,7 @@ namespace RTC
96
96
  return static_cast<float>(this->fractionLost) * 100 / 256;
97
97
  }
98
98
 
99
- size_t GetPacketsDiscarded() const
99
+ uint64_t GetPacketsDiscarded() const
100
100
  {
101
101
  return this->packetsDiscarded;
102
102
  }
@@ -131,15 +131,21 @@ namespace RTC
131
131
  uint32_t maxPacketTs{ 0 }; // Highest timestamp seen.
132
132
  int32_t packetsLost{ 0 };
133
133
  uint8_t fractionLost{ 0 };
134
- size_t packetsDiscarded{ 0 };
135
- size_t packetsCount{ 0 };
134
+ // NOTE: These counters are never reset and nothing bounds them, so they are
135
+ // as wide as the stats fields they end up in rather than as wide as a
136
+ // pointer.
137
+ uint64_t packetsDiscarded{ 0 };
138
+ uint64_t packetsCount{ 0 };
136
139
 
137
140
  private:
138
141
  // Whether at least a RTP packet has been received.
139
142
  bool started{ false };
140
143
  // Fields for generating Receiver Reports.
144
+ // NOTE: Each one is as wide as the counter it snapshots, so that the
145
+ // expected one follows the wrap of the sequence number while the received
146
+ // one, which does not wrap, stays exact however long the stream runs.
141
147
  uint32_t expectedPrior{ 0 };
142
- uint32_t receivedPrior{ 0 };
148
+ uint64_t receivedPrior{ 0 };
143
149
  // Timing data of the most recent Sender Report received.
144
150
  std::optional<SenderReportTiming> lastSenderReportTiming;
145
151
  int32_t reportedPacketsLost{ 0 };