mediasoup 3.26.0 → 3.27.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.
- package/CHANGELOG.md +11 -0
- package/node/lib/DataConsumer.js +1 -1
- package/node/lib/Router.js +1 -1
- package/node/lib/Transport.js +15 -15
- package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts +2 -6
- package/node/lib/fbs/rtp-parameters/encoding-mapping.d.ts.map +1 -1
- package/node/lib/fbs/rtp-parameters/encoding-mapping.js +7 -19
- package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.d.ts +4 -4
- package/node/lib/fbs/rtp-parameters/rtp-encoding-parameters.js +2 -2
- package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts +5 -5
- package/node/lib/fbs/rtp-stream/bitrate-by-layer.d.ts.map +1 -1
- package/node/lib/fbs/rtp-stream/bitrate-by-layer.js +3 -3
- package/node/lib/fbs/rtp-stream/recv-stats.d.ts +5 -5
- package/node/lib/fbs/rtp-stream/recv-stats.d.ts.map +1 -1
- package/node/lib/fbs/rtp-stream/recv-stats.js +3 -3
- package/node/lib/fbs/rtp-stream/send-stats.d.ts +5 -5
- package/node/lib/fbs/rtp-stream/send-stats.d.ts.map +1 -1
- package/node/lib/fbs/rtp-stream/send-stats.js +3 -3
- package/node/lib/fbs/transport/bwe-trace-info.d.ts +23 -23
- package/node/lib/fbs/transport/bwe-trace-info.d.ts.map +1 -1
- package/node/lib/fbs/transport/bwe-trace-info.js +15 -15
- package/node/lib/fbs/transport/options.d.ts +5 -5
- package/node/lib/fbs/transport/options.js +2 -2
- package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts +5 -5
- package/node/lib/fbs/transport/set-max-incoming-bitrate-request.d.ts.map +1 -1
- package/node/lib/fbs/transport/set-max-incoming-bitrate-request.js +3 -3
- package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts +5 -5
- package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.d.ts.map +1 -1
- package/node/lib/fbs/transport/set-max-outgoing-bitrate-request.js +3 -3
- package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts +5 -5
- package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.d.ts.map +1 -1
- package/node/lib/fbs/transport/set-min-outgoing-bitrate-request.js +3 -3
- package/node/lib/fbs/transport/stats.d.ts +38 -38
- package/node/lib/fbs/transport/stats.d.ts.map +1 -1
- package/node/lib/fbs/transport/stats.js +25 -25
- package/node/lib/ortc.d.ts +0 -1
- package/node/lib/ortc.d.ts.map +1 -1
- package/node/lib/ortc.js +1 -2
- package/node/lib/rtpParametersFbsUtils.d.ts.map +1 -1
- package/node/lib/rtpParametersFbsUtils.js +2 -2
- package/package.json +9 -9
- package/worker/deps/libwebrtc/libwebrtc/call/rtp_transport_controller_send.cc +10 -10
- package/worker/deps/libwebrtc/libwebrtc/mediasoup_helpers.h +6 -6
- package/worker/deps/libwebrtc/libwebrtc/modules/congestion_controller/goog_cc/alr_detector.cc +1 -1
- package/worker/deps/libwebrtc/libwebrtc/modules/pacing/paced_sender.cc +7 -7
- package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h +1 -1
- package/worker/deps/libwebrtc/libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.cc +1 -1
- package/worker/fbs/rtpParameters.fbs +1 -2
- package/worker/fbs/rtpStream.fbs +3 -3
- package/worker/fbs/transport.fbs +23 -23
- package/worker/fuzzer/include/RTC/FuzzerDtlsTransport.hpp +4 -1
- package/worker/fuzzer/src/FuzzerUtils.cpp +5 -3
- package/worker/fuzzer/src/RTC/FuzzerDtlsTransport.cpp +8 -5
- package/worker/fuzzer/src/RTC/FuzzerRateCalculator.cpp +3 -3
- package/worker/fuzzer/src/RTC/FuzzerTrendCalculator.cpp +6 -6
- package/worker/fuzzer/src/RTC/RTCP/FuzzerFeedbackRtpTransport.cpp +3 -3
- package/worker/fuzzer/src/RTC/RTP/FuzzerPacket.cpp +2 -2
- package/worker/fuzzer/src/RTC/RTP/FuzzerRetransmissionBuffer.cpp +5 -5
- package/worker/fuzzer/src/RTC/RTP/FuzzerRtpStreamSend.cpp +3 -3
- package/worker/fuzzer/src/fuzzer.cpp +4 -0
- package/worker/include/Channel/ChannelNotification.hpp +3 -3
- package/worker/include/Channel/ChannelRequest.hpp +1 -1
- package/worker/include/Channel/ChannelSocket.hpp +11 -0
- package/worker/include/DepLibUV.hpp +16 -33
- package/worker/include/RTC/ActiveSpeakerObserver.hpp +11 -11
- package/worker/include/RTC/AudioLevelObserver.hpp +4 -4
- package/worker/include/RTC/BWE/AcknowledgedBitrateEstimatorInterface.hpp +55 -0
- package/worker/include/RTC/BWE/AimdRateControl.hpp +190 -0
- package/worker/include/RTC/BWE/BweTypes.hpp +211 -0
- package/worker/include/RTC/BWE/DelayBasedBwe.hpp +173 -0
- package/worker/include/RTC/BWE/FeedbackAdapter.hpp +72 -0
- package/worker/include/RTC/BWE/InterArrivalDelta.hpp +106 -0
- package/worker/include/RTC/BWE/LinkCapacityEstimator.hpp +84 -0
- package/worker/include/RTC/BWE/RobustThroughputEstimator.hpp +94 -0
- package/worker/include/RTC/BWE/SendPacketHistory.hpp +137 -0
- package/worker/include/RTC/BWE/TrendlineEstimator.hpp +101 -0
- package/worker/include/RTC/Consts.hpp +6 -6
- package/worker/include/RTC/Consumer.hpp +14 -12
- package/worker/include/RTC/DataConsumer.hpp +3 -3
- package/worker/include/RTC/DataProducer.hpp +3 -3
- package/worker/include/RTC/DtlsTransport.hpp +5 -2
- package/worker/include/RTC/ICE/IceCandidate.hpp +2 -2
- package/worker/include/RTC/ICE/IceServer.hpp +3 -3
- package/worker/include/RTC/KeyFrameRequestManager.hpp +3 -3
- package/worker/include/RTC/NEW_RTCP/packet/Packet.hpp +1 -1
- package/worker/include/RTC/NackGenerator.hpp +12 -12
- package/worker/include/RTC/PipeProducerStreamManager.hpp +3 -4
- package/worker/include/RTC/PipeTransport.hpp +18 -5
- package/worker/include/RTC/PlainTransport.hpp +18 -5
- package/worker/include/RTC/PortManager.hpp +4 -4
- package/worker/include/RTC/Producer.hpp +21 -12
- package/worker/include/RTC/ProducerStreamManager.hpp +12 -6
- package/worker/include/RTC/RTCP/Bye.hpp +2 -2
- package/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +4 -4
- package/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp +3 -3
- package/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +54 -39
- package/worker/include/RTC/RTCP/Packet.hpp +3 -3
- package/worker/include/RTC/RTCP/ReceiverReport.hpp +3 -3
- package/worker/include/RTC/RTCP/Sdes.hpp +2 -2
- package/worker/include/RTC/RTCP/XR.hpp +2 -2
- package/worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp +1 -1
- package/worker/include/RTC/RTP/Codecs/H264.hpp +1 -1
- package/worker/include/RTC/RTP/Codecs/Opus.hpp +2 -2
- package/worker/include/RTC/RTP/Codecs/PayloadDescriptorHandler.hpp +3 -3
- package/worker/include/RTC/RTP/Codecs/VP8.hpp +2 -2
- package/worker/include/RTC/RTP/Codecs/VP9.hpp +2 -2
- package/worker/include/RTC/RTP/HeaderExtensionIds.hpp +12 -12
- package/worker/include/RTC/RTP/Packet.hpp +13 -13
- package/worker/include/RTC/RTP/ProbationGenerator.hpp +1 -1
- package/worker/include/RTC/RTP/RetransmissionBuffer.hpp +7 -7
- package/worker/include/RTC/RTP/RtpStream.hpp +37 -51
- package/worker/include/RTC/RTP/RtpStreamRecv.hpp +59 -41
- package/worker/include/RTC/RTP/RtpStreamSend.hpp +20 -14
- package/worker/include/RTC/RTP/RtxStream.hpp +12 -13
- package/worker/include/RTC/RateCalculator.hpp +50 -44
- package/worker/include/RTC/RemoteCaptureTimeEstimator.hpp +5 -4
- package/worker/include/RTC/RemoteClockOffsetEstimator.hpp +11 -11
- package/worker/include/RTC/Router.hpp +6 -0
- package/worker/include/RTC/RtcLogger.hpp +1 -1
- package/worker/include/RTC/RtpDictionaries.hpp +10 -10
- package/worker/include/RTC/SCTP/association/Association.hpp +56 -28
- package/worker/include/RTC/SCTP/association/HeartbeatHandler.hpp +4 -4
- package/worker/include/RTC/SCTP/association/StateCookie.hpp +14 -14
- package/worker/include/RTC/SCTP/association/StreamResetHandler.hpp +2 -2
- package/worker/include/RTC/SCTP/association/TransmissionControlBlock.hpp +12 -12
- package/worker/include/RTC/SCTP/association/TransmissionControlBlockContextInterface.hpp +4 -4
- package/worker/include/RTC/SCTP/packet/TLV.hpp +1 -1
- package/worker/include/RTC/SCTP/packet/parameters/StateCookieParameter.hpp +3 -3
- package/worker/include/RTC/SCTP/public/AssociationInterface.hpp +4 -1
- package/worker/include/RTC/SCTP/public/AssociationMetrics.hpp +1 -1
- package/worker/include/RTC/SCTP/public/SctpOptions.hpp +12 -12
- package/worker/include/RTC/SCTP/public/SctpTypes.hpp +1 -1
- package/worker/include/RTC/SCTP/tx/OutstandingData.hpp +15 -16
- package/worker/include/RTC/SCTP/tx/RetransmissionQueue.hpp +7 -8
- package/worker/include/RTC/SCTP/tx/RetransmissionTimeout.hpp +20 -16
- package/worker/include/RTC/SCTP/tx/RoundRobinSendQueue.hpp +5 -6
- package/worker/include/RTC/SCTP/tx/SendQueueInterface.hpp +2 -2
- package/worker/include/RTC/SCTP/tx/StreamScheduler.hpp +5 -5
- package/worker/include/RTC/SctpDictionaries.hpp +3 -3
- package/worker/include/RTC/Serializable.hpp +1 -1
- package/worker/include/RTC/SimpleProducerStreamManager.hpp +3 -4
- package/worker/include/RTC/SimulcastProducerStreamManager.hpp +6 -7
- package/worker/include/RTC/SvcProducerStreamManager.hpp +6 -5
- package/worker/include/RTC/TcpConnection.hpp +9 -3
- package/worker/include/RTC/TcpServer.hpp +3 -0
- package/worker/include/RTC/Transport.hpp +52 -45
- package/worker/include/RTC/TransportCongestionControlClient.hpp +30 -25
- package/worker/include/RTC/TransportCongestionControlServer.hpp +17 -17
- package/worker/include/RTC/TrendCalculator.hpp +5 -5
- package/worker/include/RTC/UdpSocket.hpp +11 -2
- package/worker/include/RTC/WebRtcServer.hpp +20 -5
- package/worker/include/RTC/WebRtcTransport.hpp +35 -10
- package/worker/include/Settings.hpp +4 -2
- package/worker/include/Shared.hpp +5 -20
- package/worker/include/SharedInterface.hpp +6 -28
- package/worker/include/Utils.hpp +40 -21
- package/worker/include/common.hpp +4 -0
- package/worker/include/handles/BackoffTimerHandle.hpp +4 -4
- package/worker/include/handles/BackoffTimerHandleInterface.hpp +5 -5
- package/worker/include/handles/TcpConnectionHandle.hpp +6 -6
- package/worker/include/handles/TcpServerHandle.hpp +1 -1
- package/worker/include/handles/TimerHandle.hpp +15 -9
- package/worker/include/handles/TimerHandleInterface.hpp +10 -4
- package/worker/include/handles/UdpSocketHandle.hpp +3 -3
- package/worker/include/handles/UnixStreamSocketHandle.hpp +2 -2
- package/worker/meson.build +81 -36
- package/worker/meson_options.txt +1 -0
- package/worker/mocks/include/MockShared.hpp +24 -23
- package/worker/mocks/include/RTC/SCTP/association/MockTransmissionControlBlockContext.hpp +51 -27
- package/worker/mocks/include/RTC/SCTP/tx/MockSendQueue.hpp +11 -11
- package/worker/mocks/include/handles/MockBackoffTimerHandle.hpp +10 -10
- package/worker/mocks/include/handles/MockTimerHandle.hpp +60 -22
- package/worker/mocks/src/MockShared.cpp +51 -5
- package/worker/mocks/src/handles/MockBackoffTimerHandle.cpp +29 -15
- package/worker/mocks/src/handles/MockTimerHandle.cpp +117 -0
- package/worker/scripts/clang-scripts.mjs +2 -2
- package/worker/src/Channel/ChannelNotification.cpp +5 -6
- package/worker/src/Channel/ChannelSocket.cpp +20 -2
- package/worker/src/DepLibUV.cpp +4 -5
- package/worker/src/RTC/ActiveSpeakerObserver.cpp +59 -47
- package/worker/src/RTC/AudioLevelObserver.cpp +7 -7
- package/worker/src/RTC/BWE/AimdRateControl.cpp +468 -0
- package/worker/src/RTC/BWE/BweTypes.cpp +61 -0
- package/worker/src/RTC/BWE/DelayBasedBwe.cpp +275 -0
- package/worker/src/RTC/BWE/FeedbackAdapter.cpp +148 -0
- package/worker/src/RTC/BWE/InterArrivalDelta.cpp +181 -0
- package/worker/src/RTC/BWE/LinkCapacityEstimator.cpp +133 -0
- package/worker/src/RTC/BWE/RobustThroughputEstimator.cpp +245 -0
- package/worker/src/RTC/BWE/SendPacketHistory.cpp +184 -0
- package/worker/src/RTC/BWE/TrendlineEstimator.cpp +233 -0
- package/worker/src/RTC/Consumer.cpp +48 -35
- package/worker/src/RTC/DataConsumer.cpp +4 -4
- package/worker/src/RTC/DataProducer.cpp +3 -3
- package/worker/src/RTC/DirectTransport.cpp +2 -2
- package/worker/src/RTC/DtlsTransport.cpp +14 -11
- package/worker/src/RTC/ICE/IceServer.cpp +2 -2
- package/worker/src/RTC/KeyFrameRequestManager.cpp +16 -12
- package/worker/src/RTC/NackGenerator.cpp +12 -12
- package/worker/src/RTC/PipeProducerStreamManager.cpp +6 -6
- package/worker/src/RTC/PipeTransport.cpp +16 -13
- package/worker/src/RTC/PlainTransport.cpp +25 -16
- package/worker/src/RTC/Producer.cpp +50 -36
- package/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +13 -6
- package/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp +14 -5
- package/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +76 -50
- package/worker/src/RTC/RTP/Codecs/VP8.cpp +1 -1
- package/worker/src/RTC/RTP/Codecs/VP9.cpp +4 -4
- package/worker/src/RTC/RTP/Packet.cpp +9 -10
- package/worker/src/RTC/RTP/RetransmissionBuffer.cpp +6 -6
- package/worker/src/RTC/RTP/RtpStream.cpp +19 -19
- package/worker/src/RTC/RTP/RtpStreamRecv.cpp +146 -81
- package/worker/src/RTC/RTP/RtpStreamSend.cpp +49 -44
- package/worker/src/RTC/RTP/RtxStream.cpp +7 -10
- package/worker/src/RTC/RateCalculator.cpp +99 -136
- package/worker/src/RTC/RemoteCaptureTimeEstimator.cpp +13 -13
- package/worker/src/RTC/RemoteClockOffsetEstimator.cpp +18 -17
- package/worker/src/RTC/Router.cpp +18 -1
- package/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp +5 -2
- package/worker/src/RTC/SCTP/association/Association.cpp +131 -102
- package/worker/src/RTC/SCTP/association/AssociationListenerDeferrer.cpp +4 -4
- package/worker/src/RTC/SCTP/association/Capabilities.cpp +1 -1
- package/worker/src/RTC/SCTP/association/HeartbeatHandler.cpp +25 -18
- package/worker/src/RTC/SCTP/association/StateCookie.cpp +7 -6
- package/worker/src/RTC/SCTP/association/StreamResetHandler.cpp +16 -13
- package/worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp +28 -26
- package/worker/src/RTC/SCTP/packet/chunks/SackChunk.cpp +0 -1
- package/worker/src/RTC/SCTP/packet/parameters/StateCookieParameter.cpp +2 -2
- package/worker/src/RTC/SCTP/public/AssociationMetrics.cpp +1 -1
- package/worker/src/RTC/SCTP/public/SctpOptions.cpp +13 -13
- package/worker/src/RTC/SCTP/rx/DataTracker.cpp +1 -1
- package/worker/src/RTC/SCTP/rx/ReassemblyQueue.cpp +5 -5
- package/worker/src/RTC/SCTP/tx/OutstandingData.cpp +15 -15
- package/worker/src/RTC/SCTP/tx/RetransmissionQueue.cpp +15 -15
- package/worker/src/RTC/SCTP/tx/RetransmissionTimeout.cpp +29 -26
- package/worker/src/RTC/SCTP/tx/RoundRobinSendQueue.cpp +12 -11
- package/worker/src/RTC/SCTP/tx/StreamScheduler.cpp +4 -4
- package/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp +2 -2
- package/worker/src/RTC/SimpleProducerStreamManager.cpp +10 -10
- package/worker/src/RTC/SimulcastProducerStreamManager.cpp +39 -37
- package/worker/src/RTC/SvcProducerStreamManager.cpp +39 -25
- package/worker/src/RTC/TcpConnection.cpp +9 -3
- package/worker/src/RTC/TcpServer.cpp +7 -2
- package/worker/src/RTC/Transport.cpp +242 -302
- package/worker/src/RTC/TransportCongestionControlClient.cpp +78 -71
- package/worker/src/RTC/TransportCongestionControlServer.cpp +38 -40
- package/worker/src/RTC/TrendCalculator.cpp +3 -3
- package/worker/src/RTC/UdpSocket.cpp +14 -3
- package/worker/src/RTC/WebRtcServer.cpp +20 -14
- package/worker/src/RTC/WebRtcTransport.cpp +35 -30
- package/worker/src/Settings.cpp +10 -0
- package/worker/src/Shared.cpp +2 -2
- package/worker/src/Utils/Crypto.cpp +2 -2
- package/worker/src/Worker.cpp +5 -1
- package/worker/src/handles/BackoffTimerHandle.cpp +24 -11
- package/worker/src/handles/TimerHandle.cpp +74 -25
- package/worker/src/lib.cpp +6 -0
- package/worker/tasks.py +171 -44
- package/worker/test/include/RTC/BWE/helpers/LinkSimulator.hpp +117 -0
- package/worker/test/src/RTC/BWE/TestAimdRateControl.cpp +400 -0
- package/worker/test/src/RTC/BWE/TestDelayBasedBwe.cpp +568 -0
- package/worker/test/src/RTC/BWE/TestFeedbackAdapter.cpp +546 -0
- package/worker/test/src/RTC/BWE/TestInterArrivalDelta.cpp +301 -0
- package/worker/test/src/RTC/BWE/TestLinkCapacityEstimator.cpp +115 -0
- package/worker/test/src/RTC/BWE/TestRobustThroughputEstimator.cpp +433 -0
- package/worker/test/src/RTC/BWE/TestSendPacketHistory.cpp +259 -0
- package/worker/test/src/RTC/BWE/TestTrendlineEstimator.cpp +137 -0
- package/worker/test/src/RTC/BWE/helpers/LinkSimulator.cpp +171 -0
- package/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +1 -1
- package/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +1 -1
- package/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +246 -208
- package/worker/test/src/RTC/RTP/TestPacket.cpp +11 -11
- package/worker/test/src/RTC/RTP/TestRetransmissionBuffer.cpp +12 -12
- package/worker/test/src/RTC/RTP/TestRtpStreamRecv.cpp +23 -16
- package/worker/test/src/RTC/RTP/TestRtpStreamSend.cpp +13 -13
- package/worker/test/src/RTC/SCTP/association/TestAssociation.cpp +27 -22
- package/worker/test/src/RTC/SCTP/association/TestHeartbeatHandler.cpp +21 -15
- package/worker/test/src/RTC/SCTP/association/TestStateCookie.cpp +6 -6
- package/worker/test/src/RTC/SCTP/association/TestStreamResetHandler.cpp +17 -13
- package/worker/test/src/RTC/SCTP/association/TestTransmissionControlBlock.cpp +3 -3
- package/worker/test/src/RTC/SCTP/packet/chunks/TestForwardTsnChunk.cpp +2 -2
- package/worker/test/src/RTC/SCTP/packet/chunks/TestIForwardTsnChunk.cpp +23 -23
- package/worker/test/src/RTC/SCTP/packet/chunks/TestInitChunk.cpp +1 -1
- package/worker/test/src/RTC/SCTP/packet/chunks/TestSackChunk.cpp +1 -1
- package/worker/test/src/RTC/SCTP/packet/parameters/TestIPv6AddressParameter.cpp +1 -1
- package/worker/test/src/RTC/SCTP/rx/TestDataTracker.cpp +37 -37
- package/worker/test/src/RTC/SCTP/rx/TestInterleavedReassemblyStreams.cpp +10 -10
- package/worker/test/src/RTC/SCTP/rx/TestReassemblyQueue.cpp +1 -1
- package/worker/test/src/RTC/SCTP/tx/TestOutstandingData.cpp +93 -93
- package/worker/test/src/RTC/SCTP/tx/TestRetransmissionQueue.cpp +247 -247
- package/worker/test/src/RTC/SCTP/tx/TestRetransmissionTimeout.cpp +100 -80
- package/worker/test/src/RTC/SCTP/tx/TestRoundRobinSendQueue.cpp +163 -163
- package/worker/test/src/RTC/SCTP/tx/TestStreamScheduler.cpp +76 -77
- package/worker/test/src/RTC/TestConsumer.cpp +8 -3
- package/worker/test/src/RTC/TestKeyFrameRequestManager.cpp +3 -3
- package/worker/test/src/RTC/TestNackGenerator.cpp +3 -3
- package/worker/test/src/RTC/TestPipeProducerStreamManager.cpp +5 -5
- package/worker/test/src/RTC/TestRateCalculator.cpp +110 -14
- package/worker/test/src/RTC/TestRemoteCaptureTimeEstimator.cpp +22 -17
- package/worker/test/src/RTC/TestRemoteClockOffsetEstimator.cpp +87 -85
- package/worker/test/src/RTC/TestSimpleProducerStreamManager.cpp +54 -47
- package/worker/test/src/RTC/TestSimulcastProducerStreamManager.cpp +83 -69
- package/worker/test/src/RTC/TestSvcProducerStreamManager.cpp +76 -65
- package/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +72 -66
- package/worker/test/src/RTC/TestTransportTuple.cpp +19 -4
- package/worker/test/src/TestDepLibUV.cpp +19 -0
- package/worker/test/src/Utils/TestTime.cpp +57 -26
- package/worker/test/src/testHelpers.cpp +1 -1
- package/worker/test/src/tests.cpp +6 -0
- package/worker/include/RTC/SenderBandwidthEstimator.hpp +0 -118
- package/worker/src/RTC/SenderBandwidthEstimator.cpp +0 -269
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
#include "RTC/RTP/RtpStreamSend.hpp"
|
|
5
5
|
#include "Logger.hpp"
|
|
6
|
+
#include "RTC/RTCP/FeedbackPsFir.hpp"
|
|
7
|
+
#include "RTC/RTCP/FeedbackPsPli.hpp"
|
|
6
8
|
#include "RTC/RtpDictionaries.hpp"
|
|
7
9
|
#include "Utils.hpp"
|
|
8
10
|
#include <vector>
|
|
@@ -14,12 +16,12 @@ namespace RTC
|
|
|
14
16
|
/* Static. */
|
|
15
17
|
|
|
16
18
|
// Limit max number of items in the retransmission buffer.
|
|
17
|
-
static constexpr size_t RetransmissionBufferMaxItems{
|
|
19
|
+
static constexpr size_t RetransmissionBufferMaxItems{ 2500 };
|
|
18
20
|
// 17: 16 bit mask + the initial sequence number.
|
|
19
|
-
static constexpr size_t MaxRequestedPackets{
|
|
21
|
+
static constexpr size_t MaxRequestedPackets{ 17 };
|
|
20
22
|
static thread_local std::vector<RTP::RetransmissionBuffer::Item*> RetransmissionContainer(
|
|
21
23
|
MaxRequestedPackets + 1);
|
|
22
|
-
static constexpr
|
|
24
|
+
static constexpr int64_t DefaultRttMs{ 100 };
|
|
23
25
|
|
|
24
26
|
/* Instance methods. */
|
|
25
27
|
|
|
@@ -36,7 +38,7 @@ namespace RTC
|
|
|
36
38
|
|
|
37
39
|
if (this->params.useNack)
|
|
38
40
|
{
|
|
39
|
-
|
|
41
|
+
int64_t maxRetransmissionDelayMs{ 0 };
|
|
40
42
|
|
|
41
43
|
switch (params.mimeType.type)
|
|
42
44
|
{
|
|
@@ -74,7 +76,7 @@ namespace RTC
|
|
|
74
76
|
{
|
|
75
77
|
MS_TRACE();
|
|
76
78
|
|
|
77
|
-
const
|
|
79
|
+
const int64_t nowMs = this->shared->GetTimeMs();
|
|
78
80
|
|
|
79
81
|
auto baseStats = RTP::RtpStream::FillBufferStats(builder);
|
|
80
82
|
auto stats = FBS::RtpStream::CreateSendStats(
|
|
@@ -82,7 +84,7 @@ namespace RTC
|
|
|
82
84
|
baseStats,
|
|
83
85
|
this->transmissionCounter.GetPacketCount(),
|
|
84
86
|
this->transmissionCounter.GetBytes(),
|
|
85
|
-
this->transmissionCounter.GetBitrate(nowMs));
|
|
87
|
+
static_cast<uint64_t>(this->transmissionCounter.GetBitrate(nowMs)));
|
|
86
88
|
|
|
87
89
|
return FBS::RtpStream::CreateStats(builder, FBS::RtpStream::StatsData::SendStats, stats.Union());
|
|
88
90
|
}
|
|
@@ -270,17 +272,17 @@ namespace RTC
|
|
|
270
272
|
}
|
|
271
273
|
}
|
|
272
274
|
|
|
273
|
-
void RtpStreamSend::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
|
|
275
|
+
void RtpStreamSend::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report, int64_t receivedAtUs)
|
|
274
276
|
{
|
|
275
277
|
MS_TRACE();
|
|
276
278
|
|
|
277
279
|
/* Calculate RTT. */
|
|
278
280
|
|
|
279
|
-
// Get the NTP representation of the
|
|
280
|
-
|
|
281
|
-
auto ntp
|
|
281
|
+
// Get the NTP representation of the time at which the Receiver Report
|
|
282
|
+
// arrived, which is what the round trip is measured against.
|
|
283
|
+
auto ntp = Utils::Time::TimeUs2Ntp(receivedAtUs + this->shared->GetNtpOffsetUs());
|
|
282
284
|
|
|
283
|
-
// Get the compact NTP representation of the
|
|
285
|
+
// Get the compact NTP representation of the arrival time.
|
|
284
286
|
uint32_t compactNtp = (ntp.seconds & 0x0000FFFF) << 16;
|
|
285
287
|
|
|
286
288
|
compactNtp |= (ntp.fractions & 0xFFFF0000) >> 16;
|
|
@@ -289,21 +291,20 @@ namespace RTC
|
|
|
289
291
|
const uint32_t dlsr = report->GetDelaySinceLastSenderReport();
|
|
290
292
|
|
|
291
293
|
// RTT in 1/2^16 second fractions.
|
|
292
|
-
uint32_t
|
|
294
|
+
uint32_t rttCompactNtp{ 0 };
|
|
293
295
|
|
|
294
296
|
// If no Sender Report was received by the remote endpoint yet, ignore lastSr
|
|
295
297
|
// and dlsr values in the Receiver Report.
|
|
296
298
|
if (lastSr && dlsr && (compactNtp > dlsr + lastSr))
|
|
297
299
|
{
|
|
298
|
-
|
|
300
|
+
rttCompactNtp = compactNtp - dlsr - lastSr;
|
|
299
301
|
}
|
|
300
302
|
|
|
301
|
-
|
|
302
|
-
this->
|
|
303
|
-
this->rtt += (static_cast<float>(rtt & 0x0000FFFF) / 65536) * 1000;
|
|
303
|
+
this->rttMs = static_cast<float>(rttCompactNtp >> 16) * 1000;
|
|
304
|
+
this->rttMs += (static_cast<float>(rttCompactNtp & 0x0000FFFF) / 65536) * 1000;
|
|
304
305
|
|
|
305
306
|
// Avoid negative RTT value since it doesn't make sense.
|
|
306
|
-
this->
|
|
307
|
+
this->rttMs = std::max(this->rttMs, 0.0f);
|
|
307
308
|
|
|
308
309
|
this->packetsLost = report->GetTotalLost();
|
|
309
310
|
this->fractionLost = report->GetFractionLost();
|
|
@@ -313,7 +314,8 @@ namespace RTC
|
|
|
313
314
|
UpdateScore(report);
|
|
314
315
|
}
|
|
315
316
|
|
|
316
|
-
void RtpStreamSend::ReceiveRtcpXrReceiverReferenceTime(
|
|
317
|
+
void RtpStreamSend::ReceiveRtcpXrReceiverReferenceTime(
|
|
318
|
+
RTC::RTCP::ReceiverReferenceTime* report, int64_t receivedAtUs)
|
|
317
319
|
{
|
|
318
320
|
MS_TRACE();
|
|
319
321
|
|
|
@@ -322,12 +324,12 @@ namespace RTC
|
|
|
322
324
|
compactNtp += report->GetNtpFrac() >> 16;
|
|
323
325
|
|
|
324
326
|
this->lastReceiverReferenceTime = ReceiverReferenceTime{
|
|
325
|
-
.compactNtp
|
|
326
|
-
.
|
|
327
|
+
.compactNtp = compactNtp,
|
|
328
|
+
.receivedAtUs = receivedAtUs,
|
|
327
329
|
};
|
|
328
330
|
}
|
|
329
331
|
|
|
330
|
-
RTC::RTCP::SenderReport* RtpStreamSend::GetRtcpSenderReport(
|
|
332
|
+
RTC::RTCP::SenderReport* RtpStreamSend::GetRtcpSenderReport(int64_t nowUs)
|
|
331
333
|
{
|
|
332
334
|
MS_TRACE();
|
|
333
335
|
|
|
@@ -338,22 +340,22 @@ namespace RTC
|
|
|
338
340
|
|
|
339
341
|
// A stream that stopped sending cannot tell where its RTP timeline is now, and
|
|
340
342
|
// extrapolating would claim RTP timestamps of packets never sent.
|
|
341
|
-
if (
|
|
343
|
+
if ((nowUs - this->maxPacketAtUs) / 1000 > RtpStreamSend::MaxSenderReportReferenceAgeMs)
|
|
342
344
|
{
|
|
343
345
|
return nullptr;
|
|
344
346
|
}
|
|
345
347
|
|
|
346
|
-
auto ntp = Utils::Time::
|
|
348
|
+
auto ntp = Utils::Time::TimeUs2Ntp(nowUs + this->shared->GetNtpOffsetUs());
|
|
347
349
|
auto* report = new RTC::RTCP::SenderReport();
|
|
348
350
|
|
|
349
351
|
// Calculate TS difference between now and the instant at which the media in the
|
|
350
352
|
// packet holding the highest RTP timestamp was captured, falling back to the
|
|
351
353
|
// instant that packet was seen while the capture instant cannot be told.
|
|
352
|
-
const
|
|
354
|
+
const int64_t referenceUs = this->maxPacketCaptureAtUs.value_or(this->maxPacketAtUs);
|
|
353
355
|
// NOTE: The capture instant is an estimation, so it may land ahead of now.
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const auto rtpTs
|
|
356
|
+
const int64_t diffUs = nowUs > referenceUs ? nowUs - referenceUs : 0;
|
|
357
|
+
const int64_t diffTs = (diffUs * GetClockRate()) / 1000000;
|
|
358
|
+
const auto rtpTs = static_cast<uint32_t>(this->maxPacketTs + diffTs);
|
|
357
359
|
|
|
358
360
|
report->SetSsrc(GetSsrc());
|
|
359
361
|
report->SetPacketCount(this->transmissionCounter.GetPacketCount());
|
|
@@ -363,15 +365,18 @@ namespace RTC
|
|
|
363
365
|
report->SetRtpTs(rtpTs);
|
|
364
366
|
|
|
365
367
|
// Update info about last Sender Report.
|
|
368
|
+
//
|
|
369
|
+
// NOTE: It is the very instant announced in the report above, so that the
|
|
370
|
+
// mapping means the same thing here and in a receive stream.
|
|
366
371
|
this->lastSenderReportMapping = RTP::RtpStream::SenderReportMapping{
|
|
367
|
-
.
|
|
372
|
+
.ntpUs = nowUs + this->shared->GetNtpOffsetUs(),
|
|
368
373
|
.ts = rtpTs,
|
|
369
374
|
};
|
|
370
375
|
|
|
371
376
|
return report;
|
|
372
377
|
}
|
|
373
378
|
|
|
374
|
-
RTC::RTCP::DelaySinceLastRr::SsrcInfo* RtpStreamSend::GetRtcpXrDelaySinceLastRrSsrcInfo(
|
|
379
|
+
RTC::RTCP::DelaySinceLastRr::SsrcInfo* RtpStreamSend::GetRtcpXrDelaySinceLastRrSsrcInfo(int64_t nowUs)
|
|
375
380
|
{
|
|
376
381
|
MS_TRACE();
|
|
377
382
|
|
|
@@ -381,12 +386,12 @@ namespace RTC
|
|
|
381
386
|
}
|
|
382
387
|
|
|
383
388
|
const auto& receiverReferenceTime = this->lastReceiverReferenceTime.value();
|
|
384
|
-
// Get delay in
|
|
385
|
-
|
|
389
|
+
// Get delay in microseconds.
|
|
390
|
+
const int64_t delayUs = nowUs - receiverReferenceTime.receivedAtUs;
|
|
386
391
|
// Express delay in units of 1/65536 seconds.
|
|
387
|
-
|
|
392
|
+
auto dlrr = static_cast<uint32_t>((delayUs / 1000000) << 16);
|
|
388
393
|
|
|
389
|
-
dlrr |= uint32_t
|
|
394
|
+
dlrr |= static_cast<uint32_t>(((delayUs % 1000000) * 65536) / 1000000);
|
|
390
395
|
|
|
391
396
|
auto* ssrcInfo = new RTC::RTCP::DelaySinceLastRr::SsrcInfo();
|
|
392
397
|
|
|
@@ -430,23 +435,23 @@ namespace RTC
|
|
|
430
435
|
MS_TRACE();
|
|
431
436
|
}
|
|
432
437
|
|
|
433
|
-
|
|
434
|
-
|
|
438
|
+
int64_t RtpStreamSend::GetBitrate(
|
|
439
|
+
int64_t /*nowMs*/, uint8_t /*spatialLayer*/, uint8_t /*temporalLayer*/)
|
|
435
440
|
{
|
|
436
441
|
MS_TRACE();
|
|
437
442
|
|
|
438
443
|
MS_ABORT("invalid method call");
|
|
439
444
|
}
|
|
440
445
|
|
|
441
|
-
|
|
446
|
+
int64_t RtpStreamSend::GetSpatialLayerBitrate(int64_t /*nowMs*/, uint8_t /*spatialLayer*/)
|
|
442
447
|
{
|
|
443
448
|
MS_TRACE();
|
|
444
449
|
|
|
445
450
|
MS_ABORT("invalid method call");
|
|
446
451
|
}
|
|
447
452
|
|
|
448
|
-
|
|
449
|
-
|
|
453
|
+
int64_t RtpStreamSend::GetLayerBitrate(
|
|
454
|
+
int64_t /*nowMs*/, uint8_t /*spatialLayer*/, uint8_t /*temporalLayer*/)
|
|
450
455
|
{
|
|
451
456
|
MS_TRACE();
|
|
452
457
|
|
|
@@ -480,9 +485,9 @@ namespace RTC
|
|
|
480
485
|
}
|
|
481
486
|
|
|
482
487
|
// Look for each requested packet.
|
|
483
|
-
const
|
|
484
|
-
const
|
|
485
|
-
uint16_t currentSeq
|
|
488
|
+
const int64_t nowMs = this->shared->GetTimeMs();
|
|
489
|
+
const int64_t rttMs = (this->rttMs > 0.0f ? this->rttMs : DefaultRttMs);
|
|
490
|
+
uint16_t currentSeq = seq;
|
|
486
491
|
bool requested{ true };
|
|
487
492
|
size_t containerIdx{ 0 };
|
|
488
493
|
|
|
@@ -507,14 +512,14 @@ namespace RTC
|
|
|
507
512
|
// Do nothing.
|
|
508
513
|
}
|
|
509
514
|
// Don't resent the packet if it was resent in the last RTT ms.
|
|
510
|
-
else if (item->resentAtMs !=
|
|
515
|
+
else if (item->resentAtMs != 0 && nowMs - item->resentAtMs <= rttMs)
|
|
511
516
|
{
|
|
512
517
|
MS_DEBUG_TAG(
|
|
513
518
|
rtx,
|
|
514
519
|
"ignoring retransmission for a packet already resent in the last RTT ms "
|
|
515
|
-
"[seq:%" PRIu16 ", rtt:%"
|
|
520
|
+
"[seq:%" PRIu16 ", rtt:%" PRIi64 " ms]",
|
|
516
521
|
item->sequenceNumber,
|
|
517
|
-
|
|
522
|
+
rttMs);
|
|
518
523
|
}
|
|
519
524
|
// Stored packet is valid for retransmission. Resend it.
|
|
520
525
|
else
|
|
@@ -57,7 +57,6 @@ namespace RTC
|
|
|
57
57
|
this->started = true;
|
|
58
58
|
this->maxSeq = seq - 1;
|
|
59
59
|
this->maxPacketTs = packet->GetTimestamp();
|
|
60
|
-
this->maxPacketMs = this->shared->GetTimeMs();
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
// If not a valid packet ignore it.
|
|
@@ -76,7 +75,6 @@ namespace RTC
|
|
|
76
75
|
if (Utils::Number::IsHigherThan<uint32_t>(packet->GetTimestamp(), this->maxPacketTs))
|
|
77
76
|
{
|
|
78
77
|
this->maxPacketTs = packet->GetTimestamp();
|
|
79
|
-
this->maxPacketMs = this->shared->GetTimeMs();
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// Increase packet count.
|
|
@@ -141,12 +139,12 @@ namespace RTC
|
|
|
141
139
|
if (this->lastSenderReportTiming.has_value())
|
|
142
140
|
{
|
|
143
141
|
const auto& senderReportTiming = this->lastSenderReportTiming.value();
|
|
144
|
-
// Get delay in
|
|
145
|
-
const
|
|
142
|
+
// Get delay in microseconds.
|
|
143
|
+
const int64_t delayUs = this->shared->GetTimeUs() - senderReportTiming.receivedAtUs;
|
|
146
144
|
// Express delay in units of 1/65536 seconds.
|
|
147
|
-
|
|
145
|
+
auto dlsr = static_cast<uint32_t>((delayUs / 1000000) << 16);
|
|
148
146
|
|
|
149
|
-
dlsr |= uint32_t
|
|
147
|
+
dlsr |= static_cast<uint32_t>(((delayUs % 1000000) * 65536) / 1000000);
|
|
150
148
|
|
|
151
149
|
report->SetDelaySinceLastSenderReport(dlsr);
|
|
152
150
|
report->SetLastSenderReport(senderReportTiming.compactNtp);
|
|
@@ -160,7 +158,7 @@ namespace RTC
|
|
|
160
158
|
return report;
|
|
161
159
|
}
|
|
162
160
|
|
|
163
|
-
void RtxStream::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
|
|
161
|
+
void RtxStream::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report, int64_t receivedAtUs)
|
|
164
162
|
{
|
|
165
163
|
MS_TRACE();
|
|
166
164
|
|
|
@@ -169,8 +167,8 @@ namespace RTC
|
|
|
169
167
|
compactNtp += report->GetNtpFrac() >> 16;
|
|
170
168
|
|
|
171
169
|
this->lastSenderReportTiming = SenderReportTiming{
|
|
172
|
-
.compactNtp
|
|
173
|
-
.
|
|
170
|
+
.compactNtp = compactNtp,
|
|
171
|
+
.receivedAtUs = receivedAtUs,
|
|
174
172
|
};
|
|
175
173
|
}
|
|
176
174
|
|
|
@@ -215,7 +213,6 @@ namespace RTC
|
|
|
215
213
|
InitSeq(seq);
|
|
216
214
|
|
|
217
215
|
this->maxPacketTs = packet->GetTimestamp();
|
|
218
|
-
this->maxPacketMs = this->shared->GetTimeMs();
|
|
219
216
|
}
|
|
220
217
|
else
|
|
221
218
|
{
|
|
@@ -3,129 +3,76 @@
|
|
|
3
3
|
|
|
4
4
|
#include "RTC/RateCalculator.hpp"
|
|
5
5
|
#include "Logger.hpp"
|
|
6
|
-
#include
|
|
7
|
-
#include <
|
|
8
|
-
#include <cstring> // std::memset()
|
|
6
|
+
#include <cmath> // std::trunc()
|
|
7
|
+
#include <limits> // std::numeric_limits()
|
|
9
8
|
|
|
10
9
|
namespace RTC
|
|
11
10
|
{
|
|
12
|
-
RateCalculator::RateCalculator(
|
|
13
|
-
: windowSizeMs(windowSizeMs),
|
|
14
|
-
scale(scale),
|
|
15
|
-
windowItems(windowItems),
|
|
16
|
-
itemSizeMs(std::max(windowSizeMs / windowItems, size_t{ 1 }))
|
|
11
|
+
RateCalculator::RateCalculator(int64_t windowSizeMs, float scale, uint16_t windowItems)
|
|
17
12
|
{
|
|
18
13
|
MS_TRACE();
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
// Clamp the given values so every derived value is safe to use.
|
|
16
|
+
this->windowSizeMs = std::max<int64_t>(windowSizeMs, 1);
|
|
21
17
|
|
|
22
|
-
std::
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const int64_t items = std::max<int64_t>(windowItems, 1);
|
|
19
|
+
|
|
20
|
+
// Item granularity, rounded up so that `items` items always suffice to cover
|
|
21
|
+
// the window.
|
|
22
|
+
this->itemSizeMs = (this->windowSizeMs + items - 1) / items;
|
|
23
|
+
|
|
24
|
+
// Number of items needed to cover the whole window, rounded up. It is never
|
|
25
|
+
// higher than `items`, and it guarantees that in-window data can never
|
|
26
|
+
// overrun the ring. The window it spans overshoots windowSizeMs by less than
|
|
27
|
+
// one item, which is inherent to splitting the window into items.
|
|
28
|
+
this->buffer.resize(
|
|
29
|
+
static_cast<size_t>((this->windowSizeMs + this->itemSizeMs - 1) / this->itemSizeMs));
|
|
30
|
+
|
|
31
|
+
this->rateScale = static_cast<double>(scale) / static_cast<double>(this->windowSizeMs);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
void RateCalculator::Update(size_t size,
|
|
34
|
+
void RateCalculator::Update(size_t size, int64_t nowMs)
|
|
29
35
|
{
|
|
30
36
|
MS_TRACE();
|
|
31
37
|
|
|
32
|
-
// Ignore
|
|
33
|
-
if (
|
|
38
|
+
// Ignore data older than the window. Should never happen.
|
|
39
|
+
if (!SlideWindow(nowMs))
|
|
34
40
|
{
|
|
35
|
-
MS_WARN_DEV("nowMs
|
|
41
|
+
MS_WARN_DEV("given nowMs is older than the current window, ignoring data");
|
|
36
42
|
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
this->bytes += size;
|
|
42
|
-
|
|
43
|
-
RemoveOldData(nowMs);
|
|
44
|
-
|
|
45
|
-
// If the elapsed time from the newest item start time is greater than the
|
|
46
|
-
// item size (in milliseconds), increase the item index.
|
|
47
|
-
if (
|
|
48
|
-
this->newestItemIndex < 0 || !this->newestItemStartTimeMs.has_value() ||
|
|
49
|
-
Utils::Number::IsHigherOrEqualThan<uint64_t>(
|
|
50
|
-
nowMs - *this->newestItemStartTimeMs, this->itemSizeMs))
|
|
51
|
-
{
|
|
52
|
-
this->newestItemIndex++;
|
|
53
|
-
this->newestItemStartTimeMs = nowMs;
|
|
54
|
-
|
|
55
|
-
if (this->newestItemIndex >= this->windowItems)
|
|
56
|
-
{
|
|
57
|
-
MS_DEBUG_DEV("this->newestItemIndex >= this->windowItems, setting this->newestItemIndex = 0");
|
|
58
|
-
|
|
59
|
-
this->newestItemIndex = 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Advance oldestItemIndex if buffer is full.
|
|
63
|
-
// NOTE: This avoids a crash:
|
|
64
|
-
// https://github.com/versatica/mediasoup/issues/1316
|
|
65
|
-
if (this->newestItemIndex == this->oldestItemIndex && this->oldestItemIndex != -1)
|
|
66
|
-
{
|
|
67
|
-
if (++this->oldestItemIndex >= this->windowItems)
|
|
68
|
-
{
|
|
69
|
-
this->oldestItemIndex = 0;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
MS_ASSERT(
|
|
74
|
-
this->newestItemIndex != this->oldestItemIndex || this->oldestItemIndex == -1,
|
|
75
|
-
"newest index overlaps with the oldest one [newestItemIndex:%" PRIi32
|
|
76
|
-
", oldestItemIndex:%" PRIi32 "]",
|
|
77
|
-
this->newestItemIndex,
|
|
78
|
-
this->oldestItemIndex);
|
|
79
|
-
|
|
80
|
-
// Set the newest item.
|
|
81
|
-
BufferItem& item = this->buffer[this->newestItemIndex];
|
|
82
|
-
|
|
83
|
-
item.count = size;
|
|
84
|
-
item.timeMs = nowMs;
|
|
85
|
-
}
|
|
86
|
-
else
|
|
87
|
-
{
|
|
88
|
-
// Update the newest item.
|
|
89
|
-
BufferItem& item = this->buffer[this->newestItemIndex];
|
|
90
|
-
|
|
91
|
-
item.count += size;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Set the oldest item index and time, if not set.
|
|
95
|
-
if (this->oldestItemIndex < 0)
|
|
96
|
-
{
|
|
97
|
-
MS_DEBUG_DEV(
|
|
98
|
-
"this->oldestItemIndex < 0, setting this->oldestItemIndex and this->oldestItemStartTimeMs");
|
|
99
|
-
|
|
100
|
-
this->oldestItemIndex = this->newestItemIndex;
|
|
101
|
-
this->oldestItemStartTimeMs = nowMs;
|
|
102
|
-
}
|
|
103
|
-
|
|
46
|
+
this->buffer[this->newestItemIndex] += size;
|
|
104
47
|
this->totalCount += size;
|
|
105
|
-
|
|
106
|
-
// Reset `lastRate` and `lastTimeMs` so `GetRate()` will calculate rate
|
|
107
|
-
// again even if called with same now in the same loop iteration.
|
|
108
|
-
this->lastRate = 0;
|
|
109
|
-
this->lastTimeMs = std::nullopt;
|
|
48
|
+
this->bytes += size;
|
|
110
49
|
}
|
|
111
50
|
|
|
112
|
-
|
|
51
|
+
int64_t RateCalculator::GetRate(int64_t nowMs)
|
|
113
52
|
{
|
|
114
53
|
MS_TRACE();
|
|
115
54
|
|
|
116
|
-
|
|
55
|
+
// If both keys match, the memoized rate is still exact. `lastRate` is a pure
|
|
56
|
+
// function of `totalCount`, so the value is right, and no expiration can be
|
|
57
|
+
// pending: SlideWindow() already ran for this very `nowMs` and
|
|
58
|
+
// `newestItemStartTimeMs` only moves forward afterwards, while the initial and
|
|
59
|
+
// post Reset() state has an empty ring anyway.
|
|
60
|
+
if (nowMs == this->lastTimeMs && this->totalCount == this->lastTotalCount)
|
|
117
61
|
{
|
|
118
|
-
MS_DEBUG_DEV("
|
|
62
|
+
MS_DEBUG_DEV("nothing changed since the latest call, early return");
|
|
119
63
|
|
|
120
64
|
return this->lastRate;
|
|
121
65
|
}
|
|
122
66
|
|
|
123
|
-
|
|
67
|
+
SlideWindow(nowMs);
|
|
124
68
|
|
|
125
|
-
const
|
|
69
|
+
const double rate = std::trunc((static_cast<double>(this->totalCount) * this->rateScale) + 0.5);
|
|
126
70
|
|
|
127
|
-
|
|
128
|
-
this->
|
|
71
|
+
// NOTE: Must be read after SlideWindow(), which may have expired data.
|
|
72
|
+
this->lastTotalCount = this->totalCount;
|
|
73
|
+
this->lastTimeMs = nowMs;
|
|
74
|
+
this->lastRate =
|
|
75
|
+
static_cast<int64_t>(std::min(rate, static_cast<double>(std::numeric_limits<int64_t>::max())));
|
|
129
76
|
|
|
130
77
|
return this->lastRate;
|
|
131
78
|
}
|
|
@@ -134,73 +81,89 @@ namespace RTC
|
|
|
134
81
|
{
|
|
135
82
|
MS_TRACE();
|
|
136
83
|
|
|
137
|
-
std::
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this->
|
|
143
|
-
this->
|
|
144
|
-
this->
|
|
145
|
-
this->oldestItemIndex = -1;
|
|
146
|
-
this->totalCount = 0u;
|
|
147
|
-
this->lastRate = 0u;
|
|
148
|
-
this->lastTimeMs = std::nullopt;
|
|
84
|
+
std::ranges::fill(this->buffer, 0);
|
|
85
|
+
|
|
86
|
+
this->newestItemIndex = 0;
|
|
87
|
+
this->newestItemStartTimeMs = 0;
|
|
88
|
+
this->totalCount = 0;
|
|
89
|
+
this->lastRate = 0;
|
|
90
|
+
this->lastTimeMs = 0;
|
|
91
|
+
this->lastTotalCount = 0;
|
|
149
92
|
}
|
|
150
93
|
|
|
151
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Expires the items that no longer belong to the window ending at `nowMs`,
|
|
96
|
+
* and makes the item holding `nowMs` the newest one.
|
|
97
|
+
*
|
|
98
|
+
* Returns false if `nowMs` is so far in the past that it lies outside of the
|
|
99
|
+
* window, in which case nothing is modified.
|
|
100
|
+
*/
|
|
101
|
+
bool RateCalculator::SlideWindow(int64_t nowMs)
|
|
152
102
|
{
|
|
153
103
|
MS_TRACE();
|
|
154
104
|
|
|
155
|
-
|
|
105
|
+
// Time elapsed since the newest item started, negative when `nowMs` lies in
|
|
106
|
+
// the past.
|
|
107
|
+
const int64_t elapsedMs = nowMs - this->newestItemStartTimeMs;
|
|
108
|
+
|
|
109
|
+
// `nowMs` is older than the whole window.
|
|
110
|
+
if (elapsedMs <= -this->windowSizeMs)
|
|
156
111
|
{
|
|
157
|
-
return;
|
|
112
|
+
return false;
|
|
158
113
|
}
|
|
159
114
|
|
|
160
|
-
//
|
|
161
|
-
|
|
115
|
+
// `nowMs` belongs to the newest item, or to an already existing one still
|
|
116
|
+
// within the window, so there is nothing to expire.
|
|
117
|
+
if (elapsedMs < this->itemSizeMs)
|
|
162
118
|
{
|
|
163
|
-
return;
|
|
119
|
+
return true;
|
|
164
120
|
}
|
|
165
121
|
|
|
166
|
-
|
|
122
|
+
// NOTE: Positive since `elapsedMs` is not lower than `itemSizeMs` here.
|
|
123
|
+
const int64_t steps = elapsedMs / this->itemSizeMs;
|
|
167
124
|
|
|
168
|
-
//
|
|
169
|
-
if (
|
|
125
|
+
// A whole window elapsed since the newest item, so every item is gone.
|
|
126
|
+
if (std::cmp_greater_equal(steps, this->buffer.size()))
|
|
170
127
|
{
|
|
171
|
-
|
|
172
|
-
}
|
|
128
|
+
MS_DEBUG_DEV("a whole window elapsed, resetting every item");
|
|
173
129
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
130
|
+
// NOTE: totalCount is the sum of every item, so a zero total means that
|
|
131
|
+
// the ring is already zeroed.
|
|
132
|
+
if (this->totalCount != 0)
|
|
133
|
+
{
|
|
134
|
+
std::ranges::fill(this->buffer, 0);
|
|
135
|
+
|
|
136
|
+
this->totalCount = 0;
|
|
137
|
+
}
|
|
180
138
|
|
|
181
|
-
|
|
139
|
+
this->newestItemIndex = 0;
|
|
140
|
+
this->newestItemStartTimeMs = nowMs;
|
|
182
141
|
|
|
183
|
-
return;
|
|
142
|
+
return true;
|
|
184
143
|
}
|
|
185
144
|
|
|
186
|
-
|
|
145
|
+
// Walk the ring forward. Every item being passed holds the count of exactly
|
|
146
|
+
// buffer.size() items ago, which is now out of the window.
|
|
147
|
+
for (int64_t i{ 0 }; i < steps; ++i)
|
|
187
148
|
{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this->totalCount -= oldestItem.count;
|
|
191
|
-
|
|
192
|
-
oldestItem.count = 0u;
|
|
193
|
-
oldestItem.timeMs = 0u;
|
|
194
|
-
|
|
195
|
-
if (++this->oldestItemIndex >= this->windowItems)
|
|
149
|
+
if (++this->newestItemIndex == this->buffer.size())
|
|
196
150
|
{
|
|
197
|
-
this->
|
|
151
|
+
this->newestItemIndex = 0;
|
|
198
152
|
}
|
|
199
153
|
|
|
200
|
-
|
|
154
|
+
this->totalCount -= this->buffer[this->newestItemIndex];
|
|
201
155
|
|
|
202
|
-
this->
|
|
156
|
+
this->buffer[this->newestItemIndex] = 0;
|
|
203
157
|
}
|
|
158
|
+
|
|
159
|
+
// Advance by whole items rather than jumping to `nowMs`. The window is
|
|
160
|
+
// derived from item geometry (buffer.size() * itemSizeMs) instead of from per
|
|
161
|
+
// item timestamps, so absorbing the `elapsedMs % itemSizeMs` remainder here
|
|
162
|
+
// would stretch items past itemSizeMs, making the ring span more time than
|
|
163
|
+
// windowSizeMs and hence over-report the rate.
|
|
164
|
+
this->newestItemStartTimeMs += steps * this->itemSizeMs;
|
|
165
|
+
|
|
166
|
+
return true;
|
|
204
167
|
}
|
|
205
168
|
|
|
206
169
|
void RtpDataCounter::Update(const RTC::RTP::Packet* packet)
|
|
@@ -31,29 +31,29 @@ namespace RTC
|
|
|
31
31
|
rtcp,
|
|
32
32
|
"capture instant source set to %s",
|
|
33
33
|
this->source == RemoteCaptureTimeEstimator::Source::ABS_CAPTURE_TIME ? "abs-capture-time"
|
|
34
|
-
|
|
34
|
+
: "Sender Report");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
void RemoteCaptureTimeEstimator::SenderReportReceived(const RTC::RTP::RtpStreamRecv* rtpStream)
|
|
38
38
|
{
|
|
39
39
|
MS_TRACE();
|
|
40
40
|
|
|
41
|
-
const auto senderReportMapping
|
|
42
|
-
const auto
|
|
41
|
+
const auto senderReportMapping = rtpStream->GetSenderReportMapping();
|
|
42
|
+
const auto senderReportReceivedAtUs = rtpStream->GetSenderReportReceivedAtUs();
|
|
43
43
|
|
|
44
44
|
// Both are stored together, so either both are set or none of them is.
|
|
45
|
-
if (!senderReportMapping.has_value() || !
|
|
45
|
+
if (!senderReportMapping.has_value() || !senderReportReceivedAtUs.has_value())
|
|
46
46
|
{
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
this->clockOffsetEstimator.AddSenderReport(
|
|
51
|
-
senderReportMapping.value().
|
|
52
|
-
|
|
53
|
-
static_cast<
|
|
51
|
+
senderReportMapping.value().ntpUs,
|
|
52
|
+
senderReportReceivedAtUs.value(),
|
|
53
|
+
static_cast<int64_t>(rtpStream->GetRttMs()));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
std::optional<
|
|
56
|
+
std::optional<int64_t> RemoteCaptureTimeEstimator::GetLocalCaptureAtUs(
|
|
57
57
|
const RTC::RTP::RtpStreamRecv* rtpStream, uint32_t ts) const
|
|
58
58
|
{
|
|
59
59
|
MS_TRACE();
|
|
@@ -63,15 +63,15 @@ namespace RTC
|
|
|
63
63
|
return std::nullopt;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const auto
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const auto remoteCaptureAtUs = this->source == RemoteCaptureTimeEstimator::Source::ABS_CAPTURE_TIME
|
|
67
|
+
? rtpStream->GetRemoteCaptureAtUsFromAbsCaptureTime(ts)
|
|
68
|
+
: rtpStream->GetRemoteCaptureAtUsFromSenderReport(ts);
|
|
69
69
|
|
|
70
|
-
if (!
|
|
70
|
+
if (!remoteCaptureAtUs.has_value())
|
|
71
71
|
{
|
|
72
72
|
return std::nullopt;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
return this->clockOffsetEstimator.
|
|
75
|
+
return this->clockOffsetEstimator.RemoteUsToLocalUs(remoteCaptureAtUs.value());
|
|
76
76
|
}
|
|
77
77
|
} // namespace RTC
|