From ff17d135957513aff86d45d99e82ffce45187318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Wed, 2 Mar 2022 10:41:30 +0100 Subject: [PATCH] Use more efficient collections (#782) * Replace `std::map` with `std::unordered_map` in all places where applicable * Replace most of `std::map/set/unordered_map/unordered_set` with more efficient collections from abseil-cpp Taken from 'memory optimizations' branch to make it more readable and concise. Co-authored-by: Nazar Mokrynskyi --- worker/include/Channel/ChannelRequest.hpp | 4 ++-- worker/include/DepUsrSCTP.hpp | 4 ++-- .../include/PayloadChannel/Notification.hpp | 4 ++-- .../PayloadChannel/PayloadChannelRequest.hpp | 4 ++-- worker/include/RTC/ActiveSpeakerObserver.hpp | 4 ++-- worker/include/RTC/AudioLevelObserver.hpp | 4 ++-- worker/include/RTC/Consumer.hpp | 4 ++-- worker/include/RTC/DtlsTransport.hpp | 8 +++---- worker/include/RTC/KeyFrameRequestManager.hpp | 6 +++--- worker/include/RTC/NackGenerator.hpp | 8 ++++--- worker/include/RTC/Parameters.hpp | 4 ++-- worker/include/RTC/PipeConsumer.hpp | 8 +++---- worker/include/RTC/PlainTransport.hpp | 6 +++--- worker/include/RTC/PortManager.hpp | 6 +++--- worker/include/RTC/Producer.hpp | 13 ++++++------ worker/include/RTC/RTCP/Feedback.hpp | 3 ++- .../include/RTC/RTCP/FeedbackRtpTransport.hpp | 2 +- worker/include/RTC/RTCP/Packet.hpp | 4 ++-- worker/include/RTC/RTCP/Sdes.hpp | 3 +-- worker/include/RTC/Router.hpp | 21 ++++++++++--------- worker/include/RTC/RtpDictionaries.hpp | 21 +++++++++---------- worker/include/RTC/RtpPacket.hpp | 6 +++--- .../include/RTC/SenderBandwidthEstimator.hpp | 2 +- worker/include/RTC/SimulcastConsumer.hpp | 2 +- worker/include/RTC/Transport.hpp | 14 ++++++------- worker/include/RTC/WebRtcTransport.hpp | 4 ++-- worker/include/Settings.hpp | 6 +++--- worker/include/Worker.hpp | 4 ++-- worker/include/handles/TcpServerHandler.hpp | 4 ++-- worker/meson.build | 2 ++ worker/src/Channel/ChannelRequest.cpp | 2 +- worker/src/DepUsrSCTP.cpp | 2 +- worker/src/PayloadChannel/Notification.cpp | 2 +- .../PayloadChannel/PayloadChannelRequest.cpp | 2 +- worker/src/RTC/AudioLevelObserver.cpp | 2 +- worker/src/RTC/DtlsTransport.cpp | 6 +++--- worker/src/RTC/NackGenerator.cpp | 6 +++--- worker/src/RTC/PlainTransport.cpp | 4 ++-- worker/src/RTC/PortManager.cpp | 4 ++-- worker/src/RTC/Producer.cpp | 1 + worker/src/RTC/RTCP/Feedback.cpp | 4 ++-- worker/src/RTC/RTCP/FeedbackRtpTransport.cpp | 2 +- worker/src/RTC/RTCP/Packet.cpp | 2 +- worker/src/RTC/RTCP/Sdes.cpp | 2 +- worker/src/RTC/RtpDictionaries/Media.cpp | 4 ++-- .../RTC/RtpDictionaries/RtpCodecMimeType.cpp | 8 +++---- .../RtpDictionaries/RtpHeaderExtensionUri.cpp | 2 +- .../src/RTC/RtpDictionaries/RtpParameters.cpp | 8 +++---- worker/src/Settings.cpp | 7 +++---- worker/src/lib.cpp | 4 ++-- 50 files changed, 131 insertions(+), 128 deletions(-) diff --git a/worker/include/Channel/ChannelRequest.hpp b/worker/include/Channel/ChannelRequest.hpp index 6e421418e6..cca5dda3fc 100644 --- a/worker/include/Channel/ChannelRequest.hpp +++ b/worker/include/Channel/ChannelRequest.hpp @@ -2,9 +2,9 @@ #define MS_CHANNEL_REQUEST_HPP #include "common.hpp" +#include #include #include -#include using json = nlohmann::json; @@ -75,7 +75,7 @@ namespace Channel }; private: - static std::unordered_map string2MethodId; + static absl::flat_hash_map string2MethodId; public: ChannelRequest(Channel::ChannelSocket* channel, json& jsonRequest); diff --git a/worker/include/DepUsrSCTP.hpp b/worker/include/DepUsrSCTP.hpp index 2ab0688793..b7df08620b 100644 --- a/worker/include/DepUsrSCTP.hpp +++ b/worker/include/DepUsrSCTP.hpp @@ -4,7 +4,7 @@ #include "common.hpp" #include "RTC/SctpAssociation.hpp" #include "handles/Timer.hpp" -#include +#include class DepUsrSCTP { @@ -42,7 +42,7 @@ class DepUsrSCTP thread_local static Checker* checker; static uint64_t numSctpAssociations; static uintptr_t nextSctpAssociationId; - static std::unordered_map mapIdSctpAssociation; + static absl::flat_hash_map mapIdSctpAssociation; }; #endif diff --git a/worker/include/PayloadChannel/Notification.hpp b/worker/include/PayloadChannel/Notification.hpp index 79cbac7023..585a6704e9 100644 --- a/worker/include/PayloadChannel/Notification.hpp +++ b/worker/include/PayloadChannel/Notification.hpp @@ -2,9 +2,9 @@ #define MS_PAYLOAD_CHANNEL_NOTIFICATION_HPP #include "common.hpp" +#include #include #include -#include using json = nlohmann::json; @@ -24,7 +24,7 @@ namespace PayloadChannel static bool IsNotification(json& jsonNotification); private: - static std::unordered_map string2EventId; + static absl::flat_hash_map string2EventId; public: explicit Notification(json& jsonNotification); diff --git a/worker/include/PayloadChannel/PayloadChannelRequest.hpp b/worker/include/PayloadChannel/PayloadChannelRequest.hpp index e1fceedcca..c4e44ee0d6 100644 --- a/worker/include/PayloadChannel/PayloadChannelRequest.hpp +++ b/worker/include/PayloadChannel/PayloadChannelRequest.hpp @@ -2,9 +2,9 @@ #define MS_PAYLOAD_CHANNEL_REQUEST_HPP #include "common.hpp" +#include #include #include -#include using json = nlohmann::json; @@ -26,7 +26,7 @@ namespace PayloadChannel static bool IsRequest(json& jsonRequest); private: - static std::unordered_map string2MethodId; + static absl::flat_hash_map string2MethodId; public: PayloadChannelRequest(PayloadChannel::PayloadChannelSocket* channel, json& jsonRequest); diff --git a/worker/include/RTC/ActiveSpeakerObserver.hpp b/worker/include/RTC/ActiveSpeakerObserver.hpp index 81d2e4cfdb..23709ab595 100644 --- a/worker/include/RTC/ActiveSpeakerObserver.hpp +++ b/worker/include/RTC/ActiveSpeakerObserver.hpp @@ -3,8 +3,8 @@ #include "RTC/RtpObserver.hpp" #include "handles/Timer.hpp" +#include #include -#include #include #include @@ -89,7 +89,7 @@ namespace RTC std::string dominantId{ "" }; Timer* periodicTimer{ nullptr }; uint16_t interval{ 300u }; - std::unordered_map mapProducerSpeaker; + absl::flat_hash_map mapProducerSpeaker; uint64_t lastLevelIdleTime{ 0 }; }; } // namespace RTC diff --git a/worker/include/RTC/AudioLevelObserver.hpp b/worker/include/RTC/AudioLevelObserver.hpp index f6dfb8a4fa..6500ecaae6 100644 --- a/worker/include/RTC/AudioLevelObserver.hpp +++ b/worker/include/RTC/AudioLevelObserver.hpp @@ -3,8 +3,8 @@ #include "RTC/RtpObserver.hpp" #include "handles/Timer.hpp" +#include #include -#include using json = nlohmann::json; @@ -48,7 +48,7 @@ namespace RTC // Allocated by this. Timer* periodicTimer{ nullptr }; // Others. - std::unordered_map mapProducerDBovs; + absl::flat_hash_map mapProducerDBovs; bool silence{ true }; }; } // namespace RTC diff --git a/worker/include/RTC/Consumer.hpp b/worker/include/RTC/Consumer.hpp index 5ebc0daadc..425c655baa 100644 --- a/worker/include/RTC/Consumer.hpp +++ b/worker/include/RTC/Consumer.hpp @@ -14,9 +14,9 @@ #include "RTC/RtpPacket.hpp" #include "RTC/RtpStream.hpp" #include "RTC/RtpStreamSend.hpp" +#include #include #include -#include #include using json = nlohmann::json; @@ -182,7 +182,7 @@ namespace RTC struct RTC::RtpHeaderExtensionIds rtpHeaderExtensionIds; const std::vector* producerRtpStreamScores{ nullptr }; // Others. - std::unordered_set supportedCodecPayloadTypes; + absl::flat_hash_set supportedCodecPayloadTypes; uint64_t lastRtcpSentTime{ 0u }; uint16_t maxRtcpInterval{ 0u }; bool externallyManagedBitrate{ false }; diff --git a/worker/include/RTC/DtlsTransport.hpp b/worker/include/RTC/DtlsTransport.hpp index 53d9ab9b2e..9cf922351e 100644 --- a/worker/include/RTC/DtlsTransport.hpp +++ b/worker/include/RTC/DtlsTransport.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -144,9 +144,9 @@ namespace RTC thread_local static EVP_PKEY* privateKey; thread_local static SSL_CTX* sslCtx; thread_local static uint8_t sslReadBuffer[]; - static std::map string2Role; - static std::map string2FingerprintAlgorithm; - static std::map fingerprintAlgorithm2String; + static absl::flat_hash_map string2Role; + static absl::flat_hash_map string2FingerprintAlgorithm; + static absl::flat_hash_map fingerprintAlgorithm2String; thread_local static std::vector localFingerprints; static std::vector srtpCryptoSuites; diff --git a/worker/include/RTC/KeyFrameRequestManager.hpp b/worker/include/RTC/KeyFrameRequestManager.hpp index c1eb65a4ea..d3d52c6b34 100644 --- a/worker/include/RTC/KeyFrameRequestManager.hpp +++ b/worker/include/RTC/KeyFrameRequestManager.hpp @@ -2,7 +2,7 @@ #define MS_KEY_FRAME_REQUEST_MANAGER_HPP #include "handles/Timer.hpp" -#include +#include namespace RTC { @@ -122,8 +122,8 @@ namespace RTC private: Listener* listener{ nullptr }; uint32_t keyFrameRequestDelay{ 0u }; // 0 means disabled. - std::map mapSsrcPendingKeyFrameInfo; - std::map mapSsrcKeyFrameRequestDelayer; + absl::flat_hash_map mapSsrcPendingKeyFrameInfo; + absl::flat_hash_map mapSsrcKeyFrameRequestDelayer; }; } // namespace RTC diff --git a/worker/include/RTC/NackGenerator.hpp b/worker/include/RTC/NackGenerator.hpp index 845d8df9d5..34d3c1c419 100644 --- a/worker/include/RTC/NackGenerator.hpp +++ b/worker/include/RTC/NackGenerator.hpp @@ -5,6 +5,8 @@ #include "RTC/RtpPacket.hpp" #include "RTC/SeqManager.hpp" #include "handles/Timer.hpp" +#include +#include #include #include #include @@ -75,9 +77,9 @@ namespace RTC // Allocated by this. Timer* timer{ nullptr }; // Others. - std::map::SeqLowerThan> nackList; - std::set::SeqLowerThan> keyFrameList; - std::set::SeqLowerThan> recoveredList; + absl::btree_map::SeqLowerThan> nackList; + absl::btree_set::SeqLowerThan> keyFrameList; + absl::btree_set::SeqLowerThan> recoveredList; bool started{ false }; uint16_t lastSeq{ 0u }; // Seq number of last valid packet. uint32_t rtt{ 0u }; // Round trip time (ms). diff --git a/worker/include/RTC/Parameters.hpp b/worker/include/RTC/Parameters.hpp index d096a284bf..eb7cd8f188 100644 --- a/worker/include/RTC/Parameters.hpp +++ b/worker/include/RTC/Parameters.hpp @@ -2,9 +2,9 @@ #define MS_RTC_PARAMETERS_HPP #include "common.hpp" +#include #include #include -#include #include using json = nlohmann::json; @@ -78,7 +78,7 @@ namespace RTC const std::vector& GetArrayOfIntegers(const std::string& key) const; private: - std::unordered_map mapKeyValues; + absl::flat_hash_map mapKeyValues; }; } // namespace RTC diff --git a/worker/include/RTC/PipeConsumer.hpp b/worker/include/RTC/PipeConsumer.hpp index 1918c0640f..56f6fa0d62 100644 --- a/worker/include/RTC/PipeConsumer.hpp +++ b/worker/include/RTC/PipeConsumer.hpp @@ -60,11 +60,11 @@ namespace RTC // Allocated by this. std::vector rtpStreams; // Others. - std::unordered_map mapMappedSsrcSsrc; - std::unordered_map mapSsrcRtpStream; + absl::flat_hash_map mapMappedSsrcSsrc; + absl::flat_hash_map mapSsrcRtpStream; bool keyFrameSupported{ false }; - std::unordered_map mapRtpStreamSyncRequired; - std::unordered_map> mapRtpStreamRtpSeqManager; + absl::flat_hash_map mapRtpStreamSyncRequired; + absl::flat_hash_map> mapRtpStreamRtpSeqManager; }; } // namespace RTC diff --git a/worker/include/RTC/PlainTransport.hpp b/worker/include/RTC/PlainTransport.hpp index 9f63bac171..0522be51aa 100644 --- a/worker/include/RTC/PlainTransport.hpp +++ b/worker/include/RTC/PlainTransport.hpp @@ -5,7 +5,7 @@ #include "RTC/Transport.hpp" #include "RTC/TransportTuple.hpp" #include "RTC/UdpSocket.hpp" -#include +#include namespace RTC { @@ -19,8 +19,8 @@ namespace RTC }; private: - static std::map string2SrtpCryptoSuite; - static std::map srtpCryptoSuite2String; + static absl::flat_hash_map string2SrtpCryptoSuite; + static absl::flat_hash_map srtpCryptoSuite2String; static size_t srtpMasterLength; public: diff --git a/worker/include/RTC/PortManager.hpp b/worker/include/RTC/PortManager.hpp index 04f350b01e..ca925ef46f 100644 --- a/worker/include/RTC/PortManager.hpp +++ b/worker/include/RTC/PortManager.hpp @@ -4,9 +4,9 @@ #include "common.hpp" #include "Settings.hpp" #include +#include #include #include -#include #include namespace RTC @@ -54,8 +54,8 @@ namespace RTC static std::vector& GetPorts(Transport transport, const std::string& ip); private: - thread_local static std::unordered_map> mapUdpIpPorts; - thread_local static std::unordered_map> mapTcpIpPorts; + thread_local static absl::flat_hash_map> mapUdpIpPorts; + thread_local static absl::flat_hash_map> mapTcpIpPorts; }; } // namespace RTC diff --git a/worker/include/RTC/Producer.hpp b/worker/include/RTC/Producer.hpp index 64f74a343d..f52d132ea5 100644 --- a/worker/include/RTC/Producer.hpp +++ b/worker/include/RTC/Producer.hpp @@ -12,7 +12,6 @@ #include "RTC/RtpHeaderExtensionIds.hpp" #include "RTC/RtpPacket.hpp" #include "RTC/RtpStreamRecv.hpp" -#include #include #include #include @@ -55,7 +54,7 @@ namespace RTC private: struct RtpMapping { - std::map codecs; + absl::flat_hash_map codecs; std::vector encodings; }; @@ -113,7 +112,7 @@ namespace RTC { return this->paused; } - const std::map& GetRtpStreams() + const absl::flat_hash_map& GetRtpStreams() { return this->mapRtpStreamMappedSsrc; } @@ -161,7 +160,7 @@ namespace RTC // Passed by argument. RTC::Producer::Listener* listener{ nullptr }; // Allocated by this. - std::map mapSsrcRtpStream; + absl::flat_hash_map mapSsrcRtpStream; RTC::KeyFrameRequestManager* keyFrameRequestManager{ nullptr }; // Others. RTC::Media::Kind kind; @@ -170,9 +169,9 @@ namespace RTC struct RtpMapping rtpMapping; std::vector rtpStreamByEncodingIdx; std::vector rtpStreamScores; - std::map mapRtxSsrcRtpStream; - std::map mapRtpStreamMappedSsrc; - std::map mapMappedSsrcSsrc; + absl::flat_hash_map mapRtxSsrcRtpStream; + absl::flat_hash_map mapRtpStreamMappedSsrc; + absl::flat_hash_map mapMappedSsrcSsrc; struct RTC::RtpHeaderExtensionIds rtpHeaderExtensionIds; bool paused{ false }; RTC::RtpPacket* currentRtpPacket{ nullptr }; diff --git a/worker/include/RTC/RTCP/Feedback.hpp b/worker/include/RTC/RTCP/Feedback.hpp index a51ba17b70..2fab054645 100644 --- a/worker/include/RTC/RTCP/Feedback.hpp +++ b/worker/include/RTC/RTCP/Feedback.hpp @@ -4,6 +4,7 @@ #include "common.hpp" #include "RTC/RTCP/FeedbackItem.hpp" #include "RTC/RTCP/Packet.hpp" +#include namespace RTC { @@ -27,7 +28,7 @@ namespace RTC static const std::string& MessageType2String(typename T::MessageType type); private: - static std::map type2String; + static absl::flat_hash_map type2String; public: typename T::MessageType GetMessageType() const diff --git a/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp b/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp index 763f565fb7..d23ea69dec 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp @@ -197,7 +197,7 @@ namespace RTC static FeedbackRtpTransportPacket* Parse(const uint8_t* data, size_t len); private: - static std::map status2String; + static absl::flat_hash_map status2String; public: FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc) diff --git a/worker/include/RTC/RTCP/Packet.hpp b/worker/include/RTC/RTCP/Packet.hpp index 53c0b7dd97..bf771fad22 100644 --- a/worker/include/RTC/RTCP/Packet.hpp +++ b/worker/include/RTC/RTCP/Packet.hpp @@ -2,7 +2,7 @@ #define MS_RTC_RTCP_PACKET_HPP #include "common.hpp" -#include +#include #include namespace RTC @@ -72,7 +72,7 @@ namespace RTC static const std::string& Type2String(Type type); private: - static std::map type2String; + static absl::flat_hash_map type2String; public: explicit Packet(Type type) : type(type) diff --git a/worker/include/RTC/RTCP/Sdes.hpp b/worker/include/RTC/RTCP/Sdes.hpp index 2b195aa78a..79a021a41f 100644 --- a/worker/include/RTC/RTCP/Sdes.hpp +++ b/worker/include/RTC/RTCP/Sdes.hpp @@ -3,7 +3,6 @@ #include "common.hpp" #include "RTC/RTCP/Packet.hpp" -#include #include #include @@ -77,7 +76,7 @@ namespace RTC std::unique_ptr raw; private: - static std::map type2String; + static absl::flat_hash_map type2String; }; class SdesChunk diff --git a/worker/include/RTC/Router.hpp b/worker/include/RTC/Router.hpp index abaebeaf32..02b331b42d 100644 --- a/worker/include/RTC/Router.hpp +++ b/worker/include/RTC/Router.hpp @@ -13,9 +13,9 @@ #include "RTC/RtpPacket.hpp" #include "RTC/RtpStream.hpp" #include "RTC/Transport.hpp" +#include #include #include -#include #include using json = nlohmann::json; @@ -93,16 +93,17 @@ namespace RTC private: // Allocated by this. - std::unordered_map mapTransports; - std::unordered_map mapRtpObservers; + absl::flat_hash_map mapTransports; + absl::flat_hash_map mapRtpObservers; // Others. - std::unordered_map> mapProducerConsumers; - std::unordered_map mapConsumerProducer; - std::unordered_map> mapProducerRtpObservers; - std::unordered_map mapProducers; - std::unordered_map> mapDataProducerDataConsumers; - std::unordered_map mapDataConsumerDataProducer; - std::unordered_map mapDataProducers; + absl::flat_hash_map> mapProducerConsumers; + absl::flat_hash_map mapConsumerProducer; + absl::flat_hash_map> mapProducerRtpObservers; + absl::flat_hash_map mapProducers; + absl::flat_hash_map> + mapDataProducerDataConsumers; + absl::flat_hash_map mapDataConsumerDataProducer; + absl::flat_hash_map mapDataProducers; }; } // namespace RTC diff --git a/worker/include/RTC/RtpDictionaries.hpp b/worker/include/RTC/RtpDictionaries.hpp index 00185c6dee..3204165128 100644 --- a/worker/include/RTC/RtpDictionaries.hpp +++ b/worker/include/RTC/RtpDictionaries.hpp @@ -3,10 +3,9 @@ #include "common.hpp" #include "RTC/Parameters.hpp" -#include +#include #include #include -#include #include using json = nlohmann::json; @@ -29,8 +28,8 @@ namespace RTC static const std::string& GetString(Kind kind); private: - static std::unordered_map string2Kind; - static std::map kind2String; + static absl::flat_hash_map string2Kind; + static absl::flat_hash_map kind2String; }; class RtpCodecMimeType @@ -75,10 +74,10 @@ namespace RTC }; public: - static std::unordered_map string2Type; - static std::map type2String; - static std::unordered_map string2Subtype; - static std::map subtype2String; + static absl::flat_hash_map string2Type; + static absl::flat_hash_map type2String; + static absl::flat_hash_map string2Subtype; + static absl::flat_hash_map subtype2String; public: RtpCodecMimeType() = default; @@ -145,7 +144,7 @@ namespace RTC }; private: - static std::unordered_map string2Type; + static absl::flat_hash_map string2Type; public: static Type GetType(std::string& uri); @@ -269,8 +268,8 @@ namespace RTC static std::string& GetTypeString(Type type); private: - static std::unordered_map string2Type; - static std::map type2String; + static absl::flat_hash_map string2Type; + static absl::flat_hash_map type2String; public: RtpParameters() = default; diff --git a/worker/include/RTC/RtpPacket.hpp b/worker/include/RTC/RtpPacket.hpp index ba0f01331f..2d200fb78f 100644 --- a/worker/include/RTC/RtpPacket.hpp +++ b/worker/include/RTC/RtpPacket.hpp @@ -4,7 +4,7 @@ #include "common.hpp" #include "Utils.hpp" #include "RTC/Codecs/PayloadDescriptorHandler.hpp" -#include +#include #include #include #include @@ -611,8 +611,8 @@ namespace RTC Header* header{ nullptr }; uint8_t* csrcList{ nullptr }; HeaderExtension* headerExtension{ nullptr }; - std::map mapOneByteExtensions; - std::map mapTwoBytesExtensions; + absl::btree_map mapOneByteExtensions; + absl::btree_map mapTwoBytesExtensions; uint8_t midExtensionId{ 0u }; uint8_t ridExtensionId{ 0u }; uint8_t rridExtensionId{ 0u }; diff --git a/worker/include/RTC/SenderBandwidthEstimator.hpp b/worker/include/RTC/SenderBandwidthEstimator.hpp index 7496cc1f55..68fb189669 100644 --- a/worker/include/RTC/SenderBandwidthEstimator.hpp +++ b/worker/include/RTC/SenderBandwidthEstimator.hpp @@ -102,7 +102,7 @@ namespace RTC uint32_t initialAvailableBitrate{ 0u }; uint32_t availableBitrate{ 0u }; uint64_t lastAvailableBitrateEventAtMs{ 0u }; - std::map::SeqLowerThan> sentInfos; + absl::btree_map::SeqLowerThan> sentInfos; float rtt{ 0 }; // Round trip time in ms. CummulativeResult cummulativeResult; CummulativeResult probationCummulativeResult; diff --git a/worker/include/RTC/SimulcastConsumer.hpp b/worker/include/RTC/SimulcastConsumer.hpp index 5193d9b5ba..4b53add6ce 100644 --- a/worker/include/RTC/SimulcastConsumer.hpp +++ b/worker/include/RTC/SimulcastConsumer.hpp @@ -97,7 +97,7 @@ namespace RTC // Allocated by this. RTC::RtpStreamSend* rtpStream{ nullptr }; // Others. - std::unordered_map mapMappedSsrcSpatialLayer; + absl::flat_hash_map mapMappedSsrcSpatialLayer; std::vector rtpStreams; std::vector producerRtpStreams; // Indexed by spatial layer. bool syncRequired{ false }; diff --git a/worker/include/RTC/Transport.hpp b/worker/include/RTC/Transport.hpp index ecfaf73424..d1195504a1 100644 --- a/worker/include/RTC/Transport.hpp +++ b/worker/include/RTC/Transport.hpp @@ -26,9 +26,9 @@ #include "RTC/TransportCongestionControlClient.hpp" #include "RTC/TransportCongestionControlServer.hpp" #include "handles/Timer.hpp" +#include #include #include -#include using json = nlohmann::json; @@ -273,12 +273,12 @@ namespace RTC // Passed by argument. Listener* listener{ nullptr }; // Allocated by this. - std::unordered_map mapProducers; - std::unordered_map mapConsumers; - std::unordered_map mapDataProducers; - std::unordered_map mapDataConsumers; - std::unordered_map mapSsrcConsumer; - std::unordered_map mapRtxSsrcConsumer; + absl::flat_hash_map mapProducers; + absl::flat_hash_map mapConsumers; + absl::flat_hash_map mapDataProducers; + absl::flat_hash_map mapDataConsumers; + absl::flat_hash_map mapSsrcConsumer; + absl::flat_hash_map mapRtxSsrcConsumer; Timer* rtcpTimer{ nullptr }; RTC::TransportCongestionControlClient* tccClient{ nullptr }; RTC::TransportCongestionControlServer* tccServer{ nullptr }; diff --git a/worker/include/RTC/WebRtcTransport.hpp b/worker/include/RTC/WebRtcTransport.hpp index d8e8003422..bcaed162af 100644 --- a/worker/include/RTC/WebRtcTransport.hpp +++ b/worker/include/RTC/WebRtcTransport.hpp @@ -110,8 +110,8 @@ namespace RTC // Allocated by this. RTC::IceServer* iceServer{ nullptr }; // Map of UdpSocket/TcpServer and local announced IP (if any). - std::unordered_map udpSockets; - std::unordered_map tcpServers; + absl::flat_hash_map udpSockets; + absl::flat_hash_map tcpServers; RTC::DtlsTransport* dtlsTransport{ nullptr }; RTC::SrtpSession* srtpRecvSession{ nullptr }; RTC::SrtpSession* srtpSendSession{ nullptr }; diff --git a/worker/include/Settings.hpp b/worker/include/Settings.hpp index c4225c7892..445cde97a2 100644 --- a/worker/include/Settings.hpp +++ b/worker/include/Settings.hpp @@ -4,7 +4,7 @@ #include "common.hpp" #include "LogLevel.hpp" #include "Channel/ChannelRequest.hpp" -#include +#include #include #include @@ -54,8 +54,8 @@ class Settings thread_local static struct Configuration configuration; private: - static std::map string2LogLevel; - static std::map logLevel2String; + static absl::flat_hash_map string2LogLevel; + static absl::flat_hash_map logLevel2String; }; #endif diff --git a/worker/include/Worker.hpp b/worker/include/Worker.hpp index 85ec27dc5f..bbed438e4e 100644 --- a/worker/include/Worker.hpp +++ b/worker/include/Worker.hpp @@ -9,9 +9,9 @@ #include "PayloadChannel/PayloadChannelSocket.hpp" #include "RTC/Router.hpp" #include "handles/SignalsHandler.hpp" +#include #include #include -#include using json = nlohmann::json; @@ -55,7 +55,7 @@ class Worker : public Channel::ChannelSocket::Listener, PayloadChannel::PayloadChannelSocket* payloadChannel{ nullptr }; // Allocated by this. SignalsHandler* signalsHandler{ nullptr }; - std::unordered_map mapRouters; + absl::flat_hash_map mapRouters; // Others. bool closed{ false }; }; diff --git a/worker/include/handles/TcpServerHandler.hpp b/worker/include/handles/TcpServerHandler.hpp index b3e72418b1..7c5ddc400c 100644 --- a/worker/include/handles/TcpServerHandler.hpp +++ b/worker/include/handles/TcpServerHandler.hpp @@ -4,8 +4,8 @@ #include "common.hpp" #include "handles/TcpConnectionHandler.hpp" #include +#include #include -#include class TcpServerHandler : public TcpConnectionHandler::Listener { @@ -68,7 +68,7 @@ class TcpServerHandler : public TcpConnectionHandler::Listener // Allocated by this (may be passed by argument). uv_tcp_t* uvHandle{ nullptr }; // Others. - std::unordered_set connections; + absl::flat_hash_set connections; bool closed{ false }; }; diff --git a/worker/meson.build b/worker/meson.build index eefb2d514b..b9e0294910 100644 --- a/worker/meson.build +++ b/worker/meson.build @@ -196,6 +196,7 @@ libwebrtc_include_directories = include_directories('include') subdir('deps/libwebrtc') dependencies = [ + abseil_cpp_proj.get_variable('absl_container_dep'), openssl_proj.get_variable('openssl_dep'), nlohmann_json_proj.get_variable('nlohmann_json_dep'), libuv_proj.get_variable('libuv_dep'), @@ -205,6 +206,7 @@ dependencies = [ ] link_whole = [ + abseil_cpp_proj.get_variable('absl_container_lib'), openssl_proj.get_variable('libcrypto_lib'), openssl_proj.get_variable('libssl_lib'), libuv_proj.get_variable('libuv'), diff --git a/worker/src/Channel/ChannelRequest.cpp b/worker/src/Channel/ChannelRequest.cpp index 1e40aab5d2..1171900f91 100644 --- a/worker/src/Channel/ChannelRequest.cpp +++ b/worker/src/Channel/ChannelRequest.cpp @@ -11,7 +11,7 @@ namespace Channel /* Class variables. */ // clang-format off - std::unordered_map ChannelRequest::string2MethodId = + absl::flat_hash_map ChannelRequest::string2MethodId = { { "worker.close", ChannelRequest::MethodId::WORKER_CLOSE }, { "worker.dump", ChannelRequest::MethodId::WORKER_DUMP }, diff --git a/worker/src/DepUsrSCTP.cpp b/worker/src/DepUsrSCTP.cpp index ed75cb264a..c7ef6d1e8e 100644 --- a/worker/src/DepUsrSCTP.cpp +++ b/worker/src/DepUsrSCTP.cpp @@ -55,7 +55,7 @@ inline static void sctpDebug(const char* format, ...) thread_local DepUsrSCTP::Checker* DepUsrSCTP::checker{ nullptr }; uint64_t DepUsrSCTP::numSctpAssociations{ 0u }; uintptr_t DepUsrSCTP::nextSctpAssociationId{ 0u }; -std::unordered_map DepUsrSCTP::mapIdSctpAssociation; +absl::flat_hash_map DepUsrSCTP::mapIdSctpAssociation; /* Static methods. */ diff --git a/worker/src/PayloadChannel/Notification.cpp b/worker/src/PayloadChannel/Notification.cpp index 7a04c136ca..3f259129e3 100644 --- a/worker/src/PayloadChannel/Notification.cpp +++ b/worker/src/PayloadChannel/Notification.cpp @@ -11,7 +11,7 @@ namespace PayloadChannel /* Class variables. */ // clang-format off - std::unordered_map Notification::string2EventId = + absl::flat_hash_map Notification::string2EventId = { { "transport.sendRtcp", Notification::EventId::TRANSPORT_SEND_RTCP }, { "producer.send", Notification::EventId::PRODUCER_SEND }, diff --git a/worker/src/PayloadChannel/PayloadChannelRequest.cpp b/worker/src/PayloadChannel/PayloadChannelRequest.cpp index 141b51a87f..d53a668941 100644 --- a/worker/src/PayloadChannel/PayloadChannelRequest.cpp +++ b/worker/src/PayloadChannel/PayloadChannelRequest.cpp @@ -12,7 +12,7 @@ namespace PayloadChannel /* Class variables. */ // clang-format off - std::unordered_map PayloadChannelRequest::string2MethodId = + absl::flat_hash_map PayloadChannelRequest::string2MethodId = { { "dataConsumer.send", PayloadChannelRequest::MethodId::DATA_CONSUMER_SEND }, }; diff --git a/worker/src/RTC/AudioLevelObserver.cpp b/worker/src/RTC/AudioLevelObserver.cpp index 3afc29eb1f..7a58381ec6 100644 --- a/worker/src/RTC/AudioLevelObserver.cpp +++ b/worker/src/RTC/AudioLevelObserver.cpp @@ -146,7 +146,7 @@ namespace RTC { MS_TRACE(); - std::map mapDBovsProducer; + absl::btree_map mapDBovsProducer; for (auto& kv : this->mapProducerDBovs) { diff --git a/worker/src/RTC/DtlsTransport.cpp b/worker/src/RTC/DtlsTransport.cpp index a4b187c058..234520b89a 100644 --- a/worker/src/RTC/DtlsTransport.cpp +++ b/worker/src/RTC/DtlsTransport.cpp @@ -83,7 +83,7 @@ namespace RTC thread_local SSL_CTX* DtlsTransport::sslCtx{ nullptr }; thread_local uint8_t DtlsTransport::sslReadBuffer[SslReadBufferSize]; // clang-format off - std::map DtlsTransport::string2FingerprintAlgorithm = + absl::flat_hash_map DtlsTransport::string2FingerprintAlgorithm = { { "sha-1", DtlsTransport::FingerprintAlgorithm::SHA1 }, { "sha-224", DtlsTransport::FingerprintAlgorithm::SHA224 }, @@ -91,7 +91,7 @@ namespace RTC { "sha-384", DtlsTransport::FingerprintAlgorithm::SHA384 }, { "sha-512", DtlsTransport::FingerprintAlgorithm::SHA512 } }; - std::map DtlsTransport::fingerprintAlgorithm2String = + absl::flat_hash_map DtlsTransport::fingerprintAlgorithm2String = { { DtlsTransport::FingerprintAlgorithm::SHA1, "sha-1" }, { DtlsTransport::FingerprintAlgorithm::SHA224, "sha-224" }, @@ -99,7 +99,7 @@ namespace RTC { DtlsTransport::FingerprintAlgorithm::SHA384, "sha-384" }, { DtlsTransport::FingerprintAlgorithm::SHA512, "sha-512" } }; - std::map DtlsTransport::string2Role = + absl::flat_hash_map DtlsTransport::string2Role = { { "auto", DtlsTransport::Role::AUTO }, { "client", DtlsTransport::Role::CLIENT }, diff --git a/worker/src/RTC/NackGenerator.cpp b/worker/src/RTC/NackGenerator.cpp index 15e27d2f7f..b48ca388a5 100644 --- a/worker/src/RTC/NackGenerator.cpp +++ b/worker/src/RTC/NackGenerator.cpp @@ -152,18 +152,18 @@ namespace RTC // clear it and request a keyframe. uint16_t numNewNacks = seqEnd - seqStart; - if (this->nackList.size() + numNewNacks > MaxNackPackets) + if (static_cast(this->nackList.size()) + numNewNacks > MaxNackPackets) { // clang-format off while ( RemoveNackItemsUntilKeyFrame() && - this->nackList.size() + numNewNacks > MaxNackPackets + static_cast(this->nackList.size()) + numNewNacks > MaxNackPackets ) // clang-format on { } - if (this->nackList.size() + numNewNacks > MaxNackPackets) + if (static_cast(this->nackList.size()) + numNewNacks > MaxNackPackets) { MS_WARN_TAG( rtx, "NACK list full, clearing it and requesting a key frame [seqEnd:%" PRIu16 "]", seqEnd); diff --git a/worker/src/RTC/PlainTransport.cpp b/worker/src/RTC/PlainTransport.cpp index c88e6a7088..830fd0d9ca 100644 --- a/worker/src/RTC/PlainTransport.cpp +++ b/worker/src/RTC/PlainTransport.cpp @@ -14,12 +14,12 @@ namespace RTC // NOTE: PlainTransport allows AES_CM_128_HMAC_SHA1_80 and // AES_CM_128_HMAC_SHA1_32 SRTP crypto suites. // clang-format off - std::map PlainTransport::string2SrtpCryptoSuite = + absl::flat_hash_map PlainTransport::string2SrtpCryptoSuite = { { "AES_CM_128_HMAC_SHA1_80", RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80 }, { "AES_CM_128_HMAC_SHA1_32", RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_32 } }; - std::map PlainTransport::srtpCryptoSuite2String = + absl::flat_hash_map PlainTransport::srtpCryptoSuite2String = { { RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80, "AES_CM_128_HMAC_SHA1_80" }, { RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_32, "AES_CM_128_HMAC_SHA1_32" } diff --git a/worker/src/RTC/PortManager.cpp b/worker/src/RTC/PortManager.cpp index 0862312733..a032a05d70 100644 --- a/worker/src/RTC/PortManager.cpp +++ b/worker/src/RTC/PortManager.cpp @@ -26,8 +26,8 @@ namespace RTC { /* Class variables. */ - thread_local std::unordered_map> PortManager::mapUdpIpPorts; - thread_local std::unordered_map> PortManager::mapTcpIpPorts; + thread_local absl::flat_hash_map> PortManager::mapUdpIpPorts; + thread_local absl::flat_hash_map> PortManager::mapTcpIpPorts; /* Class methods. */ diff --git a/worker/src/RTC/Producer.cpp b/worker/src/RTC/Producer.cpp index f10922121f..603d9410bd 100644 --- a/worker/src/RTC/Producer.cpp +++ b/worker/src/RTC/Producer.cpp @@ -11,6 +11,7 @@ #include "RTC/RTCP/FeedbackPs.hpp" #include "RTC/RTCP/FeedbackRtp.hpp" #include "RTC/RTCP/XrReceiverReferenceTime.hpp" +#include #include // std::memcpy() #include // std::ostream_iterator #include // std::ostringstream diff --git a/worker/src/RTC/RTCP/Feedback.cpp b/worker/src/RTC/RTCP/Feedback.cpp index 13e204a622..8d290e10e9 100644 --- a/worker/src/RTC/RTCP/Feedback.cpp +++ b/worker/src/RTC/RTCP/Feedback.cpp @@ -98,7 +98,7 @@ namespace RTC // clang-format off template<> - std::map FeedbackPacket::type2String = + absl::flat_hash_map FeedbackPacket::type2String = { { FeedbackPs::MessageType::PLI, "PLI" }, { FeedbackPs::MessageType::SLI, "SLI" }, @@ -188,7 +188,7 @@ namespace RTC // clang-format off template<> - std::map FeedbackPacket::type2String = + absl::flat_hash_map FeedbackPacket::type2String = { { FeedbackRtp::MessageType::NACK, "NACK" }, { FeedbackRtp::MessageType::TMMBR, "TMMBR" }, diff --git a/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp b/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp index 3f466622eb..d310110094 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp @@ -60,7 +60,7 @@ namespace RTC int16_t FeedbackRtpTransportPacket::maxPacketDelta{ 0x7FFF }; // clang-format off - std::map FeedbackRtpTransportPacket::status2String = + absl::flat_hash_map FeedbackRtpTransportPacket::status2String = { { FeedbackRtpTransportPacket::Status::NotReceived, "NR" }, { FeedbackRtpTransportPacket::Status::SmallDelta, "SD" }, diff --git a/worker/src/RTC/RTCP/Packet.cpp b/worker/src/RTC/RTCP/Packet.cpp index cf74864939..d2f38e8c0d 100644 --- a/worker/src/RTC/RTCP/Packet.cpp +++ b/worker/src/RTC/RTCP/Packet.cpp @@ -21,7 +21,7 @@ namespace RTC /* Class variables. */ // clang-format off - std::map Packet::type2String = + absl::flat_hash_map Packet::type2String = { { Type::SR, "SR" }, { Type::RR, "RR" }, diff --git a/worker/src/RTC/RTCP/Sdes.cpp b/worker/src/RTC/RTCP/Sdes.cpp index 05ada25864..a31cd64965 100644 --- a/worker/src/RTC/RTCP/Sdes.cpp +++ b/worker/src/RTC/RTCP/Sdes.cpp @@ -13,7 +13,7 @@ namespace RTC /* Item Class variables. */ // clang-format off - std::map SdesItem::type2String = + absl::flat_hash_map SdesItem::type2String = { { SdesItem::Type::END, "END" }, { SdesItem::Type::CNAME, "CNAME" }, diff --git a/worker/src/RTC/RtpDictionaries/Media.cpp b/worker/src/RTC/RtpDictionaries/Media.cpp index 38cdd3e41b..35a780546d 100644 --- a/worker/src/RTC/RtpDictionaries/Media.cpp +++ b/worker/src/RTC/RtpDictionaries/Media.cpp @@ -11,13 +11,13 @@ namespace RTC /* Class variables. */ // clang-format off - std::unordered_map Media::string2Kind = + absl::flat_hash_map Media::string2Kind = { { "", Media::Kind::ALL }, { "audio", Media::Kind::AUDIO }, { "video", Media::Kind::VIDEO } }; - std::map Media::kind2String = + absl::flat_hash_map Media::kind2String = { { Media::Kind::ALL, "" }, { Media::Kind::AUDIO, "audio" }, diff --git a/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp b/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp index 6933fabed5..0231c25cf9 100644 --- a/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp @@ -11,17 +11,17 @@ namespace RTC /* Class variables. */ // clang-format off - std::unordered_map RtpCodecMimeType::string2Type = + absl::flat_hash_map RtpCodecMimeType::string2Type = { { "audio", RtpCodecMimeType::Type::AUDIO }, { "video", RtpCodecMimeType::Type::VIDEO } }; - std::map RtpCodecMimeType::type2String = + absl::flat_hash_map RtpCodecMimeType::type2String = { { RtpCodecMimeType::Type::AUDIO, "audio" }, { RtpCodecMimeType::Type::VIDEO, "video" } }; - std::unordered_map RtpCodecMimeType::string2Subtype = + absl::flat_hash_map RtpCodecMimeType::string2Subtype = { // Audio codecs: { "opus", RtpCodecMimeType::Subtype::OPUS }, @@ -48,7 +48,7 @@ namespace RTC { "x-ulpfecuc", RtpCodecMimeType::Subtype::X_ULPFECUC }, { "red", RtpCodecMimeType::Subtype::RED } }; - std::map RtpCodecMimeType::subtype2String = + absl::flat_hash_map RtpCodecMimeType::subtype2String = { // Audio codecs: { RtpCodecMimeType::Subtype::OPUS, "opus" }, diff --git a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp index 6a49c6bd11..e4e11e67fe 100644 --- a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp @@ -10,7 +10,7 @@ namespace RTC /* Class variables. */ // clang-format off - std::unordered_map RtpHeaderExtensionUri::string2Type = + absl::flat_hash_map RtpHeaderExtensionUri::string2Type = { { "urn:ietf:params:rtp-hdrext:sdes:mid", RtpHeaderExtensionUri::Type::MID }, { "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", RtpHeaderExtensionUri::Type::RTP_STREAM_ID }, diff --git a/worker/src/RTC/RtpDictionaries/RtpParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpParameters.cpp index f5251706cb..5ea8bc1bc4 100644 --- a/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpParameters.cpp @@ -4,14 +4,14 @@ #include "Logger.hpp" #include "MediaSoupErrors.hpp" #include "RTC/RtpDictionaries.hpp" -#include +#include namespace RTC { /* Class variables. */ // clang-format off - std::unordered_map RtpParameters::string2Type = + absl::flat_hash_map RtpParameters::string2Type = { { "none", RtpParameters::Type::NONE }, { "simple", RtpParameters::Type::SIMPLE }, @@ -19,7 +19,7 @@ namespace RTC { "svc", RtpParameters::Type::SVC }, { "pipe", RtpParameters::Type::PIPE } }; - std::map RtpParameters::type2String = + absl::flat_hash_map RtpParameters::type2String = { { RtpParameters::Type::NONE, "none" }, { RtpParameters::Type::SIMPLE, "simple" }, @@ -266,7 +266,7 @@ namespace RTC static const std::string AptString{ "apt" }; - std::unordered_set payloadTypes; + absl::flat_hash_set payloadTypes; for (auto& codec : this->codecs) { diff --git a/worker/src/Settings.cpp b/worker/src/Settings.cpp index 98ad54a3d7..86137e47b6 100644 --- a/worker/src/Settings.cpp +++ b/worker/src/Settings.cpp @@ -5,8 +5,7 @@ #include "Logger.hpp" #include "MediaSoupErrors.hpp" #include "Utils.hpp" -#include // isprint() -#include +#include // isprint() #include // std::ostream_iterator #include #include @@ -24,14 +23,14 @@ static std::mutex globalSyncMutex; thread_local struct Settings::Configuration Settings::configuration; // clang-format off -std::map Settings::string2LogLevel = +absl::flat_hash_map Settings::string2LogLevel = { { "debug", LogLevel::LOG_DEBUG }, { "warn", LogLevel::LOG_WARN }, { "error", LogLevel::LOG_ERROR }, { "none", LogLevel::LOG_NONE } }; -std::map Settings::logLevel2String = +absl::flat_hash_map Settings::logLevel2String = { { LogLevel::LOG_DEBUG, "debug" }, { LogLevel::LOG_WARN, "warn" }, diff --git a/worker/src/lib.cpp b/worker/src/lib.cpp index f1d54b44a3..149eff203e 100644 --- a/worker/src/lib.cpp +++ b/worker/src/lib.cpp @@ -19,11 +19,11 @@ #include "RTC/DtlsTransport.hpp" #include "RTC/SrtpSession.hpp" #include +#include #include #include // sigaction() #include // std::_Exit(), std::genenv() #include // std::cerr, std::endl -#include #include void IgnoreSignals(); @@ -210,7 +210,7 @@ void IgnoreSignals() struct sigaction act; // NOLINT(cppcoreguidelines-pro-type-member-init) // clang-format off - std::map ignoredSignals = + absl::flat_hash_map ignoredSignals = { { "PIPE", SIGPIPE }, { "HUP", SIGHUP },