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
@@ -0,0 +1,187 @@
1
+ #ifndef MS_RTC_BWE_PROBING_SCHEDULER_HPP
2
+ #define MS_RTC_BWE_PROBING_SCHEDULER_HPP
3
+
4
+ #include "common.hpp"
5
+ #include "handles/TimerHandleInterface.hpp"
6
+ #include "RTC/BWE/BitrateProber.hpp"
7
+ #include "RTC/BWE/BweTypes.hpp"
8
+ #include "RTC/BWE/ProbePacketGenerator.hpp"
9
+ #include "RTC/RTP/Packet.hpp"
10
+ #include "SharedInterface.hpp"
11
+ #include <vector>
12
+
13
+ namespace RTC
14
+ {
15
+ namespace BWE
16
+ {
17
+ /**
18
+ * Puts a probing burst on the wire at the pace it was asked for.
19
+ *
20
+ * Somebody else decides that a burst is worth sending and at what bitrate;
21
+ * this is what turns that decision into packets leaving at the right
22
+ * instants. It holds the burst, asks for the packets that carry the bytes
23
+ * due right now, hands them over one by one, and arms a timer for the next
24
+ * shot.
25
+ *
26
+ * The spacing is the whole point. A burst is a bitrate held for a few
27
+ * milliseconds, so letting its packets go as fast as the socket takes them
28
+ * measures the queue of whoever is in the way instead of the link. The
29
+ * instants come from the burst's own start and the bytes gone out so far, so
30
+ * a packet that leaves late is made up for by the ones behind it rather than
31
+ * dragging the whole burst below the bitrate asked for.
32
+ *
33
+ * @remarks
34
+ * - It is not a pacer. Nothing but the packets of a burst goes through here,
35
+ * media is never queued, and there is no timer running while no burst is
36
+ * being emitted.
37
+ */
38
+ class ProbingScheduler : public ProbePacketGenerator::Listener,
39
+ public TimerHandleInterface::Listener
40
+ {
41
+ public:
42
+ class Listener
43
+ {
44
+ public:
45
+ virtual ~Listener() = default;
46
+
47
+ public:
48
+ /**
49
+ * A packet of the burst is ready to go out.
50
+ *
51
+ * @returns Whether the rest of the burst is still wanted, so that a
52
+ * packet that couldn't be sent stops the ones behind it.
53
+ *
54
+ * @remarks
55
+ * - The packet must be sent before returning, since the next one is
56
+ * built over the very same instance.
57
+ * - It carries room for the abs-send-time and for the transport wide
58
+ * sequence number but no value for either, so both have to be written
59
+ * here.
60
+ * - This must not destroy the `ProbingScheduler`, not even indirectly.
61
+ * It goes on reading its own members after this returns, so
62
+ * returning false is no way out of it either.
63
+ */
64
+ virtual bool OnProbingSchedulerSendRtpPacket(
65
+ ProbingScheduler* probingScheduler,
66
+ RTC::RTP::Packet* packet,
67
+ const Types::ProbeCluster& probeCluster) = 0;
68
+ };
69
+
70
+ private:
71
+ /**
72
+ * Holds what a shot needs while it is being emitted. The packets are
73
+ * handed over through a callback, so there is no scope of our own to keep
74
+ * it in, and this makes sure it doesn't outlive the shot.
75
+ */
76
+ class ScopedShot
77
+ {
78
+ public:
79
+ ScopedShot(ProbingScheduler& probingScheduler, const Types::ProbeCluster& probeCluster);
80
+
81
+ ~ScopedShot();
82
+
83
+ ScopedShot(const ScopedShot&) = delete;
84
+ ScopedShot& operator=(const ScopedShot&) = delete;
85
+
86
+ private:
87
+ ProbingScheduler& probingScheduler;
88
+ };
89
+
90
+ public:
91
+ ProbingScheduler(Listener* listener, SharedInterface* shared);
92
+
93
+ ~ProbingScheduler() override = default;
94
+
95
+ // NOTE: It hands itself over as the listener of what it owns, so a copy
96
+ // would leave those pointing at the instance it came from.
97
+ ProbingScheduler(const ProbingScheduler&) = delete;
98
+ ProbingScheduler& operator=(const ProbingScheduler&) = delete;
99
+
100
+ /**
101
+ * Take the bursts that have been asked for.
102
+ *
103
+ * @remarks
104
+ * - Nothing goes out within this call. The first burst begins on the turn
105
+ * of the event loop that follows, so that the send path never runs
106
+ * inside a call that may itself come from the send path.
107
+ * - They are emitted in the order they were asked for, and one asked for
108
+ * long ago is dropped rather than sent late.
109
+ */
110
+ void CreateProbeClusters(const std::vector<Types::ProbeClusterConfig>& clusterConfigs);
111
+
112
+ /**
113
+ * Bytes that every packet carries on top of its own length once it's on
114
+ * the network, so that a burst measures what the link really has to
115
+ * carry.
116
+ *
117
+ * @remarks
118
+ * - It depends on the path the packets take, so it has to be set again
119
+ * whenever that changes.
120
+ */
121
+ void SetPacketOverhead(size_t packetOverhead)
122
+ {
123
+ this->packetOverhead = packetOverhead;
124
+ }
125
+
126
+ /**
127
+ * Whether a burst is being emitted right now.
128
+ */
129
+ bool IsProbing() const
130
+ {
131
+ return this->bitrateProber.IsProbing();
132
+ }
133
+
134
+ /* Pure virtual methods inherited from RTC::BWE::ProbePacketGenerator::Listener. */
135
+ public:
136
+ bool OnProbePacketGeneratorSendRtpPacket(
137
+ ProbePacketGenerator* probePacketGenerator, RTC::RTP::Packet* packet) override;
138
+
139
+ /* Pure virtual methods inherited from TimerHandleInterface::Listener. */
140
+ public:
141
+ void OnTimer(TimerHandleInterface* timer) override;
142
+
143
+ private:
144
+ /**
145
+ * Emit every shot that is due by now and arm the timer for the next one,
146
+ * or stop it if there is nothing left to emit.
147
+ *
148
+ * @remarks
149
+ * - More than one may be due when the event loop was held up for longer
150
+ * than the time between two shots. Leaving them for later turns of the
151
+ * loop would stretch the burst and have it measure a bitrate below the
152
+ * one it was asked for.
153
+ */
154
+ void Process();
155
+
156
+ /**
157
+ * Arm the timer for the given instant, or stop it if there is none.
158
+ */
159
+ void ScheduleNextProbe(std::optional<int64_t> nextProbeTimeUs, int64_t nowUs);
160
+
161
+ private:
162
+ // Passed by argument.
163
+ Listener* listener{ nullptr };
164
+ SharedInterface* shared{ nullptr };
165
+ // Others.
166
+ // Decides which burst is being emitted and at what instant each of its
167
+ // packets is due.
168
+ BitrateProber bitrateProber;
169
+ // Makes the packets that carry the bytes of a burst.
170
+ ProbePacketGenerator probePacketGenerator;
171
+ // Allocated by this.
172
+ const std::unique_ptr<TimerHandleInterface> nextProbeTimer;
173
+ // Bytes each packet carries on top of its own length once it's on the
174
+ // network.
175
+ size_t packetOverhead{ 0 };
176
+ // The burst the current shot belongs to, which travels with each of its
177
+ // packets. Only meaningful while a shot is being emitted, since it's the
178
+ // generator that calls back and it knows nothing about bursts.
179
+ Types::ProbeCluster shotProbeCluster;
180
+ // Bytes of the current shot that have gone out, overhead included, which
181
+ // is only meaningful while one is being emitted.
182
+ size_t shotSentBytes{ 0 };
183
+ };
184
+ } // namespace BWE
185
+ } // namespace RTC
186
+
187
+ #endif
@@ -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
  };