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
@@ -1,6 +1,7 @@
1
1
  #ifndef MS_RTC_WEBRTC_TRANSPORT_HPP
2
2
  #define MS_RTC_WEBRTC_TRANSPORT_HPP
3
3
 
4
+ #include "handles/SendCallbacks.hpp"
4
5
  #include "RTC/DtlsTransport.hpp"
5
6
  #include "RTC/ICE/IceCandidate.hpp"
6
7
  #include "RTC/ICE/IceServer.hpp"
@@ -82,17 +83,15 @@ namespace RTC
82
83
 
83
84
  private:
84
85
  bool IsConnected() const override;
86
+ size_t GetPacketOverhead() const override;
85
87
  void MayRunDtlsTransport();
86
- void SendRtpPacket(
87
- RTC::Consumer* consumer,
88
- RTC::RTP::Packet* packet,
89
- RTC::Transport::onSendCallback* cb = nullptr) override;
88
+ void SendRtpPacket(RTC::Consumer* consumer, RTC::RTP::Packet* packet, onSendCallback cb = {}) override;
90
89
  void SendRtcpPacket(RTC::RTCP::Packet* packet) override;
91
90
  void SendRtcpCompoundPacket(RTC::RTCP::CompoundPacket* packet) override;
92
91
  void SendMessage(
93
92
  RTC::DataConsumer* dataConsumer,
94
93
  RTC::SCTP::Message message,
95
- onQueuedCallback* cb = nullptr) override;
94
+ onMessageQueuedCallback cb = {}) override;
96
95
  bool SendData(const uint8_t* data, size_t len) override;
97
96
  void RecvStreamClosed(uint32_t ssrc) override;
98
97
  void SendStreamClosed(uint32_t ssrc) override;
@@ -41,6 +41,11 @@ public:
41
41
  return DepLibUV::GetTimeUs();
42
42
  }
43
43
 
44
+ uint64_t GetLoopTimeMs() override
45
+ {
46
+ return DepLibUV::GetLoopTimeMs();
47
+ }
48
+
44
49
  int64_t GetNtpOffsetUs() override
45
50
  {
46
51
  return DepLibUV::GetNtpOffsetUs();
@@ -51,6 +51,16 @@ public:
51
51
  */
52
52
  virtual int64_t GetTimeUs() = 0;
53
53
 
54
+ /**
55
+ * Get the time at which the current iteration of the event loop began (ms).
56
+ *
57
+ * @remarks
58
+ * - It stays the same throughout an iteration no matter how long it takes, so it is
59
+ * what tells two iterations apart. The clocks above cannot, since they move while
60
+ * the iteration runs.
61
+ */
62
+ virtual uint64_t GetLoopTimeMs() = 0;
63
+
54
64
  /**
55
65
  * Distance from the clock above to the NTP epoch (us), which is what has to be added
56
66
  * to it to obtain the NTP timestamps of the RTCP we generate.
@@ -515,10 +515,40 @@ namespace Utils
515
515
  uint32_t fractions;
516
516
  };
517
517
 
518
+ /**
519
+ * Convert microseconds into milliseconds.
520
+ *
521
+ * @remarks
522
+ * - The result is rounded to the nearest millisecond, halves upwards.
523
+ */
524
+ static int64_t TimeUsToMs(int64_t timeUs)
525
+ {
526
+ // NOTE: The remainder decides the rounding instead of adding half the
527
+ // divisor first, which would overflow for a time close to the maximum.
528
+ // Integer division truncates towards zero, so a negative remainder is
529
+ // walked down to the next whole millisecond for halves to go upwards
530
+ // there too.
531
+ const int64_t quotient = timeUs / 1000;
532
+ const int64_t remainder = timeUs % 1000;
533
+
534
+ if (remainder >= 500)
535
+ {
536
+ return quotient + 1;
537
+ }
538
+ else if (remainder < -500)
539
+ {
540
+ return quotient - 1;
541
+ }
542
+ else
543
+ {
544
+ return quotient;
545
+ }
546
+ }
547
+
518
548
  /**
519
549
  * Convert microseconds into an NTP timestamp.
520
550
  */
521
- static Time::Ntp TimeUs2Ntp(int64_t timeUs)
551
+ static Time::Ntp TimeUsToNtp(int64_t timeUs)
522
552
  {
523
553
  Time::Ntp ntp{}; // NOLINT(cppcoreguidelines-pro-type-member-init)
524
554
 
@@ -536,7 +566,7 @@ namespace Utils
536
566
  /**
537
567
  * Convert an NTP timestamp into microseconds.
538
568
  */
539
- static int64_t Ntp2TimeUs(Time::Ntp ntp)
569
+ static int64_t NtpToTimeUs(Time::Ntp ntp)
540
570
  {
541
571
  return (
542
572
  (static_cast<int64_t>(ntp.seconds) * 1000000) +
@@ -544,6 +574,45 @@ namespace Utils
544
574
  std::round((static_cast<double>(ntp.fractions) * 1000000) / NtpFractionalUnit)));
545
575
  }
546
576
 
577
+ /**
578
+ * Convert an interval in compact NTP representation (the middle 32 bits of an
579
+ * NTP timestamp, so 1/65536 seconds units) into microseconds.
580
+ *
581
+ * @remarks
582
+ * - The interval is usually the difference between two compact NTP timestamps,
583
+ * which wraps around every 65536 seconds. Values above 0x80000000 are hence
584
+ * taken as negative intervals rather than as intervals of more than 32768
585
+ * seconds.
586
+ * - The result is rounded to the nearest microsecond, halves upwards.
587
+ */
588
+ static int64_t CompactNtpIntervalToTimeUs(uint32_t compactNtpInterval)
589
+ {
590
+ auto value = static_cast<int64_t>(compactNtpInterval);
591
+
592
+ if (compactNtpInterval > 0x80000000)
593
+ {
594
+ value -= (int64_t{ 1 } << 32);
595
+ }
596
+
597
+ // NOTE: Right shifting a negative value rounds towards negative infinity,
598
+ // so adding half the divisor first rounds to the nearest value.
599
+ return ((value * 1000000) + (1 << 15)) >> 16;
600
+ }
601
+
602
+ /**
603
+ * Convert a round trip time in compact NTP representation into microseconds.
604
+ *
605
+ * @remarks
606
+ * - A non-monotonic clock can make the round trip time negative, so a negative
607
+ * value, as well as one too small to be true, yields 1 millisecond.
608
+ */
609
+ static int64_t CompactNtpRttToTimeUs(uint32_t compactNtpRtt)
610
+ {
611
+ static constexpr int64_t MinRttUs{ 1000 };
612
+
613
+ return std::max(CompactNtpIntervalToTimeUs(compactNtpRtt), MinRttUs);
614
+ }
615
+
547
616
  /**
548
617
  * Convert microseconds into the 6.18 fixed point seconds of the
549
618
  * `abs-send-time` RTP header extension, whose resolution is hence 1/262144
@@ -572,7 +641,7 @@ namespace Utils
572
641
  *
573
642
  * @see https://datatracker.ietf.org/doc/html/draft-ietf-avtcore-abs-capture-time-00
574
643
  */
575
- static std::optional<int64_t> TimeUs2Q32x32(int64_t timeUs)
644
+ static std::optional<int64_t> TimeUsToQ32x32(int64_t timeUs)
576
645
  {
577
646
  // The seconds of the format are 32 bits wide, so from here on it does not fit.
578
647
  static constexpr int64_t OutOfRangeUs{ (1LL << 31) * 1000000 };
@@ -29,14 +29,22 @@ typedef SSIZE_T ssize_t;
29
29
  #endif
30
30
  // IWYU pragma: end_exports
31
31
 
32
- // This is a macro to silence false warnings in GCC in switch() blocks with FBS
33
- // types.
32
+ // This is a macro to silence false warnings in switch() blocks that already
33
+ // cover every value of their enum and hence need no default label.
34
+ //
35
+ // GCC warns that the enum is not fully handled (typically with FBS types) and
36
+ // MSVC warns that the function may fall off its end without returning a value,
37
+ // so each of them is told that reaching the default label is impossible.
34
38
  #if defined(__GNUC__) && !defined(__clang__)
35
- #define NO_DEFAULT_GCC() \
39
+ #define NO_DEFAULT() \
36
40
  default: \
37
41
  __builtin_unreachable()
42
+ #elif defined(_MSC_VER)
43
+ #define NO_DEFAULT() \
44
+ default: \
45
+ __assume(0)
38
46
  #else
39
- #define NO_DEFAULT_GCC()
47
+ #define NO_DEFAULT()
40
48
  #endif
41
49
 
42
50
  using ChannelReadCtx = void*;
@@ -0,0 +1,34 @@
1
+ #ifndef MS_SEND_CALLBACKS_HPP
2
+ #define MS_SEND_CALLBACKS_HPP
3
+
4
+ #include "common.hpp"
5
+
6
+ // NOTE: Nothing ever copies one of these, so what they want to be is move only
7
+ // callables. `std::function` is used instead because we are on C++20, and it
8
+ // additionally demands that the callable be copyable, so a lambda capturing
9
+ // anything move only is rejected.
10
+ //
11
+ // TODO: Once we upgrade to C++23, replace both with `std::move_only_function`.
12
+ // Its signature must carry a trailing `const` so that its `operator()` is const
13
+ // and the paths that hold one by const reference keep compiling:
14
+ // using onSendCallback = std::move_only_function<void(bool sent) const>;
15
+ // using onMessageQueuedCallback =
16
+ // std::move_only_function<void(bool queued, bool isSendBufferFull) const>;
17
+
18
+ /**
19
+ * Told whether a packet handed over for sending actually left the socket.
20
+ *
21
+ * It travels by value down the send path and is moved at every step, so it
22
+ * cannot be leaked nor released twice, and any failure path can answer `false`
23
+ * by just invoking it. An empty one means that nobody wants to know, which is
24
+ * the common case, so every send path must tolerate it.
25
+ */
26
+ using onSendCallback = std::function<void(bool sent)>;
27
+
28
+ /**
29
+ * Told whether a message (such as SCTP message) was queued for sending, and
30
+ * whether it was the send buffer being full what kept it from being queued.
31
+ */
32
+ using onMessageQueuedCallback = std::function<void(bool queued, bool isSendBufferFull)>;
33
+
34
+ #endif
@@ -2,14 +2,12 @@
2
2
  #define MS_TCP_CONNECTION_HANDLE_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "handles/SendCallbacks.hpp"
5
6
  #include <uv.h>
6
7
  #include <string>
7
8
 
8
9
  class TcpConnectionHandle
9
10
  {
10
- protected:
11
- using onSendCallback = const std::function<void(bool sent)>;
12
-
13
11
  public:
14
12
  class Listener
15
13
  {
@@ -34,12 +32,11 @@ public:
34
32
  ~UvWriteData()
35
33
  {
36
34
  delete[] this->store;
37
- delete this->cb;
38
35
  }
39
36
 
40
37
  uv_write_t req{};
41
38
  uint8_t* store{ nullptr };
42
- TcpConnectionHandle::onSendCallback* cb{ nullptr };
39
+ onSendCallback cb;
43
40
  };
44
41
 
45
42
  public:
@@ -65,12 +62,7 @@ public:
65
62
  return this->uvHandle;
66
63
  }
67
64
  bool Start() noexcept;
68
- void Write(
69
- const uint8_t* data1,
70
- size_t len1,
71
- const uint8_t* data2,
72
- size_t len2,
73
- TcpConnectionHandle::onSendCallback* cb);
65
+ void Write(const uint8_t* data1, size_t len1, const uint8_t* data2, size_t len2, onSendCallback cb);
74
66
  void ErrorReceiving();
75
67
  const struct sockaddr* GetLocalAddress() const
76
68
  {
@@ -117,7 +109,7 @@ private:
117
109
  public:
118
110
  void OnUvReadAlloc(size_t suggestedSize, uv_buf_t* buf);
119
111
  void OnUvRead(ssize_t nread, const uv_buf_t* buf);
120
- void OnUvWrite(int status, onSendCallback* cb);
112
+ void OnUvWrite(int status, const onSendCallback& cb);
121
113
 
122
114
  /* Pure virtual methods that must be implemented by the subclass. */
123
115
  protected:
@@ -2,14 +2,12 @@
2
2
  #define MS_UDP_SOCKET_HANDLE_HPP
3
3
 
4
4
  #include "common.hpp"
5
+ #include "handles/SendCallbacks.hpp"
5
6
  #include <uv.h>
6
7
  #include <string>
7
8
 
8
9
  class UdpSocketHandle
9
10
  {
10
- protected:
11
- using onSendCallback = const std::function<void(bool sent)>;
12
-
13
11
  public:
14
12
  /* Struct for the data field of uv_req_t when sending a datagram. */
15
13
  struct UvSendData
@@ -24,12 +22,11 @@ public:
24
22
  ~UvSendData()
25
23
  {
26
24
  delete[] this->store;
27
- delete this->cb;
28
25
  }
29
26
 
30
27
  uv_udp_send_t req{};
31
28
  uint8_t* store{ nullptr };
32
- UdpSocketHandle::onSendCallback* cb{ nullptr };
29
+ onSendCallback cb;
33
30
  };
34
31
 
35
32
  public:
@@ -47,8 +44,7 @@ public:
47
44
  return this->closed;
48
45
  }
49
46
  void Dump(int indentation = 0) const;
50
- void Send(
51
- const uint8_t* data, size_t len, const struct sockaddr* addr, UdpSocketHandle::onSendCallback* cb);
47
+ void Send(const uint8_t* data, size_t len, const struct sockaddr* addr, onSendCallback cb);
52
48
  const struct sockaddr* GetLocalAddress() const
53
49
  {
54
50
  return reinterpret_cast<const struct sockaddr*>(std::addressof(this->localAddr));
@@ -86,7 +82,7 @@ private:
86
82
  public:
87
83
  void OnUvRecvAlloc(size_t suggestedSize, uv_buf_t* buf);
88
84
  void OnUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags);
89
- void OnUvSend(int status, UdpSocketHandle::onSendCallback* cb);
85
+ void OnUvSend(int status, const onSendCallback& cb);
90
86
 
91
87
  /* Pure virtual methods that must be implemented by the subclass. */
92
88
  protected:
@@ -23,6 +23,11 @@ if host_machine.system() == 'windows'
23
23
  '-D_SCL_SECURE_NO_WARNINGS',
24
24
  # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage.
25
25
  '-D_ENABLE_EXTENDED_ALIGNED_STORAGE',
26
+ # Don't warn about flexible array members (a C99 feature that C++ lacks and
27
+ # every compiler offers as an extension). They are how RTP and RTCP headers
28
+ # give a name to the bytes that follow them, so their length is part of the
29
+ # parsing arithmetic and cannot be declared.
30
+ '/wd4200',
26
31
  ]
27
32
  endif
28
33
 
@@ -44,6 +49,12 @@ if get_option('ms_rtc_logger_rtp')
44
49
  ]
45
50
  endif
46
51
 
52
+ if get_option('ms_rtc_logger_send_burst')
53
+ cpp_args += [
54
+ '-DMS_RTC_LOGGER_SEND_BURST',
55
+ ]
56
+ endif
57
+
47
58
  if get_option('ms_dump_rtp_payload_descriptor')
48
59
  cpp_args += [
49
60
  '-DMS_DUMP_RTP_PAYLOAD_DESCRIPTOR',
@@ -132,7 +143,8 @@ common_sources = [
132
143
  'src/RTC/RemoteCaptureTimeEstimator.cpp',
133
144
  'src/RTC/RemoteClockOffsetEstimator.cpp',
134
145
  'src/RTC/Router.cpp',
135
- 'src/RTC/RtcLogger.cpp',
146
+ 'src/RTC/RtcLogger/RtpPacket.cpp',
147
+ 'src/RTC/RtcLogger/SendBurst.cpp',
136
148
  'src/RTC/RtpListener.cpp',
137
149
  'src/RTC/RtpObserver.cpp',
138
150
  'src/RTC/SctpListener.cpp',
@@ -164,17 +176,30 @@ common_sources = [
164
176
  'src/RTC/RtpDictionaries/RtpRtxParameters.cpp',
165
177
  'src/RTC/SctpDictionaries/SctpStreamParameters.cpp',
166
178
  'src/RTC/BWE/AimdRateControl.cpp',
179
+ 'src/RTC/BWE/AlrDetector.cpp',
180
+ 'src/RTC/BWE/BitrateProber.cpp',
181
+ 'src/RTC/BWE/BitrateUtils.cpp',
167
182
  'src/RTC/BWE/BweTypes.cpp',
168
183
  'src/RTC/BWE/DelayBasedBwe.cpp',
169
184
  'src/RTC/BWE/FeedbackAdapter.cpp',
185
+ 'src/RTC/BWE/InterArrival.cpp',
170
186
  'src/RTC/BWE/InterArrivalDelta.cpp',
187
+ 'src/RTC/BWE/IntervalBudget.cpp',
171
188
  'src/RTC/BWE/LinkCapacityEstimator.cpp',
172
189
  'src/RTC/BWE/LossBasedController.cpp',
190
+ 'src/RTC/BWE/OveruseDetector.cpp',
191
+ 'src/RTC/BWE/OveruseEstimator.cpp',
192
+ 'src/RTC/BWE/ProbeBitrateEstimator.cpp',
193
+ 'src/RTC/BWE/ProbeController.cpp',
194
+ 'src/RTC/BWE/ProbePacketGenerator.cpp',
195
+ 'src/RTC/BWE/ProbingScheduler.cpp',
196
+ 'src/RTC/BWE/RembGenerator.cpp',
197
+ 'src/RTC/BWE/RemoteBitrateEstimatorAbsSendTime.cpp',
173
198
  'src/RTC/BWE/RobustThroughputEstimator.cpp',
174
199
  'src/RTC/BWE/SendPacketHistory.cpp',
175
200
  'src/RTC/BWE/TargetRateController.cpp',
201
+ 'src/RTC/BWE/TransportWideCcFeedbackGenerator.cpp',
176
202
  'src/RTC/BWE/TrendlineEstimator.cpp',
177
- 'src/RTC/BWE/Utils.cpp',
178
203
  'src/RTC/ICE/IceCandidate.cpp',
179
204
  'src/RTC/ICE/IceServer.cpp',
180
205
  'src/RTC/ICE/StunPacket.cpp',
@@ -473,17 +498,30 @@ test_sources = [
473
498
  'test/src/RTC/TestTransportTuple.cpp',
474
499
  'test/src/RTC/TestTrendCalculator.cpp',
475
500
  'test/src/RTC/BWE/helpers/LinkSimulator.cpp',
501
+ 'test/src/RTC/BWE/helpers/RemoteBitrateEstimatorAbsSendTimeTestHelper.cpp',
476
502
  'test/src/RTC/BWE/TestAimdRateControl.cpp',
503
+ 'test/src/RTC/BWE/TestAlrDetector.cpp',
504
+ 'test/src/RTC/BWE/TestBitrateProber.cpp',
505
+ 'test/src/RTC/BWE/TestBitrateUtils.cpp',
477
506
  'test/src/RTC/BWE/TestDelayBasedBwe.cpp',
478
507
  'test/src/RTC/BWE/TestFeedbackAdapter.cpp',
508
+ 'test/src/RTC/BWE/TestInterArrival.cpp',
479
509
  'test/src/RTC/BWE/TestInterArrivalDelta.cpp',
510
+ 'test/src/RTC/BWE/TestIntervalBudget.cpp',
480
511
  'test/src/RTC/BWE/TestLinkCapacityEstimator.cpp',
481
512
  'test/src/RTC/BWE/TestLossBasedController.cpp',
513
+ 'test/src/RTC/BWE/TestOveruseDetector.cpp',
514
+ 'test/src/RTC/BWE/TestProbeBitrateEstimator.cpp',
515
+ 'test/src/RTC/BWE/TestProbeController.cpp',
516
+ 'test/src/RTC/BWE/TestProbePacketGenerator.cpp',
517
+ 'test/src/RTC/BWE/TestProbingScheduler.cpp',
518
+ 'test/src/RTC/BWE/TestRembGenerator.cpp',
519
+ 'test/src/RTC/BWE/TestRemoteBitrateEstimatorAbsSendTime.cpp',
482
520
  'test/src/RTC/BWE/TestRobustThroughputEstimator.cpp',
483
521
  'test/src/RTC/BWE/TestSendPacketHistory.cpp',
484
522
  'test/src/RTC/BWE/TestTargetRateController.cpp',
523
+ 'test/src/RTC/BWE/TestTransportWideCcFeedbackGenerator.cpp',
485
524
  'test/src/RTC/BWE/TestTrendlineEstimator.cpp',
486
- 'test/src/RTC/BWE/TestUtils.cpp',
487
525
  'test/src/RTC/ICE/iceCommon.cpp',
488
526
  'test/src/RTC/ICE/TestStunPacket.cpp',
489
527
  'test/src/RTC/RTP/rtpCommon.cpp',
@@ -1,6 +1,7 @@
1
1
  option('ms_log_trace', type: 'boolean', value: false, description: 'Logs the current method/function if current log level is "debug"')
2
2
  option('ms_log_file_line', type: 'boolean', value: false, description: 'Logging macros print more verbose information, including current file and line')
3
3
  option('ms_rtc_logger_rtp', type: 'boolean', value: false, description: 'Prints a line with information for each processed RTP packet')
4
+ option('ms_rtc_logger_send_burst', type: 'boolean', value: false, description: 'Prints how many RTP packets each transport sends within a single iteration of the event loop')
4
5
  option('ms_dump_rtp_payload_descriptor', type: 'boolean', value: false, description: 'RTC::RTP::Packet::Dump() method also dumps payload descriptor details')
5
6
  option('ms_dump_rtp_shared_packet_memory_usage', type: 'boolean', value: false, description: 'prints information about total memory allocated by RTC::RTP::SharedPacket instances')
6
7
  option('ms_build_tests', type: 'boolean', value: false, description: 'Must be enabled when building mediasoup worker tests')
@@ -46,8 +46,22 @@ namespace mocks
46
46
  return this->getTimeUs();
47
47
  }
48
48
 
49
- // NOTE: The NTP epoch is made to be the very clock given by argument, so that tests
50
- // can reason about a single set of values.
49
+ /**
50
+ * @remarks
51
+ * - There is no event loop here, and the clock given by argument only moves when the
52
+ * test moves it, which is the very semantics of a time that stays put for the whole
53
+ * iteration.
54
+ */
55
+ uint64_t GetLoopTimeMs() override
56
+ {
57
+ return static_cast<uint64_t>(GetTimeMs());
58
+ }
59
+
60
+ /**
61
+ * @remarks
62
+ * - The NTP epoch is made to be the very clock given by argument, so that tests can
63
+ * reason about a single set of values.
64
+ */
51
65
  int64_t GetNtpOffsetUs() override
52
66
  {
53
67
  return 0;
@@ -133,7 +133,7 @@ namespace mocks
133
133
  return std::min<int64_t>(timeoutMs, BackoffTimerHandleInterface::MaxTimeoutMs);
134
134
  }
135
135
 
136
- NO_DEFAULT_GCC();
136
+ NO_DEFAULT();
137
137
  }
138
138
  }
139
139
 
@@ -21,9 +21,9 @@
21
21
  }
22
22
  },
23
23
  "node_modules/brace-expansion": {
24
- "version": "5.0.9",
25
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz",
26
- "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==",
24
+ "version": "5.0.12",
25
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
26
+ "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "balanced-match": "^4.0.2"
@@ -105,9 +105,9 @@
105
105
  "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="
106
106
  },
107
107
  "brace-expansion": {
108
- "version": "5.0.9",
109
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz",
110
- "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==",
108
+ "version": "5.0.12",
109
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
110
+ "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
111
111
  "requires": {
112
112
  "balanced-match": "^4.0.2"
113
113
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "RTC/BWE/AimdRateControl.hpp"
5
5
  #include "Logger.hpp"
6
+ #include "RTC/Consts.hpp"
6
7
  #include <cmath>
7
8
 
8
9
  namespace RTC
@@ -21,8 +22,6 @@ namespace RTC
21
22
  // Bounds of how often the bitrate may be reduced, derived from the RTT.
22
23
  static constexpr int64_t MinBitrateReductionIntervalUs{ 10 * 1000 };
23
24
  static constexpr int64_t MaxBitrateReductionIntervalUs{ 200 * 1000 };
24
- // Bitrate the target is never taken below unless configured otherwise (bps).
25
- static constexpr int64_t CongestionControllerMinBitrate{ 5000 };
26
25
  // Bitrate the target starts from before anything has been measured (bps).
27
26
  static constexpr int64_t MaxConfiguredBitrate{ 30000 * 1000 };
28
27
  // Headroom allowed on top of the measured throughput when increasing (bps).
@@ -64,7 +63,7 @@ namespace RTC
64
63
 
65
64
  AimdRateControl::AimdRateControl(AimdRateControlOptions options)
66
65
  : options(options),
67
- minConfiguredBitrate(CongestionControllerMinBitrate),
66
+ minConfiguredBitrate(Consts::BweMinBitrate),
68
67
  maxConfiguredBitrate(MaxConfiguredBitrate),
69
68
  currentBitrate(this->maxConfiguredBitrate),
70
69
  latestEstimatedThroughput(this->currentBitrate),
@@ -358,7 +357,7 @@ namespace RTC
358
357
  break;
359
358
  }
360
359
 
361
- NO_DEFAULT_GCC();
360
+ NO_DEFAULT();
362
361
  }
363
362
 
364
363
  this->currentBitrate = ClampBitrate(newBitrate.value_or(this->currentBitrate));
@@ -398,7 +397,7 @@ namespace RTC
398
397
  break;
399
398
  }
400
399
 
401
- NO_DEFAULT_GCC();
400
+ NO_DEFAULT();
402
401
  }
403
402
  }
404
403
 
@@ -0,0 +1,80 @@
1
+ #define MS_CLASS "RTC::BWE::AlrDetector"
2
+ // #define MS_LOG_DEV_LEVEL 3
3
+
4
+ #include "RTC/BWE/AlrDetector.hpp"
5
+ #include "Logger.hpp"
6
+ #include "RTC/BWE/BitrateUtils.hpp"
7
+
8
+ namespace RTC
9
+ {
10
+ namespace BWE
11
+ {
12
+ /* Instance methods. */
13
+
14
+ AlrDetector::AlrDetector(SharedInterface* shared) : AlrDetector(shared, AlrDetectorOptions{})
15
+ {
16
+ MS_TRACE();
17
+ }
18
+
19
+ AlrDetector::AlrDetector(SharedInterface* shared, AlrDetectorOptions options)
20
+ : shared(shared),
21
+ options(options),
22
+ // What an interval leaves unspent builds up, since not filling the link
23
+ // is precisely a state that has to accumulate to be noticed.
24
+ alrBudget(/*initialTargetBitrate*/ 0, /*canBuildUpUnderuse*/ true)
25
+ {
26
+ MS_TRACE();
27
+ }
28
+
29
+ void AlrDetector::OnBytesSent(int64_t bytesSent, int64_t sentAtUs)
30
+ {
31
+ MS_TRACE();
32
+
33
+ // How long those bytes took to go out is unknown until there is a previous
34
+ // send to measure them against.
35
+ if (!this->lastSentAtUs.has_value())
36
+ {
37
+ this->lastSentAtUs = sentAtUs;
38
+
39
+ return;
40
+ }
41
+
42
+ const int64_t deltaTimeUs = sentAtUs - this->lastSentAtUs.value();
43
+
44
+ this->lastSentAtUs = sentAtUs;
45
+
46
+ this->alrBudget.UseBudget(bytesSent);
47
+ this->alrBudget.IncreaseBudget(deltaTimeUs);
48
+
49
+ const double budgetRatio = this->alrBudget.GetBudgetRatio();
50
+
51
+ if (budgetRatio > this->options.startBudgetLevelRatio && !this->alrStartTimeUs.has_value())
52
+ {
53
+ // The instant this state began is what the rest of the module reasons
54
+ // about, so it's the current one and not that of the send that revealed
55
+ // it.
56
+ this->alrStartTimeUs = this->shared->GetTimeUs();
57
+
58
+ MS_DEBUG_DEV("sender is not filling the link [budgetRatio:%f]", budgetRatio);
59
+ }
60
+ else if (budgetRatio < this->options.stopBudgetLevelRatio && this->alrStartTimeUs.has_value())
61
+ {
62
+ this->alrStartTimeUs.reset();
63
+
64
+ MS_DEBUG_DEV("sender is filling the link again [budgetRatio:%f]", budgetRatio);
65
+ }
66
+ }
67
+
68
+ void AlrDetector::SetEstimatedBitrate(int64_t bitrate)
69
+ {
70
+ MS_TRACE();
71
+
72
+ // NOTE: The target this comes from is clamped to the minimum bitrate of
73
+ // the congestion controller, so anything else is a programming error.
74
+ MS_ASSERT(bitrate > 0, "bitrate must be positive [bitrate:%" PRIi64 "]", bitrate);
75
+
76
+ this->alrBudget.SetTargetBitrate(
77
+ BitrateUtils::ApplyBitrateFactor(bitrate, this->options.bandwidthUsageRatio));
78
+ }
79
+ } // namespace BWE
80
+ } // namespace RTC