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,625 @@
1
+ #define MS_CLASS "test::bweHelpers::RemoteBitrateEstimatorAbsSendTimeTestHelper"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "test/include/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.hpp"
5
+ #include "Logger.hpp"
6
+ #include "RTC/RTP/HeaderExtensionIds.hpp"
7
+ #include "RTC/RtpDictionaries.hpp"
8
+ #include "Utils.hpp"
9
+ #include "test/include/RTC/RTP/rtpCommon.hpp"
10
+ #include <catch2/catch_test_macros.hpp>
11
+ #include <cstdlib> // std::abs()
12
+ #include <limits>
13
+
14
+ namespace bweHelpers
15
+ {
16
+ /* Static. */
17
+
18
+ // How far off the expected bitrate an estimation may be (bps).
19
+ static constexpr int64_t AcceptedBitrateErrorBps{ 50000 };
20
+ // Packets needed before there is a valid estimation.
21
+ static constexpr int NumInitialPackets{ 2 };
22
+ // Instant the scenarios start at, which is only far from zero so that nothing
23
+ // passes by sharing an origin with something else.
24
+ static constexpr int64_t InitialTimeUs{ 100000000 };
25
+ // Capacity of the link the scenarios start with (bps).
26
+ static constexpr int64_t InitialCapacityBps{ 1000000 };
27
+ // Id the scenarios give to the 'abs-send-time' extension.
28
+ static constexpr uint8_t AbsSendTimeId{ 1 };
29
+
30
+ /* Instance methods. */
31
+
32
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::RemoteBitrateEstimatorAbsSendTimeTestHelper()
33
+ : nowUs(InitialTimeUs),
34
+ linkSimulator(InitialCapacityBps, InitialTimeUs),
35
+ remoteBitrateEstimator(this)
36
+ {
37
+ MS_TRACE();
38
+ }
39
+
40
+ uint32_t RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(int64_t t, int64_t denom)
41
+ {
42
+ MS_TRACE();
43
+
44
+ return (((t << 18) + (denom >> 1)) / denom) & 0x00FFFFFF;
45
+ }
46
+
47
+ uint32_t RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(uint32_t t1, uint32_t t2)
48
+ {
49
+ MS_TRACE();
50
+
51
+ return (t1 + t2) & 0x00FFFFFF;
52
+ }
53
+
54
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::AddDefaultStream()
55
+ {
56
+ MS_TRACE();
57
+
58
+ this->linkSimulator.AddStream(
59
+ std::make_unique<RtpStream>(
60
+ /*fps*/ 30,
61
+ /*bitrateBps*/ 300000,
62
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
63
+ /*frequency*/ 90000,
64
+ /*rtpTimestampOffset*/ 0xFFFFF000));
65
+ }
66
+
67
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::IncomingPacket(
68
+ uint32_t ssrc, size_t payloadSize, int64_t arrivalTimeMs, uint32_t rtpTimestamp, uint32_t absSendTime)
69
+ {
70
+ MS_TRACE();
71
+
72
+ std::unique_ptr<RTC::RTP::Packet> packet(
73
+ RTC::RTP::Packet::Factory(rtpCommon::FactoryBuffer, sizeof(rtpCommon::FactoryBuffer)));
74
+
75
+ REQUIRE(packet);
76
+
77
+ packet->SetSsrc(ssrc);
78
+ // NOTE: The estimator never reads the RTP timestamp, it works off the
79
+ // 'abs-send-time' extension alone. It is set because the scenarios below
80
+ // move it around on purpose, wrapping it included.
81
+ packet->SetTimestamp(rtpTimestamp);
82
+
83
+ const std::vector<RTC::RTP::Packet::Extension> extensions{
84
+ { RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME, AbsSendTimeId, /*len*/ 3, rtpCommon::DataBuffer }
85
+ };
86
+
87
+ packet->SetExtensions(RTC::RTP::Packet::ExtensionsType::OneByte, extensions);
88
+
89
+ RTC::RTP::HeaderExtensionIds headerExtensionIds;
90
+
91
+ headerExtensionIds.absSendTime = AbsSendTimeId;
92
+
93
+ packet->AssignExtensionIds(headerExtensionIds);
94
+
95
+ packet->SetPayloadLength(payloadSize);
96
+
97
+ REQUIRE(packet->UpdateAbsSendTime(absSendTime));
98
+
99
+ const int64_t arrivalTimeUs = (arrivalTimeMs + this->arrivalTimeOffsetMs) * 1000;
100
+
101
+ this->remoteBitrateEstimator.IncomingPacket(packet.get(), arrivalTimeUs, this->nowUs);
102
+ }
103
+
104
+ bool RemoteBitrateEstimatorAbsSendTimeTestHelper::GenerateAndProcessFrame(
105
+ uint32_t /*ssrc*/, int64_t bitrateBps)
106
+ {
107
+ MS_TRACE();
108
+
109
+ REQUIRE(bitrateBps > 0);
110
+
111
+ this->linkSimulator.SetBitrateBps(bitrateBps);
112
+
113
+ std::vector<Packet> packets;
114
+
115
+ const int64_t nextTimeUs = this->linkSimulator.GenerateFrame(this->nowUs, packets);
116
+ bool overuse{ false };
117
+
118
+ for (const auto& packet : packets)
119
+ {
120
+ this->updated = false;
121
+
122
+ // The instant has to match the arrival time of the packet, since both are
123
+ // used when it is fed in.
124
+ this->nowUs = packet.arrivalTimeUs;
125
+
126
+ IncomingPacket(
127
+ packet.ssrc,
128
+ packet.size,
129
+ (packet.arrivalTimeUs + 500) / 1000,
130
+ packet.rtpTimestamp,
131
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(packet.sendTimeUs, 1000000));
132
+
133
+ if (this->updated && this->latestBitrate < bitrateBps)
134
+ {
135
+ overuse = true;
136
+ }
137
+ }
138
+
139
+ this->nowUs = nextTimeUs;
140
+
141
+ return overuse;
142
+ }
143
+
144
+ int64_t RemoteBitrateEstimatorAbsSendTimeTestHelper::SteadyStateRun(
145
+ uint32_t ssrc,
146
+ int maxNumberOfFrames,
147
+ int64_t startBitrate,
148
+ int64_t minBitrate,
149
+ int64_t maxBitrate,
150
+ int64_t targetBitrate)
151
+ {
152
+ MS_TRACE();
153
+
154
+ int64_t bitrateBps{ startBitrate };
155
+ bool bitrateUpdateSeen{ false };
156
+
157
+ for (int idx{ 0 }; idx < maxNumberOfFrames; ++idx)
158
+ {
159
+ const bool overuse = GenerateAndProcessFrame(ssrc, bitrateBps);
160
+
161
+ if (overuse)
162
+ {
163
+ REQUIRE(this->latestBitrate < maxBitrate);
164
+ REQUIRE(this->latestBitrate > minBitrate);
165
+
166
+ bitrateBps = this->latestBitrate;
167
+ bitrateUpdateSeen = true;
168
+ }
169
+ else if (this->updated)
170
+ {
171
+ bitrateBps = this->latestBitrate;
172
+ this->updated = false;
173
+ }
174
+
175
+ if (bitrateUpdateSeen && bitrateBps > targetBitrate)
176
+ {
177
+ break;
178
+ }
179
+ }
180
+
181
+ REQUIRE(bitrateUpdateSeen);
182
+
183
+ return bitrateBps;
184
+ }
185
+
186
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::InitialBehaviorTestHelper(
187
+ int64_t expectedConvergeBitrate)
188
+ {
189
+ MS_TRACE();
190
+
191
+ // 50 fps to avoid rounding errors.
192
+ constexpr int Framerate{ 50 };
193
+ constexpr int FrameIntervalMs{ 1000 / Framerate };
194
+
195
+ const uint32_t frameIntervalAbsSendTime =
196
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(1, Framerate);
197
+ uint32_t rtpTimestamp{ 0 };
198
+ uint32_t absSendTime{ 0 };
199
+
200
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == 0);
201
+
202
+ this->nowUs += 1000 * 1000;
203
+
204
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == 0);
205
+ REQUIRE(!this->updated);
206
+
207
+ this->updated = false;
208
+ this->nowUs += 1000 * 1000;
209
+
210
+ // Inserting packets for 5 seconds to get a valid estimate.
211
+ for (int idx{ 0 }; idx < (5 * Framerate) + 1 + NumInitialPackets; ++idx)
212
+ {
213
+ if (idx == NumInitialPackets)
214
+ {
215
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == 0);
216
+ REQUIRE(!this->updated);
217
+
218
+ this->updated = false;
219
+ }
220
+
221
+ IncomingPacket(
222
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
223
+ Mtu,
224
+ Utils::Time::TimeUsToMs(this->nowUs),
225
+ rtpTimestamp,
226
+ absSendTime);
227
+
228
+ this->nowUs += FrameIntervalMs * 1000;
229
+ rtpTimestamp += 90 * FrameIntervalMs;
230
+
231
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
232
+ absSendTime, frameIntervalAbsSendTime);
233
+ }
234
+
235
+ const int64_t bitrateBps = this->remoteBitrateEstimator.GetLatestEstimate();
236
+
237
+ REQUIRE(std::abs(bitrateBps - expectedConvergeBitrate) <= AcceptedBitrateErrorBps);
238
+ REQUIRE(this->updated);
239
+
240
+ this->updated = false;
241
+
242
+ REQUIRE(this->latestBitrate == bitrateBps);
243
+
244
+ this->remoteBitrateEstimator.RemoveStream(
245
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc);
246
+
247
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == 0);
248
+ }
249
+
250
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::RateIncreaseReorderingTestHelper(
251
+ int64_t expectedBitrate)
252
+ {
253
+ MS_TRACE();
254
+
255
+ // 50 fps to avoid rounding errors.
256
+ constexpr int Framerate{ 50 };
257
+ constexpr int FrameIntervalMs{ 1000 / Framerate };
258
+
259
+ const uint32_t frameIntervalAbsSendTime =
260
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(1, Framerate);
261
+ uint32_t rtpTimestamp{ 0 };
262
+ uint32_t absSendTime{ 0 };
263
+
264
+ // Inserting packets for five seconds to get a valid estimate.
265
+ for (int idx{ 0 }; idx < (5 * Framerate) + 1 + NumInitialPackets; ++idx)
266
+ {
267
+ if (idx == NumInitialPackets)
268
+ {
269
+ // No valid estimate yet.
270
+ REQUIRE(!this->updated);
271
+ }
272
+
273
+ IncomingPacket(
274
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
275
+ Mtu,
276
+ Utils::Time::TimeUsToMs(this->nowUs),
277
+ rtpTimestamp,
278
+ absSendTime);
279
+
280
+ this->nowUs += FrameIntervalMs * 1000;
281
+ rtpTimestamp += 90 * FrameIntervalMs;
282
+
283
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
284
+ absSendTime, frameIntervalAbsSendTime);
285
+ }
286
+
287
+ REQUIRE(this->updated);
288
+ REQUIRE(std::abs(this->latestBitrate - expectedBitrate) <= AcceptedBitrateErrorBps);
289
+
290
+ // The same stream with every pair of packets swapped, which the estimation
291
+ // has to ride out unchanged.
292
+ for (int idx{ 0 }; idx < 10; ++idx)
293
+ {
294
+ this->nowUs += 2 * FrameIntervalMs * 1000;
295
+ rtpTimestamp += 2 * 90 * FrameIntervalMs;
296
+
297
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
298
+ absSendTime, 2 * frameIntervalAbsSendTime);
299
+
300
+ IncomingPacket(
301
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
302
+ 1000,
303
+ Utils::Time::TimeUsToMs(this->nowUs),
304
+ rtpTimestamp,
305
+ absSendTime);
306
+
307
+ IncomingPacket(
308
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
309
+ 1000,
310
+ Utils::Time::TimeUsToMs(this->nowUs),
311
+ rtpTimestamp - (90 * FrameIntervalMs),
312
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
313
+ absSendTime, -static_cast<int>(frameIntervalAbsSendTime)));
314
+ }
315
+
316
+ REQUIRE(this->updated);
317
+ REQUIRE(std::abs(this->latestBitrate - expectedBitrate) <= AcceptedBitrateErrorBps);
318
+ }
319
+
320
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::RateIncreaseRtpTimestampsTestHelper(
321
+ int expectedIterations)
322
+ {
323
+ MS_TRACE();
324
+
325
+ // This threshold corresponds approximately to increasing linearly with
326
+ // bitrate(i) = 1.04 * bitrate(i-1) + 1000
327
+ // until bitrate(i) > 500000, with bitrate(1) ~= 30000.
328
+ int64_t bitrateBps{ 30000 };
329
+ int iterations{ 0 };
330
+
331
+ AddDefaultStream();
332
+
333
+ // Feed the estimator with a stream of packets and verify that it reaches
334
+ // 500 kbps at the expected time.
335
+ while (bitrateBps < 500000)
336
+ {
337
+ const bool overuse = GenerateAndProcessFrame(
338
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc, bitrateBps);
339
+
340
+ if (overuse)
341
+ {
342
+ REQUIRE(this->latestBitrate > bitrateBps);
343
+
344
+ bitrateBps = this->latestBitrate;
345
+ this->updated = false;
346
+ }
347
+ else if (this->updated)
348
+ {
349
+ bitrateBps = this->latestBitrate;
350
+ this->updated = false;
351
+ }
352
+
353
+ ++iterations;
354
+
355
+ REQUIRE(iterations <= expectedIterations);
356
+ }
357
+
358
+ REQUIRE(iterations == expectedIterations);
359
+ }
360
+
361
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::CapacityDropTestHelper(
362
+ int numberOfStreams,
363
+ bool wrapTimestamp,
364
+ int64_t expectedBitrateDropDeltaMs,
365
+ int64_t receiverClockOffsetChangeMs)
366
+ {
367
+ MS_TRACE();
368
+
369
+ constexpr int Framerate{ 30 };
370
+ constexpr int64_t StartBitrate{ 900000 };
371
+ constexpr int64_t MinExpectedBitrate{ 800000 };
372
+ constexpr int64_t MaxExpectedBitrate{ 1100000 };
373
+ constexpr int64_t CapacityBps{ 1000000 };
374
+ constexpr int64_t ReducedCapacityBps{ 500000 };
375
+
376
+ int steadyStateTime{ 0 };
377
+
378
+ if (numberOfStreams <= 1)
379
+ {
380
+ steadyStateTime = 10;
381
+
382
+ AddDefaultStream();
383
+ }
384
+ else
385
+ {
386
+ steadyStateTime = 10 * numberOfStreams;
387
+
388
+ int64_t bitrateSum{ 0 };
389
+ const int64_t bitrateDenom = numberOfStreams * (numberOfStreams - 1);
390
+
391
+ for (int idx{ 0 }; idx < numberOfStreams; ++idx)
392
+ {
393
+ // The first stream gets half of the bitrate and the rest share the
394
+ // other half.
395
+ int64_t bitrate = StartBitrate / 2;
396
+
397
+ if (idx > 0)
398
+ {
399
+ bitrate = ((StartBitrate * idx) + (bitrateDenom / 2)) / bitrateDenom;
400
+ }
401
+
402
+ const auto mask = static_cast<uint32_t>(~0ULL << (32 - idx));
403
+
404
+ this->linkSimulator.AddStream(
405
+ std::make_unique<RtpStream>(
406
+ Framerate,
407
+ bitrate,
408
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc + idx,
409
+ /*frequency*/ 90000,
410
+ /*rtpTimestampOffset*/ 0xFFFFF000 ^ mask));
411
+
412
+ bitrateSum += bitrate;
413
+ }
414
+
415
+ REQUIRE(bitrateSum == StartBitrate);
416
+ }
417
+
418
+ if (wrapTimestamp)
419
+ {
420
+ this->linkSimulator.SetRtpTimestampOffset(
421
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
422
+ std::numeric_limits<uint32_t>::max() - (steadyStateTime * 90000));
423
+ }
424
+
425
+ // Run in steady state to make the estimator converge.
426
+ this->linkSimulator.SetCapacityBps(CapacityBps);
427
+
428
+ int64_t bitrateBps = SteadyStateRun(
429
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
430
+ steadyStateTime * Framerate,
431
+ StartBitrate,
432
+ MinExpectedBitrate,
433
+ MaxExpectedBitrate,
434
+ CapacityBps);
435
+
436
+ REQUIRE(bitrateBps >= (85 * CapacityBps) / 100);
437
+ REQUIRE(bitrateBps <= (105 * CapacityBps) / 100);
438
+
439
+ this->updated = false;
440
+
441
+ // Move the receiver's clock to make sure the estimation copes with it.
442
+ this->arrivalTimeOffsetMs += receiverClockOffsetChangeMs;
443
+
444
+ // Reduce the capacity and see how long the estimation takes to follow.
445
+ this->linkSimulator.SetCapacityBps(ReducedCapacityBps);
446
+
447
+ const int64_t overuseStartTimeMs = Utils::Time::TimeUsToMs(this->nowUs);
448
+ int64_t bitrateDropTimeMs{ -1 };
449
+
450
+ for (int idx{ 0 }; idx < 100 * numberOfStreams; ++idx)
451
+ {
452
+ GenerateAndProcessFrame(RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc, bitrateBps);
453
+
454
+ if (bitrateDropTimeMs == -1 && this->latestBitrate <= ReducedCapacityBps)
455
+ {
456
+ bitrateDropTimeMs = Utils::Time::TimeUsToMs(this->nowUs);
457
+ }
458
+
459
+ if (this->updated)
460
+ {
461
+ bitrateBps = this->latestBitrate;
462
+ }
463
+ }
464
+
465
+ REQUIRE(std::abs((bitrateDropTimeMs - overuseStartTimeMs) - expectedBitrateDropDeltaMs) <= 33);
466
+
467
+ // Remove the streams one by one.
468
+ for (int idx{ 0 }; idx < numberOfStreams; ++idx)
469
+ {
470
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == bitrateBps);
471
+
472
+ this->remoteBitrateEstimator.RemoveStream(
473
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc + idx);
474
+ }
475
+
476
+ REQUIRE(this->remoteBitrateEstimator.GetLatestEstimate() == 0);
477
+ }
478
+
479
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::TestTimestampGroupingTestHelper()
480
+ {
481
+ MS_TRACE();
482
+
483
+ // 50 fps to avoid rounding errors.
484
+ constexpr int Framerate{ 50 };
485
+ constexpr int FrameIntervalMs{ 1000 / Framerate };
486
+ // How many frames go out with a single timestamp tick between them, which
487
+ // the estimator has to take as one group.
488
+ constexpr int TimestampGroupLength{ 15 };
489
+
490
+ const uint32_t frameIntervalAbsSendTime =
491
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(1, Framerate);
492
+ uint32_t rtpTimestamp{ 0 };
493
+ // Started near the top of the 24 bits so that it definitely wraps during
494
+ // the run.
495
+ uint32_t absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
496
+ 1 << 24, -static_cast<int>(50 * frameIntervalAbsSendTime));
497
+
498
+ // Initial set of frames to increase the bitrate, over six seconds so that
499
+ // there is time for the first estimation to come out.
500
+ for (int idx{ 0 }; idx <= 6 * Framerate; ++idx)
501
+ {
502
+ IncomingPacket(
503
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
504
+ 1000,
505
+ Utils::Time::TimeUsToMs(this->nowUs),
506
+ rtpTimestamp,
507
+ absSendTime);
508
+
509
+ this->nowUs += FrameIntervalMs * 1000;
510
+ rtpTimestamp += 90 * FrameIntervalMs;
511
+
512
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
513
+ absSendTime, frameIntervalAbsSendTime);
514
+ }
515
+
516
+ REQUIRE(this->updated);
517
+ REQUIRE(this->latestBitrate >= 400000);
518
+
519
+ const uint32_t timestampGroupLengthAbsSendTime =
520
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(TimestampGroupLength, 90000);
521
+ const uint32_t singleRtpTickAbsSendTime =
522
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(1, 90000);
523
+
524
+ // Batches of frames sent very close together, with the gap between batches
525
+ // stretched so that the link looks overused.
526
+ for (int idx{ 0 }; idx < 100; ++idx)
527
+ {
528
+ for (int groupIdx{ 0 }; groupIdx < TimestampGroupLength; ++groupIdx)
529
+ {
530
+ IncomingPacket(
531
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
532
+ 100,
533
+ Utils::Time::TimeUsToMs(this->nowUs),
534
+ rtpTimestamp,
535
+ absSendTime);
536
+
537
+ this->nowUs += (FrameIntervalMs / TimestampGroupLength) * 1000;
538
+ rtpTimestamp += 1;
539
+
540
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
541
+ absSendTime, singleRtpTickAbsSendTime);
542
+ }
543
+
544
+ this->nowUs += 10 * 1000;
545
+ rtpTimestamp += (90 * FrameIntervalMs) - TimestampGroupLength;
546
+
547
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
548
+ absSendTime,
549
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
550
+ frameIntervalAbsSendTime, -static_cast<int>(timestampGroupLengthAbsSendTime)));
551
+ }
552
+
553
+ REQUIRE(this->updated);
554
+ // It should have brought the estimation down.
555
+ REQUIRE(this->latestBitrate < 400000);
556
+ }
557
+
558
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::TestWrappingHelper(int silenceTimeS)
559
+ {
560
+ MS_TRACE();
561
+
562
+ constexpr int Framerate{ 100 };
563
+ constexpr int FrameIntervalMs{ 1000 / Framerate };
564
+
565
+ const uint32_t frameIntervalAbsSendTime =
566
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(1, Framerate);
567
+ uint32_t rtpTimestamp{ 0 };
568
+ uint32_t absSendTime{ 0 };
569
+
570
+ for (size_t idx{ 0 }; idx < 3000; ++idx)
571
+ {
572
+ IncomingPacket(
573
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
574
+ 1000,
575
+ Utils::Time::TimeUsToMs(this->nowUs),
576
+ rtpTimestamp,
577
+ absSendTime);
578
+
579
+ rtpTimestamp += FrameIntervalMs;
580
+ this->nowUs += FrameIntervalMs * 1000;
581
+
582
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
583
+ absSendTime, frameIntervalAbsSendTime);
584
+ }
585
+
586
+ const int64_t bitrateBefore = this->remoteBitrateEstimator.GetLatestEstimate();
587
+
588
+ // The sender goes quiet for long enough to make the 24 bits wrap.
589
+ this->nowUs += static_cast<int64_t>(silenceTimeS) * 1000 * 1000;
590
+
591
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
592
+ absSendTime, RemoteBitrateEstimatorAbsSendTimeTestHelper::AbsSendTime(silenceTimeS, 1));
593
+
594
+ for (size_t idx{ 0 }; idx < 21; ++idx)
595
+ {
596
+ IncomingPacket(
597
+ RemoteBitrateEstimatorAbsSendTimeTestHelper::DefaultSsrc,
598
+ 1000,
599
+ Utils::Time::TimeUsToMs(this->nowUs),
600
+ rtpTimestamp,
601
+ absSendTime);
602
+
603
+ rtpTimestamp += FrameIntervalMs;
604
+ this->nowUs += 2 * FrameIntervalMs * 1000;
605
+
606
+ absSendTime = RemoteBitrateEstimatorAbsSendTimeTestHelper::AddAbsSendTime(
607
+ absSendTime, frameIntervalAbsSendTime);
608
+ }
609
+
610
+ const int64_t bitrateAfter = this->remoteBitrateEstimator.GetLatestEstimate();
611
+
612
+ REQUIRE(bitrateAfter < bitrateBefore);
613
+ }
614
+
615
+ void RemoteBitrateEstimatorAbsSendTimeTestHelper::OnRemoteBitrateEstimatorAbsSendTimeBitrateChanged(
616
+ RTC::BWE::RemoteBitrateEstimatorAbsSendTime* /*remoteBitrateEstimator*/,
617
+ const std::vector<uint32_t>& /*ssrcs*/,
618
+ int64_t bitrate)
619
+ {
620
+ MS_TRACE();
621
+
622
+ this->latestBitrate = bitrate;
623
+ this->updated = true;
624
+ }
625
+ } // namespace bweHelpers
@@ -66,4 +66,23 @@ SCENARIO("RTCP Feedback PS REMB", "[rtcp][feedback-ps][remb]")
66
66
 
67
67
  verify(&packet);
68
68
  }
69
+
70
+ SECTION("more ssrcs than the packet can count are dropped")
71
+ {
72
+ RTC::RTCP::FeedbackPsRembPacket packet(senderSsrc, mediaSsrc);
73
+
74
+ // One more than fits, since the field that counts them is a single byte.
75
+ std::vector<uint32_t> manySsrcs;
76
+
77
+ manySsrcs.reserve(RTC::RTCP::FeedbackPsRembPacket::MaxNumberOfSsrcs + 1);
78
+
79
+ for (uint32_t ssrc{ 1 }; ssrc <= RTC::RTCP::FeedbackPsRembPacket::MaxNumberOfSsrcs + 1; ++ssrc)
80
+ {
81
+ manySsrcs.push_back(ssrc);
82
+ }
83
+
84
+ packet.SetSsrcs(manySsrcs);
85
+
86
+ REQUIRE(packet.GetSsrcs().size() == RTC::RTCP::FeedbackPsRembPacket::MaxNumberOfSsrcs);
87
+ }
69
88
  }