mediasoup 3.27.1 → 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 (203) hide show
  1. package/CHANGELOG.md +14 -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/rtpParameters.fbs +0 -1
  38. package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
  39. package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +16 -2
  40. package/worker/include/DepLibUV.hpp +13 -0
  41. package/worker/include/RTC/BWE/AlrDetector.hpp +97 -0
  42. package/worker/include/RTC/BWE/BitrateProber.hpp +217 -0
  43. package/worker/include/RTC/BWE/{Utils.hpp → BitrateUtils.hpp} +3 -3
  44. package/worker/include/RTC/BWE/BweTypes.hpp +170 -2
  45. package/worker/include/RTC/BWE/FeedbackAdapter.hpp +0 -14
  46. package/worker/include/RTC/BWE/InterArrival.hpp +117 -0
  47. package/worker/include/RTC/BWE/IntervalBudget.hpp +81 -0
  48. package/worker/include/RTC/BWE/LossBasedController.hpp +105 -0
  49. package/worker/include/RTC/BWE/OveruseDetector.hpp +71 -0
  50. package/worker/include/RTC/BWE/OveruseEstimator.hpp +115 -0
  51. package/worker/include/RTC/BWE/ProbeBitrateEstimator.hpp +84 -0
  52. package/worker/include/RTC/BWE/ProbeController.hpp +379 -0
  53. package/worker/include/RTC/BWE/ProbePacketGenerator.hpp +130 -0
  54. package/worker/include/RTC/BWE/ProbingScheduler.hpp +187 -0
  55. package/worker/include/RTC/BWE/RembGenerator.hpp +96 -0
  56. package/worker/include/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.hpp +237 -0
  57. package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +26 -0
  58. package/worker/include/RTC/BWE/SendPacketHistory.hpp +161 -25
  59. package/worker/include/RTC/BWE/TransportWideCcFeedbackGenerator.hpp +146 -0
  60. package/worker/include/RTC/BWE/TrendlineEstimator.hpp +15 -0
  61. package/worker/include/RTC/Consts.hpp +70 -0
  62. package/worker/include/RTC/DataConsumer.hpp +3 -5
  63. package/worker/include/RTC/DirectTransport.hpp +4 -5
  64. package/worker/include/RTC/PipeTransport.hpp +4 -5
  65. package/worker/include/RTC/PlainTransport.hpp +4 -5
  66. package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +6 -7
  67. package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +3 -1
  68. package/worker/include/RTC/RTP/Codecs/Tools.hpp +1 -1
  69. package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +0 -1
  70. package/worker/include/RTC/RTP/Packet.hpp +16 -4
  71. package/worker/include/RTC/RTP/ProbationGenerator.hpp +0 -8
  72. package/worker/include/RTC/RTP/RtpStream.hpp +12 -9
  73. package/worker/include/RTC/RTP/RtpStreamRecv.hpp +22 -4
  74. package/worker/include/RTC/RTP/RtpStreamSend.hpp +4 -2
  75. package/worker/include/RTC/RTP/RtxStream.hpp +10 -4
  76. package/worker/include/RTC/RateCalculator.hpp +103 -24
  77. package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +33 -3
  78. package/worker/include/RTC/{RtcLogger.hpp → RtcLogger/RtpPacket.hpp} +5 -3
  79. package/worker/include/RTC/RtcLogger/SendBurst.hpp +88 -0
  80. package/worker/include/RTC/RtpDictionaries.hpp +3 -4
  81. package/worker/include/RTC/SCTP/association/Association.hpp +1 -1
  82. package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +0 -1
  83. package/worker/include/RTC/SCTP/public/SctpTypes.hpp +4 -4
  84. package/worker/include/RTC/SCTP/rx/DataTracker.hpp +1 -1
  85. package/worker/include/RTC/SCTP/rx/ReassemblyQueue.hpp +1 -1
  86. package/worker/include/RTC/SctpDictionaries.hpp +2 -2
  87. package/worker/include/RTC/TcpConnection.hpp +2 -1
  88. package/worker/include/RTC/Transport.hpp +23 -8
  89. package/worker/include/RTC/TransportTuple.hpp +61 -6
  90. package/worker/include/RTC/WebRtcTransport.hpp +4 -5
  91. package/worker/include/Shared.hpp +5 -0
  92. package/worker/include/SharedInterface.hpp +10 -0
  93. package/worker/include/Utils.hpp +72 -3
  94. package/worker/include/common.hpp +12 -4
  95. package/worker/include/handles/SendCallbacks.hpp +34 -0
  96. package/worker/include/handles/TcpConnectionHandle.hpp +4 -12
  97. package/worker/include/handles/UdpSocketHandle.hpp +4 -8
  98. package/worker/meson.build +41 -3
  99. package/worker/meson_options.txt +1 -0
  100. package/worker/mocks/include/MockShared.hpp +16 -2
  101. package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +1 -1
  102. package/worker/scripts/package-lock.json +6 -6
  103. package/worker/src/RTC/BWE/AimdRateControl.cpp +4 -5
  104. package/worker/src/RTC/BWE/AlrDetector.cpp +80 -0
  105. package/worker/src/RTC/BWE/BitrateProber.cpp +256 -0
  106. package/worker/src/RTC/BWE/{Utils.cpp → BitrateUtils.cpp} +4 -4
  107. package/worker/src/RTC/BWE/DelayBasedBwe.cpp +2 -2
  108. package/worker/src/RTC/BWE/FeedbackAdapter.cpp +20 -37
  109. package/worker/src/RTC/BWE/InterArrival.cpp +216 -0
  110. package/worker/src/RTC/BWE/IntervalBudget.cpp +93 -0
  111. package/worker/src/RTC/BWE/LossBasedController.cpp +189 -41
  112. package/worker/src/RTC/BWE/OveruseDetector.cpp +128 -0
  113. package/worker/src/RTC/BWE/OveruseEstimator.cpp +166 -0
  114. package/worker/src/RTC/BWE/ProbeBitrateEstimator.cpp +222 -0
  115. package/worker/src/RTC/BWE/ProbeController.cpp +645 -0
  116. package/worker/src/RTC/BWE/ProbePacketGenerator.cpp +140 -0
  117. package/worker/src/RTC/BWE/ProbingScheduler.cpp +196 -0
  118. package/worker/src/RTC/BWE/RembGenerator.cpp +169 -0
  119. package/worker/src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp +497 -0
  120. package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +47 -0
  121. package/worker/src/RTC/BWE/SendPacketHistory.cpp +173 -50
  122. package/worker/src/RTC/BWE/TargetRateController.cpp +12 -14
  123. package/worker/src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp +377 -0
  124. package/worker/src/RTC/BWE/TrendlineEstimator.cpp +19 -0
  125. package/worker/src/RTC/Consumer.cpp +7 -5
  126. package/worker/src/RTC/DataConsumer.cpp +8 -10
  127. package/worker/src/RTC/DirectTransport.cpp +14 -8
  128. package/worker/src/RTC/DtlsTransport.cpp +8 -8
  129. package/worker/src/RTC/ICE/IceCandidate.cpp +4 -4
  130. package/worker/src/RTC/ICE/IceServer.cpp +1 -1
  131. package/worker/src/RTC/PipeTransport.cpp +13 -8
  132. package/worker/src/RTC/PlainTransport.cpp +13 -8
  133. package/worker/src/RTC/Producer.cpp +14 -31
  134. package/worker/src/RTC/RTCP/Bye.cpp +1 -1
  135. package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +18 -0
  136. package/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +2 -2
  137. package/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +2 -1
  138. package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +2 -2
  139. package/worker/src/RTC/RTCP/Sdes.cpp +1 -1
  140. package/worker/src/RTC/RTP/Codecs/DependencyDescriptor.cpp +2 -1
  141. package/worker/src/RTC/RTP/Packet.cpp +26 -11
  142. package/worker/src/RTC/RTP/ProbationGenerator.cpp +5 -6
  143. package/worker/src/RTC/RTP/RtpStream.cpp +1 -1
  144. package/worker/src/RTC/RTP/RtpStreamRecv.cpp +69 -48
  145. package/worker/src/RTC/RTP/RtpStreamSend.cpp +31 -31
  146. package/worker/src/RTC/RTP/RtxStream.cpp +22 -7
  147. package/worker/src/RTC/RateCalculator.cpp +133 -28
  148. package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +56 -1
  149. package/worker/src/RTC/{RtcLogger.cpp → RtcLogger/RtpPacket.cpp} +2 -2
  150. package/worker/src/RTC/RtcLogger/SendBurst.cpp +124 -0
  151. package/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +2 -12
  152. package/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +1 -1
  153. package/worker/src/RTC/SCTP/association/Association.cpp +1 -1
  154. package/worker/src/RTC/SCTP/rx/InterleavedReassemblyStreams.cpp +3 -3
  155. package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +2 -1
  156. package/worker/src/RTC/SCTP/rx/TraditionalReassemblyStreams.cpp +4 -4
  157. package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +4 -4
  158. package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +6 -10
  159. package/worker/src/RTC/SimulcastProducerStreamManager.cpp +2 -2
  160. package/worker/src/RTC/SrtpSession.cpp +2 -2
  161. package/worker/src/RTC/SvcProducerStreamManager.cpp +2 -2
  162. package/worker/src/RTC/TcpConnection.cpp +2 -2
  163. package/worker/src/RTC/Transport.cpp +111 -93
  164. package/worker/src/RTC/TransportTuple.cpp +4 -4
  165. package/worker/src/RTC/WebRtcServer.cpp +4 -3
  166. package/worker/src/RTC/WebRtcTransport.cpp +20 -13
  167. package/worker/src/Utils/BitStream.cpp +24 -0
  168. package/worker/src/handles/BackoffTimerHandle.cpp +1 -1
  169. package/worker/src/handles/TcpConnectionHandle.cpp +13 -23
  170. package/worker/src/handles/UdpSocketHandle.cpp +14 -21
  171. package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +68 -14
  172. package/worker/test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp +125 -0
  173. package/worker/test/src/RTC/BWE/TestAlrDetector.cpp +110 -0
  174. package/worker/test/src/RTC/BWE/TestBitrateProber.cpp +418 -0
  175. package/worker/test/src/RTC/BWE/TestBitrateUtils.cpp +61 -0
  176. package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +4 -4
  177. package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +53 -37
  178. package/worker/test/src/RTC/BWE/TestInterArrival.cpp +643 -0
  179. package/worker/test/src/RTC/BWE/TestIntervalBudget.cpp +130 -0
  180. package/worker/test/src/RTC/BWE/TestOveruseDetector.cpp +519 -0
  181. package/worker/test/src/RTC/BWE/TestProbeBitrateEstimator.cpp +266 -0
  182. package/worker/test/src/RTC/BWE/TestProbeController.cpp +1682 -0
  183. package/worker/test/src/RTC/BWE/TestProbePacketGenerator.cpp +265 -0
  184. package/worker/test/src/RTC/BWE/TestProbingScheduler.cpp +260 -0
  185. package/worker/test/src/RTC/BWE/TestRembGenerator.cpp +285 -0
  186. package/worker/test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp +414 -0
  187. package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +296 -77
  188. package/worker/test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp +578 -0
  189. package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +133 -29
  190. package/worker/test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp +625 -0
  191. package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +19 -0
  192. package/worker/test/src/RTC/RTP/TestPacket.cpp +58 -4
  193. package/worker/test/src/RTC/RTP/TestProbationGenerator.cpp +3 -2
  194. package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +50 -0
  195. package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +59 -0
  196. package/worker/test/src/RTC/TestRateCalculator.cpp +322 -60
  197. package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +95 -7
  198. package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +34 -16
  199. package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +31 -13
  200. package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +37 -19
  201. package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +10 -10
  202. package/worker/test/src/Utils/TestTime.cpp +120 -21
  203. package/worker/test/src/RTC/BWE/TestUtils.cpp +0 -61
@@ -0,0 +1,96 @@
1
+ #ifndef MS_RTC_BWE_REMB_GENERATOR_HPP
2
+ #define MS_RTC_BWE_REMB_GENERATOR_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "RTC/RTCP/FeedbackPsRemb.hpp"
6
+ #include <vector>
7
+
8
+ namespace RTC
9
+ {
10
+ namespace BWE
11
+ {
12
+ /**
13
+ * Tells the remote sender how much it may send towards us, as a REMB.
14
+ *
15
+ * Two things end up in that single number: what the incoming link is
16
+ * estimated to bear, and the cap the application asked for.
17
+ */
18
+ class RembGenerator
19
+ {
20
+ public:
21
+ class Listener
22
+ {
23
+ public:
24
+ virtual ~Listener() = default;
25
+
26
+ public:
27
+ /**
28
+ * A REMB packet is ready for the remote sender.
29
+ *
30
+ * @param packet - Packet to send, only valid for the duration of this
31
+ * call.
32
+ */
33
+ virtual void OnRembGeneratorSendRemb(
34
+ RembGenerator* rembGenerator, RTC::RTCP::FeedbackPsRembPacket* packet) = 0;
35
+ };
36
+
37
+ public:
38
+ explicit RembGenerator(Listener* listener);
39
+
40
+ RembGenerator(const RembGenerator&) = delete;
41
+ RembGenerator& operator=(const RembGenerator&) = delete;
42
+
43
+ /**
44
+ * Feed a new estimation of what the incoming link bears (bps).
45
+ *
46
+ * @param nowMs - Current instant.
47
+ * @param ssrcs - Streams the estimation applies to.
48
+ *
49
+ * @remarks
50
+ * - A REMB goes out when the estimation drops enough to be worth telling
51
+ * right away, and otherwise no more often than every 200 ms.
52
+ */
53
+ void OnReceiveBitrateChanged(int64_t nowMs, const std::vector<uint32_t>& ssrcs, int64_t bitrate);
54
+
55
+ /**
56
+ * Cap what is announced to the remote sender (bps), or no value to
57
+ * announce whatever is estimated.
58
+ *
59
+ * @param nowMs - Current instant.
60
+ */
61
+ void SetMaxIncomingBitrate(int64_t nowMs, std::optional<int64_t> bitrate);
62
+
63
+ /**
64
+ * Announce the cap again, or that it is gone, which is what gets either
65
+ * across when there is no estimation driving anything.
66
+ *
67
+ * @param nowMs - Current instant.
68
+ */
69
+ void MaySendLimitationRembFeedback(int64_t nowMs);
70
+
71
+ private:
72
+ /**
73
+ * Build a REMB carrying the given bitrate and hand it to the listener.
74
+ */
75
+ void SendRemb(int64_t bitrate, const std::vector<uint32_t>& ssrcs);
76
+
77
+ private:
78
+ // Passed by argument.
79
+ Listener* listener{ nullptr };
80
+ // Others.
81
+ // Instant the latest REMB was sent at, or no value until one is.
82
+ std::optional<int64_t> lastRembSentAtMs;
83
+ // Bitrate the latest REMB carried, or no value until one is sent. Zero is
84
+ // a value of its own, since that is how a REMB says there is no limit.
85
+ std::optional<int64_t> lastSentRembBitrate;
86
+ // Most that may be announced, or no value when there is no cap.
87
+ std::optional<int64_t> maxIncomingBitrate;
88
+ // Instant the cap was last announced at, or no value until it is.
89
+ std::optional<int64_t> limitationRembSentAtMs;
90
+ // How many REMBs announcing that the cap is gone are still owed.
91
+ uint8_t unlimitedRembCounter{ 0 };
92
+ };
93
+ } // namespace BWE
94
+ } // namespace RTC
95
+
96
+ #endif
@@ -0,0 +1,237 @@
1
+ #ifndef MS_RTC_BWE_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
2
+ #define MS_RTC_BWE_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "RTC/BWE/AimdRateControl.hpp"
6
+ #include "RTC/BWE/InterArrival.hpp"
7
+ #include "RTC/BWE/OveruseDetector.hpp"
8
+ #include "RTC/BWE/OveruseEstimator.hpp"
9
+ #include "RTC/RTP/Packet.hpp"
10
+ #include "RTC/RateCalculator.hpp"
11
+ #include <ankerl/unordered_dense.h>
12
+ #include <list>
13
+ #include <vector>
14
+
15
+ namespace RTC
16
+ {
17
+ namespace BWE
18
+ {
19
+ /**
20
+ * Estimates the bandwidth of the incoming link out of the 'abs-send-time' RTP
21
+ * extension, for senders that do not negotiate transport-cc.
22
+ *
23
+ * There is no feedback to work with here: all the information available is
24
+ * the instant each packet says it left the sender and the instant it arrived,
25
+ * so the estimation is the delay based detection over the whole group of
26
+ * incoming streams. It also detects the bursts a sender emits at the
27
+ * beginning of a call and takes their rate as a shortcut to an estimate,
28
+ * which is what makes the first seconds of a call usable.
29
+ *
30
+ * The result travels back to the sender as a REMB, so whoever owns this class
31
+ * gets both the estimate and the streams it applies to.
32
+ */
33
+ class RemoteBitrateEstimatorAbsSendTime
34
+ {
35
+ public:
36
+ class Listener
37
+ {
38
+ public:
39
+ virtual ~Listener() = default;
40
+
41
+ public:
42
+ /**
43
+ * The estimation of the incoming link changed, so the remote senders of
44
+ * the given streams have to be told about it.
45
+ *
46
+ * @param ssrcs - Streams the estimation applies to, which are those that
47
+ * have sent something recently.
48
+ * @param bitrate - Estimated bitrate of the incoming link (bps).
49
+ */
50
+ virtual void OnRemoteBitrateEstimatorAbsSendTimeBitrateChanged(
51
+ RemoteBitrateEstimatorAbsSendTime* remoteBitrateEstimator,
52
+ const std::vector<uint32_t>& ssrcs,
53
+ int64_t bitrate) = 0;
54
+ };
55
+
56
+ private:
57
+ /**
58
+ * A packet that may belong to a burst emitted by the sender.
59
+ */
60
+ struct Probe
61
+ {
62
+ /**
63
+ * Instant the packet says it left the sender, in the sender's own
64
+ * timeline (us).
65
+ */
66
+ int64_t sendTimeUs;
67
+ /**
68
+ * Instant the packet arrived (us).
69
+ */
70
+ int64_t receiveTimeUs;
71
+ /**
72
+ * Size of the packet (bytes).
73
+ */
74
+ size_t payloadSize;
75
+ };
76
+
77
+ /**
78
+ * A run of consecutive probes whose send deltas are close enough to each
79
+ * other to look like a single burst.
80
+ *
81
+ * @remarks
82
+ * - While a run is being accumulated the fields below hold sums rather than
83
+ * means, and they are divided by `count` when the run is closed.
84
+ */
85
+ struct Cluster
86
+ {
87
+ /**
88
+ * Rate at which the burst was sent (bps).
89
+ */
90
+ int64_t GetSendBitrate() const
91
+ {
92
+ return (static_cast<int64_t>(this->meanSize) * 8 * 1000000) / this->sendMeanUs;
93
+ }
94
+
95
+ /**
96
+ * Rate at which the burst was received (bps).
97
+ */
98
+ int64_t GetReceiveBitrate() const
99
+ {
100
+ return (static_cast<int64_t>(this->meanSize) * 8 * 1000000) / this->receiveMeanUs;
101
+ }
102
+
103
+ /**
104
+ * Mean time between the send instants of two consecutive probes (us).
105
+ */
106
+ int64_t sendMeanUs{ 0 };
107
+ /**
108
+ * Mean time between the arrival instants of two consecutive probes (us).
109
+ */
110
+ int64_t receiveMeanUs{ 0 };
111
+ /**
112
+ * Mean size of the probes (bytes).
113
+ */
114
+ size_t meanSize{ 0 };
115
+ /**
116
+ * Number of probes in the run.
117
+ */
118
+ int count{ 0 };
119
+ /**
120
+ * How many of those probes came far enough apart from the previous one
121
+ * for the gap to be measurable.
122
+ */
123
+ int numAboveMinDelta{ 0 };
124
+ };
125
+
126
+ enum class ProbeResult : uint8_t
127
+ {
128
+ BITRATE_UPDATED,
129
+ NO_UPDATE
130
+ };
131
+
132
+ public:
133
+ explicit RemoteBitrateEstimatorAbsSendTime(Listener* listener);
134
+
135
+ RemoteBitrateEstimatorAbsSendTime(const RemoteBitrateEstimatorAbsSendTime&) = delete;
136
+ RemoteBitrateEstimatorAbsSendTime& operator=(const RemoteBitrateEstimatorAbsSendTime&) = delete;
137
+
138
+ /**
139
+ * Feed a received RTP packet.
140
+ *
141
+ * @param packet - Received packet, which is ignored unless it carries the
142
+ * 'abs-send-time' extension.
143
+ * @param arrivalTimeUs - Instant the packet arrived.
144
+ * @param nowUs - Current instant, which is not the one above when packets
145
+ * are processed in batches.
146
+ */
147
+ void IncomingPacket(const RTC::RTP::Packet* packet, int64_t arrivalTimeUs, int64_t nowUs);
148
+
149
+ /**
150
+ * Feed the round trip time towards the senders, which bounds how often the
151
+ * estimation may be reduced.
152
+ */
153
+ void OnRttUpdate(int64_t avgRttUs);
154
+
155
+ /**
156
+ * Forget a stream, so that it no longer takes part in the estimation nor in
157
+ * the streams reported to the listener.
158
+ */
159
+ void RemoveStream(uint32_t ssrc);
160
+
161
+ /**
162
+ * Latest estimation of the incoming link (bps), or zero while there is
163
+ * none or no stream is active.
164
+ */
165
+ int64_t GetLatestEstimate() const;
166
+
167
+ private:
168
+ /**
169
+ * Whether the given send delta is close enough to the mean of the run being
170
+ * accumulated to belong to it.
171
+ */
172
+ static bool IsWithinClusterBounds(int64_t sendDeltaUs, const Cluster& clusterAggregate);
173
+
174
+ /**
175
+ * Close the run being accumulated and keep it, unless it is too short or
176
+ * covers no time at all.
177
+ */
178
+ static void MaybeAddCluster(const Cluster& clusterAggregate, std::list<Cluster>& clusters);
179
+
180
+ /**
181
+ * Split the probes seen so far into runs of similar send deltas.
182
+ */
183
+ std::list<Cluster> ComputeClusters() const;
184
+
185
+ /**
186
+ * The fastest run that looks like a burst that made it through, or none if
187
+ * no run does.
188
+ */
189
+ const Cluster* FindBestProbe(const std::list<Cluster>& clusters) const;
190
+
191
+ /**
192
+ * Look at the probes seen so far and take the rate of the best burst as the
193
+ * estimation, if it beats what is already known.
194
+ */
195
+ ProbeResult ProcessClusters(int64_t nowUs);
196
+
197
+ /**
198
+ * Whether the given rate says something that the current estimation does
199
+ * not already say.
200
+ */
201
+ bool IsBitrateImproving(int64_t probeBitrate) const;
202
+
203
+ /**
204
+ * Forget the streams that have been silent for too long, and start the
205
+ * delay based detection over when none is left.
206
+ */
207
+ void TimeoutStreams(int64_t nowUs);
208
+
209
+ private:
210
+ Listener* listener{ nullptr };
211
+ // Recreated whenever every stream times out, since the groups of a stream
212
+ // that is gone say nothing about the ones of whatever comes next.
213
+ std::unique_ptr<InterArrival> interArrival;
214
+ std::unique_ptr<OveruseEstimator> overuseEstimator;
215
+ OveruseDetector overuseDetector;
216
+ // Rate at which data is coming in, which is what bounds the estimation.
217
+ RTC::RateCalculator incomingRateCalculator;
218
+ // Whether the meter above has reported a rate at least once, so that a
219
+ // stream falling silent can be told apart from never having measured
220
+ // anything.
221
+ bool incomingBitrateInitialized{ false };
222
+ // Packets big enough to have been paced by the sender, kept while a burst
223
+ // is still being looked for.
224
+ std::list<Probe> probes;
225
+ // Instant of the first packet ever fed, which bounds how long bursts are
226
+ // looked for.
227
+ std::optional<int64_t> firstPacketTimeUs;
228
+ // Instant the listener was told about the estimation for the last time.
229
+ std::optional<int64_t> lastUpdateUs;
230
+ // Instant each stream was last seen at.
231
+ ankerl::unordered_dense::map<uint32_t, int64_t> ssrcs;
232
+ AimdRateControl remoteRateControl;
233
+ };
234
+ } // namespace BWE
235
+ } // namespace RTC
236
+
237
+ #endif
@@ -23,29 +23,54 @@ namespace RTC
23
23
  class RobustThroughputEstimator : public AcknowledgedBitrateEstimatorInterface
24
24
  {
25
25
  public:
26
+ /**
27
+ * @remarks
28
+ * - Every constraint documented below is checked by the constructor and
29
+ * aborts when it doesn't hold. These options are set from C++ alone,
30
+ * never from the network nor from the API, so breaking one of them is a
31
+ * programming error.
32
+ */
26
33
  struct RobustThroughputEstimatorOptions
27
34
  {
28
35
  /**
29
36
  * Smallest number of packets the window holds.
37
+ *
38
+ * @remarks
39
+ * - It must be between 10 and 1000.
30
40
  */
31
41
  size_t windowPackets{ 20 };
32
42
  /**
33
43
  * Largest number of packets the window holds, so that a high bitrate
34
44
  * doesn't make it grow without bound.
45
+ *
46
+ * @remarks
47
+ * - It must be between 10 and 1000, and never below `windowPackets`.
35
48
  */
36
49
  size_t maxWindowPackets{ 500 };
37
50
  /**
38
51
  * Smallest duration the window covers, so that a low bitrate still gets
39
52
  * enough packets to measure.
53
+ *
54
+ * @remarks
55
+ * - It must be between 100 and 3000 ms, and never above
56
+ * `maxWindowDurationUs`.
40
57
  */
41
58
  int64_t minWindowDurationUs{ 1000 * 1000 };
42
59
  /**
43
60
  * Largest duration the window covers, so that very old packets don't
44
61
  * weigh on the estimate after sending was paused.
62
+ *
63
+ * @remarks
64
+ * - It must be between 1 and 15 s.
45
65
  */
46
66
  int64_t maxWindowDurationUs{ 5 * 1000 * 1000 };
47
67
  /**
48
68
  * Number of packets the window needs before it produces an estimate.
69
+ *
70
+ * @remarks
71
+ * - It must be between 10 and 1000, and never above `windowPackets`,
72
+ * since a window that requires more packets than it holds would reach
73
+ * the sending rate with no send time to compute it from.
49
74
  */
50
75
  size_t requiredPackets{ 10 };
51
76
  /**
@@ -56,6 +81,7 @@ namespace RTC
56
81
  * - Set it to 0 when audio is not included in the allocation, and to 1
57
82
  * when it is included in the allocation but not in the estimation.
58
83
  * Its value is irrelevant once every packet is tracked.
84
+ * - It must be between 0 and 1.
59
85
  */
60
86
  double unackedWeight{ 1.0 };
61
87
  };
@@ -2,6 +2,7 @@
2
2
  #define MS_RTC_BWE_SEND_PACKET_HISTORY_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "Utils/UnwrappedSequenceNumber.hpp"
5
6
  #include "RTC/BWE/BweTypes.hpp"
6
7
  #include <map>
7
8
  #include <tuple>
@@ -37,14 +38,113 @@ namespace RTC
37
38
  int64_t windowDurationUs{ 60 * 1000 * 1000 };
38
39
  };
39
40
 
40
- private:
41
+ /**
42
+ * Everything about a packet that this history has to be told, since none
43
+ * of it can be read back from the bytes that go on the wire.
44
+ */
45
+ struct AddPacketOptions
46
+ {
47
+ uint32_t ssrc{ 0 };
48
+ /**
49
+ * RTP sequence number of the packet, which is what a feedback that
50
+ * doesn't carry the one above identifies it by.
51
+ */
52
+ uint16_t seq{ 0 };
53
+ /**
54
+ * Size of the packet including the overhead up to the IP layer (bytes).
55
+ *
56
+ * @remarks
57
+ * - What the link has to carry is what the estimation is about, so the
58
+ * length of the packet on its own falls short. The overhead of the
59
+ * path it takes is what `RTC::TransportTuple::GetPacketOverhead()`
60
+ * answers.
61
+ */
62
+ size_t size{ 0 };
63
+ /**
64
+ * Whether it's an audio packet. False for video, padding and RTX.
65
+ */
66
+ bool isAudio{ false };
67
+ bool isRetransmission{ false };
68
+ /**
69
+ * SSRC of the packet a retransmission carries, which is the SSRC above
70
+ * itself when it goes without RTX. No value when the packet isn't a
71
+ * retransmission.
72
+ */
73
+ std::optional<uint32_t> originalSsrc;
74
+ /**
75
+ * Whether the packet is marked as ECT(1), which asks the network to
76
+ * report congestion instead of dropping the packet.
77
+ *
78
+ * @see https://www.rfc-editor.org/rfc/rfc9331.html
79
+ */
80
+ bool sentWithEct1{ false };
81
+ /**
82
+ * The burst the packet belongs to, or no value if it isn't part of one.
83
+ */
84
+ std::optional<Types::ProbeCluster> probeCluster;
85
+ /**
86
+ * Time at which the packet is taken note of, which is not yet the time
87
+ * at which it was sent.
88
+ */
89
+ int64_t createdAtUs{ 0 };
90
+ };
91
+
92
+ /**
93
+ * A packet as this history holds it, which is what it was sent with plus
94
+ * what identifies it on the wire.
95
+ */
41
96
  struct SentPacketEntry
42
97
  {
43
98
  Types::SentPacket sentPacket;
99
+ /**
100
+ * Time at which the packet was taken note of, which is what makes it
101
+ * fall out of the window. It comes before the packet was sent, and by
102
+ * an unbounded amount when the socket cannot take the datagram right
103
+ * away.
104
+ */
105
+ int64_t createdAtUs{ 0 };
44
106
  uint32_t ssrc{ 0 };
45
107
  uint16_t seq{ 0 };
108
+ bool isRetransmission{ false };
109
+ /**
110
+ * Whether what a feedback reports as the arrival time of this packet
111
+ * cannot be told from that of another one, which happens when the very
112
+ * same SSRC and RTP sequence number were sent more than once.
113
+ *
114
+ * @remark
115
+ * - Nothing in this estimator reads it. It is only of use to SCReAM,
116
+ * another way of estimating the bandwidth, which discards the delay
117
+ * of a packet it cannot tell apart.
118
+ *
119
+ * @link https://datatracker.ietf.org/doc/draft-johansson-ccwg-rfc8298bis-screamv2
120
+ */
121
+ bool ambiguousReceiveTime{ false };
122
+ /**
123
+ * Whether the packet was sent marked as ECT(1), which asks the network
124
+ * to report congestion instead of dropping the packet.
125
+ *
126
+ * @remark
127
+ * - Only a feedback that reports ECN carries it back, which is the one
128
+ * of RFC 8888 and not the transport-cc one.
129
+ *
130
+ * @see https://datatracker.ietf.org/doc/html/rfc8888
131
+ * @see https://www.rfc-editor.org/rfc/rfc9331.html
132
+ */
133
+ bool sentWithEct1{ false };
134
+ /**
135
+ * Whether a feedback already reported this packet as lost, which is
136
+ * what tells a first loss from the same loss reported again.
137
+ *
138
+ * @remark
139
+ * - Only a feedback that reports on a whole range of packets makes use
140
+ * of it, which is the one of RFC 8888 and not the transport-cc one.
141
+ *
142
+ * @see https://datatracker.ietf.org/doc/html/rfc8888
143
+ */
144
+ bool previouslyReportedLost{ false };
46
145
  };
47
146
 
147
+ private:
48
148
  struct SsrcAndSeq
49
149
  {
50
150
  bool operator<(const SsrcAndSeq& other) const
@@ -62,23 +162,58 @@ namespace RTC
62
162
  explicit SendPacketHistory(SendPacketHistoryOptions options);
63
163
 
64
164
  /**
65
- * Take note of a packet that has just been sent.
165
+ * Take note of a packet that is about to be sent.
166
+ *
167
+ * @returns The sequence number given to the packet, whose lowest 16 bits
168
+ * are what has to go into the transport-wide sequence number RTP header
169
+ * extension, and which is what a feedback resolves into.
170
+ */
171
+ int64_t AddPacket(const AddPacketOptions& options);
172
+
173
+ /**
174
+ * Recover the sequence number this history gave a packet out of the
175
+ * lowest 16 bits of it that the wire carries.
176
+ *
177
+ * @remarks
178
+ * - Each number is resolved against the previous one resolved, be it of a
179
+ * packet taken note of or of another feedback, which is what carries the
180
+ * count across a turn of the wire's 16 bits. So one further than half
181
+ * that range away from the previous cannot be told apart from the same
182
+ * number a turn later.
183
+ */
184
+ int64_t UnwrapSequenceNumber(uint16_t wrappedSequenceNumber);
185
+
186
+ /**
187
+ * Take note that the packet with the given sequence number has left.
66
188
  *
67
- * @param size - Size of the packet including overhead up to the IP layer
68
- * (bytes).
69
- * @param audio - Whether it's an audio packet. False for video, padding
70
- * and RTX.
71
- * @returns The sequence number given to the packet, which is what a
72
- * feedback has to be resolved into.
189
+ * @returns The packet as it was sent, or no value if this history doesn't
190
+ * hold it anymore or it had already left.
191
+ *
192
+ * @remarks
193
+ * - This is what makes the packet count as in flight, and what settles how
194
+ * many bytes were in flight when it left.
195
+ * - A packet sent under a sequence number that already left is not taken
196
+ * note of twice, so that its bytes are not counted twice either.
197
+ */
198
+ std::optional<Types::SentPacket> ProcessSentPacket(int64_t sequenceNumber, int64_t sentAtUs);
199
+
200
+ /**
201
+ * Take note of bytes that left without being tracked one by one, which is
202
+ * what packets carrying no sequence number of this history amount to.
203
+ *
204
+ * @remarks
205
+ * - They are held until the next tracked packet leaves and are attributed
206
+ * to it, so that whoever measures the acknowledged bitrate doesn't
207
+ * believe the link carried less than it did.
73
208
  */
74
- int64_t AddPacket(uint32_t ssrc, uint16_t seq, size_t size, bool audio, int64_t sentAtUs);
209
+ void ProcessSentUntrackedPacket(size_t size, int64_t sentAtUs);
75
210
 
76
211
  /**
77
212
  * Resolve what a feedback reported about a single packet.
78
213
  *
79
214
  * @param received - Whether the feedback reported the packet as received.
80
- * @returns The packet as it was sent, or no value if this history doesn't
81
- * hold it anymore.
215
+ * @returns The packet as this history holds it, or no value if it doesn't
216
+ * hold it anymore or it was never reported as sent.
82
217
  *
83
218
  * @remarks
84
219
  * - Every packet up to the given one stops counting as in flight, since
@@ -86,24 +221,13 @@ namespace RTC
86
221
  * - A packet reported as received is dropped, while one reported as lost
87
222
  * is kept, since a later feedback may still report it as received.
88
223
  */
89
- std::optional<Types::SentPacket> RetrievePacket(int64_t sequenceNumber, bool received);
224
+ std::optional<SentPacketEntry> RetrievePacket(int64_t sequenceNumber, bool received);
90
225
 
91
226
  /**
92
227
  * Same, for a feedback that identifies the packet by its SSRC and RTP
93
228
  * sequence number rather than by the sequence number given to it.
94
229
  */
95
- std::optional<Types::SentPacket> RetrievePacket(uint32_t ssrc, uint16_t seq, bool received);
96
-
97
- /**
98
- * Sequence number this history gave to the latest packet added, or no
99
- * value if no packet was ever added.
100
- *
101
- * @remarks
102
- * - It's the sequence number of this history, not the RTP one, so it
103
- * never wraps around. It's also the highest a feedback carrying only
104
- * the lowest bits of it can possibly stand for.
105
- */
106
- std::optional<int64_t> GetLastSequenceNumber() const;
230
+ std::optional<SentPacketEntry> RetrievePacket(uint32_t ssrc, uint16_t seq, bool received);
107
231
 
108
232
  /**
109
233
  * Bytes that were sent and no feedback has reported on yet.
@@ -126,10 +250,22 @@ namespace RTC
126
250
  const SendPacketHistoryOptions options;
127
251
  std::map<int64_t, SentPacketEntry> history;
128
252
  std::map<SsrcAndSeq, int64_t> ssrcAndSeqToSequenceNumber;
129
- int64_t nextSequenceNumber{ 0 };
253
+ // Hands out the sequence numbers and recovers them out of the lowest bits
254
+ // the wire carries, which keeps both to a single count.
255
+ Utils::UnwrappedSequenceNumber<uint16_t>::Unwrapper sequenceNumberUnwrapper;
256
+ uint16_t nextWrappedSequenceNumber{ 0 };
257
+ // Highest sequence number ever taken note of, or no value if none was.
258
+ std::optional<int64_t> highestSequenceNumber;
130
259
  // Sequence numbers are never negative, so this sits below all of them.
131
260
  int64_t lastAckSequenceNumber{ -1 };
132
261
  size_t outstandingBytes{ 0 };
262
+ // Bytes that left untracked and no packet has been attributed yet.
263
+ size_t pendingUntrackedBytes{ 0 };
264
+ // Time at which the latest tracked packet left, or no value if none has.
265
+ std::optional<int64_t> lastSendTimeUs;
266
+ // Time at which the latest untracked bytes left, or no value if none
267
+ // have.
268
+ std::optional<int64_t> lastUntrackedSendTimeUs;
133
269
  };
134
270
  } // namespace BWE
135
271
  } // namespace RTC