From b44294784a3c3069b785b3ca597cf9552937ec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sun, 9 Apr 2017 19:32:07 +0200 Subject: [PATCH] Clang format (fixes #74) (#98) * More C++ syntax work * Fix test-rtcp * More camelCase * Working on C++ style. * More C++ styling * More work in C++ styling * More work on C++ styling * C++ style: remove #defines * doc/RoomOverview.md: some fixes * More C++ styling: camelCase RTCP * More C++ styling: camelCase RemoteBitrateEstimator * C++ styling * C++ styling * clang-format proposal clang-format can be disabled for certain code by using clang-format [off|on] comments May be usefull for static class maps for example. * .clang-format: minimal change * .clang-format: improve IncludeCategories * clang-format: improve IncludeCategories * Logger.hpp: ignore clang-format * clang-format: mostly done * Add clang-format off in map initializations * Remove comment * "gulp lint" includes C++ linter * Habemus clang-format --- TODO_CPP_SYNTAX.md | 25 - doc/RoomOverview.md | 16 +- gulpfile.js | 4 +- worker/.clang-format | 58 +- worker/include/Channel/Notifier.hpp | 9 +- worker/include/Channel/Request.hpp | 4 +- worker/include/Channel/UnixStreamSocket.hpp | 24 +- worker/include/DepLibSRTP.hpp | 10 +- worker/include/DepLibUV.hpp | 8 +- worker/include/DepOpenSSL.hpp | 6 +- worker/include/LogLevel.hpp | 2 +- worker/include/Logger.hpp | 50 +- worker/include/Loop.hpp | 23 +- worker/include/MediaSoupError.hpp | 48 +- worker/include/RTC/DtlsTransport.hpp | 89 +- worker/include/RTC/IceCandidate.hpp | 4 +- worker/include/RTC/IceServer.hpp | 24 +- worker/include/RTC/NackGenerator.hpp | 29 +- worker/include/RTC/Parameters.hpp | 96 +- worker/include/RTC/Peer.hpp | 92 +- worker/include/RTC/RTCP/Bye.hpp | 161 +- worker/include/RTC/RTCP/CompoundPacket.hpp | 99 +- worker/include/RTC/RTCP/Feedback.hpp | 223 +- worker/include/RTC/RTCP/FeedbackItem.hpp | 86 +- worker/include/RTC/RTCP/FeedbackPs.hpp | 133 +- worker/include/RTC/RTCP/FeedbackPsAfb.hpp | 100 +- worker/include/RTC/RTCP/FeedbackPsFir.hpp | 117 +- worker/include/RTC/RTCP/FeedbackPsLei.hpp | 102 +- worker/include/RTC/RTCP/FeedbackPsPli.hpp | 58 +- worker/include/RTC/RTCP/FeedbackPsRemb.hpp | 150 +- worker/include/RTC/RTCP/FeedbackPsRpsi.hpp | 141 +- worker/include/RTC/RTCP/FeedbackPsSli.hpp | 151 +- worker/include/RTC/RTCP/FeedbackPsTst.hpp | 153 +- worker/include/RTC/RTCP/FeedbackPsVbcm.hpp | 161 +- worker/include/RTC/RTCP/FeedbackRtp.hpp | 133 +- worker/include/RTC/RTCP/FeedbackRtpEcn.hpp | 178 +- worker/include/RTC/RTCP/FeedbackRtpNack.hpp | 115 +- worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp | 56 +- worker/include/RTC/RTCP/FeedbackRtpTllei.hpp | 115 +- worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp | 196 +- worker/include/RTC/RTCP/Packet.hpp | 234 +- worker/include/RTC/RTCP/ReceiverReport.hpp | 436 +- worker/include/RTC/RTCP/Sdes.hpp | 428 +- worker/include/RTC/RTCP/SenderReport.hpp | 356 +- .../AimdRateControl.hpp | 82 +- .../RemoteBitrateEstimator/InterArrival.hpp | 81 +- .../OveruseDetector.hpp | 23 +- .../OveruseEstimator.hpp | 67 +- .../RateControlInput.hpp | 15 +- .../RemoteBitrateEstimator.hpp | 20 +- .../RemoteBitrateEstimatorAbsSendTime.hpp | 81 +- .../RemoteBitrateEstimatorSingleStream.hpp | 68 +- worker/include/RTC/Room.hpp | 46 +- worker/include/RTC/RtpDataCounter.hpp | 40 +- worker/include/RTC/RtpDictionaries.hpp | 112 +- worker/include/RTC/RtpListener.hpp | 19 +- worker/include/RTC/RtpPacket.hpp | 174 +- worker/include/RTC/RtpReceiver.hpp | 60 +- worker/include/RTC/RtpSender.hpp | 51 +- worker/include/RTC/RtpStream.hpp | 31 +- worker/include/RTC/RtpStreamRecv.hpp | 25 +- worker/include/RTC/RtpStreamSend.hpp | 27 +- worker/include/RTC/SrtpSession.hpp | 3 +- worker/include/RTC/StunMessage.hpp | 116 +- worker/include/RTC/TcpConnection.hpp | 9 +- worker/include/RTC/TcpServer.hpp | 26 +- worker/include/RTC/Transport.hpp | 141 +- worker/include/RTC/TransportTuple.hpp | 52 +- worker/include/RTC/UdpSocket.hpp | 24 +- worker/include/Settings.hpp | 53 +- worker/include/Utils.hpp | 180 +- worker/include/common.hpp | 17 +- worker/include/handles/SignalsHandler.hpp | 12 +- worker/include/handles/TcpConnection.hpp | 66 +- worker/include/handles/TcpServer.hpp | 39 +- worker/include/handles/Timer.hpp | 10 +- worker/include/handles/UdpSocket.hpp | 43 +- worker/include/handles/UnixStreamSocket.hpp | 28 +- worker/src/Channel/Notifier.cpp | 23 +- worker/src/Channel/Request.cpp | 24 +- worker/src/Channel/UnixStreamSocket.cpp | 191 +- worker/src/DepLibSRTP.cpp | 58 +- worker/src/DepLibUV.cpp | 2 +- worker/src/DepOpenSSL.cpp | 6 +- worker/src/Logger.cpp | 10 +- worker/src/Loop.cpp | 29 +- worker/src/RTC/DtlsTransport.cpp | 317 +- worker/src/RTC/IceCandidate.cpp | 34 +- worker/src/RTC/IceServer.cpp | 80 +- worker/src/RTC/NackGenerator.cpp | 66 +- worker/src/RTC/Peer.cpp | 185 +- worker/src/RTC/RTCP/Bye.cpp | 137 +- worker/src/RTC/RTCP/CompoundPacket.cpp | 148 +- worker/src/RTC/RTCP/Feedback.cpp | 400 +- worker/src/RTC/RTCP/FeedbackPs.cpp | 128 +- worker/src/RTC/RTCP/FeedbackPsAfb.cpp | 81 +- worker/src/RTC/RTCP/FeedbackPsFir.cpp | 79 +- worker/src/RTC/RTCP/FeedbackPsLei.cpp | 73 +- worker/src/RTC/RTCP/FeedbackPsPli.cpp | 45 +- worker/src/RTC/RTCP/FeedbackPsRemb.cpp | 196 +- worker/src/RTC/RTCP/FeedbackPsRpsi.cpp | 141 +- worker/src/RTC/RTCP/FeedbackPsSli.cpp | 84 +- worker/src/RTC/RTCP/FeedbackPsTst.cpp | 111 +- worker/src/RTC/RTCP/FeedbackPsVbcm.cpp | 108 +- worker/src/RTC/RTCP/FeedbackRtp.cpp | 120 +- worker/src/RTC/RTCP/FeedbackRtpEcn.cpp | 71 +- worker/src/RTC/RTCP/FeedbackRtpNack.cpp | 79 +- worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp | 41 +- worker/src/RTC/RTCP/FeedbackRtpTllei.cpp | 75 +- worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp | 145 +- worker/src/RTC/RTCP/Packet.cpp | 250 +- worker/src/RTC/RTCP/ReceiverReport.cpp | 187 +- worker/src/RTC/RTCP/Sdes.cpp | 305 +- worker/src/RTC/RTCP/SenderReport.cpp | 139 +- .../AimdRateControl.cpp | 37 +- .../RemoteBitrateEstimator/InterArrival.cpp | 110 +- .../OveruseDetector.cpp | 20 +- .../OveruseEstimator.cpp | 36 +- .../RemoteBitrateEstimatorAbsSendTime.cpp | 131 +- .../RemoteBitrateEstimatorSingleStream.cpp | 59 +- worker/src/RTC/Room.cpp | 122 +- worker/src/RTC/RtpDataCounter.cpp | 4 +- worker/src/RTC/RtpDictionaries/Media.cpp | 9 +- worker/src/RTC/RtpDictionaries/Parameters.cpp | 37 +- .../src/RTC/RtpDictionaries/RtcpFeedback.cpp | 4 +- .../RTC/RtpDictionaries/RtcpParameters.cpp | 4 +- .../RTC/RtpDictionaries/RtpCapabilities.cpp | 41 +- .../src/RTC/RtpDictionaries/RtpCodecMime.cpp | 19 +- .../RtpDictionaries/RtpCodecParameters.cpp | 47 +- .../RtpDictionaries/RtpEncodingParameters.cpp | 16 +- .../RTC/RtpDictionaries/RtpFecParameters.cpp | 4 +- .../RtpDictionaries/RtpHeaderExtension.cpp | 4 +- .../RtpHeaderExtensionParameters.cpp | 4 +- .../RtpDictionaries/RtpHeaderExtensionUri.cpp | 6 +- .../src/RTC/RtpDictionaries/RtpParameters.cpp | 67 +- .../RTC/RtpDictionaries/RtpRtxParameters.cpp | 4 +- worker/src/RTC/RtpListener.cpp | 32 +- worker/src/RTC/RtpPacket.cpp | 76 +- worker/src/RTC/RtpReceiver.cpp | 100 +- worker/src/RTC/RtpSender.cpp | 70 +- worker/src/RTC/RtpStream.cpp | 67 +- worker/src/RTC/RtpStreamRecv.cpp | 34 +- worker/src/RTC/RtpStreamSend.cpp | 115 +- worker/src/RTC/SrtpSession.cpp | 19 +- worker/src/RTC/StunMessage.cpp | 208 +- worker/src/RTC/TcpConnection.cpp | 33 +- worker/src/RTC/TcpServer.cpp | 86 +- worker/src/RTC/Transport.cpp | 366 +- worker/src/RTC/TransportTuple.cpp | 36 +- worker/src/RTC/UdpSocket.cpp | 76 +- worker/src/Settings.cpp | 83 +- worker/src/Utils/Crypto.cpp | 107 +- worker/src/Utils/File.cpp | 6 +- worker/src/Utils/IP.cpp | 7662 ++++++++++------- worker/src/Utils/IP.rl | 18 +- worker/src/handles/SignalsHandler.cpp | 22 +- worker/src/handles/TcpConnection.cpp | 133 +- worker/src/handles/TcpServer.cpp | 81 +- worker/src/handles/Timer.cpp | 20 +- worker/src/handles/UdpSocket.cpp | 111 +- worker/src/handles/UnixStreamSocket.cpp | 89 +- worker/src/main.cpp | 51 +- worker/test/include/helpers.hpp | 4 +- worker/test/test-bitrate.cpp | 6 +- worker/test/test-nack.cpp | 39 +- worker/test/test-rtcp.cpp | 53 +- worker/test/test-rtp.cpp | 113 +- worker/test/test-rtpstreamrecv.cpp | 44 +- 168 files changed, 11376 insertions(+), 10081 deletions(-) delete mode 100644 TODO_CPP_SYNTAX.md diff --git a/TODO_CPP_SYNTAX.md b/TODO_CPP_SYNTAX.md deleted file mode 100644 index 7368ebcf26..0000000000 --- a/TODO_CPP_SYNTAX.md +++ /dev/null @@ -1,25 +0,0 @@ -## Peer.cpp - -uint8_t Peer::rtcpBuffer[MS_RTCP_BUFFER_SIZE]; - -this->timer->Start(uint64_t(RTC::RTCP::MAX_VIDEO_INTERVAL_MS / 2)); - -if (packet->GetSize() > MS_RTCP_BUFFER_SIZE) - -uint64_t interval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS; - -if (interval > RTC::RTCP::MAX_VIDEO_INTERVAL_MS) - - -## RtpReceiver.cpp - -uint8_t RtpReceiver::rtcpBuffer[MS_RTCP_BUFFER_SIZE]; - -if (packet.GetSize() > MS_RTCP_BUFFER_SIZE) - -packet.Serialize(RtpReceiver::rtcpBuffer); - - -##RtpSender.cpp - -this->maxRtcpInterval = RTC::RTCP::MAX_AUDIO_INTERVAL_MS; diff --git a/doc/RoomOverview.md b/doc/RoomOverview.md index 6ddc5571f0..f0e66a5aab 100644 --- a/doc/RoomOverview.md +++ b/doc/RoomOverview.md @@ -63,26 +63,12 @@ These codecs have the same fields as the peer's capabilities codecs above, with * `kind` is ignored. * `payloadType` MUST match the same value as the one set by the room (otherwise it will fail). -If `receive()` is called ith a codec that is not supported by the room or not present in the peer's given capabilities, it fails. +If `receive()` is called with a codec that is not supported by the room or not present in the peer's given capabilities, it fails. Unsupported RTCP feedback mechanisms and RTP header extensions not supported by mediasoup or by the peer itself are removed. Effective RTP parameters are returned to the `receive()` promise. -After that, C++ `RtpReceiver::FillRtpParameters()` is called. This method does nothing right now. - -*TODO:* C++ `RtpReceiver::FillRtpParameters()` should: - -* Set a random `muxId` and map the original value. -* If any SSRC value is not given, set a random one and be ready to match the unknown incoming SSRC value to it. -* If not given, set the `rtcp` field. -* Should map the `id` of the supported ones to a static value. - * *NOTE:* This is important so we can deal with PlanB in which all the RTP streams are sent over a single `m=` section. - -*TODO:* The whole mapping system could be implemented by maintaing two `RtpParameters` objects within each `RtpReceiver`: the original one and the maped one (although that wouldn't be efficient when it comes to mangle each RTP packet so it may be better to handle an internal value mapping...). - -After that, C++ `Peer::onRtpReceiverParametersDone()` is called, which just calls to C++ `Room::onPeerRtpReceiverParameters()`. - `Room::onPeerRtpReceiverParameters()` creates `RtpSenders` associated to this `RtpReceiver` (for every other `Peer` with its capabilities already set) by calling `Peer::AddRtpSender()` on them. `Peer::AddRtpSender()` takes the associated `RtpParameters` of the `RtpReceiver` as parameter and call `RtpSender::Send(parameters)`. diff --git a/gulpfile.js b/gulpfile.js index 2d7733968c..66785102c1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -92,9 +92,7 @@ gulp.task('rtpcapabilities', () => .pipe(touch()); }); -// TODO: Uncomment when C++ syntax and clang-format stuff is done. -// gulp.task('lint', gulp.series('lint:node', 'lint:worker')); -gulp.task('lint', gulp.series('lint:node')); +gulp.task('lint', gulp.series('lint:node', 'lint:worker')); gulp.task('test', gulp.series('test:node', 'test:worker')); diff --git a/worker/.clang-format b/worker/.clang-format index f345af3156..14f20e55e8 100644 --- a/worker/.clang-format +++ b/worker/.clang-format @@ -1,16 +1,22 @@ +Language: Cpp AccessModifierOffset: -2 -AlignConsecutiveAssignments: false -AlignEscapedNewlinesLeft: true +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false AlignOperands: true AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false BreakBeforeBraces: Custom BraceWrapping: AfterClass: true @@ -23,32 +29,47 @@ BraceWrapping: BeforeCatch: true BeforeElse: true IndentBraces: false -BinPackArguments: true BreakBeforeBinaryOperators: None +BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true BreakStringLiterals: true -ColumnLimit: 150 +ColumnLimit: 100 ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 1 -DerivePointerAlignment: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: true +IncludeCategories: + - Regex: '"common.hpp"' + Priority: 1 + - Regex: '^"(Channel|RTC|handles)/' + Priority: 3 + - Regex: '"*"' + Priority: 2 + - Regex: '^<(uv|openssl|srtp|json|netstring)(.|/)' + Priority: 4 + - Regex: '<*>' + Priority: 5 +IncludeIsMainRegex: '$' IndentCaseLabels: true IndentWidth: 2 -IndentWrappedFunctionNames: true +IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: false -Language: Cpp MaxEmptyLinesToKeep: 1 NamespaceIndentation: All -PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakBeforeFirstCallParameter: 5 PenaltyBreakComment: 100 -PenaltyBreakFirstLessLess: 100 -PenaltyBreakString: 100 -PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 100 +PenaltyBreakFirstLessLess: 200 +PenaltyBreakString: 20 +PenaltyExcessCharacter: 10 +PenaltyReturnTypeOnItsOwnLine: 1000 PointerAlignment: Left -ReflowComments: false -SortIncludes: false -SpaceAfterCStyleCast: true +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements @@ -56,6 +77,7 @@ SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Cpp11 diff --git a/worker/include/Channel/Notifier.hpp b/worker/include/Channel/Notifier.hpp index 05d11d403f..ae6617869c 100644 --- a/worker/include/Channel/Notifier.hpp +++ b/worker/include/Channel/Notifier.hpp @@ -3,8 +3,8 @@ #include "common.hpp" #include "Channel/UnixStreamSocket.hpp" -#include #include +#include namespace Channel { @@ -15,7 +15,12 @@ namespace Channel void Emit(uint32_t targetId, std::string event); void Emit(uint32_t targetId, std::string event, Json::Value& data); - void EmitWithBinary(uint32_t targetId, std::string event, Json::Value& data, const uint8_t* binary_data, size_t binary_len); + void EmitWithBinary( + uint32_t targetId, + std::string event, + Json::Value& data, + const uint8_t* binaryData, + size_t binaryLen); public: // Passed by argument. diff --git a/worker/include/Channel/Request.hpp b/worker/include/Channel/Request.hpp index a7d5a46cc9..eb583571ad 100644 --- a/worker/include/Channel/Request.hpp +++ b/worker/include/Channel/Request.hpp @@ -2,9 +2,9 @@ #define MS_CHANNEL_REQUEST_HPP #include "common.hpp" +#include #include #include -#include namespace Channel { @@ -50,7 +50,7 @@ namespace Channel virtual ~Request(); void Accept(); - void Accept(Json::Value &data); + void Accept(Json::Value& data); void Reject(std::string& reason); void Reject(const char* reason = nullptr); diff --git a/worker/include/Channel/UnixStreamSocket.hpp b/worker/include/Channel/UnixStreamSocket.hpp index 17200c8d7f..d567f25b53 100644 --- a/worker/include/Channel/UnixStreamSocket.hpp +++ b/worker/include/Channel/UnixStreamSocket.hpp @@ -2,14 +2,13 @@ #define MS_CHANNEL_UNIX_STREAM_SOCKET_HPP #include "common.hpp" -#include "handles/UnixStreamSocket.hpp" #include "Channel/Request.hpp" +#include "handles/UnixStreamSocket.hpp" #include namespace Channel { - class UnixStreamSocket : - public ::UnixStreamSocket + class UnixStreamSocket : public ::UnixStreamSocket { public: class Listener @@ -19,9 +18,6 @@ namespace Channel virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0; }; - private: - static uint8_t writeBuffer[]; - public: explicit UnixStreamSocket(int fd); @@ -30,23 +26,23 @@ namespace Channel public: void SetListener(Listener* listener); - void Send(Json::Value &json); - void SendLog(char* ns_payload, size_t ns_payload_len); - void SendBinary(const uint8_t* ns_payload, size_t ns_payload_len); + void Send(Json::Value& json); + void SendLog(char* nsPayload, size_t nsPayloadLen); + void SendBinary(const uint8_t* nsPayload, size_t nsPayloadLen); - /* Pure virtual methods inherited from ::UnixStreamSocket. */ + /* Pure virtual methods inherited from ::UnixStreamSocket. */ public: virtual void userOnUnixStreamRead() override; - virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) override; + virtual void userOnUnixStreamSocketClosed(bool isClosedByPeer) override; private: // Passed by argument. Listener* listener = nullptr; // Others. - Json::CharReader* jsonReader = nullptr; + Json::CharReader* jsonReader = nullptr; Json::StreamWriter* jsonWriter = nullptr; - size_t msgStart = 0; // Where the latest message starts. - bool closed = false; + size_t msgStart = 0; // Where the latest message starts. + bool closed = false; }; } diff --git a/worker/include/DepLibSRTP.hpp b/worker/include/DepLibSRTP.hpp index 3370673013..14c7e9a7d8 100644 --- a/worker/include/DepLibSRTP.hpp +++ b/worker/include/DepLibSRTP.hpp @@ -1,8 +1,8 @@ #ifndef MS_DEP_LIBSRTP_HPP -#define MS_DEP_LIBSRTP_HPP +#define MS_DEP_LIBSRTP_HPP -#include #include +#include class DepLibSRTP { @@ -18,14 +18,12 @@ class DepLibSRTP /* Inline static methods. */ -inline -bool DepLibSRTP::IsError(srtp_err_status_t code) +inline bool DepLibSRTP::IsError(srtp_err_status_t code) { return (code != srtp_err_status_ok); } -inline -const char* DepLibSRTP::GetErrorString(srtp_err_status_t code) +inline const char* DepLibSRTP::GetErrorString(srtp_err_status_t code) { // This throws out_of_range if the given index is not in the vector. return DepLibSRTP::errors.at(code); diff --git a/worker/include/DepLibUV.hpp b/worker/include/DepLibUV.hpp index 66b064f0c5..7ec42ce5bb 100644 --- a/worker/include/DepLibUV.hpp +++ b/worker/include/DepLibUV.hpp @@ -1,5 +1,5 @@ #ifndef MS_DEP_LIBUV_HPP -#define MS_DEP_LIBUV_HPP +#define MS_DEP_LIBUV_HPP #include "common.hpp" #include @@ -20,14 +20,12 @@ class DepLibUV /* Inline static methods. */ -inline -uv_loop_t* DepLibUV::GetLoop() +inline uv_loop_t* DepLibUV::GetLoop() { return DepLibUV::loop; } -inline -uint64_t DepLibUV::GetTime() +inline uint64_t DepLibUV::GetTime() { return uv_now(DepLibUV::loop); } diff --git a/worker/include/DepOpenSSL.hpp b/worker/include/DepOpenSSL.hpp index 3a9e127cc8..770ca3da2e 100644 --- a/worker/include/DepOpenSSL.hpp +++ b/worker/include/DepOpenSSL.hpp @@ -1,9 +1,9 @@ #ifndef MS_DEP_OPENSSL_HPP -#define MS_DEP_OPENSSL_HPP +#define MS_DEP_OPENSSL_HPP #include "common.hpp" -#include #include +#include #include /* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */ @@ -20,7 +20,7 @@ class DepOpenSSL private: static void SetThreadId(CRYPTO_THREADID* id); - static void LockingFunction(int mode, int n, const char *file, int line); + static void LockingFunction(int mode, int n, const char* file, int line); static CRYPTO_dynlock_value* DynCreateFunction(const char* file, int line); static void DynLockFunction(int mode, CRYPTO_dynlock_value* v, const char* file, int line); static void DynDestroyFunction(CRYPTO_dynlock_value* v, const char* file, int line); diff --git a/worker/include/LogLevel.hpp b/worker/include/LogLevel.hpp index 9dcfdaf186..9ab6f90ad5 100644 --- a/worker/include/LogLevel.hpp +++ b/worker/include/LogLevel.hpp @@ -1,5 +1,5 @@ #ifndef MS_LOG_LEVEL_HPP -#define MS_LOG_LEVEL_HPP +#define MS_LOG_LEVEL_HPP #include "common.hpp" diff --git a/worker/include/Logger.hpp b/worker/include/Logger.hpp index eb03a2107b..bd39e60938 100644 --- a/worker/include/Logger.hpp +++ b/worker/include/Logger.hpp @@ -64,17 +64,18 @@ */ #ifndef MS_LOGGER_HPP -#define MS_LOGGER_HPP +#define MS_LOGGER_HPP #include "LogLevel.hpp" #include "Settings.hpp" #include "Channel/UnixStreamSocket.hpp" -#include -#include // std::snprintf(), std::fprintf(), stdout, stderr -#include +#include // std::snprintf(), std::fprintf(), stdout, stderr #include // std::abort() +#include +#include + +// clang-format off -#define MS_LOGGER_BUFFER_SIZE 10000 #define _MS_TAG_ENABLED(tag) Settings::configuration.logTags.tag #define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::configuration.logTags.tag1 || Settings::configuration.logTags.tag2) #ifdef MS_LOG_DEV @@ -113,6 +114,7 @@ class Logger public: static std::string id; static Channel::UnixStreamSocket* channel; + static const size_t bufferSize = 10000; static char buffer[]; }; @@ -137,8 +139,8 @@ class Logger { \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -169,8 +171,8 @@ class Logger { \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -191,8 +193,8 @@ class Logger { \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -213,8 +215,8 @@ class Logger { \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -235,8 +237,8 @@ class Logger { \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -258,8 +260,8 @@ class Logger { \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -280,8 +282,8 @@ class Logger { \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ } \ while (0) @@ -306,8 +308,8 @@ class Logger #define MS_DUMP(desc, ...) \ do \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ while (0) @@ -322,8 +324,8 @@ class Logger #define MS_ERROR(desc, ...) \ do \ { \ - int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ - Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ + int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + Logger::channel->SendLog(Logger::buffer, loggerWritten); \ } \ while (0) @@ -371,4 +373,6 @@ class Logger #define MS_ERROR MS_ERROR_STD #endif +// clang-format on + #endif diff --git a/worker/include/Loop.hpp b/worker/include/Loop.hpp index 3ba4647284..50d3959528 100644 --- a/worker/include/Loop.hpp +++ b/worker/include/Loop.hpp @@ -1,18 +1,17 @@ #ifndef MS_LOOP_HPP -#define MS_LOOP_HPP +#define MS_LOOP_HPP #include "common.hpp" -#include "handles/SignalsHandler.hpp" -#include "Channel/UnixStreamSocket.hpp" -#include "Channel/Request.hpp" #include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" +#include "Channel/UnixStreamSocket.hpp" #include "RTC/Room.hpp" +#include "handles/SignalsHandler.hpp" #include -class Loop : - public SignalsHandler::Listener, - public Channel::UnixStreamSocket::Listener, - public RTC::Room::Listener +class Loop : public SignalsHandler::Listener, + public Channel::UnixStreamSocket::Listener, + public RTC::Room::Listener { public: explicit Loop(Channel::UnixStreamSocket* channel); @@ -22,16 +21,16 @@ class Loop : void Close(); RTC::Room* GetRoomFromRequest(Channel::Request* request, uint32_t* roomId = nullptr); -/* Methods inherited from SignalsHandler::Listener. */ + /* Methods inherited from SignalsHandler::Listener. */ public: virtual void onSignal(SignalsHandler* signalsHandler, int signum) override; -/* Methods inherited from Channel::lUnixStreamSocket::Listener. */ + /* Methods inherited from Channel::lUnixStreamSocket::Listener. */ public: virtual void onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) override; virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) override; -/* Methods inherited from RTC::Room::Listener. */ + /* Methods inherited from RTC::Room::Listener. */ public: virtual void onRoomClosed(RTC::Room* room) override; @@ -39,7 +38,7 @@ class Loop : // Passed by argument. Channel::UnixStreamSocket* channel = nullptr; // Allocated by this. - Channel::Notifier* notifier = nullptr; + Channel::Notifier* notifier = nullptr; SignalsHandler* signalsHandler = nullptr; // Others. bool closed = false; diff --git a/worker/include/MediaSoupError.hpp b/worker/include/MediaSoupError.hpp index 42428c97f6..998756cf49 100644 --- a/worker/include/MediaSoupError.hpp +++ b/worker/include/MediaSoupError.hpp @@ -2,12 +2,10 @@ #define MS_MEDIASOUP_ERROR_HPP #include "Logger.hpp" +#include // std::snprintf() #include -#include -#include // std::snprintf -class MediaSoupError : - public std::runtime_error +class MediaSoupError : public std::runtime_error { public: explicit MediaSoupError(const char* description); @@ -15,29 +13,27 @@ class MediaSoupError : /* Inline methods. */ -inline -MediaSoupError::MediaSoupError(const char* description) : - std::runtime_error(description) -{} +inline MediaSoupError::MediaSoupError(const char* description) + : std::runtime_error(description) +{ +} -#define MS_THROW_ERROR(desc, ...) \ - do \ - { \ - MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ - static char buffer[2000]; \ - std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ - throw MediaSoupError(buffer); \ - } \ - while (0) +#define MS_THROW_ERROR(desc, ...) \ + do \ + { \ + MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ + static char buffer[2000]; \ + std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ + throw MediaSoupError(buffer); \ + } while (0) -#define MS_THROW_ERROR_STD(desc, ...) \ - do \ - { \ - MS_ERROR_STD("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ - static char buffer[2000]; \ - std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ - throw MediaSoupError(buffer); \ - } \ - while (0) +#define MS_THROW_ERROR_STD(desc, ...) \ + do \ + { \ + MS_ERROR_STD("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ + static char buffer[2000]; \ + std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ + throw MediaSoupError(buffer); \ + } while (0) #endif diff --git a/worker/include/RTC/DtlsTransport.hpp b/worker/include/RTC/DtlsTransport.hpp index 2f3a80c4a7..ba2f50b1c2 100644 --- a/worker/include/RTC/DtlsTransport.hpp +++ b/worker/include/RTC/DtlsTransport.hpp @@ -4,19 +4,17 @@ #include "common.hpp" #include "RTC/SrtpSession.hpp" #include "handles/Timer.hpp" -#include -#include -#include -#include +#include #include +#include #include -#include -#include +#include +#include +#include namespace RTC { - class DtlsTransport : - public Timer::Listener + class DtlsTransport : public Timer::Listener { public: enum class DtlsState @@ -52,7 +50,7 @@ namespace RTC struct Fingerprint { FingerprintAlgorithm algorithm; - std::string value; + std::string value; }; private: @@ -69,24 +67,33 @@ namespace RTC // DTLS is in the process of negotiating a secure connection. Incoming // media can flow through. // NOTE: The caller MUST NOT call any method during this callback. - virtual void onDtlsConnecting(const DtlsTransport* dtlsTransport) = 0; + virtual void onDtlsConnecting(const RTC::DtlsTransport* dtlsTransport) = 0; // DTLS has completed negotiation of a secure connection (including DTLS-SRTP // and remote fingerprint verification). Outgoing media can now flow through. // NOTE: The caller MUST NOT call any method during this callback. - virtual void onDtlsConnected(const DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) = 0; + virtual void onDtlsConnected( + const RTC::DtlsTransport* dtlsTransport, + RTC::SrtpSession::Profile srtpProfile, + uint8_t* srtpLocalKey, + size_t srtpLocalKeyLen, + uint8_t* srtpRemoteKey, + size_t srtpRemoteKeyLen, + std::string& remoteCert) = 0; // The DTLS connection has been closed as the result of an error (such as a // DTLS alert or a failure to validate the remote fingerprint). // NOTE: The caller MUST NOT call Destroy() during this callback. - virtual void onDtlsFailed(const DtlsTransport* dtlsTransport) = 0; + virtual void onDtlsFailed(const RTC::DtlsTransport* dtlsTransport) = 0; // The DTLS connection has been closed due to receipt of a close_notify alert. // NOTE: The caller MUST NOT call Destroy() during this callback. - virtual void onDtlsClosed(const DtlsTransport* dtlsTransport) = 0; + virtual void onDtlsClosed(const RTC::DtlsTransport* dtlsTransport) = 0; // Need to send DTLS data to the peer. // NOTE: The caller MUST NOT call Destroy() during this callback. - virtual void onOutgoingDtlsData(const DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; + virtual void onOutgoingDtlsData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; // DTLS application data received. // NOTE: The caller MUST NOT call Destroy() during this callback. - virtual void onDtlsApplicationData(const DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; + virtual void onDtlsApplicationData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; }; public: @@ -137,14 +144,14 @@ namespace RTC bool SetTimeout(); void ProcessHandshake(); bool CheckRemoteFingerprint(); - void ExtractSrtpKeys(RTC::SrtpSession::Profile srtp_profile); + void ExtractSrtpKeys(RTC::SrtpSession::Profile srtpProfile); RTC::SrtpSession::Profile GetNegotiatedSrtpProfile(); - /* Callbacks fired by OpenSSL events. */ + /* Callbacks fired by OpenSSL events. */ public: void onSSLInfo(int where, int ret); - /* Pure virtual methods inherited from Timer::Listener. */ + /* Pure virtual methods inherited from Timer::Listener. */ public: virtual void onTimer(Timer* timer) override; @@ -152,29 +159,27 @@ namespace RTC // Passed by argument. Listener* listener = nullptr; // Allocated by this. - SSL* ssl = nullptr; + SSL* ssl = nullptr; BIO* sslBioFromNetwork = nullptr; // The BIO from which ssl reads. - BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes. - Timer* timer = nullptr; + BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes. + Timer* timer = nullptr; // Others. - DtlsState state = DtlsState::NEW; - Role localRole = Role::NONE; - Fingerprint remoteFingerprint = { FingerprintAlgorithm::NONE, "" }; - bool handshakeDone = false; - bool handshakeDoneNow = false; + DtlsState state = DtlsState::NEW; + Role localRole = Role::NONE; + Fingerprint remoteFingerprint = {FingerprintAlgorithm::NONE, ""}; + bool handshakeDone = false; + bool handshakeDoneNow = false; std::string remoteCert; }; /* Inline static methods. */ - inline - Json::Value& DtlsTransport::GetLocalFingerprints() + inline Json::Value& DtlsTransport::GetLocalFingerprints() { return DtlsTransport::localFingerprints; } - inline - DtlsTransport::Role DtlsTransport::StringToRole(std::string role) + inline DtlsTransport::Role DtlsTransport::StringToRole(std::string role) { auto it = DtlsTransport::string2Role.find(role); @@ -184,8 +189,7 @@ namespace RTC return DtlsTransport::Role::NONE; } - inline - DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(std::string fingerprint) + inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(std::string fingerprint) { auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint); @@ -195,33 +199,28 @@ namespace RTC return DtlsTransport::FingerprintAlgorithm::NONE; } - inline - bool DtlsTransport::IsDtls(const uint8_t* data, size_t len) + inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len) { return ( - // Minimum DTLS record length is 13 bytes. - (len >= 13) && - // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes - (data[0] > 19 && data[0] < 64) - ); + // Minimum DTLS record length is 13 bytes. + (len >= 13) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] > 19 && data[0] < 64)); } /* Inline instance methods. */ - inline - DtlsTransport::DtlsState DtlsTransport::GetState() const + inline DtlsTransport::DtlsState DtlsTransport::GetState() const { return this->state; } - inline - DtlsTransport::Role DtlsTransport::GetLocalRole() const + inline DtlsTransport::Role DtlsTransport::GetLocalRole() const { return this->localRole; } - inline - bool DtlsTransport::IsRunning() const + inline bool DtlsTransport::IsRunning() const { switch (this->state) { diff --git a/worker/include/RTC/IceCandidate.hpp b/worker/include/RTC/IceCandidate.hpp index 8869c97544..c31035b14c 100644 --- a/worker/include/RTC/IceCandidate.hpp +++ b/worker/include/RTC/IceCandidate.hpp @@ -2,10 +2,10 @@ #define MS_RTC_ICE_CANDIDATE_HPP #include "common.hpp" -#include "RTC/UdpSocket.hpp" #include "RTC/TcpServer.hpp" -#include +#include "RTC/UdpSocket.hpp" #include +#include namespace RTC { diff --git a/worker/include/RTC/IceServer.hpp b/worker/include/RTC/IceServer.hpp index ad15ea223d..684993b5e4 100644 --- a/worker/include/RTC/IceServer.hpp +++ b/worker/include/RTC/IceServer.hpp @@ -4,8 +4,8 @@ #include "common.hpp" #include "RTC/StunMessage.hpp" #include "RTC/TransportTuple.hpp" -#include #include +#include namespace RTC { @@ -24,18 +24,19 @@ namespace RTC class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: /** * These callbacks are guaranteed to be called before ProcessStunMessage() * returns, so the given pointers are still usable. */ - virtual void onOutgoingStunMessage(const IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0; - virtual void onIceSelectedTuple(const IceServer* iceServer, RTC::TransportTuple* tuple) = 0; - virtual void onIceConnected(const IceServer* iceServer) = 0; - virtual void onIceCompleted(const IceServer* iceServer) = 0; - virtual void onIceDisconnected(const IceServer* iceServer) = 0; + virtual void onOutgoingStunMessage( + const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0; + virtual void onIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0; + virtual void onIceConnected(const RTC::IceServer* iceServer) = 0; + virtual void onIceCompleted(const RTC::IceServer* iceServer) = 0; + virtual void onIceDisconnected(const RTC::IceServer* iceServer) = 0; }; public: @@ -81,20 +82,17 @@ namespace RTC /* Inline instance methods. */ - inline - const std::string& IceServer::GetUsernameFragment() const + inline const std::string& IceServer::GetUsernameFragment() const { return this->usernameFragment; } - inline - const std::string& IceServer::GetPassword() const + inline const std::string& IceServer::GetPassword() const { return this->password; } - inline - IceServer::IceState IceServer::GetState() const + inline IceServer::IceState IceServer::GetState() const { return this->state; } diff --git a/worker/include/RTC/NackGenerator.hpp b/worker/include/RTC/NackGenerator.hpp index 5572be747d..96f5e88f09 100644 --- a/worker/include/RTC/NackGenerator.hpp +++ b/worker/include/RTC/NackGenerator.hpp @@ -9,27 +9,26 @@ namespace RTC { - class NackGenerator : - public Timer::Listener + class NackGenerator : public Timer::Listener { public: class Listener { public: virtual void onNackRequired(const std::vector& seqNumbers) = 0; - virtual void onFullFrameRequired() = 0; + virtual void onFullFrameRequired() = 0; }; private: struct NackInfo { - NackInfo() {}; + NackInfo(){}; explicit NackInfo(uint32_t seq32, uint32_t sendAtSeqNum); - uint32_t seq32 = 0; + uint32_t seq32 = 0; uint32_t sendAtSeqNum = 0; - uint64_t sentAtTime = 0; - uint8_t retries = 0; + uint64_t sentAtTime = 0; + uint8_t retries = 0; }; enum class NackFilter @@ -49,7 +48,7 @@ namespace RTC std::vector GetNackBatch(NackFilter filter); void MayRunTimer() const; - /* Pure virtual methods inherited from Timer::Listener. */ + /* Pure virtual methods inherited from Timer::Listener. */ public: virtual void onTimer(Timer* timer) override; @@ -60,18 +59,18 @@ namespace RTC Timer* timer = nullptr; // Others. std::map nackList; - bool started = false; + bool started = false; uint32_t lastSeq32 = 0; // Extended seq number of last valid packet. - uint32_t rtt = 0; // Round trip time (ms). + uint32_t rtt = 0; // Round trip time (ms). }; // Inline instance methods. - inline - NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum) : - seq32(seq32), - sendAtSeqNum(sendAtSeqNum) - {} + inline NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum) + : seq32(seq32) + , sendAtSeqNum(sendAtSeqNum) + { + } } #endif diff --git a/worker/include/RTC/Parameters.hpp b/worker/include/RTC/Parameters.hpp index 1d3ee124ee..e1d856ce35 100644 --- a/worker/include/RTC/Parameters.hpp +++ b/worker/include/RTC/Parameters.hpp @@ -2,10 +2,10 @@ #define MS_RTC_PARAMETERS_HPP #include "common.hpp" +#include #include -#include #include -#include +#include namespace RTC { @@ -25,44 +25,49 @@ namespace RTC }; public: - Value() {}; + Value(){}; - explicit Value(bool booleanValue) : - type(Type::BOOLEAN), - booleanValue(booleanValue) - {} + explicit Value(bool booleanValue) + : type(Type::BOOLEAN) + , booleanValue(booleanValue) + { + } - explicit Value(int32_t integerValue) : - type(Type::INTEGER), - integerValue(integerValue) - {} + explicit Value(int32_t integerValue) + : type(Type::INTEGER) + , integerValue(integerValue) + { + } - explicit Value(double doubleValue) : - type(Type::DOUBLE), - doubleValue(doubleValue) - {} + explicit Value(double doubleValue) + : type(Type::DOUBLE) + , doubleValue(doubleValue) + { + } - explicit Value(std::string& stringValue) : - type(Type::STRING), - stringValue(stringValue) - {} + explicit Value(std::string& stringValue) + : type(Type::STRING) + , stringValue(stringValue) + { + } - explicit Value(std::vector& arrayOfIntegers) : - type(Type::ARRAY_OF_INTEGERS), - arrayOfIntegers(arrayOfIntegers) - {} + explicit Value(std::vector& arrayOfIntegers) + : type(Type::ARRAY_OF_INTEGERS) + , arrayOfIntegers(arrayOfIntegers) + { + } public: - Type type; - bool booleanValue = false; - int32_t integerValue = 0; - double doubleValue = 0.0; - std::string stringValue; + Type type; + bool booleanValue = false; + int32_t integerValue = 0; + double doubleValue = 0.0; + std::string stringValue; std::vector arrayOfIntegers; }; public: - Parameters() {}; + Parameters(){}; Json::Value toJson() const; void Set(Json::Value& data); @@ -92,8 +97,7 @@ namespace RTC /* Inline methods. */ - inline - bool Parameters::HasBoolean(std::string& key) + inline bool Parameters::HasBoolean(std::string& key) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -101,8 +105,7 @@ namespace RTC return this->mapKeyValues[key].type == Value::Type::BOOLEAN; } - inline - bool Parameters::HasInteger(std::string& key) + inline bool Parameters::HasInteger(std::string& key) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -110,8 +113,7 @@ namespace RTC return this->mapKeyValues[key].type == Value::Type::INTEGER; } - inline - bool Parameters::HasDouble(std::string& key) + inline bool Parameters::HasDouble(std::string& key) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -119,8 +121,7 @@ namespace RTC return this->mapKeyValues[key].type == Value::Type::DOUBLE; } - inline - bool Parameters::HasString(std::string& key) + inline bool Parameters::HasString(std::string& key) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -128,8 +129,7 @@ namespace RTC return this->mapKeyValues[key].type == Value::Type::STRING; } - inline - bool Parameters::HasArrayOfIntegers(std::string& key) + inline bool Parameters::HasArrayOfIntegers(std::string& key) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -137,8 +137,7 @@ namespace RTC return this->mapKeyValues[key].type == Value::Type::ARRAY_OF_INTEGERS; } - inline - bool Parameters::IncludesInteger(std::string& key, int32_t integer) + inline bool Parameters::IncludesInteger(std::string& key, int32_t integer) { if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) return false; @@ -148,32 +147,27 @@ namespace RTC return std::find(array.begin(), array.end(), integer) != array.end(); } - inline - void Parameters::SetBoolean(std::string& key, bool booleanValue) + inline void Parameters::SetBoolean(std::string& key, bool booleanValue) { this->mapKeyValues[key] = Value(booleanValue); } - inline - void Parameters::SetInteger(std::string& key, int32_t integerValue) + inline void Parameters::SetInteger(std::string& key, int32_t integerValue) { this->mapKeyValues[key] = Value(integerValue); } - inline - void Parameters::SetDouble(std::string& key, double doubleValue) + inline void Parameters::SetDouble(std::string& key, double doubleValue) { this->mapKeyValues[key] = Value(doubleValue); } - inline - void Parameters::SetString(std::string& key, std::string& stringValue) + inline void Parameters::SetString(std::string& key, std::string& stringValue) { this->mapKeyValues[key] = Value(stringValue); } - inline - void Parameters::SetArrayOfIntegers(std::string& key, std::vector& arrayOfIntegers) + inline void Parameters::SetArrayOfIntegers(std::string& key, std::vector& arrayOfIntegers) { this->mapKeyValues[key] = Value(arrayOfIntegers); } diff --git a/worker/include/RTC/Peer.hpp b/worker/include/RTC/Peer.hpp index c8d8ff117f..564e8c42e6 100644 --- a/worker/include/RTC/Peer.hpp +++ b/worker/include/RTC/Peer.hpp @@ -2,50 +2,52 @@ #define MS_RTC_PEER_HPP #include "common.hpp" -#include "RTC/Transport.hpp" -#include "RTC/RtpReceiver.hpp" -#include "RTC/RtpSender.hpp" -#include "RTC/RtpDictionaries.hpp" -#include "RTC/RtpPacket.hpp" +#include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" +#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/SenderReport.hpp" -#include "RTC/RTCP/Feedback.hpp" -#include "Channel/Request.hpp" -#include "Channel/Notifier.hpp" +#include "RTC/RtpDictionaries.hpp" +#include "RTC/RtpPacket.hpp" +#include "RTC/RtpReceiver.hpp" +#include "RTC/RtpSender.hpp" +#include "RTC/Transport.hpp" #include "handles/Timer.hpp" +#include #include #include #include -#include namespace RTC { - class Peer : - public RTC::Transport::Listener, - public RTC::RtpReceiver::Listener, - public RTC::RtpSender::Listener, - public Timer::Listener + class Peer : public RTC::Transport::Listener, + public RTC::RtpReceiver::Listener, + public RTC::RtpSender::Listener, + public Timer::Listener { public: class Listener { public: - virtual void onPeerClosed(const RTC::Peer* peer) = 0; + virtual void onPeerClosed(const RTC::Peer* peer) = 0; virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) = 0; virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) = 0; - virtual void onPeerRtpReceiverClosed(const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) = 0; + virtual void onPeerRtpReceiverClosed( + const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) = 0; virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0; - virtual void onPeerRtpPacket(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; - virtual void onPeerRtcpReceiverReport(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) = 0; - virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) = 0; - virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) = 0; - virtual void onPeerRtcpSenderReport(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) = 0; + virtual void onPeerRtpPacket( + const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; + virtual void onPeerRtcpReceiverReport( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) = 0; + virtual void onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) = 0; + virtual void onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) = 0; + virtual void onPeerRtcpSenderReport( + const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) = 0; virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0; }; - private: - static uint8_t rtcpBuffer[]; - public: Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName); @@ -62,37 +64,41 @@ namespace RTC const std::unordered_map& GetTransports() const; /** * Add a new RtpSender to the Peer. - * @param rtpSender Instance of RtpSender. - * @param peerName Name of the receiver Peer. + * @param rtpSender - Instance of RtpSender. + * @param peerName - Name of the receiver Peer. */ - void AddRtpSender(RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters); + void AddRtpSender( + RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters); RTC::RtpSender* GetRtpSender(uint32_t ssrc) const; void SendRtcp(uint64_t now); private: - RTC::Transport* GetTransportFromRequest(Channel::Request* request, uint32_t* transportId = nullptr) const; - RTC::RtpReceiver* GetRtpReceiverFromRequest(Channel::Request* request, uint32_t* rtpReceiverId = nullptr) const; - RTC::RtpSender* GetRtpSenderFromRequest(Channel::Request* request, uint32_t* rtpSenderId = nullptr) const; - - /* Pure virtual methods inherited from RTC::Transport::Listener. */ + RTC::Transport* GetTransportFromRequest( + Channel::Request* request, uint32_t* transportId = nullptr) const; + RTC::RtpReceiver* GetRtpReceiverFromRequest( + Channel::Request* request, uint32_t* rtpReceiverId = nullptr) const; + RTC::RtpSender* GetRtpSenderFromRequest( + Channel::Request* request, uint32_t* rtpSenderId = nullptr) const; + + /* Pure virtual methods inherited from RTC::Transport::Listener. */ public: virtual void onTransportConnected(RTC::Transport* transport) override; virtual void onTransportClosed(RTC::Transport* transport) override; virtual void onTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) override; virtual void onTransportFullFrameRequired(RTC::Transport* transport) override; - /* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */ + /* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */ public: virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) override; virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) override; virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override; virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) override; - /* Pure virtual methods inherited from RTC::RtpSender::Listener. */ + /* Pure virtual methods inherited from RTC::RtpSender::Listener. */ public: virtual void onRtpSenderClosed(RTC::RtpSender* rtpSender) override; - /* Pure virtual methods inherited from Timer::Listener. */ + /* Pure virtual methods inherited from Timer::Listener. */ public: virtual void onTimer(Timer* timer) override; @@ -103,10 +109,10 @@ namespace RTC private: // Passed by argument. - Listener* listener = nullptr; + Listener* listener = nullptr; Channel::Notifier* notifier = nullptr; // Others. - Timer* timer = nullptr; + Timer* timer = nullptr; bool hasCapabilities = false; RTC::RtpCapabilities capabilities; std::unordered_map transports; @@ -116,14 +122,12 @@ namespace RTC /* Inline methods. */ - inline - bool Peer::HasCapabilities() const + inline bool Peer::HasCapabilities() const { return this->hasCapabilities; } - inline - std::vector Peer::GetRtpReceivers() const + inline std::vector Peer::GetRtpReceivers() const { std::vector rtpReceivers; @@ -135,8 +139,7 @@ namespace RTC return rtpReceivers; } - inline - std::vector Peer::GetRtpSenders() const + inline std::vector Peer::GetRtpSenders() const { std::vector rtpSenders; @@ -148,8 +151,7 @@ namespace RTC return rtpSenders; } - inline - const std::unordered_map& Peer::GetTransports() const + inline const std::unordered_map& Peer::GetTransports() const { return this->transports; } diff --git a/worker/include/RTC/RTCP/Bye.hpp b/worker/include/RTC/RTCP/Bye.hpp index 61316012d3..166baad60c 100644 --- a/worker/include/RTC/RTCP/Bye.hpp +++ b/worker/include/RTC/RTCP/Bye.hpp @@ -3,102 +3,97 @@ #include "common.hpp" #include "RTC/RTCP/Packet.hpp" -#include #include +#include -namespace RTC { namespace RTCP +namespace RTC { - class ByePacket - : public Packet - { - public: - typedef std::vector::iterator Iterator; - - public: - static ByePacket* Parse(const uint8_t* data, size_t len); - - public: - ByePacket(); - virtual ~ByePacket() {}; - - void AddSsrc(uint32_t ssrc); - void SetReason(const std::string& reason); - const std::string& GetReason() const; - Iterator Begin(); - Iterator End(); - - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetCount() const override; - virtual size_t GetSize() const override; - - private: - std::vector ssrcs; - std::string reason; - }; - - /* Inline instance methods. */ - - inline - ByePacket::ByePacket() - : Packet(Type::BYE) - {} - - inline - size_t ByePacket::GetCount() const + namespace RTCP { - return this->ssrcs.size(); - } - - inline - size_t ByePacket::GetSize() const - { - size_t size = sizeof(Packet::CommonHeader); - - size += ssrcs.size() * sizeof(uint32_t); + class ByePacket : public Packet + { + public: + typedef std::vector::iterator Iterator; + + public: + static ByePacket* Parse(const uint8_t* data, size_t len); + + public: + ByePacket(); + virtual ~ByePacket(){}; + + void AddSsrc(uint32_t ssrc); + void SetReason(const std::string& reason); + const std::string& GetReason() const; + Iterator Begin(); + Iterator End(); + + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetCount() const override; + virtual size_t GetSize() const override; + + private: + std::vector ssrcs; + std::string reason; + }; + + /* Inline instance methods. */ + + inline ByePacket::ByePacket() + : Packet(Type::BYE) + { + } - if (!this->reason.empty()) + inline size_t ByePacket::GetCount() const { - size += sizeof(uint8_t); // Length field. - size += this->reason.length(); + return this->ssrcs.size(); } - // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment - // Consider pading to 32 bits (4 bytes) boundary. - return (size + 3) & ~3; - } + inline size_t ByePacket::GetSize() const + { + size_t size = sizeof(Packet::CommonHeader); - inline - void ByePacket::AddSsrc(uint32_t ssrc) - { - this->ssrcs.push_back(ssrc); - } + size += ssrcs.size() * sizeof(uint32_t); - inline - void ByePacket::SetReason(const std::string& reason) - { - this->reason = reason; - } + if (!this->reason.empty()) + { + size += sizeof(uint8_t); // Length field. + size += this->reason.length(); + } - inline - const std::string& ByePacket::GetReason() const - { - return this->reason; - } + // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment + // Consider pading to 32 bits (4 bytes) boundary. + return (size + 3) & ~3; + } - inline - ByePacket::Iterator ByePacket::Begin() - { - return this->ssrcs.begin(); - } + inline void ByePacket::AddSsrc(uint32_t ssrc) + { + this->ssrcs.push_back(ssrc); + } - inline - ByePacket::Iterator ByePacket::End() - { - return this->ssrcs.end(); + inline void ByePacket::SetReason(const std::string& reason) + { + this->reason = reason; + } + + inline const std::string& ByePacket::GetReason() const + { + return this->reason; + } + + inline ByePacket::Iterator ByePacket::Begin() + { + return this->ssrcs.begin(); + } + + inline ByePacket::Iterator ByePacket::End() + { + return this->ssrcs.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/CompoundPacket.hpp b/worker/include/RTC/RTCP/CompoundPacket.hpp index 313cd3d09e..5ff9982839 100644 --- a/worker/include/RTC/RTCP/CompoundPacket.hpp +++ b/worker/include/RTC/RTCP/CompoundPacket.hpp @@ -2,71 +2,68 @@ #define MS_RTC_RTCP_COMPOUND_PACKET_HPP #include "common.hpp" -#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/Sdes.hpp" +#include "RTC/RTCP/SenderReport.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - class CompoundPacket + namespace RTCP { - public: - const uint8_t* GetData() const; - size_t GetSize() const; - size_t GetSenderReportCount() const; - size_t GetReceiverReportCount() const; - void Dump() const; - void AddSenderReport(SenderReport* report); - void AddReceiverReport(ReceiverReport* report); - void AddSdesChunk(SdesChunk* chunk); - void Serialize(uint8_t* buffer); + class CompoundPacket + { + public: + const uint8_t* GetData() const; + size_t GetSize() const; + size_t GetSenderReportCount() const; + size_t GetReceiverReportCount() const; + void Dump() const; + void AddSenderReport(SenderReport* report); + void AddReceiverReport(ReceiverReport* report); + void AddSdesChunk(SdesChunk* chunk); + void Serialize(uint8_t* buffer); - private: - uint8_t* header = nullptr; - size_t size = 0; - SenderReportPacket senderReportPacket; - ReceiverReportPacket receiverReportPacket; - SdesPacket sdesPacket; - }; + private: + uint8_t* header = nullptr; + size_t size = 0; + SenderReportPacket senderReportPacket; + ReceiverReportPacket receiverReportPacket; + SdesPacket sdesPacket; + }; - /* Inline methods. */ + /* Inline methods. */ - inline - const uint8_t* CompoundPacket::GetData() const - { - return this->header; - } + inline const uint8_t* CompoundPacket::GetData() const + { + return this->header; + } - inline - size_t CompoundPacket::GetSize() const - { - return this->size; - } + inline size_t CompoundPacket::GetSize() const + { + return this->size; + } - inline - size_t CompoundPacket::GetSenderReportCount() const - { - return this->senderReportPacket.GetCount(); - } + inline size_t CompoundPacket::GetSenderReportCount() const + { + return this->senderReportPacket.GetCount(); + } - inline - size_t CompoundPacket::GetReceiverReportCount() const - { - return this->receiverReportPacket.GetCount(); - } + inline size_t CompoundPacket::GetReceiverReportCount() const + { + return this->receiverReportPacket.GetCount(); + } - inline - void CompoundPacket::AddReceiverReport(ReceiverReport* report) - { - this->receiverReportPacket.AddReport(report); - } + inline void CompoundPacket::AddReceiverReport(ReceiverReport* report) + { + this->receiverReportPacket.AddReport(report); + } - inline - void CompoundPacket::AddSdesChunk(SdesChunk* chunk) - { - this->sdesPacket.AddChunk(chunk); + inline void CompoundPacket::AddSdesChunk(SdesChunk* chunk) + { + this->sdesPacket.AddChunk(chunk); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/Feedback.hpp b/worker/include/RTC/RTCP/Feedback.hpp index 1a4c0d0512..9f751f7f9b 100644 --- a/worker/include/RTC/RTCP/Feedback.hpp +++ b/worker/include/RTC/RTCP/Feedback.hpp @@ -2,137 +2,140 @@ #define MS_RTC_RTCP_FEEDBACK_HPP #include "common.hpp" -#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/FeedbackItem.hpp" +#include "RTC/RTCP/Packet.hpp" -namespace RTC { namespace RTCP +namespace RTC { - template class FeedbackPacket - : public Packet + namespace RTCP { - public: - /* Struct for RTP Feedback message. */ - struct Header + template + class FeedbackPacket : public Packet { - uint32_t s_ssrc; - uint32_t m_ssrc; + public: + /* Struct for RTP Feedback message. */ + struct Header + { + uint32_t senderSsrc; + uint32_t mediaSsrc; + }; + + public: + static RTCP::Type RtcpType; + static FeedbackPacket* Parse(const uint8_t* data, size_t len); + static const std::string& MessageType2String(typename T::MessageType type); + + private: + static std::map type2String; + + public: + typename T::MessageType GetMessageType() const; + uint32_t GetSenderSsrc() const; + void SetSenderSsrc(uint32_t ssrc); + uint32_t GetMediaSsrc() const; + void SetMediaSsrc(uint32_t ssrc); + + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetCount() const override; + virtual size_t GetSize() const override; + + protected: + explicit FeedbackPacket(CommonHeader* commonHeader); + FeedbackPacket(typename T::MessageType type, uint32_t senderSsrc, uint32_t mediaSsrc); + virtual ~FeedbackPacket(); + + private: + Header* header = nullptr; + uint8_t* raw = nullptr; + typename T::MessageType messageType; }; - public: - static RTCP::Type RtcpType; - static FeedbackPacket* Parse(const uint8_t* data, size_t len); - static const std::string& MessageType2String(typename T::MessageType type); - - private: - static std::map type2String; - - public: - typename T::MessageType GetMessageType() const; - uint32_t GetSenderSsrc() const; - void SetSenderSsrc(uint32_t ssrc); - uint32_t GetMediaSsrc() const; - void SetMediaSsrc(uint32_t ssrc); - - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetCount() const override; - virtual size_t GetSize() const override; - - protected: - explicit FeedbackPacket(CommonHeader* commonHeader); - FeedbackPacket(typename T::MessageType type, uint32_t sender_ssrc, uint32_t media_ssrc); - virtual ~FeedbackPacket(); - - private: - Header* header = nullptr; - uint8_t* raw = nullptr; - typename T::MessageType messageType; - }; - - class FeedbackPs - { - public: - enum class MessageType : uint8_t + class FeedbackPs { - PLI = 1, - SLI = 2, - RPSI = 3, - FIR = 4, - TSTR = 5, - TSTN = 6, - VBCM = 7, - PSLEI = 8, - ROI = 9, - AFB = 15, - EXT = 31 + public: + enum class MessageType : uint8_t + { + PLI = 1, + SLI = 2, + RPSI = 3, + FIR = 4, + TSTR = 5, + TSTN = 6, + VBCM = 7, + PSLEI = 8, + ROI = 9, + AFB = 15, + EXT = 31 + }; }; - }; - class FeedbackRtp - { - public: - enum class MessageType : uint8_t + class FeedbackRtp { - NACK = 1, - TMMBR = 3, - TMMBN = 4, - SR_REQ = 5, - RAMS = 6, - TLLEI = 7, - ECN = 8, - PS = 9, - EXT = 31 + public: + enum class MessageType : uint8_t + { + NACK = 1, + TMMBR = 3, + TMMBN = 4, + SR_REQ = 5, + RAMS = 6, + TLLEI = 7, + ECN = 8, + PS = 9, + EXT = 31 + }; }; - }; - typedef FeedbackPacket FeedbackPsPacket; - typedef FeedbackPacket FeedbackRtpPacket; + typedef FeedbackPacket FeedbackPsPacket; + typedef FeedbackPacket FeedbackRtpPacket; - /* Inline instance methods. */ + /* Inline instance methods. */ - template - typename T::MessageType FeedbackPacket::GetMessageType() const - { - return this->messageType; - } + template + typename T::MessageType FeedbackPacket::GetMessageType() const + { + return this->messageType; + } - template - size_t FeedbackPacket::GetCount() const - { - return (size_t)this->GetMessageType(); - } + template + size_t FeedbackPacket::GetCount() const + { + return (size_t)this->GetMessageType(); + } - template - size_t FeedbackPacket::GetSize() const - { - return sizeof(CommonHeader) + sizeof(Header); - } + template + size_t FeedbackPacket::GetSize() const + { + return sizeof(CommonHeader) + sizeof(Header); + } - template - uint32_t FeedbackPacket::GetSenderSsrc() const - { - return (uint32_t)ntohl(this->header->s_ssrc); - } + template + uint32_t FeedbackPacket::GetSenderSsrc() const + { + return (uint32_t)ntohl(this->header->senderSsrc); + } - template - void FeedbackPacket::SetSenderSsrc(uint32_t ssrc) - { - this->header->s_ssrc = (uint32_t)htonl(ssrc); - } + template + void FeedbackPacket::SetSenderSsrc(uint32_t ssrc) + { + this->header->senderSsrc = (uint32_t)htonl(ssrc); + } - template - uint32_t FeedbackPacket::GetMediaSsrc() const - { - return (uint32_t)ntohl(this->header->m_ssrc); - } + template + uint32_t FeedbackPacket::GetMediaSsrc() const + { + return (uint32_t)ntohl(this->header->mediaSsrc); + } - template - void FeedbackPacket::SetMediaSsrc(uint32_t ssrc) - { - this->header->m_ssrc = (uint32_t)htonl(ssrc); + template + void FeedbackPacket::SetMediaSsrc(uint32_t ssrc) + { + this->header->mediaSsrc = (uint32_t)htonl(ssrc); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackItem.hpp b/worker/include/RTC/RTCP/FeedbackItem.hpp index 850409dff6..4272caf5fb 100644 --- a/worker/include/RTC/RTCP/FeedbackItem.hpp +++ b/worker/include/RTC/RTCP/FeedbackItem.hpp @@ -3,51 +3,51 @@ #include "common.hpp" -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackItem + namespace RTCP { - public: - bool IsCorrect() const; - - protected: - virtual ~FeedbackItem(); - - public: - virtual void Dump() const = 0; - virtual void Serialize(); - virtual size_t Serialize(uint8_t* buffer) = 0; - virtual size_t GetSize() const = 0; - - protected: - uint8_t* raw = nullptr; - bool isCorrect = true; - }; - - /* Inline instance methods */ - - inline - FeedbackItem::~FeedbackItem() - { - if (this->raw) - delete this->raw; - } - - inline - void FeedbackItem::Serialize() - { - if (this->raw) - delete this->raw; - - this->raw = new uint8_t[this->GetSize()]; - this->Serialize(this->raw); - } - - inline - bool FeedbackItem::IsCorrect() const - { - return this->isCorrect; + class FeedbackItem + { + public: + bool IsCorrect() const; + + protected: + virtual ~FeedbackItem(); + + public: + virtual void Dump() const = 0; + virtual void Serialize(); + virtual size_t Serialize(uint8_t* buffer) = 0; + virtual size_t GetSize() const = 0; + + protected: + uint8_t* raw = nullptr; + bool isCorrect = true; + }; + + /* Inline instance methods */ + + inline FeedbackItem::~FeedbackItem() + { + if (this->raw) + delete this->raw; + } + + inline void FeedbackItem::Serialize() + { + if (this->raw) + delete this->raw; + + this->raw = new uint8_t[this->GetSize()]; + this->Serialize(this->raw); + } + + inline bool FeedbackItem::IsCorrect() const + { + return this->isCorrect; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPs.hpp b/worker/include/RTC/RTCP/FeedbackPs.hpp index 8fedfc711c..eadaccd60b 100644 --- a/worker/include/RTC/RTCP/FeedbackPs.hpp +++ b/worker/include/RTC/RTCP/FeedbackPs.hpp @@ -5,79 +5,84 @@ #include "RTC/RTCP/Feedback.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - template class FeedbackPsItemsPacket - : public FeedbackPsPacket + namespace RTCP { - public: - typedef typename std::vector::iterator Iterator; - - public: - static FeedbackPsItemsPacket* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit FeedbackPsItemsPacket(CommonHeader* commonHeader); - explicit FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); - virtual ~FeedbackPsItemsPacket() {}; - - void AddItem(Item* item); - Iterator Begin(); - Iterator End(); - - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - std::vector items; - }; - - /* Inline instance methods. */ - - template - FeedbackPsItemsPacket::FeedbackPsItemsPacket(CommonHeader* commonHeader): - FeedbackPsPacket(commonHeader) - {} - - template - FeedbackPsItemsPacket::FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc): - FeedbackPsPacket(Item::MessageType, sender_ssrc, media_ssrc) - {} - - template - size_t FeedbackPsItemsPacket::GetSize() const - { - size_t size = FeedbackPsPacket::GetSize(); + template + class FeedbackPsItemsPacket : public FeedbackPsPacket + { + public: + typedef typename std::vector::iterator Iterator; + + public: + static FeedbackPsItemsPacket* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit FeedbackPsItemsPacket(CommonHeader* commonHeader); + explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0); + virtual ~FeedbackPsItemsPacket(){}; + + void AddItem(Item* item); + Iterator Begin(); + Iterator End(); + + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + std::vector items; + }; - for (auto item : this->items) + /* Inline instance methods. */ + + template + FeedbackPsItemsPacket::FeedbackPsItemsPacket(CommonHeader* commonHeader) + : FeedbackPsPacket(commonHeader) { - size += item->GetSize(); } - return size; - } + template + FeedbackPsItemsPacket::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc) + : FeedbackPsPacket(Item::MessageType, senderSsrc, mediaSsrc) + { + } - template - void FeedbackPsItemsPacket::AddItem(Item* item) - { - this->items.push_back(item); - } + template + size_t FeedbackPsItemsPacket::GetSize() const + { + size_t size = FeedbackPsPacket::GetSize(); - template - typename FeedbackPsItemsPacket::Iterator FeedbackPsItemsPacket::Begin() - { - return this->items.begin(); - } + for (auto item : this->items) + { + size += item->GetSize(); + } - template - typename FeedbackPsItemsPacket::Iterator FeedbackPsItemsPacket::End() - { - return this->items.end(); + return size; + } + + template + void FeedbackPsItemsPacket::AddItem(Item* item) + { + this->items.push_back(item); + } + + template + typename FeedbackPsItemsPacket::Iterator FeedbackPsItemsPacket::Begin() + { + return this->items.begin(); + } + + template + typename FeedbackPsItemsPacket::Iterator FeedbackPsItemsPacket::End() + { + return this->items.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsAfb.hpp b/worker/include/RTC/RTCP/FeedbackPsAfb.hpp index f25c130f06..b1401fb053 100644 --- a/worker/include/RTC/RTCP/FeedbackPsAfb.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsAfb.hpp @@ -4,70 +4,68 @@ #include "common.hpp" #include "RTC/RTCP/Feedback.hpp" -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsAfbPacket - : public FeedbackPsPacket + namespace RTCP { - public: - typedef enum Application : uint8_t + class FeedbackPsAfbPacket : public FeedbackPsPacket { - UNKNOWN = 0, - REMB = 1 - } Application; + public: + typedef enum Application : uint8_t { UNKNOWN = 0, REMB = 1 } Application; - public: - static FeedbackPsAfbPacket* Parse(const uint8_t* data, size_t len); + public: + static FeedbackPsAfbPacket* Parse(const uint8_t* data, size_t len); - public: - // Parsed Report. Points to an external data. - explicit FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application = UNKNOWN); - FeedbackPsAfbPacket(uint32_t sender_ssrc, uint32_t media_ssrc, Application application = UNKNOWN); - virtual ~FeedbackPsAfbPacket() {}; + public: + // Parsed Report. Points to an external data. + explicit FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application = UNKNOWN); + FeedbackPsAfbPacket(uint32_t senderSsrc, uint32_t mediaSsrc, Application application = UNKNOWN); + virtual ~FeedbackPsAfbPacket(){}; - Application GetApplication() const; + Application GetApplication() const; - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; - private: - Application application = UNKNOWN; - uint8_t* data = nullptr; - size_t size = 0; - }; + private: + Application application = UNKNOWN; + uint8_t* data = nullptr; + size_t size = 0; + }; - /* Inline instance methods. */ + /* Inline instance methods. */ - inline - FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application): - FeedbackPsPacket(commonHeader) - { - this->size = ((ntohs(commonHeader->length) + 1) * 4) - (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header)); - this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); - this->application = application; - } + inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application) + : FeedbackPsPacket(commonHeader) + { + this->size = ((ntohs(commonHeader->length) + 1) * 4) - + (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header)); - inline - FeedbackPsAfbPacket::FeedbackPsAfbPacket(uint32_t sender_ssrc, uint32_t media_ssrc, Application application): - FeedbackPsPacket(FeedbackPs::MessageType::AFB, sender_ssrc, media_ssrc) - { - this->application = application; - } + this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); - inline - FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const - { - return this->application; - } + this->application = application; + } - inline - size_t FeedbackPsAfbPacket::GetSize() const - { - return FeedbackPsPacket::GetSize() + this->size; + inline FeedbackPsAfbPacket::FeedbackPsAfbPacket( + uint32_t senderSsrc, uint32_t mediaSsrc, Application application) + : FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc) + { + this->application = application; + } + + inline FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const + { + return this->application; + } + + inline size_t FeedbackPsAfbPacket::GetSize() const + { + return FeedbackPsPacket::GetSize() + this->size; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsFir.hpp b/worker/include/RTC/RTCP/FeedbackPsFir.hpp index 5b751b549a..6858f79a08 100644 --- a/worker/include/RTC/RTCP/FeedbackPsFir.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsFir.hpp @@ -16,76 +16,75 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsFirItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackPsFirItem : public FeedbackItem { - uint32_t ssrc; - uint8_t sequence_number; - uint32_t reserved:24; + private: + struct Header + { + uint32_t ssrc; + uint8_t sequenceNumber; + uint32_t reserved : 24; + }; + + public: + static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; + + public: + static FeedbackPsFirItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsFirItem(Header* header); + explicit FeedbackPsFirItem(FeedbackPsFirItem* item); + FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber); + virtual ~FeedbackPsFirItem(){}; + + uint32_t GetSsrc() const; + uint8_t GetSequenceNumber() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; + // Fir packet declaration. + typedef FeedbackPsItemsPacket FeedbackPsFirPacket; - public: - static FeedbackPsFirItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackPsFirItem(Header* header); - explicit FeedbackPsFirItem(FeedbackPsFirItem* item); - FeedbackPsFirItem(uint32_t ssrc, uint8_t sequence_number); - virtual ~FeedbackPsFirItem() {}; - - uint32_t GetSsrc() const; - uint8_t GetSequenceNumber() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Fir packet declaration. - typedef FeedbackPsItemsPacket FeedbackPsFirPacket; - - /* Inline instance methods. */ - - inline - FeedbackPsFirItem::FeedbackPsFirItem(Header* header): - header(header) - {} + inline FeedbackPsFirItem::FeedbackPsFirItem(Header* header) + : header(header) + { + } - inline - FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item) : - header(item->header) - {} + inline FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item) + : header(item->header) + { + } - inline - size_t FeedbackPsFirItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackPsFirItem::GetSize() const + { + return sizeof(Header); + } - inline - uint32_t FeedbackPsFirItem::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); - } + inline uint32_t FeedbackPsFirItem::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } - inline - uint8_t FeedbackPsFirItem::GetSequenceNumber() const - { - return (uint8_t)this->header->sequence_number; + inline uint8_t FeedbackPsFirItem::GetSequenceNumber() const + { + return (uint8_t)this->header->sequenceNumber; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsLei.hpp b/worker/include/RTC/RTCP/FeedbackPsLei.hpp index 990b12f0e3..1acd38ff03 100644 --- a/worker/include/RTC/RTCP/FeedbackPsLei.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsLei.hpp @@ -13,67 +13,67 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsLeiItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackPsLeiItem : public FeedbackItem { - uint32_t ssrc; + private: + struct Header + { + uint32_t ssrc; + }; + + public: + static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::PSLEI; + + public: + static FeedbackPsLeiItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsLeiItem(Header* header); + explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); + explicit FeedbackPsLeiItem(uint32_t ssrc); + virtual ~FeedbackPsLeiItem(){}; + + uint32_t GetSsrc() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::PSLEI; + // Lei packet declaration. + typedef FeedbackPsItemsPacket FeedbackPsLeiPacket; - public: - static FeedbackPsLeiItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackPsLeiItem(Header* header); - explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); - explicit FeedbackPsLeiItem(uint32_t ssrc); - virtual ~FeedbackPsLeiItem() {}; - - uint32_t GetSsrc() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Lei packet declaration. - typedef FeedbackPsItemsPacket FeedbackPsLeiPacket; - - /* Inline instance methods. */ - - inline - FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header): - header(header) - {} + inline FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header) + : header(header) + { + } - inline - FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item): - header(item->header) - {} + inline FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item) + : header(item->header) + { + } - inline - size_t FeedbackPsLeiItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackPsLeiItem::GetSize() const + { + return sizeof(Header); + } - inline - uint32_t FeedbackPsLeiItem::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); + inline uint32_t FeedbackPsLeiItem::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsPli.hpp b/worker/include/RTC/RTCP/FeedbackPsPli.hpp index dc3637e54a..ab65418be0 100644 --- a/worker/include/RTC/RTCP/FeedbackPsPli.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsPli.hpp @@ -4,35 +4,37 @@ #include "common.hpp" #include "RTC/RTCP/Feedback.hpp" -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsPliPacket - : public FeedbackPsPacket + namespace RTCP { - public: - static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit FeedbackPsPliPacket(CommonHeader* commonHeader); - FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc); - virtual ~FeedbackPsPliPacket() {}; - - public: - virtual void Dump() const override; - }; - - /* Inline instance methods. */ - - inline - FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader): - FeedbackPsPacket(commonHeader) - {} - - inline - FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc): - FeedbackPsPacket(FeedbackPs::MessageType::PLI, sender_ssrc, media_ssrc) - {} -}} + class FeedbackPsPliPacket : public FeedbackPsPacket + { + public: + static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit FeedbackPsPliPacket(CommonHeader* commonHeader); + FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc); + virtual ~FeedbackPsPliPacket(){}; + + public: + virtual void Dump() const override; + }; + + /* Inline instance methods. */ + + inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader) + : FeedbackPsPacket(commonHeader) + { + } + + inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc) + : FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc) + { + } + } +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsRemb.hpp b/worker/include/RTC/RTCP/FeedbackPsRemb.hpp index e5741fca70..635292e136 100644 --- a/worker/include/RTC/RTCP/FeedbackPsRemb.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsRemb.hpp @@ -25,85 +25,81 @@ | ... | */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsRembPacket - : public FeedbackPsAfbPacket + namespace RTCP { - public: - // 'R' 'E' 'M' 'B'. - static uint32_t UniqueIdentifier; - - public: - static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit FeedbackPsRembPacket(CommonHeader* commonHeader); - FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc); - virtual ~FeedbackPsRembPacket() {}; - - bool IsCorrect(); - void SetBitrate(uint64_t bitrate); - void SetSsrcs(const std::vector& ssrcs); - uint64_t GetBitrate(); - const std::vector& GetSsrcs(); - - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - std::vector ssrcs; - // Bitrate represented in bps. - uint64_t bitrate = 0; - bool isCorrect = true; - }; - - /* Inline instance methods. */ - - inline - FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc): - FeedbackPsAfbPacket(sender_ssrc, media_ssrc, FeedbackPsAfbPacket::Application::REMB) - {} - - inline - bool FeedbackPsRembPacket::IsCorrect() - { - return this->isCorrect; - } - - inline - void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate) - { - this->bitrate = bitrate; - } - - inline - void FeedbackPsRembPacket::SetSsrcs(const std::vector& ssrcs) - { - this->ssrcs = ssrcs; - } - - inline - uint64_t FeedbackPsRembPacket::GetBitrate() - { - return this->bitrate; - } - - inline - const std::vector& FeedbackPsRembPacket::GetSsrcs() - { - return this->ssrcs; - } - - inline - size_t FeedbackPsRembPacket::GetSize() const - { - return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size()); + class FeedbackPsRembPacket : public FeedbackPsAfbPacket + { + public: + // 'R' 'E' 'M' 'B'. + static uint32_t UniqueIdentifier; + + public: + static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit FeedbackPsRembPacket(CommonHeader* commonHeader); + FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc); + virtual ~FeedbackPsRembPacket(){}; + + bool IsCorrect(); + void SetBitrate(uint64_t bitrate); + void SetSsrcs(const std::vector& ssrcs); + uint64_t GetBitrate(); + const std::vector& GetSsrcs(); + + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + std::vector ssrcs; + // Bitrate represented in bps. + uint64_t bitrate = 0; + bool isCorrect = true; + }; + + /* Inline instance methods. */ + + inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc) + : FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB) + { + } + + inline bool FeedbackPsRembPacket::IsCorrect() + { + return this->isCorrect; + } + + inline void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate) + { + this->bitrate = bitrate; + } + + inline void FeedbackPsRembPacket::SetSsrcs(const std::vector& ssrcs) + { + this->ssrcs = ssrcs; + } + + inline uint64_t FeedbackPsRembPacket::GetBitrate() + { + return this->bitrate; + } + + inline const std::vector& FeedbackPsRembPacket::GetSsrcs() + { + return this->ssrcs; + } + + inline size_t FeedbackPsRembPacket::GetSize() const + { + return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size()); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsRpsi.hpp b/worker/include/RTC/RTCP/FeedbackPsRpsi.hpp index 02f7fab919..6f4b48db56 100644 --- a/worker/include/RTC/RTCP/FeedbackPsRpsi.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsRpsi.hpp @@ -17,90 +17,87 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsRpsiItem - : public FeedbackItem + namespace RTCP { - const static size_t MaxBitStringSize = 6; - const static size_t BitStringOffset = 2; - - private: - struct Header + class FeedbackPsRpsiItem : public FeedbackItem { - uint8_t padding_bits; - uint8_t zero:1; - uint8_t payload_type:7; - uint8_t bit_string[MaxBitStringSize]; + const static size_t MaxBitStringSize = 6; + const static size_t BitStringOffset = 2; + + private: + struct Header + { + uint8_t paddingBits; + uint8_t zero : 1; + uint8_t payloadType : 7; + uint8_t bitString[MaxBitStringSize]; + }; + + public: + static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::RPSI; + + public: + static FeedbackPsRpsiItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsRpsiItem(Header* header); + explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item); + FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length); + virtual ~FeedbackPsRpsiItem(){}; + + bool IsCorrect() const; + uint8_t GetPayloadType() const; + uint8_t* GetBitString() const; + size_t GetLength() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; + size_t length = 0; }; - public: - static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::RPSI; - - public: - static FeedbackPsRpsiItem* Parse(const uint8_t* data, size_t len); - - public: - explicit FeedbackPsRpsiItem(Header* header); - explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item); - FeedbackPsRpsiItem(uint8_t payload_type, uint8_t* bit_string, size_t length); - virtual ~FeedbackPsRpsiItem() {}; - - bool IsCorrect() const; - uint8_t GetPayloadType() const; - uint8_t* GetBitString() const; - size_t GetLength() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - size_t length = 0; - }; + // Rpsi packet declaration. + typedef FeedbackPsItemsPacket FeedbackPsRpsiPacket; - // Rpsi packet declaration. - typedef FeedbackPsItemsPacket FeedbackPsRpsiPacket; + /* Inline instance methods. */ - /* Inline instance methods. */ - - inline - FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : - header(item->header) - {} + inline FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) + : header(item->header) + { + } - inline - size_t FeedbackPsRpsiItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackPsRpsiItem::GetSize() const + { + return sizeof(Header); + } - inline - uint8_t FeedbackPsRpsiItem::GetPayloadType() const - { - return this->header->payload_type; - } + inline uint8_t FeedbackPsRpsiItem::GetPayloadType() const + { + return this->header->payloadType; + } - inline - uint8_t* FeedbackPsRpsiItem::GetBitString() const - { - return this->header->bit_string; - } + inline uint8_t* FeedbackPsRpsiItem::GetBitString() const + { + return this->header->bitString; + } - inline - size_t FeedbackPsRpsiItem::GetLength() const - { - return this->length; - } + inline size_t FeedbackPsRpsiItem::GetLength() const + { + return this->length; + } - inline - bool FeedbackPsRpsiItem::IsCorrect() const - { - return this->isCorrect; + inline bool FeedbackPsRpsiItem::IsCorrect() const + { + return this->isCorrect; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsSli.hpp b/worker/include/RTC/RTCP/FeedbackPsSli.hpp index e769ed8772..efd6a42954 100644 --- a/worker/include/RTC/RTCP/FeedbackPsSli.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsSli.hpp @@ -13,95 +13,90 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsSliItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackPsSliItem : public FeedbackItem { - uint32_t compact; + private: + struct Header + { + uint32_t compact; + }; + + public: + static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::SLI; + + public: + static FeedbackPsSliItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsSliItem(Header* header); + explicit FeedbackPsSliItem(FeedbackPsSliItem* item); + FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId); + virtual ~FeedbackPsSliItem(){}; + + uint16_t GetFirst() const; + void SetFirst(uint16_t first); + uint16_t GetNumber() const; + void SetNumber(uint16_t number); + uint8_t GetPictureId() const; + void SetPictureId(uint8_t pictureId); + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; + uint16_t first; + uint16_t number; + uint8_t pictureId; }; - public: - static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::SLI; - - public: - static FeedbackPsSliItem* Parse(const uint8_t* data, size_t len); - - public: - explicit FeedbackPsSliItem(Header* header); - explicit FeedbackPsSliItem(FeedbackPsSliItem* item); - FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId); - virtual ~FeedbackPsSliItem() {}; - - uint16_t GetFirst() const; - void SetFirst(uint16_t first); - uint16_t GetNumber() const; - void SetNumber(uint16_t number); - uint8_t GetPictureId() const; - void SetPictureId(uint8_t pictureId); - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - uint16_t first; - uint16_t number; - uint8_t pictureId; - }; - - // Sli packet declaration. - typedef FeedbackPsItemsPacket FeedbackPsSliPacket; - - /* Inline instance methods. */ - - inline - size_t FeedbackPsSliItem::GetSize() const - { - return sizeof(Header); - } + // Sli packet declaration. + typedef FeedbackPsItemsPacket FeedbackPsSliPacket; - inline - uint16_t FeedbackPsSliItem::GetFirst() const - { - return this->first; - } + /* Inline instance methods. */ - inline - void FeedbackPsSliItem::SetFirst(uint16_t first) - { - this->first = first; - } + inline size_t FeedbackPsSliItem::GetSize() const + { + return sizeof(Header); + } - inline - uint16_t FeedbackPsSliItem::GetNumber() const - { - return this->number; - } + inline uint16_t FeedbackPsSliItem::GetFirst() const + { + return this->first; + } - inline - void FeedbackPsSliItem::SetNumber(uint16_t number) - { - this->number = number; - } + inline void FeedbackPsSliItem::SetFirst(uint16_t first) + { + this->first = first; + } - inline - uint8_t FeedbackPsSliItem::GetPictureId() const - { - return this->pictureId; - } + inline uint16_t FeedbackPsSliItem::GetNumber() const + { + return this->number; + } - inline - void FeedbackPsSliItem::SetPictureId(uint8_t pictureId) - { - this->pictureId = pictureId; + inline void FeedbackPsSliItem::SetNumber(uint16_t number) + { + this->number = number; + } + + inline uint8_t FeedbackPsSliItem::GetPictureId() const + { + return this->pictureId; + } + + inline void FeedbackPsSliItem::SetPictureId(uint8_t pictureId) + { + this->pictureId = pictureId; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsTst.hpp b/worker/include/RTC/RTCP/FeedbackPsTst.hpp index cdbfe970b8..44f54c28a4 100644 --- a/worker/include/RTC/RTCP/FeedbackPsTst.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsTst.hpp @@ -17,92 +17,101 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - template class FeedbackPsTstItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + template + class FeedbackPsTstItem : public FeedbackItem { - uint32_t ssrc; - uint32_t sequence_number:8; - uint32_t reserved:19; - uint32_t index:5; + private: + struct Header + { + uint32_t ssrc; + uint32_t sequenceNumber : 8; + uint32_t reserved : 19; + uint32_t index : 5; + }; + + public: + static const FeedbackPs::MessageType MessageType; + + public: + static FeedbackPsTstItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsTstItem(Header* header); + explicit FeedbackPsTstItem(FeedbackPsTstItem* item); + FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index); + virtual ~FeedbackPsTstItem(){}; + + uint32_t GetSsrc() const; + uint8_t GetSequenceNumber() const; + uint8_t GetIndex() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackPs::MessageType MessageType; - - public: - static FeedbackPsTstItem* Parse(const uint8_t* data, size_t len); - - public: - explicit FeedbackPsTstItem(Header* header); - explicit FeedbackPsTstItem(FeedbackPsTstItem* item); - FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index); - virtual ~FeedbackPsTstItem() {}; - - uint32_t GetSsrc() const; - uint8_t GetSequenceNumber() const; - uint8_t GetIndex() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - class Tstr {}; - class Tstn {}; + class Tstr + { + }; + class Tstn + { + }; - // Tst classes declaration. - typedef FeedbackPsTstItem FeedbackPsTstrItem; - typedef FeedbackPsTstItem FeedbackPsTstnItem; + // Tst classes declaration. + typedef FeedbackPsTstItem FeedbackPsTstrItem; + typedef FeedbackPsTstItem FeedbackPsTstnItem; - // Tst packets declaration. - typedef FeedbackPsItemsPacket FeedbackPsTstrPacket; - typedef FeedbackPsItemsPacket FeedbackPsTstnPacket; + // Tst packets declaration. + typedef FeedbackPsItemsPacket FeedbackPsTstrPacket; + typedef FeedbackPsItemsPacket FeedbackPsTstnPacket; - /* Inline instance methods. */ + /* Inline instance methods. */ - template - FeedbackPsTstItem::FeedbackPsTstItem(Header* header): - header(header) - {} + template + FeedbackPsTstItem::FeedbackPsTstItem(Header* header) + : header(header) + { + } - template - FeedbackPsTstItem::FeedbackPsTstItem(FeedbackPsTstItem* item) : - header(item->header) - {} + template + FeedbackPsTstItem::FeedbackPsTstItem(FeedbackPsTstItem* item) + : header(item->header) + { + } - template - size_t FeedbackPsTstItem::GetSize() const - { - return sizeof(Header); - } + template + size_t FeedbackPsTstItem::GetSize() const + { + return sizeof(Header); + } - template - uint32_t FeedbackPsTstItem::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); - } + template + uint32_t FeedbackPsTstItem::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } - template - uint8_t FeedbackPsTstItem::GetSequenceNumber() const - { - return (uint8_t)this->header->sequence_number; - } + template + uint8_t FeedbackPsTstItem::GetSequenceNumber() const + { + return (uint8_t)this->header->sequenceNumber; + } - template - uint8_t FeedbackPsTstItem::GetIndex() const - { - return (uint8_t)this->header->index; + template + uint8_t FeedbackPsTstItem::GetIndex() const + { + return (uint8_t)this->header->index; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackPsVbcm.hpp b/worker/include/RTC/RTCP/FeedbackPsVbcm.hpp index 725da65898..49c64c81a6 100644 --- a/worker/include/RTC/RTCP/FeedbackPsVbcm.hpp +++ b/worker/include/RTC/RTCP/FeedbackPsVbcm.hpp @@ -19,103 +19,100 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackPsVbcmItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackPsVbcmItem : public FeedbackItem { - uint32_t ssrc; - uint8_t sequence_number; - uint8_t zero:1; - uint8_t payload_type:7; - uint16_t length; - uint8_t value[]; + private: + struct Header + { + uint32_t ssrc; + uint8_t sequenceNumber; + uint8_t zero : 1; + uint8_t payloadType : 7; + uint16_t length; + uint8_t value[]; + }; + + public: + static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; + + public: + static FeedbackPsVbcmItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackPsVbcmItem(Header* header); + explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); + FeedbackPsVbcmItem( + uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value); + virtual ~FeedbackPsVbcmItem(){}; + + uint32_t GetSsrc() const; + uint8_t GetSequenceNumber() const; + uint8_t GetPayloadType() const; + uint16_t GetLength() const; + uint8_t* GetValue() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; + // Vbcm packet declaration + typedef FeedbackPsItemsPacket FeedbackPsVbcmPacket; - public: - static FeedbackPsVbcmItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackPsVbcmItem(Header* header); - explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); - FeedbackPsVbcmItem(uint32_t ssrc, uint8_t sequence_number, uint8_t payload_type, uint16_t length, uint8_t* value); - virtual ~FeedbackPsVbcmItem() {}; - - uint32_t GetSsrc() const; - uint8_t GetSequenceNumber() const; - uint8_t GetPayloadType() const; - uint16_t GetLength() const; - uint8_t* GetValue() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Vbcm packet declaration - typedef FeedbackPsItemsPacket FeedbackPsVbcmPacket; - - /* Inline instance methods. */ - - inline - FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header): - header(header) - {} + inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header) + : header(header) + { + } - inline - FeedbackPsVbcmItem::FeedbackPsVbcmItem(FeedbackPsVbcmItem* item): - header(item->header) - {} + inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(FeedbackPsVbcmItem* item) + : header(item->header) + { + } - inline - size_t FeedbackPsVbcmItem::GetSize() const - { - size_t size = 8 + size_t(this->header->length); + inline size_t FeedbackPsVbcmItem::GetSize() const + { + size_t size = 8 + size_t(this->header->length); - // Consider pading to 32 bits (4 bytes) boundary. - return (size + 3) & ~3; - } + // Consider pading to 32 bits (4 bytes) boundary. + return (size + 3) & ~3; + } - inline - uint32_t FeedbackPsVbcmItem::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); - } + inline uint32_t FeedbackPsVbcmItem::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } - inline - uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const - { - return (uint8_t)this->header->sequence_number; - } + inline uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const + { + return (uint8_t)this->header->sequenceNumber; + } - inline - uint8_t FeedbackPsVbcmItem::GetPayloadType() const - { - return (uint8_t)this->header->payload_type; - } + inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const + { + return (uint8_t)this->header->payloadType; + } - inline - uint16_t FeedbackPsVbcmItem::GetLength() const - { - return (uint16_t)ntohs(this->header->length); - } + inline uint16_t FeedbackPsVbcmItem::GetLength() const + { + return (uint16_t)ntohs(this->header->length); + } - inline - uint8_t* FeedbackPsVbcmItem::GetValue() const - { - return this->header->value; + inline uint8_t* FeedbackPsVbcmItem::GetValue() const + { + return this->header->value; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtp.hpp b/worker/include/RTC/RTCP/FeedbackRtp.hpp index fe99aa1fb7..21555e1f32 100644 --- a/worker/include/RTC/RTCP/FeedbackRtp.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtp.hpp @@ -5,79 +5,84 @@ #include "RTC/RTCP/Feedback.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - template class FeedbackRtpItemsPacket - : public FeedbackRtpPacket + namespace RTCP { - public: - typedef typename std::vector::iterator Iterator; - - public: - static FeedbackRtpItemsPacket* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader); - explicit FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); - virtual ~FeedbackRtpItemsPacket() {}; - - void AddItem(Item* item); - Iterator Begin(); - Iterator End(); - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - std::vector items; - }; - - /* Inline instance methods. */ - - template - FeedbackRtpItemsPacket::FeedbackRtpItemsPacket(CommonHeader* commonHeader): - FeedbackRtpPacket(commonHeader) - {} - - template - FeedbackRtpItemsPacket::FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc): - FeedbackRtpPacket(Item::MessageType, sender_ssrc, media_ssrc) - {} - - template - size_t FeedbackRtpItemsPacket::GetSize() const - { - size_t size = FeedbackRtpPacket::GetSize(); + template + class FeedbackRtpItemsPacket : public FeedbackRtpPacket + { + public: + typedef typename std::vector::iterator Iterator; + + public: + static FeedbackRtpItemsPacket* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader); + explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0); + virtual ~FeedbackRtpItemsPacket(){}; + + void AddItem(Item* item); + Iterator Begin(); + Iterator End(); + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + std::vector items; + }; - for (auto item : this->items) + /* Inline instance methods. */ + + template + FeedbackRtpItemsPacket::FeedbackRtpItemsPacket(CommonHeader* commonHeader) + : FeedbackRtpPacket(commonHeader) { - size += item->GetSize(); } - return size; - } + template + FeedbackRtpItemsPacket::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc) + : FeedbackRtpPacket(Item::MessageType, senderSsrc, mediaSsrc) + { + } - template - void FeedbackRtpItemsPacket::AddItem(Item* item) - { - this->items.push_back(item); - } + template + size_t FeedbackRtpItemsPacket::GetSize() const + { + size_t size = FeedbackRtpPacket::GetSize(); - template - typename FeedbackRtpItemsPacket::Iterator FeedbackRtpItemsPacket::Begin() - { - return this->items.begin(); - } + for (auto item : this->items) + { + size += item->GetSize(); + } - template - typename FeedbackRtpItemsPacket::Iterator FeedbackRtpItemsPacket::End() - { - return this->items.end(); + return size; + } + + template + void FeedbackRtpItemsPacket::AddItem(Item* item) + { + this->items.push_back(item); + } + + template + typename FeedbackRtpItemsPacket::Iterator FeedbackRtpItemsPacket::Begin() + { + return this->items.begin(); + } + + template + typename FeedbackRtpItemsPacket::Iterator FeedbackRtpItemsPacket::End() + { + return this->items.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtpEcn.hpp b/worker/include/RTC/RTCP/FeedbackRtpEcn.hpp index 656ca29e37..fe7fb4f814 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpEcn.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpEcn.hpp @@ -24,114 +24,108 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackRtpEcnItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackRtpEcnItem : public FeedbackItem { - uint32_t sequence_number; - uint32_t ect0_counter; - uint32_t ect1_counter; - uint16_t ecn_ce_counter; - uint16_t not_ect_counter; - uint16_t lost_packets; - uint16_t duplicated_packets; + private: + struct Header + { + uint32_t sequenceNumber; + uint32_t ect0Counter; + uint32_t ect1Counter; + uint16_t ecnCeCounter; + uint16_t notEctCounter; + uint16_t lostPackets; + uint16_t duplicatedPackets; + }; + + public: + static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::ECN; + + public: + static FeedbackRtpEcnItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackRtpEcnItem(Header* header); + explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item); + virtual ~FeedbackRtpEcnItem(){}; + + uint32_t GetSequenceNumber() const; + uint32_t GetEct0Counter() const; + uint32_t GetEct1Counter() const; + uint16_t GetEcnCeCounter() const; + uint16_t GetNotEctCounter() const; + uint16_t GetLostPackets() const; + uint16_t GetDuplicatedPackets() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::ECN; + // Ecn packet declaration. + typedef FeedbackRtpItemsPacket FeedbackRtpEcnPacket; - public: - static FeedbackRtpEcnItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackRtpEcnItem(Header* header); - explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item); - virtual ~FeedbackRtpEcnItem() {}; - - uint32_t GetSequenceNumber() const; - uint32_t GetEct0Counter() const; - uint32_t GetEct1Counter() const; - uint16_t GetEcnCeCounter() const; - uint16_t GetNotEctCounter() const; - uint16_t GetLostPackets() const; - uint16_t GetDuplicatedPackets() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Ecn packet declaration. - typedef FeedbackRtpItemsPacket FeedbackRtpEcnPacket; - - /* Inline instance methods. */ - - inline - FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header): - header(header) - {} + inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header) + : header(header) + { + } - inline - FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item): - header(item->header) - {} + inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) + : header(item->header) + { + } - inline - size_t FeedbackRtpEcnItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackRtpEcnItem::GetSize() const + { + return sizeof(Header); + } - inline - uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const - { - return ntohl(this->header->sequence_number); - } + inline uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const + { + return ntohl(this->header->sequenceNumber); + } - inline - uint32_t FeedbackRtpEcnItem::GetEct0Counter() const - { - return ntohl(this->header->ect0_counter); - } + inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const + { + return ntohl(this->header->ect0Counter); + } - inline - uint32_t FeedbackRtpEcnItem::GetEct1Counter() const - { - return ntohl(this->header->ect1_counter); - } + inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const + { + return ntohl(this->header->ect1Counter); + } - inline - uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const - { - return ntohs(this->header->ecn_ce_counter); - } + inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const + { + return ntohs(this->header->ecnCeCounter); + } - inline - uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const - { - return ntohs(this->header->not_ect_counter); - } + inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const + { + return ntohs(this->header->notEctCounter); + } - inline - uint16_t FeedbackRtpEcnItem::GetLostPackets() const - { - return ntohs(this->header->lost_packets); - } + inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const + { + return ntohs(this->header->lostPackets); + } - inline - uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const - { - return ntohs(this->header->duplicated_packets); + inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const + { + return ntohs(this->header->duplicatedPackets); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtpNack.hpp b/worker/include/RTC/RTCP/FeedbackRtpNack.hpp index 194f60fbd7..3e1fe7ca45 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpNack.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpNack.hpp @@ -13,75 +13,74 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackRtpNackItem - : public FeedbackItem + namespace RTCP { - public: - struct Header + class FeedbackRtpNackItem : public FeedbackItem { - uint16_t packet_id; - uint16_t lost_packet_bitmask; + public: + struct Header + { + uint16_t packetId; + uint16_t lostPacketBitmask; + }; + + public: + static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::NACK; + + public: + static FeedbackRtpNackItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackRtpNackItem(Header* header); + explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); + FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); + virtual ~FeedbackRtpNackItem(){}; + + uint16_t GetPacketId() const; + uint16_t GetLostPacketBitmask() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::NACK; + // Nack packet declaration. + typedef FeedbackRtpItemsPacket FeedbackRtpNackPacket; - public: - static FeedbackRtpNackItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackRtpNackItem(Header* header); - explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); - FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); - virtual ~FeedbackRtpNackItem() {}; - - uint16_t GetPacketId() const; - uint16_t GetLostPacketBitmask() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Nack packet declaration. - typedef FeedbackRtpItemsPacket FeedbackRtpNackPacket; - - /* Inline instance methods. */ - - inline - FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header): - header(header) - {} + inline FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header) + : header(header) + { + } - inline - FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item): - header(item->header) - {} + inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item) + : header(item->header) + { + } - inline - size_t FeedbackRtpNackItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackRtpNackItem::GetSize() const + { + return sizeof(Header); + } - inline - uint16_t FeedbackRtpNackItem::GetPacketId() const - { - return (uint16_t)ntohs(this->header->packet_id); - } + inline uint16_t FeedbackRtpNackItem::GetPacketId() const + { + return (uint16_t)ntohs(this->header->packetId); + } - inline - uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const - { - return (uint16_t)ntohs(this->header->lost_packet_bitmask); + inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const + { + return (uint16_t)ntohs(this->header->lostPacketBitmask); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp b/worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp index d2adf70204..b6e2ff513b 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp @@ -4,34 +4,36 @@ #include "common.hpp" #include "RTC/RTCP/Feedback.hpp" -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackRtpSrReqPacket - : public FeedbackRtpPacket + namespace RTCP { - public: - static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); - FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc); - virtual ~FeedbackRtpSrReqPacket() {}; - - virtual void Dump() const override; - }; - - /* Inline instance methods. */ - - inline - FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader): - FeedbackRtpPacket(commonHeader) - {} - - inline - FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc): - FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, sender_ssrc, media_ssrc) - {} -}} + class FeedbackRtpSrReqPacket : public FeedbackRtpPacket + { + public: + static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); + FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc); + virtual ~FeedbackRtpSrReqPacket(){}; + + virtual void Dump() const override; + }; + + /* Inline instance methods. */ + + inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader) + : FeedbackRtpPacket(commonHeader) + { + } + + inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc) + : FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc) + { + } + } +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtpTllei.hpp b/worker/include/RTC/RTCP/FeedbackRtpTllei.hpp index 13030a617a..836501bfbf 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpTllei.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpTllei.hpp @@ -13,75 +13,74 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - class FeedbackRtpTlleiItem - : public FeedbackItem + namespace RTCP { - private: - struct Header + class FeedbackRtpTlleiItem : public FeedbackItem { - uint16_t packet_id; - uint16_t lost_packet_bitmask; + private: + struct Header + { + uint16_t packetId; + uint16_t lostPacketBitmask; + }; + + public: + static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::TLLEI; + + public: + static FeedbackRtpTlleiItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackRtpTlleiItem(Header* header); + explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); + FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); + virtual ~FeedbackRtpTlleiItem(){}; + + uint16_t GetPacketId() const; + uint16_t GetLostPacketBitmask() const; + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + Header* header = nullptr; }; - public: - static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::TLLEI; + // Nack packet declaration. + typedef FeedbackRtpItemsPacket FeedbackRtpTlleiPacket; - public: - static FeedbackRtpTlleiItem* Parse(const uint8_t* data, size_t len); + /* Inline instance methods. */ - public: - explicit FeedbackRtpTlleiItem(Header* header); - explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); - FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); - virtual ~FeedbackRtpTlleiItem() {}; - - uint16_t GetPacketId() const; - uint16_t GetLostPacketBitmask() const; - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - Header* header = nullptr; - }; - - // Nack packet declaration. - typedef FeedbackRtpItemsPacket FeedbackRtpTlleiPacket; - - /* Inline instance methods. */ - - inline - FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header): - header(header) - {} + inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header) + : header(header) + { + } - inline - FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item): - header(item->header) - {} + inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item) + : header(item->header) + { + } - inline - size_t FeedbackRtpTlleiItem::GetSize() const - { - return sizeof(Header); - } + inline size_t FeedbackRtpTlleiItem::GetSize() const + { + return sizeof(Header); + } - inline - uint16_t FeedbackRtpTlleiItem::GetPacketId() const - { - return (uint16_t)ntohs(this->header->packet_id); - } + inline uint16_t FeedbackRtpTlleiItem::GetPacketId() const + { + return (uint16_t)ntohs(this->header->packetId); + } - inline - uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const - { - return (uint16_t)ntohs(this->header->lost_packet_bitmask); + inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const + { + return (uint16_t)ntohs(this->header->lostPacketBitmask); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp b/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp index fa80f98fd8..35aa5b0a97 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp @@ -16,102 +16,110 @@ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ -namespace RTC { namespace RTCP +namespace RTC { - template class FeedbackRtpTmmbItem - : public FeedbackItem + namespace RTCP { - private: - static constexpr size_t HeaderSize = 8; - - public: - static const FeedbackRtp::MessageType MessageType; - - public: - static FeedbackRtpTmmbItem* Parse(const uint8_t* data, size_t len); - - public: - explicit FeedbackRtpTmmbItem(const uint8_t* data); - FeedbackRtpTmmbItem(); - - uint32_t GetSsrc() const; - void SetSsrc(uint32_t ssrc); - uint64_t GetBitrate() const; - void SetBitrate(uint64_t bitrate); - uint16_t GetOverhead() const; - void SetOverhead(uint16_t overhead); - - /* Virtual methods inherited from FeedbackItem. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetSize() const override; - - private: - uint32_t ssrc = 0; - uint64_t bitrate = 0; - uint16_t overhead = 0; - }; - - // Tmmb types declaration. - class FeedbackRtpTmmbr {}; - class FeedbackRtpTmmbn {}; - - // Tmmbn classes declaration. - typedef FeedbackRtpTmmbItem FeedbackRtpTmmbrItem; - typedef FeedbackRtpTmmbItem FeedbackRtpTmmbnItem; - - // Tmmbn packets declaration. - typedef FeedbackRtpItemsPacket FeedbackRtpTmmbrPacket; - typedef FeedbackRtpItemsPacket FeedbackRtpTmmbnPacket; - - /* Inline instance methods. */ - - template - FeedbackRtpTmmbItem::FeedbackRtpTmmbItem() - {} - - template - size_t FeedbackRtpTmmbItem::GetSize() const - { - return HeaderSize; - } - - template - uint32_t FeedbackRtpTmmbItem::GetSsrc() const - { - return this->ssrc; - } - - template - void FeedbackRtpTmmbItem::SetSsrc(uint32_t ssrc) - { - this->ssrc = ssrc; - } - - template - uint64_t FeedbackRtpTmmbItem::GetBitrate() const - { - return this->bitrate; - } - - template - void FeedbackRtpTmmbItem::SetBitrate(uint64_t bitrate) - { - this->bitrate = bitrate; - } - - template - uint16_t FeedbackRtpTmmbItem::GetOverhead() const - { - return this->overhead; - } - - template - void FeedbackRtpTmmbItem::SetOverhead(uint16_t overhead) - { - this->overhead = overhead; + template + class FeedbackRtpTmmbItem : public FeedbackItem + { + private: + static constexpr size_t HeaderSize = 8; + + public: + static const FeedbackRtp::MessageType MessageType; + + public: + static FeedbackRtpTmmbItem* Parse(const uint8_t* data, size_t len); + + public: + explicit FeedbackRtpTmmbItem(const uint8_t* data); + FeedbackRtpTmmbItem(); + + uint32_t GetSsrc() const; + void SetSsrc(uint32_t ssrc); + uint64_t GetBitrate() const; + void SetBitrate(uint64_t bitrate); + uint16_t GetOverhead() const; + void SetOverhead(uint16_t overhead); + + /* Virtual methods inherited from FeedbackItem. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetSize() const override; + + private: + uint32_t ssrc = 0; + uint64_t bitrate = 0; + uint16_t overhead = 0; + }; + + // Tmmb types declaration. + class FeedbackRtpTmmbr + { + }; + class FeedbackRtpTmmbn + { + }; + + // Tmmbn classes declaration. + typedef FeedbackRtpTmmbItem FeedbackRtpTmmbrItem; + typedef FeedbackRtpTmmbItem FeedbackRtpTmmbnItem; + + // Tmmbn packets declaration. + typedef FeedbackRtpItemsPacket FeedbackRtpTmmbrPacket; + typedef FeedbackRtpItemsPacket FeedbackRtpTmmbnPacket; + + /* Inline instance methods. */ + + template + FeedbackRtpTmmbItem::FeedbackRtpTmmbItem() + { + } + + template + size_t FeedbackRtpTmmbItem::GetSize() const + { + return HeaderSize; + } + + template + uint32_t FeedbackRtpTmmbItem::GetSsrc() const + { + return this->ssrc; + } + + template + void FeedbackRtpTmmbItem::SetSsrc(uint32_t ssrc) + { + this->ssrc = ssrc; + } + + template + uint64_t FeedbackRtpTmmbItem::GetBitrate() const + { + return this->bitrate; + } + + template + void FeedbackRtpTmmbItem::SetBitrate(uint64_t bitrate) + { + this->bitrate = bitrate; + } + + template + uint16_t FeedbackRtpTmmbItem::GetOverhead() const + { + return this->overhead; + } + + template + void FeedbackRtpTmmbItem::SetOverhead(uint16_t overhead) + { + this->overhead = overhead; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/Packet.hpp b/worker/include/RTC/RTCP/Packet.hpp index 52685640eb..a9fb5a5898 100644 --- a/worker/include/RTC/RTCP/Packet.hpp +++ b/worker/include/RTC/RTCP/Packet.hpp @@ -5,137 +5,135 @@ #include #include -#define MS_RTCP_BUFFER_SIZE 65536 - -namespace RTC { namespace RTCP +namespace RTC { - // Maximum interval for regular RTCP mode. - constexpr uint16_t MAX_VIDEO_INTERVAL_MS = 1000; - constexpr uint16_t MAX_AUDIO_INTERVAL_MS = 5000; - - enum class Type : uint8_t - { - FIR = 192, - NACK = 193, - SR = 200, - RR = 201, - SDES = 202, - BYE = 203, - APP = 204, - RTPFB = 205, - PSFB = 206 - }; - - class Packet + namespace RTCP { - public: - /* Struct for RTCP common header. */ - struct CommonHeader - { - #if defined(MS_LITTLE_ENDIAN) - uint8_t count:5; - uint8_t padding:1; - uint8_t version:2; - #elif defined(MS_BIG_ENDIAN) - uint8_t version:2; - uint8_t padding:1; - uint8_t count:5; - #endif - uint8_t packet_type:8; - uint16_t length:16; - }; - - public: - static bool IsRtcp(const uint8_t* data, size_t len); - static Packet* Parse(const uint8_t* data, size_t len); - - private: - static const std::string& Type2String(Type type); - - private: - static std::map type2String; - - public: - explicit Packet(Type type); - virtual ~Packet(); + // Internal buffer for RTCP serialization. + constexpr size_t bufferSize = 65536; + extern uint8_t buffer[bufferSize]; - void SetNext(Packet* packet); - Packet* GetNext() const; - Type GetType() const; - const uint8_t* GetData() const; + // Maximum interval for regular RTCP mode. + constexpr uint16_t maxVideoIntervalMs = 1000; + constexpr uint16_t maxAudioIntervalMs = 5000; - public: - virtual void Dump() const = 0; - virtual size_t Serialize(uint8_t* buffer) = 0; - virtual size_t GetCount() const = 0; - virtual size_t GetSize() const = 0; - - private: - Type type; - Packet* next = nullptr; - CommonHeader* header = nullptr; - }; - - /* Inline static methods. */ + enum class Type : uint8_t + { + FIR = 192, + NACK = 193, + SR = 200, + RR = 201, + SDES = 202, + BYE = 203, + APP = 204, + RTPFB = 205, + PSFB = 206 + }; - inline - bool Packet::IsRtcp(const uint8_t* data, size_t len) - { - CommonHeader* header = const_cast(reinterpret_cast(data)); - - return ( - (len >= sizeof(CommonHeader)) && - // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes - (data[0] > 127 && data[0] < 192) && - // RTP Version must be 2. - (header->version == 2) && - // RTCP packet types defined by IANA: - // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 - // RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection. - (header->packet_type >= 192 && header->packet_type <= 223) - ); - } + class Packet + { + public: + /* Struct for RTCP common header. */ + struct CommonHeader + { +#if defined(MS_LITTLE_ENDIAN) + uint8_t count : 5; + uint8_t padding : 1; + uint8_t version : 2; +#elif defined(MS_BIG_ENDIAN) + uint8_t version : 2; + uint8_t padding : 1; + uint8_t count : 5; +#endif + uint8_t packetType : 8; + uint16_t length : 16; + }; + + public: + static bool IsRtcp(const uint8_t* data, size_t len); + static Packet* Parse(const uint8_t* data, size_t len); + + private: + static const std::string& Type2String(Type type); + + private: + static std::map type2String; + + public: + explicit Packet(Type type); + virtual ~Packet(); + + void SetNext(Packet* packet); + Packet* GetNext() const; + Type GetType() const; + const uint8_t* GetData() const; + + public: + virtual void Dump() const = 0; + virtual size_t Serialize(uint8_t* buffer) = 0; + virtual size_t GetCount() const = 0; + virtual size_t GetSize() const = 0; + + private: + Type type; + Packet* next = nullptr; + CommonHeader* header = nullptr; + }; - /* Inline instance methods. */ + /* Inline static methods. */ - inline - Packet::Packet(Type type) - :type(type) - {} + inline bool Packet::IsRtcp(const uint8_t* data, size_t len) + { + CommonHeader* header = const_cast(reinterpret_cast(data)); + + return ( + (len >= sizeof(CommonHeader)) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] > 127 && data[0] < 192) && + // RTP Version must be 2. + (header->version == 2) && + // RTCP packet types defined by IANA: + // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 + // RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection. + (header->packetType >= 192 && header->packetType <= 223)); + } + + /* Inline instance methods. */ + + inline Packet::Packet(Type type) + : type(type) + { + } - inline - Packet::~Packet() - {} + inline Packet::~Packet() + { + } - inline - Packet* Packet::GetNext() const - { - return this->next; - } + inline Packet* Packet::GetNext() const + { + return this->next; + } - inline - void Packet::SetNext(Packet* packet) - { - this->next = packet; - } + inline void Packet::SetNext(Packet* packet) + { + this->next = packet; + } - inline - Type Packet::GetType() const - { - return this->type; - } + inline Type Packet::GetType() const + { + return this->type; + } - inline - size_t Packet::GetCount() const - { - return 0; - } + inline size_t Packet::GetCount() const + { + return 0; + } - inline - const uint8_t* Packet::GetData() const - { - return (uint8_t*)this->header; + inline const uint8_t* Packet::GetData() const + { + return (uint8_t*)this->header; + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/ReceiverReport.hpp b/worker/include/RTC/RTCP/ReceiverReport.hpp index 44d91b4cc3..c6460b2abd 100644 --- a/worker/include/RTC/RTCP/ReceiverReport.hpp +++ b/worker/include/RTC/RTCP/ReceiverReport.hpp @@ -2,281 +2,257 @@ #define MS_RTC_RTCP_RECEIVER_REPORT_HPP #include "common.hpp" -#include "RTC/RTCP/Packet.hpp" #include "Utils.hpp" +#include "RTC/RTCP/Packet.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - class ReceiverReport + namespace RTCP { - public: - /* Struct for RTCP receiver report. */ - struct Header + class ReceiverReport { - uint32_t ssrc; - uint32_t fraction_lost:8; - uint32_t total_lost:24; - uint32_t last_seq; - uint32_t jitter; - uint32_t lsr; - uint32_t dlsr; + public: + /* Struct for RTCP receiver report. */ + struct Header + { + uint32_t ssrc; + uint32_t fractionLost : 8; + uint32_t totalLost : 24; + uint32_t lastSeq; + uint32_t jitter; + uint32_t lsr; + uint32_t dlsr; + }; + + public: + static ReceiverReport* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit ReceiverReport(Header* header); + explicit ReceiverReport(ReceiverReport* report); + + // Locally generated Report. Holds the data internally. + ReceiverReport(); + + void Dump() const; + size_t Serialize(uint8_t* buffer); + size_t GetSize() const; + uint32_t GetSsrc() const; + void SetSsrc(uint32_t ssrc); + uint8_t GetFractionLost() const; + void SetFractionLost(uint8_t fractionLost); + int32_t GetTotalLost() const; + void SetTotalLost(int32_t totalLost); + uint32_t GetLastSeq() const; + void SetLastSeq(uint32_t lastSeq); + uint32_t GetJitter() const; + void SetJitter(uint32_t jitter); + uint32_t GetLastSenderReport() const; + void SetLastSenderReport(uint32_t lsr); + uint32_t GetDelaySinceLastSenderReport() const; + void SetDelaySinceLastSenderReport(uint32_t dlsr); + + private: + Header* header = nullptr; + uint8_t raw[sizeof(Header)] = {0}; }; - public: - static ReceiverReport* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit ReceiverReport(Header* header); - explicit ReceiverReport(ReceiverReport* report); - - // Locally generated Report. Holds the data internally. - ReceiverReport(); - - void Dump() const; - size_t Serialize(uint8_t* buffer); - size_t GetSize() const; - uint32_t GetSsrc() const; - void SetSsrc(uint32_t ssrc); - uint8_t GetFractionLost() const; - void SetFractionLost(uint8_t fraction_lost); - int32_t GetTotalLost() const; - void SetTotalLost(int32_t total_lost); - uint32_t GetLastSeq() const; - void SetLastSeq(uint32_t last_seq); - uint32_t GetJitter() const; - void SetJitter(uint32_t jitter); - uint32_t GetLastSenderReport() const; - void SetLastSenderReport(uint32_t lsr); - uint32_t GetDelaySinceLastSenderReport() const; - void SetDelaySinceLastSenderReport(uint32_t dlsr); - - private: - Header* header = nullptr; - uint8_t raw[sizeof(Header)] = {0}; - }; - - class ReceiverReportPacket - : public Packet - { - public: - typedef std::vector::iterator Iterator; - - public: - static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset=0); - - public: - ReceiverReportPacket(); - virtual ~ReceiverReportPacket(); - - uint32_t GetSsrc() const; - void SetSsrc(uint32_t ssrc); - void AddReport(ReceiverReport* report); - Iterator Begin(); - Iterator End(); - - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetCount() const override; - virtual size_t GetSize() const override; - - private: - // SSRC of packet sender. - uint32_t ssrc = 0; - std::vector reports; - }; - - /* Inline instance methods. */ - - inline - ReceiverReport::ReceiverReport() - { - this->header = reinterpret_cast(this->raw); - } + class ReceiverReportPacket : public Packet + { + public: + typedef std::vector::iterator Iterator; + + public: + static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0); + + public: + ReceiverReportPacket(); + virtual ~ReceiverReportPacket(); + + uint32_t GetSsrc() const; + void SetSsrc(uint32_t ssrc); + void AddReport(ReceiverReport* report); + Iterator Begin(); + Iterator End(); + + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetCount() const override; + virtual size_t GetSize() const override; + + private: + // SSRC of packet sender. + uint32_t ssrc = 0; + std::vector reports; + }; - inline - ReceiverReport::ReceiverReport(Header* header) : - header(header) - {} + /* Inline instance methods. */ - inline - ReceiverReport::ReceiverReport(ReceiverReport* report) : - header(report->header) - {} + inline ReceiverReport::ReceiverReport() + { + this->header = reinterpret_cast(this->raw); + } - inline - size_t ReceiverReport::GetSize() const - { - return sizeof(Header); - } + inline ReceiverReport::ReceiverReport(Header* header) + : header(header) + { + } - inline - uint32_t ReceiverReport::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); - } + inline ReceiverReport::ReceiverReport(ReceiverReport* report) + : header(report->header) + { + } - inline - void ReceiverReport::SetSsrc(uint32_t ssrc) - { - this->header->ssrc = (uint32_t)htonl(ssrc); - } + inline size_t ReceiverReport::GetSize() const + { + return sizeof(Header); + } - inline - uint8_t ReceiverReport::GetFractionLost() const - { - return (uint8_t)Utils::Byte::Get1Byte((uint8_t*)this->header, 4); - } + inline uint32_t ReceiverReport::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } - inline - void ReceiverReport::SetFractionLost(uint8_t fraction_lost) - { - Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fraction_lost); - } + inline void ReceiverReport::SetSsrc(uint32_t ssrc) + { + this->header->ssrc = (uint32_t)htonl(ssrc); + } - inline - int32_t ReceiverReport::GetTotalLost() const - { - uint32_t value = (uint32_t)Utils::Byte::Get3Bytes((uint8_t*)this->header, 5); + inline uint8_t ReceiverReport::GetFractionLost() const + { + return (uint8_t)Utils::Byte::Get1Byte((uint8_t*)this->header, 4); + } - // Possitive value. - if (((value >> 23) & 1) == 0) - return value; + inline void ReceiverReport::SetFractionLost(uint8_t fractionLost) + { + Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost); + } - // Negative value. - if (value != 0x0800000) - value &= ~(1 << 23); + inline int32_t ReceiverReport::GetTotalLost() const + { + uint32_t value = (uint32_t)Utils::Byte::Get3Bytes((uint8_t*)this->header, 5); - return -value; - } + // Possitive value. + if (((value >> 23) & 1) == 0) + return value; - inline - void ReceiverReport::SetTotalLost(int32_t total_lost) - { - // Get the limit value for possitive and negative total_lost. - int32_t clamp = (total_lost >= 0) ? - total_lost > 0x07FFFFF? 0x07FFFFF : total_lost : - -total_lost > 0x0800000? 0x0800000 : -total_lost; + // Negative value. + if (value != 0x0800000) + value &= ~(1 << 23); - uint32_t value = (total_lost >= 0) ? - (clamp & 0x07FFFFF) : (clamp | 0x0800000); + return -value; + } - Utils::Byte::Set3Bytes((uint8_t*)this->header, 5, value); - } + inline void ReceiverReport::SetTotalLost(int32_t totalLost) + { + // Get the limit value for possitive and negative totalLost. + int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost + : -totalLost > 0x0800000 ? 0x0800000 : -totalLost; - inline - uint32_t ReceiverReport::GetLastSeq() const - { - return (uint32_t)ntohl(this->header->last_seq); - } + uint32_t value = (totalLost >= 0) ? (clamp & 0x07FFFFF) : (clamp | 0x0800000); - inline - void ReceiverReport::SetLastSeq(uint32_t last_seq) - { - this->header->last_seq = (uint32_t)htonl(last_seq); - } + Utils::Byte::Set3Bytes((uint8_t*)this->header, 5, value); + } - inline - uint32_t ReceiverReport::GetJitter() const - { - return (uint32_t)ntohl(this->header->jitter); - } + inline uint32_t ReceiverReport::GetLastSeq() const + { + return (uint32_t)ntohl(this->header->lastSeq); + } - inline - void ReceiverReport::SetJitter(uint32_t jitter) - { - this->header->jitter = (uint32_t)htonl(jitter); - } + inline void ReceiverReport::SetLastSeq(uint32_t lastSeq) + { + this->header->lastSeq = (uint32_t)htonl(lastSeq); + } - inline - uint32_t ReceiverReport::GetLastSenderReport() const - { - return (uint32_t)ntohl(this->header->lsr); - } + inline uint32_t ReceiverReport::GetJitter() const + { + return (uint32_t)ntohl(this->header->jitter); + } - inline - void ReceiverReport::SetLastSenderReport(uint32_t lsr) - { - this->header->lsr = (uint32_t)htonl(lsr); - } + inline void ReceiverReport::SetJitter(uint32_t jitter) + { + this->header->jitter = (uint32_t)htonl(jitter); + } - inline - uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const - { - return (uint32_t)ntohl(this->header->dlsr); - } + inline uint32_t ReceiverReport::GetLastSenderReport() const + { + return (uint32_t)ntohl(this->header->lsr); + } - inline - void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr) - { - this->header->dlsr = (uint32_t)htonl(dlsr); - } + inline void ReceiverReport::SetLastSenderReport(uint32_t lsr) + { + this->header->lsr = (uint32_t)htonl(lsr); + } - inline - ReceiverReportPacket::ReceiverReportPacket() - : Packet(Type::RR) - {} + inline uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const + { + return (uint32_t)ntohl(this->header->dlsr); + } - inline - ReceiverReportPacket::~ReceiverReportPacket() - { - for (auto report : this->reports) + inline void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr) { - delete report; + this->header->dlsr = (uint32_t)htonl(dlsr); } - } - inline - size_t ReceiverReportPacket::GetCount() const - { - return this->reports.size(); - } + inline ReceiverReportPacket::ReceiverReportPacket() + : Packet(Type::RR) + { + } - inline - size_t ReceiverReportPacket::GetSize() const - { - size_t size = sizeof(Packet::CommonHeader) + sizeof(this->ssrc); + inline ReceiverReportPacket::~ReceiverReportPacket() + { + for (auto report : this->reports) + { + delete report; + } + } - for (auto report : reports) + inline size_t ReceiverReportPacket::GetCount() const { - size += report->GetSize(); + return this->reports.size(); } - return size; - } + inline size_t ReceiverReportPacket::GetSize() const + { + size_t size = sizeof(Packet::CommonHeader) + sizeof(this->ssrc); - inline - uint32_t ReceiverReportPacket::GetSsrc() const - { - return (uint32_t)ntohl(this->ssrc); - } + for (auto report : reports) + { + size += report->GetSize(); + } - inline - void ReceiverReportPacket::SetSsrc(uint32_t ssrc) - { - this->ssrc = (uint32_t)htonl(ssrc); - } + return size; + } - inline - void ReceiverReportPacket::AddReport(ReceiverReport* report) - { - this->reports.push_back(report); - } + inline uint32_t ReceiverReportPacket::GetSsrc() const + { + return (uint32_t)ntohl(this->ssrc); + } - inline - ReceiverReportPacket::Iterator ReceiverReportPacket::Begin() - { - return this->reports.begin(); - } + inline void ReceiverReportPacket::SetSsrc(uint32_t ssrc) + { + this->ssrc = (uint32_t)htonl(ssrc); + } - inline - ReceiverReportPacket::Iterator ReceiverReportPacket::End() - { - return this->reports.end(); + inline void ReceiverReportPacket::AddReport(ReceiverReport* report) + { + this->reports.push_back(report); + } + + inline ReceiverReportPacket::Iterator ReceiverReportPacket::Begin() + { + return this->reports.begin(); + } + + inline ReceiverReportPacket::Iterator ReceiverReportPacket::End() + { + return this->reports.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/Sdes.hpp b/worker/include/RTC/RTCP/Sdes.hpp index b43d838451..5c5c2474a9 100644 --- a/worker/include/RTC/RTCP/Sdes.hpp +++ b/worker/include/RTC/RTCP/Sdes.hpp @@ -3,286 +3,268 @@ #include "common.hpp" #include "RTC/RTCP/Packet.hpp" -#include #include #include +#include -namespace RTC { namespace RTCP +namespace RTC { - /* SDES Item. */ - class SdesItem + namespace RTCP { - public: - enum class Type : uint8_t + /* SDES Item. */ + class SdesItem { - END = 0, - CNAME, - NAME, - EMAIL, - PHONE, - LOC, - TOOL, - NOTE, - PRIV + public: + enum class Type : uint8_t + { + END = 0, + CNAME, + NAME, + EMAIL, + PHONE, + LOC, + TOOL, + NOTE, + PRIV + }; + + private: + struct Header + { + SdesItem::Type type; + uint8_t length; + char value[]; + }; + + public: + static SdesItem* Parse(const uint8_t* data, size_t len); + static const std::string& Type2String(SdesItem::Type type); + + public: + explicit SdesItem(Header* header); + explicit SdesItem(SdesItem* item); + SdesItem(SdesItem::Type type, size_t len, const char* value); + ~SdesItem(); + + void Dump() const; + size_t Serialize(uint8_t* buffer); + size_t GetSize() const; + + SdesItem::Type GetType() const; + uint8_t GetLength() const; + char* GetValue() const; + + private: + // Passed by argument. + Header* header = nullptr; + std::unique_ptr raw; + + private: + static std::map type2String; }; - private: - struct Header + class SdesChunk { - SdesItem::Type type; - uint8_t length; - char value[]; + public: + typedef std::vector::iterator Iterator; + + public: + static SdesChunk* Parse(const uint8_t* data, size_t len); + + public: + explicit SdesChunk(const uint32_t ssrc); + explicit SdesChunk(SdesChunk* chunk); + ~SdesChunk(); + + void Dump() const; + void Serialize(); + size_t Serialize(uint8_t* buffer); + size_t GetSize() const; + uint32_t GetSsrc() const; + void SetSsrc(uint32_t ssrc); + void AddItem(SdesItem* item); + Iterator Begin(); + Iterator End(); + + private: + uint32_t ssrc; + std::vector items; }; - public: - static SdesItem* Parse(const uint8_t* data, size_t len); - static const std::string& Type2String(SdesItem::Type type); - - public: - explicit SdesItem(Header* header); - explicit SdesItem(SdesItem* item); - SdesItem(SdesItem::Type type, size_t len, const char* value); - ~SdesItem(); + class SdesPacket : public Packet + { + public: + typedef std::vector::iterator Iterator; - void Dump() const; - size_t Serialize(uint8_t* buffer); - size_t GetSize() const; + public: + static SdesPacket* Parse(const uint8_t* data, size_t len); - SdesItem::Type GetType() const; - uint8_t GetLength() const; - char* GetValue() const; + public: + SdesPacket(); + virtual ~SdesPacket(); - private: - // Passed by argument. - Header* header = nullptr; - std::unique_ptr raw; + void AddChunk(SdesChunk* chunk); + Iterator Begin(); + Iterator End(); - private: - static std::map type2String; - }; + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetCount() const override; + virtual size_t GetSize() const override; - class SdesChunk - { - public: - typedef std::vector::iterator Iterator; - - public: - static SdesChunk* Parse(const uint8_t* data, size_t len); - - public: - explicit SdesChunk(const uint32_t ssrc); - explicit SdesChunk(SdesChunk* chunk); - ~SdesChunk(); - - void Dump() const; - void Serialize(); - size_t Serialize(uint8_t* buffer); - size_t GetSize() const; - uint32_t GetSsrc() const; - void SetSsrc(uint32_t ssrc); - void AddItem(SdesItem* item); - Iterator Begin(); - Iterator End(); - - private: - uint32_t ssrc; - std::vector items; - }; - - class SdesPacket - : public Packet - { - public: - typedef std::vector::iterator Iterator; + private: + std::vector chunks; + }; - public: - static SdesPacket* Parse(const uint8_t* data, size_t len); + /* SDES Item inline instance methods */ - public: - SdesPacket(); - virtual ~SdesPacket(); + inline SdesItem::SdesItem(Header* header) + : header(header) + { + } - void AddChunk(SdesChunk* chunk); - Iterator Begin(); - Iterator End(); + inline SdesItem::SdesItem(SdesItem* item) + : header(item->header) + { + } - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetCount() const override; - virtual size_t GetSize() const override; + inline SdesItem::~SdesItem() + { + } - private: - std::vector chunks; - }; + inline size_t SdesItem::GetSize() const + { + return 2 + size_t(this->header->length); + } - /* SDES Item inline instance methods */ + inline SdesItem::Type SdesItem::GetType() const + { + return this->header->type; + } - inline - SdesItem::SdesItem(Header* header) : - header(header) - {} + inline uint8_t SdesItem::GetLength() const + { + return this->header->length; + } - inline - SdesItem::SdesItem(SdesItem* item) : - header(item->header) - {} + inline char* SdesItem::GetValue() const + { + return this->header->value; + } - inline - SdesItem::~SdesItem() - { - } + /* Inline instance methods. */ - inline - size_t SdesItem::GetSize() const - { - return 2 + size_t(this->header->length); - } + inline SdesChunk::SdesChunk(uint32_t ssrc) + { + this->ssrc = htonl(ssrc); + } - inline - SdesItem::Type SdesItem::GetType() const - { - return this->header->type; - } + inline SdesChunk::SdesChunk(SdesChunk* chunk) + { + this->ssrc = chunk->ssrc; - inline - uint8_t SdesItem::GetLength() const - { - return this->header->length; - } + for (Iterator it = chunk->Begin(); it != chunk->End(); ++it) + { + this->AddItem(new SdesItem(*it)); + } + } - inline - char* SdesItem::GetValue() const - { - return this->header->value; - } + inline SdesChunk::~SdesChunk() + { + for (auto item : this->items) + { + delete item; + } + } - /* Inline instance methods. */ + inline size_t SdesChunk::GetSize() const + { + size_t size = sizeof(this->ssrc); - inline - SdesChunk::SdesChunk(uint32_t ssrc) - { - this->ssrc = htonl(ssrc); - } + for (auto item : this->items) + { + size += item->GetSize(); + } - inline - SdesChunk::SdesChunk(SdesChunk* chunk) - { - this->ssrc = chunk->ssrc; + // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment + // Consider pading to 32 bits (4 bytes) boundary. + return (size + 3) & ~3; + } - for (Iterator it = chunk->Begin(); it != chunk->End(); ++it) + inline uint32_t SdesChunk::GetSsrc() const { - this->AddItem(new SdesItem(*it)); + return (uint32_t)ntohl(this->ssrc); } - } - inline - SdesChunk::~SdesChunk() - { - for (auto item : this->items) + inline void SdesChunk::SetSsrc(uint32_t ssrc) { - delete item; + this->ssrc = (uint32_t)htonl(ssrc); } - } - inline - size_t SdesChunk::GetSize() const - { - size_t size = sizeof(this->ssrc); + inline void SdesChunk::AddItem(SdesItem* item) + { + this->items.push_back(item); + } - for (auto item : this->items) + inline SdesChunk::Iterator SdesChunk::Begin() { - size += item->GetSize(); + return this->items.begin(); } - // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment - // Consider pading to 32 bits (4 bytes) boundary. - return (size + 3) & ~3; - } + inline SdesChunk::Iterator SdesChunk::End() + { + return this->items.end(); + } - inline - uint32_t SdesChunk::GetSsrc() const - { - return (uint32_t)ntohl(this->ssrc); - } + /* Inline instance methods. */ - inline - void SdesChunk::SetSsrc(uint32_t ssrc) - { - this->ssrc = (uint32_t)htonl(ssrc); - } + inline SdesPacket::SdesPacket() + : Packet(RTCP::Type::SDES) + { + } - inline - void SdesChunk::AddItem(SdesItem* item) - { - this->items.push_back(item); - } + inline SdesPacket::~SdesPacket() + { + for (auto chunk : this->chunks) + { + delete chunk; + } + } - inline - SdesChunk::Iterator SdesChunk::Begin() - { - return this->items.begin(); - } + inline size_t SdesPacket::GetCount() const + { + return this->chunks.size(); + } - inline - SdesChunk::Iterator SdesChunk::End() - { - return this->items.end(); - } + inline size_t SdesPacket::GetSize() const + { + size_t size = sizeof(Packet::CommonHeader); - /* Inline instance methods. */ + for (auto chunk : this->chunks) + { + size += chunk->GetSize(); + } - inline - SdesPacket::SdesPacket() - : Packet(RTCP::Type::SDES) - {} + return size; + } - inline - SdesPacket::~SdesPacket() - { - for (auto chunk : this->chunks) + inline void SdesPacket::AddChunk(SdesChunk* chunk) { - delete chunk; + this->chunks.push_back(chunk); } - } - inline - size_t SdesPacket::GetCount() const - { - return this->chunks.size(); - } - - inline - size_t SdesPacket::GetSize() const - { - size_t size = sizeof(Packet::CommonHeader); - - for (auto chunk : this->chunks) + inline SdesPacket::Iterator SdesPacket::Begin() { - size += chunk->GetSize(); + return this->chunks.begin(); } - return size; - } - - inline - void SdesPacket::AddChunk(SdesChunk* chunk) - { - this->chunks.push_back(chunk); - } - - inline - SdesPacket::Iterator SdesPacket::Begin() - { - return this->chunks.begin(); - } - - inline - SdesPacket::Iterator SdesPacket::End() - { - return this->chunks.end(); + inline SdesPacket::Iterator SdesPacket::End() + { + return this->chunks.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RTCP/SenderReport.hpp b/worker/include/RTC/RTCP/SenderReport.hpp index ba9bedde82..dc4a77a7c5 100644 --- a/worker/include/RTC/RTCP/SenderReport.hpp +++ b/worker/include/RTC/RTCP/SenderReport.hpp @@ -5,231 +5,215 @@ #include "RTC/RTCP/Packet.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - class SenderReport + namespace RTCP { - public: - /* Struct for RTCP sender report. */ - struct Header - { - uint32_t ssrc; - uint32_t ntp_sec; - uint32_t ntp_frac; - uint32_t rtp_ts; - uint32_t packet_count; - uint32_t octet_count; + class SenderReport + { + public: + /* Struct for RTCP sender report. */ + struct Header + { + uint32_t ssrc; + uint32_t ntpSec; + uint32_t ntpFrac; + uint32_t rtpTs; + uint32_t packetCount; + uint32_t octetCount; + }; + + public: + static SenderReport* Parse(const uint8_t* data, size_t len); + + public: + // Parsed Report. Points to an external data. + explicit SenderReport(Header* header); + explicit SenderReport(SenderReport* report); + + // Locally generated Report. Holds the data internally. + SenderReport(); + + void Dump() const; + size_t Serialize(uint8_t* buffer); + size_t GetSize() const; + uint32_t GetSsrc() const; + void SetSsrc(uint32_t ssrc); + uint32_t GetNtpSec() const; + void SetNtpSec(uint32_t ntpSec); + uint32_t GetNtpFrac() const; + void SetNtpFrac(uint32_t ntpFrac); + uint32_t GetRtpTs() const; + void SetRtpTs(uint32_t rtpTs); + uint32_t GetPacketCount() const; + void SetPacketCount(uint32_t packetCount); + uint32_t GetOctetCount() const; + void SetOctetCount(uint32_t octetCount); + + private: + Header* header = nullptr; + uint8_t raw[sizeof(Header)] = {0}; }; - public: - static SenderReport* Parse(const uint8_t* data, size_t len); - - public: - // Parsed Report. Points to an external data. - explicit SenderReport(Header* header); - explicit SenderReport(SenderReport* report); - - // Locally generated Report. Holds the data internally. - SenderReport(); - - void Dump() const; - size_t Serialize(uint8_t* buffer); - size_t GetSize() const; - uint32_t GetSsrc() const; - void SetSsrc(uint32_t ssrc); - uint32_t GetNtpSec() const; - void SetNtpSec(uint32_t ntp_sec); - uint32_t GetNtpFrac() const; - void SetNtpFrac(uint32_t ntp_frac); - uint32_t GetRtpTs() const; - void SetRtpTs(uint32_t rtp_ts); - uint32_t GetPacketCount() const; - void SetPacketCount(uint32_t packet_count); - uint32_t GetOctetCount() const; - void SetOctetCount(uint32_t octet_count); - - private: - Header* header = nullptr; - uint8_t raw[sizeof(Header)] = {0}; - }; - - class SenderReportPacket - : public Packet - { - public: - typedef std::vector::iterator Iterator; - - public: - static SenderReportPacket* Parse(const uint8_t* data, size_t len); + class SenderReportPacket : public Packet + { + public: + typedef std::vector::iterator Iterator; - public: - SenderReportPacket(); - virtual ~SenderReportPacket(); + public: + static SenderReportPacket* Parse(const uint8_t* data, size_t len); - void AddReport(SenderReport* report); - Iterator Begin(); - Iterator End(); + public: + SenderReportPacket(); + virtual ~SenderReportPacket(); - /* Pure virtual methods inherited from Packet. */ - public: - virtual void Dump() const override; - virtual size_t Serialize(uint8_t* buffer) override; - virtual size_t GetCount() const override; - virtual size_t GetSize() const override; + void AddReport(SenderReport* report); + Iterator Begin(); + Iterator End(); - private: - std::vector reports; - }; + /* Pure virtual methods inherited from Packet. */ + public: + virtual void Dump() const override; + virtual size_t Serialize(uint8_t* buffer) override; + virtual size_t GetCount() const override; + virtual size_t GetSize() const override; - /* Inline instance methods. */ + private: + std::vector reports; + }; - inline - SenderReport::SenderReport() - { - this->header = reinterpret_cast(this->raw); - } + /* Inline instance methods. */ - inline - SenderReport::SenderReport(Header* header) : - header(header) - {} + inline SenderReport::SenderReport() + { + this->header = reinterpret_cast(this->raw); + } - inline - SenderReport::SenderReport(SenderReport* report) : - header(report->header) - {} + inline SenderReport::SenderReport(Header* header) + : header(header) + { + } - inline - size_t SenderReport::GetSize() const - { - return sizeof(Header); - } + inline SenderReport::SenderReport(SenderReport* report) + : header(report->header) + { + } - inline - uint32_t SenderReport::GetSsrc() const - { - return (uint32_t)ntohl(this->header->ssrc); - } + inline size_t SenderReport::GetSize() const + { + return sizeof(Header); + } - inline - void SenderReport::SetSsrc(uint32_t ssrc) - { - this->header->ssrc = (uint32_t)htonl(ssrc); - } + inline uint32_t SenderReport::GetSsrc() const + { + return (uint32_t)ntohl(this->header->ssrc); + } - inline - uint32_t SenderReport::GetNtpSec() const - { - return (uint32_t)ntohl(this->header->ntp_sec); - } + inline void SenderReport::SetSsrc(uint32_t ssrc) + { + this->header->ssrc = (uint32_t)htonl(ssrc); + } - inline - void SenderReport::SetNtpSec(uint32_t ntp_sec) - { - this->header->ntp_sec = (uint32_t)htonl(ntp_sec); - } + inline uint32_t SenderReport::GetNtpSec() const + { + return (uint32_t)ntohl(this->header->ntpSec); + } - inline - uint32_t SenderReport::GetNtpFrac() const - { - return (uint32_t)ntohl(this->header->ntp_frac); - } + inline void SenderReport::SetNtpSec(uint32_t ntpSec) + { + this->header->ntpSec = (uint32_t)htonl(ntpSec); + } - inline - void SenderReport::SetNtpFrac(uint32_t ntp_frac) - { - this->header->ntp_frac = (uint32_t)htonl(ntp_frac); - } + inline uint32_t SenderReport::GetNtpFrac() const + { + return (uint32_t)ntohl(this->header->ntpFrac); + } - inline - uint32_t SenderReport::GetRtpTs() const - { - return (uint32_t)ntohl(this->header->rtp_ts); - } + inline void SenderReport::SetNtpFrac(uint32_t ntpFrac) + { + this->header->ntpFrac = (uint32_t)htonl(ntpFrac); + } - inline - void SenderReport::SetRtpTs(uint32_t rtp_ts) - { - this->header->rtp_ts = (uint32_t)htonl(rtp_ts); - } + inline uint32_t SenderReport::GetRtpTs() const + { + return (uint32_t)ntohl(this->header->rtpTs); + } - inline + inline void SenderReport::SetRtpTs(uint32_t rtpTs) + { + this->header->rtpTs = (uint32_t)htonl(rtpTs); + } - uint32_t SenderReport::GetPacketCount() const - { - return (uint32_t)ntohl(this->header->packet_count); - } + inline - inline - void SenderReport::SetPacketCount(uint32_t packet_count) - { - this->header->packet_count = (uint32_t)htonl(packet_count); - } + uint32_t + SenderReport::GetPacketCount() const + { + return (uint32_t)ntohl(this->header->packetCount); + } - inline - uint32_t SenderReport::GetOctetCount() const - { - return (uint32_t)ntohl(this->header->octet_count); - } + inline void SenderReport::SetPacketCount(uint32_t packetCount) + { + this->header->packetCount = (uint32_t)htonl(packetCount); + } - inline - void SenderReport::SetOctetCount(uint32_t octet_count) - { - this->header->octet_count = (uint32_t)htonl(octet_count); - } + inline uint32_t SenderReport::GetOctetCount() const + { + return (uint32_t)ntohl(this->header->octetCount); + } - /* Inline instance methods. */ + inline void SenderReport::SetOctetCount(uint32_t octetCount) + { + this->header->octetCount = (uint32_t)htonl(octetCount); + } - inline - SenderReportPacket::SenderReportPacket() - : Packet(Type::SR) - {} + /* Inline instance methods. */ - inline - SenderReportPacket::~SenderReportPacket() - { - for (auto report : this->reports) + inline SenderReportPacket::SenderReportPacket() + : Packet(Type::SR) { - delete report; } - } - inline - size_t SenderReportPacket::GetCount() const - { - return this->reports.size(); - } - - inline - size_t SenderReportPacket::GetSize() const - { - size_t size = sizeof(Packet::CommonHeader); + inline SenderReportPacket::~SenderReportPacket() + { + for (auto report : this->reports) + { + delete report; + } + } - for (auto report : this->reports) + inline size_t SenderReportPacket::GetCount() const { - size += report->GetSize(); + return this->reports.size(); } - return size; - } + inline size_t SenderReportPacket::GetSize() const + { + size_t size = sizeof(Packet::CommonHeader); - inline - void SenderReportPacket::AddReport(SenderReport* report) - { - this->reports.push_back(report); - } + for (auto report : this->reports) + { + size += report->GetSize(); + } - inline - SenderReportPacket::Iterator SenderReportPacket::Begin() - { - return this->reports.begin(); - } + return size; + } - inline - SenderReportPacket::Iterator SenderReportPacket::End() - { - return this->reports.end(); + inline void SenderReportPacket::AddReport(SenderReport* report) + { + this->reports.push_back(report); + } + + inline SenderReportPacket::Iterator SenderReportPacket::Begin() + { + return this->reports.begin(); + } + + inline SenderReportPacket::Iterator SenderReportPacket::End() + { + return this->reports.end(); + } } -}} +} #endif diff --git a/worker/include/RTC/RemoteBitrateEstimator/AimdRateControl.hpp b/worker/include/RTC/RemoteBitrateEstimator/AimdRateControl.hpp index f77e15bb6d..c629d0063d 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/AimdRateControl.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/AimdRateControl.hpp @@ -12,9 +12,9 @@ #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_HPP #include "common.hpp" -#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp" -#include "RTC/RemoteBitrateEstimator/RateControlInput.hpp" #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" +#include "RTC/RemoteBitrateEstimator/RateControlInput.hpp" +#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp" // A rate control implementation based on additive increases of // bitrate when no over-use is detected and multiplicative decreases when @@ -88,98 +88,88 @@ namespace RTC void ChangeRegion(RateControlRegion region); private: - uint32_t minConfiguredBitrateBps = kMinBitrateBps; - uint32_t maxConfiguredBitrateBps = 30000000; - uint32_t currentBitrateBps = this->maxConfiguredBitrateBps; - float avgMaxBitrateKbps = -1.0f; - float varMaxBitrateKbps = 0.4f; - RateControlState rateControlState = kRcHold; + uint32_t minConfiguredBitrateBps = kMinBitrateBps; + uint32_t maxConfiguredBitrateBps = 30000000; + uint32_t currentBitrateBps = this->maxConfiguredBitrateBps; + float avgMaxBitrateKbps = -1.0f; + float varMaxBitrateKbps = 0.4f; + RateControlState rateControlState = kRcHold; RateControlRegion rateControlRegion = kRcMaxUnknown; - int64_t timeLastBitrateChange = -1; + int64_t timeLastBitrateChange = -1; RateControlInput currentInput; - bool updated = false; + bool updated = false; int64_t timeFirstIncomingEstimate = -1; - bool bitrateIsInitialized = false; - float beta = 0.85f; - int64_t rtt = kDefaultRttMs; - int lastDecrease = 0; + bool bitrateIsInitialized = false; + float beta = 0.85f; + int64_t rtt = kDefaultRttMs; + int lastDecrease = 0; }; /* Inline methods. */ - inline - AimdRateControl::AimdRateControl() : - currentInput(kBwNormal, 0, 1.0) - {} + inline AimdRateControl::AimdRateControl() + : currentInput(kBwNormal, 0, 1.0) + { + } - inline - void AimdRateControl::SetStartBitrate(int startBitrateBps) + inline void AimdRateControl::SetStartBitrate(int startBitrateBps) { - this->currentBitrateBps = startBitrateBps; + this->currentBitrateBps = startBitrateBps; this->bitrateIsInitialized = true; } - inline - void AimdRateControl::SetMinBitrate(int minBitrateBps) + inline void AimdRateControl::SetMinBitrate(int minBitrateBps) { this->minConfiguredBitrateBps = minBitrateBps; - this->currentBitrateBps = std::max(minBitrateBps, this->currentBitrateBps); + this->currentBitrateBps = std::max(minBitrateBps, this->currentBitrateBps); } - inline - bool AimdRateControl::ValidEstimate() const + inline bool AimdRateControl::ValidEstimate() const { return this->bitrateIsInitialized; } - inline - uint32_t AimdRateControl::LatestEstimate() const + inline uint32_t AimdRateControl::LatestEstimate() const { return this->currentBitrateBps; } - inline - uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs) + inline uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs) { - this->currentBitrateBps = ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs); + this->currentBitrateBps = + ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs); return this->currentBitrateBps; } - inline - void AimdRateControl::SetRtt(int64_t rtt) + inline void AimdRateControl::SetRtt(int64_t rtt) { this->rtt = rtt; } - inline - void AimdRateControl::SetEstimate(int bitrateBps, int64_t nowMs) + inline void AimdRateControl::SetEstimate(int bitrateBps, int64_t nowMs) { - this->updated = true; - this->bitrateIsInitialized = true; - this->currentBitrateBps = ClampBitrate(bitrateBps, bitrateBps); + this->updated = true; + this->bitrateIsInitialized = true; + this->currentBitrateBps = ClampBitrate(bitrateBps, bitrateBps); this->timeLastBitrateChange = nowMs; } - inline - int AimdRateControl::GetLastBitrateDecreaseBps() const + inline int AimdRateControl::GetLastBitrateDecreaseBps() const { return this->lastDecrease; } - inline - uint32_t AimdRateControl::AdditiveRateIncrease(int64_t nowMs, int64_t lastMs) const + inline uint32_t AimdRateControl::AdditiveRateIncrease(int64_t nowMs, int64_t lastMs) const { return static_cast((nowMs - lastMs) * GetNearMaxIncreaseRateBps() / 1000); } - inline - void AimdRateControl::ChangeRegion(RateControlRegion region) + inline void AimdRateControl::ChangeRegion(RateControlRegion region) { this->rateControlRegion = region; } - inline - void AimdRateControl::ChangeState(RateControlState newState) + inline void AimdRateControl::ChangeState(RateControlState newState) { this->rateControlState = newState; } diff --git a/worker/include/RTC/RemoteBitrateEstimator/InterArrival.hpp b/worker/include/RTC/RemoteBitrateEstimator/InterArrival.hpp index c6134ca992..2be1f20f49 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/InterArrival.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/InterArrival.hpp @@ -23,23 +23,30 @@ namespace RTC public: // After this many packet groups received out of order InterArrival will // reset, assuming that clocks have made a jump. - static constexpr int kReorderedResetThreshold = 3; + static constexpr int kReorderedResetThreshold = 3; static constexpr int64_t kArrivalTimeOffsetThresholdMs = 3000; // A timestamp group is defined as all packets with a timestamp which are at - // most timestamp_group_length_ticks older than the first timestamp in that + // most timestampGroupLengthTicks older than the first timestamp in that // group. - InterArrival(uint32_t timestamp_group_length_ticks, double timestamp_to_ms_coeff, bool enable_burst_grouping); + InterArrival(uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping); // This function returns true if a delta was computed, or false if the current // group is still incomplete or if only one group has been completed. // |timestamp| is the timestamp. - // |arrival_time_ms| is the local time at which the packet arrived. - // |packet_size| is the size of the packet. - // |timestamp_delta| (output) is the computed timestamp delta. - // |arrival_time_delta_ms| (output) is the computed arrival-time delta. - // |packet_size_delta| (output) is the computed size delta. - bool ComputeDeltas(uint32_t timestamp, int64_t arrival_time_ms, int64_t system_time_ms, size_t packet_size, uint32_t* timestamp_delta, int64_t* arrival_time_delta_ms, int* packet_size_delta); + // |arrivalTimeMs| is the local time at which the packet arrived. + // |packetSize| is the size of the packet. + // |timestampDelta| (output) is the computed timestamp delta. + // |arrivalTimeDeltaMs| (output) is the computed arrival-time delta. + // |packetSizeDelta| (output) is the computed size delta. + bool ComputeDeltas( + uint32_t timestamp, + int64_t arrivalTimeMs, + int64_t systemTimeMs, + size_t packetSize, + uint32_t* timestampDelta, + int64_t* arrivalTimeDeltaMs, + int* packetSizeDelta); private: struct TimestampGroup @@ -47,54 +54,54 @@ namespace RTC TimestampGroup(); bool IsFirstPacket() const; - size_t size = 0; - uint32_t first_timestamp = 0; - uint32_t timestamp = 0; - int64_t complete_time_ms = 0; - int64_t last_system_time_ms = 0; + size_t size = 0; + uint32_t firstTimestamp = 0; + uint32_t timestamp = 0; + int64_t completeTimeMs = 0; + int64_t lastSystemTimeMs = 0; }; // Returns true if the packet with timestamp |timestamp| arrived in order. bool PacketInOrder(uint32_t timestamp); // Returns true if the last packet was the end of the current batch and the // packet with |timestamp| is the first of a new batch. - bool NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const; - bool BelongsToBurst(int64_t arrival_time_ms, uint32_t timestamp) const; + bool NewTimestampGroup(int64_t arrivalTimeMs, uint32_t timestamp) const; + bool BelongsToBurst(int64_t arrivalTimeMs, uint32_t timestamp) const; void Reset(); const uint32_t kTimestampGroupLengthTicks; TimestampGroup currentTimestampGroup; TimestampGroup prevTimestampGroup; - double timestampToMsCoeff = 0; - bool burstGrouping = false; + double timestampToMsCoeff = 0; + bool burstGrouping = false; int numConsecutiveReorderedPackets = 0; }; /* Inline methods. */ - inline - InterArrival::TimestampGroup::TimestampGroup() : - size(0), - first_timestamp(0), - timestamp(0), - complete_time_ms(-1) - {} + inline InterArrival::TimestampGroup::TimestampGroup() + : size(0) + , firstTimestamp(0) + , timestamp(0) + , completeTimeMs(-1) + { + } - inline - bool InterArrival::TimestampGroup::IsFirstPacket() const + inline bool InterArrival::TimestampGroup::IsFirstPacket() const { - return complete_time_ms == -1; + return completeTimeMs == -1; } - inline - InterArrival::InterArrival(uint32_t timestamp_group_length_ticks, double timestamp_to_ms_coeff, bool enable_burst_grouping) : - kTimestampGroupLengthTicks(timestamp_group_length_ticks), - currentTimestampGroup(), - prevTimestampGroup(), - timestampToMsCoeff(timestamp_to_ms_coeff), - burstGrouping(enable_burst_grouping), - numConsecutiveReorderedPackets(0) - {} + inline InterArrival::InterArrival( + uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping) + : kTimestampGroupLengthTicks(timestampGroupLengthTicks) + , currentTimestampGroup() + , prevTimestampGroup() + , timestampToMsCoeff(timestampToMsCoeff) + , burstGrouping(enableBurstGrouping) + , numConsecutiveReorderedPackets(0) + { + } } #endif diff --git a/worker/include/RTC/RemoteBitrateEstimator/OveruseDetector.hpp b/worker/include/RTC/RemoteBitrateEstimator/OveruseDetector.hpp index 8e860b273b..e6899a0ab2 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/OveruseDetector.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/OveruseDetector.hpp @@ -11,15 +11,15 @@ #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_HPP #include "common.hpp" -#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp" #include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp" +#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp" #include namespace RTC { class OveruseDetector { - private: + private: static constexpr double kOverUsingTimeThreshold = 10; public: @@ -39,19 +39,18 @@ namespace RTC void UpdateThreshold(double modifiedOffset, int64_t nowMs); private: - double kUp = 0.0087; - double kDown = 0.039; + double kUp = 0.0087; + double kDown = 0.039; double overusingTimeThreshold = kOverUsingTimeThreshold; - double threshold = 12.5; - int64_t lastUpdateMs = -1; - double prevOffset = 0.0; - double timeOverUsing = -1; - int overuseCounter = 0; - BandwidthUsage hypothesis = kBwNormal; + double threshold = 12.5; + int64_t lastUpdateMs = -1; + double prevOffset = 0.0; + double timeOverUsing = -1; + int overuseCounter = 0; + BandwidthUsage hypothesis = kBwNormal; }; - inline - BandwidthUsage OveruseDetector::State() const + inline BandwidthUsage OveruseDetector::State() const { return this->hypothesis; } diff --git a/worker/include/RTC/RemoteBitrateEstimator/OveruseEstimator.hpp b/worker/include/RTC/RemoteBitrateEstimator/OveruseEstimator.hpp index 5987bd2a7e..512f95dc1a 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/OveruseEstimator.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/OveruseEstimator.hpp @@ -12,8 +12,8 @@ #include "common.hpp" #include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp" -#include #include // std::memcpy() +#include namespace RTC { @@ -42,9 +42,10 @@ namespace RTC // Update the estimator with a new sample. The deltas should represent deltas // between timestamp groups as defined by the InterArrival class. - // |current_hypothesis| should be the hypothesis of the over-use detector at + // |currentHypothesis| should be the hypothesis of the over-use detector at // this time. - void Update(int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs); + void Update( + int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs); // Returns the estimated noise/jitter variance in ms^2. double GetVarNoise() const; // Returns the estimated inter-arrival time delta offset in ms. @@ -61,9 +62,9 @@ namespace RTC // Must be first member variable. Cannot be const because we need to be copyable. OverUseDetectorOptions options; uint16_t numOfDeltas = 0; - double slope = 0; - double offset = 0; - double prevOffset = 0; + double slope = 0; + double offset = 0; + double prevOffset = 0; double E[2][2]; double processNoise[2]; double avgNoise = 0; @@ -73,59 +74,53 @@ namespace RTC /* Inline methods. */ - inline - OverUseDetectorOptions::OverUseDetectorOptions() : - initialSlope(8.0 / 512.0), - initialOffset(0), - initialE(), - initialProcessNoise(), - initialAvgNoise(0.0), - initialVarNoise(50) + inline OverUseDetectorOptions::OverUseDetectorOptions() + : initialSlope(8.0 / 512.0) + , initialOffset(0) + , initialE() + , initialProcessNoise() + , initialAvgNoise(0.0) + , initialVarNoise(50) { initialE[0][0] = 100; initialE[1][1] = 1e-1; initialE[0][1] = initialE[1][0] = 0; - initialProcessNoise[0] = 1e-13; - initialProcessNoise[1] = 1e-3; + initialProcessNoise[0] = 1e-13; + initialProcessNoise[1] = 1e-3; } - inline - OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) : - options(options), - numOfDeltas(0), - slope(this->options.initialSlope), - offset(this->options.initialOffset), - prevOffset(this->options.initialOffset), - E(), - processNoise(), - avgNoise(this->options.initialAvgNoise), - varNoise(this->options.initialVarNoise), - tsDeltaHist() + inline OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) + : options(options) + , numOfDeltas(0) + , slope(this->options.initialSlope) + , offset(this->options.initialOffset) + , prevOffset(this->options.initialOffset) + , E() + , processNoise() + , avgNoise(this->options.initialAvgNoise) + , varNoise(this->options.initialVarNoise) + , tsDeltaHist() { std::memcpy(this->E, this->options.initialE, sizeof(this->E)); std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise)); } - inline - OveruseEstimator::~OveruseEstimator() + inline OveruseEstimator::~OveruseEstimator() { this->tsDeltaHist.clear(); } - inline - double OveruseEstimator::GetVarNoise() const + inline double OveruseEstimator::GetVarNoise() const { return this->varNoise; } - inline - double OveruseEstimator::GetOffset() const + inline double OveruseEstimator::GetOffset() const { return this->offset; } - inline - unsigned int OveruseEstimator::GetNumOfDeltas() const + inline unsigned int OveruseEstimator::GetNumOfDeltas() const { return this->numOfDeltas; } diff --git a/worker/include/RTC/RemoteBitrateEstimator/RateControlInput.hpp b/worker/include/RTC/RemoteBitrateEstimator/RateControlInput.hpp index 28a5b5432e..f904fc7cf7 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/RateControlInput.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/RateControlInput.hpp @@ -14,17 +14,18 @@ namespace RTC BandwidthUsage bwState; uint32_t incomingBitrate = 0; - double noiseVar = 0; + double noiseVar = 0; }; /* Inline methods. */ - inline - RateControlInput::RateControlInput(BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar) : - bwState(bwState), - incomingBitrate(incomingBitrate), - noiseVar(noiseVar) - {} + inline RateControlInput::RateControlInput( + BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar) + : bwState(bwState) + , incomingBitrate(incomingBitrate) + , noiseVar(noiseVar) + { + } } #endif diff --git a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp index dfd9dacf75..e509065870 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp @@ -30,7 +30,7 @@ namespace RTC public: virtual ~CallStatsObserver() = default; - virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) = 0; + virtual void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) = 0; }; class RemoteBitrateEstimator : public CallStatsObserver @@ -46,25 +46,29 @@ namespace RTC protected: static const int64_t kProcessIntervalMs = 500; - static const int64_t kStreamTimeOutMs = 2000; + static const int64_t kStreamTimeOutMs = 2000; public: virtual ~RemoteBitrateEstimator() = default; // Called for each incoming packet. Updates the incoming payload bitrate // estimate and the over-use detector. If an over-use is detected the - // remote bitrate estimate will be updated. Note that |payload_size| is the + // remote bitrate estimate will be updated. Note that |payloadSize| is the // packet size excluding headers. - // Note that |arrival_time_ms| can be of an arbitrary time base. - virtual void IncomingPacket(int64_t arrival_time_ms, size_t payload_size, const RtpPacket& packet, const uint32_t absSendTime) = 0; + // Note that |arrivalTimeMs| can be of an arbitrary time base. + virtual void IncomingPacket( + int64_t arrivalTimeMs, + size_t payloadSize, + const RtpPacket& packet, + const uint32_t absSendTime) = 0; // Removes all data for |ssrc|. virtual void RemoveStream(uint32_t ssrc) = 0; - // Returns true if a valid estimate exists and sets |bitrate_bps| to the + // Returns true if a valid estimate exists and sets |bitrateBps| to the // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs // currently being received and of which the bitrate estimate is based upon. - virtual bool LatestEstimate(std::vector* ssrcs, uint32_t* bitrate_bps) const = 0; - virtual void SetMinBitrate(int min_bitrate_bps) = 0; + virtual bool LatestEstimate(std::vector* ssrcs, uint32_t* bitrateBps) const = 0; + virtual void SetMinBitrate(int minBitrateBps) = 0; // (jmillan) borrowed from webrtc/modules/include/module.h. // // Returns the number of milliseconds until the module wants a worker diff --git a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp index 18eda60874..58d31d5ab6 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp @@ -12,18 +12,18 @@ #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP #include "common.hpp" +#include "Logger.hpp" #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" -#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include "RTC/RemoteBitrateEstimator/InterArrival.hpp" #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" #include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" +#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include "RTC/RtpDataCounter.hpp" -#include "Logger.hpp" +#include #include #include #include #include -#include namespace RTC { @@ -44,8 +44,8 @@ namespace RTC float sendMeanMs = 0.0f; float recvMeanMs = 0.0f; // TODO(holmer): Add some variance metric as well? - size_t meanSize = 0; - int count = 0; + size_t meanSize = 0; + int count = 0; int numAboveMinDelta = 0; }; @@ -59,7 +59,11 @@ namespace RTC explicit RemoteBitrateEstimatorAbsSendTime(Listener* observer); virtual ~RemoteBitrateEstimatorAbsSendTime() = default; - void IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime) override; + void IncomingPacket( + int64_t arrivalTimeMs, + size_t payloadSize, + const RtpPacket& packet, + const uint32_t absSendTime) override; // This class relies on Process() being called periodically (at least once // every other second) for streams to be timed out properly. void Process() override; @@ -79,7 +83,8 @@ namespace RTC }; private: - void IncomingPacketInfo(int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc); + void IncomingPacketInfo( + int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc); void ComputeClusters(std::list* clusters) const; std::list::const_iterator FindBestProbe(const std::list& clusters) const; @@ -99,73 +104,67 @@ namespace RTC std::vector recentUpdateTimeMs; std::list probes; size_t totalProbesReceived = 0; - int64_t firstPacketTimeMs = -1; - int64_t lastUpdateMs = -1; - bool umaRecorded = false; + int64_t firstPacketTimeMs = -1; + int64_t lastUpdateMs = -1; + bool umaRecorded = false; Ssrcs ssrcs; AimdRateControl remoteRate; }; /* Inline Methods. */ - inline - Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize) : - sendTimeMs(sendTimeMs), - recvTimeMs(recvTimeMs), - payloadSize(payloadSize) - {} + inline Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize) + : sendTimeMs(sendTimeMs) + , recvTimeMs(recvTimeMs) + , payloadSize(payloadSize) + { + } - inline - int Cluster::GetSendBitrateBps() const + inline int Cluster::GetSendBitrateBps() const { assert(sendMeanMs > 0.0f); return meanSize * 8 * 1000 / sendMeanMs; } - inline - int Cluster::GetRecvBitrateBps() const + inline int Cluster::GetRecvBitrateBps() const { assert(recvMeanMs > 0.0f); return meanSize * 8 * 1000 / recvMeanMs; } - inline - RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer) : - observer(observer), - interArrival(), - estimator(), - detector(), - incomingBitrate() - {} - - inline - void RemoteBitrateEstimatorAbsSendTime::Process() - {} - - inline - int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess() + inline RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer) + : observer(observer) + , interArrival() + , estimator() + , detector() + , incomingBitrate() + { + } + + inline void RemoteBitrateEstimatorAbsSendTime::Process() + { + } + + inline int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess() { const int64_t kDisabledModuleTime = 1000; return kDisabledModuleTime; } - inline - void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) + inline void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) { (void)maxRttMs; this->remoteRate.SetRtt(avgRttMs); } - inline - void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) + inline void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) { this->ssrcs.erase(ssrc); } - inline - void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int minBitrateBps) + inline void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int minBitrateBps) { this->remoteRate.SetMinBitrate(minBitrateBps); } diff --git a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.hpp b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.hpp index 89148492e5..fdeafd95bd 100644 --- a/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.hpp +++ b/worker/include/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.hpp @@ -13,19 +13,18 @@ #include "common.hpp" #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" -#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" -#include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" #include "RTC/RemoteBitrateEstimator/InterArrival.hpp" +#include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" +#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include "RTC/RtpDataCounter.hpp" +#include #include #include #include -#include namespace RTC { - class RemoteBitrateEstimatorSingleStream : - public RemoteBitrateEstimator + class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { private: static constexpr double kTimestampToMs = 1.0 / 90.0; @@ -34,7 +33,11 @@ namespace RTC explicit RemoteBitrateEstimatorSingleStream(Listener* observer); virtual ~RemoteBitrateEstimatorSingleStream(); - void IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t transmissionTimeOffset) override; + void IncomingPacket( + int64_t arrivalTimeMs, + size_t payloadSize, + const RtpPacket& packet, + const uint32_t transmissionTimeOffset) override; void Process() override; int64_t TimeUntilNextProcess() override; void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override; @@ -49,7 +52,8 @@ namespace RTC { kTimestampGroupLengthMs = 5 }; - explicit Detector(int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping); + explicit Detector( + int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping); int64_t lastPacketTimeMs; InterArrival interArrival; @@ -74,32 +78,33 @@ namespace RTC RateCalculator incomingBitrate; uint32_t lastValidIncomingBitrate = 0; std::unique_ptr remoteRate; - Listener* observer = nullptr; - int64_t lastProcessTime = -1; + Listener* observer = nullptr; + int64_t lastProcessTime = -1; int64_t processIntervalMs = 0; - bool umaRecorded = false; + bool umaRecorded = false; }; /* Inline Methods. */ - inline - RemoteBitrateEstimatorSingleStream::Detector::Detector(int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping) : - lastPacketTimeMs(lastPacketTimeMs), - interArrival(90 * kTimestampGroupLengthMs, kTimestampToMs, enableBurstGrouping), - estimator(options), - detector() - {} - - inline - RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer) : - incomingBitrate(), - remoteRate(new AimdRateControl()), observer(observer), processIntervalMs(kProcessIntervalMs) + inline RemoteBitrateEstimatorSingleStream::Detector::Detector( + int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping) + : lastPacketTimeMs(lastPacketTimeMs) + , interArrival(90 * kTimestampGroupLengthMs, kTimestampToMs, enableBurstGrouping) + , estimator(options) + , detector() + { + } + + inline RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer) + : incomingBitrate() + , remoteRate(new AimdRateControl()) + , observer(observer) + , processIntervalMs(kProcessIntervalMs) { // assert(this->observer); } - inline - RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream() + inline RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream() { while (!this->overuseDetectors.empty()) { @@ -109,22 +114,19 @@ namespace RTC } } - inline - void RemoteBitrateEstimatorSingleStream::Process() + inline void RemoteBitrateEstimatorSingleStream::Process() { UpdateEstimate(DepLibUV::GetTime()); this->lastProcessTime = DepLibUV::GetTime(); } - inline - void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) + inline void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) { (void)maxRttMs; GetRemoteRate()->SetRtt(avgRttMs); } - inline - void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) + inline void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc) { SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.find(ssrc); if (it != this->overuseDetectors.end()) @@ -134,16 +136,14 @@ namespace RTC } } - inline - AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate() + inline AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate() { if (!this->remoteRate) this->remoteRate.reset(new AimdRateControl()); return this->remoteRate.get(); } - inline - void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int minBitrateBps) + inline void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int minBitrateBps) { this->remoteRate->SetMinBitrate(minBitrateBps); } diff --git a/worker/include/RTC/Room.hpp b/worker/include/RTC/Room.hpp index 643f96d252..617fcbe64d 100644 --- a/worker/include/RTC/Room.hpp +++ b/worker/include/RTC/Room.hpp @@ -2,26 +2,25 @@ #define MS_RTC_ROOM_HPP #include "common.hpp" -#include "RTC/RtpDictionaries.hpp" +#include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" #include "RTC/Peer.hpp" -#include "RTC/RtpReceiver.hpp" -#include "RTC/RtpSender.hpp" -#include "RTC/RtpPacket.hpp" -#include "RTC/RTCP/ReceiverReport.hpp" -#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/Feedback.hpp" +#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/Sdes.hpp" -#include "Channel/Request.hpp" -#include "Channel/Notifier.hpp" +#include "RTC/RTCP/SenderReport.hpp" +#include "RTC/RtpDictionaries.hpp" +#include "RTC/RtpPacket.hpp" +#include "RTC/RtpReceiver.hpp" +#include "RTC/RtpSender.hpp" +#include #include #include #include -#include namespace RTC { - class Room : - public RTC::Peer::Listener + class Room : public RTC::Peer::Listener { public: class Listener @@ -53,18 +52,24 @@ namespace RTC RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const; void SetCapabilities(std::vector& mediaCodecs); - /* Pure virtual methods inherited from RTC::Peer::Listener. */ + /* Pure virtual methods inherited from RTC::Peer::Listener. */ public: virtual void onPeerClosed(const RTC::Peer* peer) override; virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) override; virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) override; - virtual void onPeerRtpReceiverClosed(const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) override; + virtual void onPeerRtpReceiverClosed( + const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) override; virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) override; - virtual void onPeerRtpPacket(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override; - virtual void onPeerRtcpReceiverReport(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) override; - virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) override; - virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) override; - virtual void onPeerRtcpSenderReport(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) override; + virtual void onPeerRtpPacket( + const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override; + virtual void onPeerRtcpReceiverReport( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) override; + virtual void onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) override; + virtual void onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) override; + virtual void onPeerRtcpSenderReport( + const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) override; virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) override; public: @@ -73,7 +78,7 @@ namespace RTC private: // Passed by argument. - Listener* listener = nullptr; + Listener* listener = nullptr; Channel::Notifier* notifier = nullptr; // Others. RTC::RtpCapabilities capabilities; @@ -84,8 +89,7 @@ namespace RTC /* Inline static methods. */ - inline - const RTC::RtpCapabilities& Room::GetCapabilities() const + inline const RTC::RtpCapabilities& Room::GetCapabilities() const { return this->capabilities; } diff --git a/worker/include/RTC/RtpDataCounter.hpp b/worker/include/RTC/RtpDataCounter.hpp index 17699c8934..336e175302 100644 --- a/worker/include/RTC/RtpDataCounter.hpp +++ b/worker/include/RTC/RtpDataCounter.hpp @@ -12,12 +12,12 @@ namespace RTC class RateCalculator { public: - static constexpr float kBpsScale = 8000.0f; - static constexpr float kbpsScale = 1000.0f; - static constexpr size_t defaultWindowSize = 1000; + static constexpr float BpsScale = 8000.0f; + static constexpr float BpsScale2 = 1000.0f; + static constexpr size_t DefaultWindowSize = 1000; public: - explicit RateCalculator(size_t windowSize = defaultWindowSize, float scale = kBpsScale); + explicit RateCalculator(size_t windowSize = DefaultWindowSize, float scale = BpsScale); void Update(size_t count, uint64_t now); uint32_t GetRate(uint64_t now); void Reset(); @@ -42,9 +42,9 @@ namespace RTC // Total count in the time window. size_t totalCount = 0; // Window Size (in milliseconds). - size_t windowSize = defaultWindowSize; + size_t windowSize = DefaultWindowSize; // Scale in which the rate is represented. - const float scale = kBpsScale; + const float scale = BpsScale; }; class RtpDataCounter @@ -58,50 +58,44 @@ namespace RTC private: RateCalculator rate; size_t packets = 0; - size_t bytes = 0; + size_t bytes = 0; }; /* Inline instance methods. */ - inline - RateCalculator::RateCalculator(size_t windowSize, float scale) : - windowSize(windowSize), - scale(scale) + inline RateCalculator::RateCalculator(size_t windowSize, float scale) + : windowSize(windowSize) + , scale(scale) { uint64_t now = DepLibUV::GetTime(); this->Reset(now); } - inline - void RateCalculator::Reset() + inline void RateCalculator::Reset() { this->Reset(this->oldestTime); } - inline - void RateCalculator::Reset(uint64_t now) + inline void RateCalculator::Reset(uint64_t now) { this->buffer.reset(new BufferItem[windowSize]); - this->totalCount = 0; + this->totalCount = 0; this->oldestIndex = 0; - this->oldestTime = now - this->windowSize; + this->oldestTime = now - this->windowSize; } - inline - uint32_t RtpDataCounter::GetRate(uint64_t now) + inline uint32_t RtpDataCounter::GetRate(uint64_t now) { return this->rate.GetRate(now); } - inline - size_t RtpDataCounter::GetPacketCount() const + inline size_t RtpDataCounter::GetPacketCount() const { return this->packets; } - inline - size_t RtpDataCounter::GetBytes() const + inline size_t RtpDataCounter::GetBytes() const { return this->bytes; } diff --git a/worker/include/RTC/RtpDictionaries.hpp b/worker/include/RTC/RtpDictionaries.hpp index b1ea31b9f3..4ca11f97ff 100644 --- a/worker/include/RTC/RtpDictionaries.hpp +++ b/worker/include/RTC/RtpDictionaries.hpp @@ -3,11 +3,11 @@ #include "common.hpp" #include "RTC/Parameters.hpp" +#include +#include #include -#include #include -#include -#include +#include namespace RTC { @@ -82,7 +82,7 @@ namespace RTC static std::map subtype2String; public: - RtpCodecMime() {}; + RtpCodecMime(){}; bool operator==(const RtpCodecMime& other) const { @@ -117,8 +117,8 @@ namespace RTC } public: - Type type = Type::UNSET; - Subtype subtype = Subtype::UNSET; + Type type = Type::UNSET; + Subtype subtype = Subtype::UNSET; std::string name; }; @@ -135,11 +135,11 @@ namespace RTC RTP_STREAM_ID = 5 }; - private: - static std::unordered_map string2Type; + private: + static std::unordered_map string2Type; - public: - static Type GetType(std::string& uri); + public: + static Type GetType(std::string& uri); }; class RtcpFeedback @@ -157,7 +157,7 @@ namespace RTC class RtpCodecParameters { public: - RtpCodecParameters() {}; + RtpCodecParameters(){}; RtpCodecParameters(Json::Value& data, RTC::Scope scope); Json::Value toJson() const; @@ -168,18 +168,18 @@ namespace RTC void CheckCodec(); private: - RTC::Scope scope = RTC::Scope::ROOM_CAPABILITY; + RTC::Scope scope = RTC::Scope::ROOM_CAPABILITY; public: - Media::Kind kind = Media::Kind::ALL; - RtpCodecMime mime; - uint8_t payloadType = 0; - bool hasPayloadType = false; - uint32_t clockRate = 0; - uint32_t maxptime = 0; - uint32_t ptime = 0; - uint32_t numChannels = 1; - RTC::Parameters parameters; + Media::Kind kind = Media::Kind::ALL; + RtpCodecMime mime; + uint8_t payloadType = 0; + bool hasPayloadType = false; + uint32_t clockRate = 0; + uint32_t maxptime = 0; + uint32_t ptime = 0; + uint32_t numChannels = 1; + RTC::Parameters parameters; std::vector rtcpFeedback; }; @@ -191,17 +191,17 @@ namespace RTC Json::Value toJson() const; public: - Media::Kind kind = Media::Kind::ALL; - std::string uri; + Media::Kind kind = Media::Kind::ALL; + std::string uri; RtpHeaderExtensionUri::Type type; - uint8_t preferredId = 0; - bool preferredEncrypt = false; + uint8_t preferredId = 0; + bool preferredEncrypt = false; }; class RtpCapabilities { public: - RtpCapabilities() {}; + RtpCapabilities(){}; RtpCapabilities(Json::Value& data, RTC::Scope scope); Json::Value toJson() const; @@ -214,26 +214,26 @@ namespace RTC public: std::vector codecs; std::vector headerExtensions; - std::vector fecMechanisms; + std::vector fecMechanisms; }; class RtpFecParameters { public: - RtpFecParameters() {}; + RtpFecParameters(){}; explicit RtpFecParameters(Json::Value& data); Json::Value toJson() const; public: std::string mechanism; - uint32_t ssrc = 0; + uint32_t ssrc = 0; }; class RtpRtxParameters { public: - RtpRtxParameters() {}; + RtpRtxParameters(){}; explicit RtpRtxParameters(Json::Value& data); Json::Value toJson() const; @@ -245,24 +245,24 @@ namespace RTC class RtpEncodingParameters { public: - RtpEncodingParameters() {}; + RtpEncodingParameters(){}; explicit RtpEncodingParameters(Json::Value& data); Json::Value toJson() const; public: - uint32_t ssrc = 0; - uint8_t codecPayloadType = 0; - bool hasCodecPayloadType = false; - RtpFecParameters fec; - bool hasFec = false; - RtpRtxParameters rtx; - bool hasRtx = false; - double resolutionScale = 1.0; - double framerateScale = 1.0; - uint32_t maxFramerate = 0; - bool active = true; - std::string encodingId; + uint32_t ssrc = 0; + uint8_t codecPayloadType = 0; + bool hasCodecPayloadType = false; + RtpFecParameters fec; + bool hasFec = false; + RtpRtxParameters rtx; + bool hasRtx = false; + double resolutionScale = 1.0; + double framerateScale = 1.0; + uint32_t maxFramerate = 0; + bool active = true; + std::string encodingId; std::vector dependencyEncodingIds; }; @@ -274,25 +274,25 @@ namespace RTC Json::Value toJson() const; public: - std::string uri; + std::string uri; RtpHeaderExtensionUri::Type type; - uint8_t id = 0; - bool encrypt = false; - RTC::Parameters parameters; + uint8_t id = 0; + bool encrypt = false; + RTC::Parameters parameters; }; class RtcpParameters { public: - RtcpParameters() {}; + RtcpParameters(){}; explicit RtcpParameters(Json::Value& data); Json::Value toJson() const; public: std::string cname; - uint32_t ssrc = 0; - bool reducedSize = true; + uint32_t ssrc = 0; + bool reducedSize = true; }; class RtpParameters @@ -311,13 +311,13 @@ namespace RTC void ValidateEncodings(); public: - std::string muxId; - std::vector codecs; - std::vector encodings; + std::string muxId; + std::vector codecs; + std::vector encodings; std::vector headerExtensions; - RtcpParameters rtcp; - bool hasRtcp = false; - Json::Value userParameters; + RtcpParameters rtcp; + bool hasRtcp = false; + Json::Value userParameters; }; } diff --git a/worker/include/RTC/RtpListener.hpp b/worker/include/RTC/RtpListener.hpp index 41b57cdd1c..cf86b9c65b 100644 --- a/worker/include/RTC/RtpListener.hpp +++ b/worker/include/RTC/RtpListener.hpp @@ -2,11 +2,11 @@ #define MS_RTC_LISTENER_HPP #include "common.hpp" -#include "RTC/RtpReceiver.hpp" #include "RTC/RtpPacket.hpp" +#include "RTC/RtpReceiver.hpp" #include -#include #include +#include namespace RTC { @@ -23,7 +23,11 @@ namespace RTC RTC::RtpReceiver* GetRtpReceiver(uint32_t ssrc); private: - void RollbackRtpReceiver(RTC::RtpReceiver* rtpReceiver, std::vector& previousSsrcs, std::string& previousMuxId, std::vector& previousPayloadTypes); + void RollbackRtpReceiver( + RTC::RtpReceiver* rtpReceiver, + std::vector& previousSsrcs, + std::string& previousMuxId, + std::vector& previousPayloadTypes); public: // Table of SSRC / RtpReceiver pairs. @@ -36,8 +40,7 @@ namespace RTC /* Inline instance methods. */ - inline - bool RtpListener::HasSsrc(uint32_t ssrc, const RTC::RtpReceiver* rtpReceiver) const + inline bool RtpListener::HasSsrc(uint32_t ssrc, const RTC::RtpReceiver* rtpReceiver) const { auto it = this->ssrcTable.find(ssrc); @@ -51,8 +54,7 @@ namespace RTC } } - inline - bool RtpListener::HasMuxId(std::string& muxId, const RTC::RtpReceiver* rtpReceiver) const + inline bool RtpListener::HasMuxId(std::string& muxId, const RTC::RtpReceiver* rtpReceiver) const { auto it = this->muxIdTable.find(muxId); @@ -66,8 +68,7 @@ namespace RTC } } - inline - bool RtpListener::HasPayloadType(uint8_t payloadType, const RTC::RtpReceiver* rtpReceiver) const + inline bool RtpListener::HasPayloadType(uint8_t payloadType, const RTC::RtpReceiver* rtpReceiver) const { auto it = this->ptTable.find(payloadType); diff --git a/worker/include/RTC/RtpPacket.hpp b/worker/include/RTC/RtpPacket.hpp index 7e1f92f360..eddbf81af0 100644 --- a/worker/include/RTC/RtpPacket.hpp +++ b/worker/include/RTC/RtpPacket.hpp @@ -2,8 +2,8 @@ #define MS_RTC_RTP_PACKET_HPP #include "common.hpp" -#include "RTC/RtpDictionaries.hpp" #include "Utils.hpp" +#include "RTC/RtpDictionaries.hpp" #include namespace RTC @@ -14,21 +14,21 @@ namespace RTC /* Struct for RTP header. */ struct Header { - #if defined(MS_LITTLE_ENDIAN) - uint8_t csrcCount:4; - uint8_t extension:1; - uint8_t padding:1; - uint8_t version:2; - uint8_t payloadType:7; - uint8_t marker:1; - #elif defined(MS_BIG_ENDIAN) - uint8_t version:2; - uint8_t padding:1; - uint8_t extension:1; - uint8_t csrcCount:4; - uint8_t marker:1; - uint8_t payloadType:7; - #endif +#if defined(MS_LITTLE_ENDIAN) + uint8_t csrcCount : 4; + uint8_t extension : 1; + uint8_t padding : 1; + uint8_t version : 2; + uint8_t payloadType : 7; + uint8_t marker : 1; +#elif defined(MS_BIG_ENDIAN) + uint8_t version : 2; + uint8_t padding : 1; + uint8_t extension : 1; + uint8_t csrcCount : 4; + uint8_t marker : 1; + uint8_t payloadType : 7; +#endif uint16_t sequenceNumber; uint32_t timestamp; uint32_t ssrc; @@ -47,13 +47,13 @@ namespace RTC /* Struct for One-Byte extension. */ struct OneByteExtension { - #if defined(MS_LITTLE_ENDIAN) - uint8_t len:4; - uint8_t id:4; - #elif defined(MS_BIG_ENDIAN) - uint8_t id:4; - uint8_t len:4; - #endif +#if defined(MS_LITTLE_ENDIAN) + uint8_t len : 4; + uint8_t id : 4; +#elif defined(MS_BIG_ENDIAN) + uint8_t id : 4; + uint8_t len : 4; +#endif uint8_t value[1]; }; @@ -61,13 +61,13 @@ namespace RTC /* Struct for Two-Bytes extension. */ struct TwoBytesExtension { - #if defined(MS_LITTLE_ENDIAN) - uint8_t len:8; - uint8_t id:8; - #elif defined(MS_BIG_ENDIAN) - uint8_t id:8; - uint8_t len:8; - #endif +#if defined(MS_LITTLE_ENDIAN) + uint8_t len : 8; + uint8_t id : 8; +#elif defined(MS_BIG_ENDIAN) + uint8_t id : 8; + uint8_t len : 8; +#endif uint8_t value[1]; }; @@ -76,7 +76,13 @@ namespace RTC static RtpPacket* Parse(const uint8_t* data, size_t len); public: - RtpPacket(Header* header, ExtensionHeader* extensionHeader, const uint8_t* payload, size_t payloadLen, uint8_t payloadPadding, size_t size); + RtpPacket( + Header* header, + ExtensionHeader* extensionHeader, + const uint8_t* payload, + size_t payloadLen, + uint8_t payloadPadding, + size_t size); ~RtpPacket(); void Dump() const; @@ -114,131 +120,113 @@ namespace RTC private: // Passed by argument. - Header* header = nullptr; - uint8_t* csrcList = nullptr; + Header* header = nullptr; + uint8_t* csrcList = nullptr; ExtensionHeader* extensionHeader = nullptr; std::map oneByteExtensions; std::map twoBytesExtensions; std::map extensionMap; - uint8_t* payload = nullptr; - size_t payloadLength = 0; + uint8_t* payload = nullptr; + size_t payloadLength = 0; uint8_t payloadPadding = 0; - size_t size = 0; // Full size of the packet in bytes. - uint32_t seq32 = 0; // Extended seq number. + size_t size = 0; // Full size of the packet in bytes. + uint32_t seq32 = 0; // Extended seq number. }; /* Inline static methods. */ - inline - bool RtpPacket::IsRtp(const uint8_t* data, size_t len) + inline bool RtpPacket::IsRtp(const uint8_t* data, size_t len) { // NOTE: RtcpPacket::IsRtcp() must always be called before this method. Header* header = const_cast(reinterpret_cast(data)); return ( - (len >= sizeof(Header)) && - // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes - (data[0] > 127 && data[0] < 192) && - // RTP Version must be 2. - (header->version == 2) - ); + (len >= sizeof(Header)) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] > 127 && data[0] < 192) && + // RTP Version must be 2. + (header->version == 2)); } /* Inline instance methods. */ - inline - const uint8_t* RtpPacket::GetData() const + inline const uint8_t* RtpPacket::GetData() const { return (const uint8_t*)this->header; } - inline - size_t RtpPacket::GetSize() const + inline size_t RtpPacket::GetSize() const { return this->size; } - inline - uint8_t RtpPacket::GetPayloadType() const + inline uint8_t RtpPacket::GetPayloadType() const { return this->header->payloadType; } - inline - void RtpPacket::SetPayloadType(uint8_t payloadType) + inline void RtpPacket::SetPayloadType(uint8_t payloadType) { this->header->payloadType = payloadType; } - inline - bool RtpPacket::HasMarker() const + inline bool RtpPacket::HasMarker() const { return this->header->marker; } - inline - void RtpPacket::SetMarker(bool marker) + inline void RtpPacket::SetMarker(bool marker) { this->header->marker = marker; } - inline - uint16_t RtpPacket::GetSequenceNumber() const + inline uint16_t RtpPacket::GetSequenceNumber() const { return (uint16_t)ntohs(this->header->sequenceNumber); } - inline - void RtpPacket::SetSequenceNumber(uint16_t seq) + inline void RtpPacket::SetSequenceNumber(uint16_t seq) { this->header->sequenceNumber = (uint16_t)htons(seq); } - inline - uint32_t RtpPacket::GetExtendedSequenceNumber() const + inline uint32_t RtpPacket::GetExtendedSequenceNumber() const { return this->seq32; } - inline - void RtpPacket::SetExtendedSequenceNumber(uint32_t seq32) + inline void RtpPacket::SetExtendedSequenceNumber(uint32_t seq32) { this->seq32 = seq32; } - inline - uint32_t RtpPacket::GetTimestamp() const + inline uint32_t RtpPacket::GetTimestamp() const { return (uint32_t)ntohl(this->header->timestamp); } - inline - void RtpPacket::SetTimestamp(uint32_t timestamp) + inline void RtpPacket::SetTimestamp(uint32_t timestamp) { this->header->timestamp = (uint32_t)htonl(timestamp); } - inline - uint32_t RtpPacket::GetSsrc() const + inline uint32_t RtpPacket::GetSsrc() const { return (uint32_t)ntohl(this->header->ssrc); } - inline - void RtpPacket::SetSsrc(uint32_t ssrc) + inline void RtpPacket::SetSsrc(uint32_t ssrc) { this->header->ssrc = (uint32_t)htonl(ssrc); } - inline - bool RtpPacket::HasExtensionHeader() const + inline bool RtpPacket::HasExtensionHeader() const { return (this->extensionHeader ? true : false); } - inline - uint16_t RtpPacket::GetExtensionHeaderId() const + inline uint16_t RtpPacket::GetExtensionHeaderId() const { if (!this->extensionHeader) return 0; @@ -246,8 +234,7 @@ namespace RTC return uint16_t(ntohs(this->extensionHeader->id)); } - inline - size_t RtpPacket::GetExtensionHeaderLength() const + inline size_t RtpPacket::GetExtensionHeaderLength() const { if (!this->extensionHeader) return 0; @@ -255,8 +242,7 @@ namespace RTC return size_t(ntohs(this->extensionHeader->length) * 4); } - inline - uint8_t* RtpPacket::GetExtensionHeaderValue() const + inline uint8_t* RtpPacket::GetExtensionHeaderValue() const { if (!this->extensionHeader) return nullptr; @@ -264,26 +250,22 @@ namespace RTC return this->extensionHeader->value; } - inline - bool RtpPacket::HasOneByteExtensions() const + inline bool RtpPacket::HasOneByteExtensions() const { return GetExtensionHeaderId() == 0xBEDE; } - inline - bool RtpPacket::HasTwoBytesExtensions() const + inline bool RtpPacket::HasTwoBytesExtensions() const { return (GetExtensionHeaderId() & 0b1111111111110000) == 0b0001000000000000; } - inline - void RtpPacket::AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id) + inline void RtpPacket::AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id) { this->extensionMap[uri] = id; } - inline - uint8_t* RtpPacket::GetExtension(RtpHeaderExtensionUri::Type uri, uint8_t* len) const + inline uint8_t* RtpPacket::GetExtension(RtpHeaderExtensionUri::Type uri, uint8_t* len) const { *len = 0; @@ -316,8 +298,7 @@ namespace RTC } } - inline - bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const + inline bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const { uint8_t extenLen; uint8_t* extenValue; @@ -328,14 +309,13 @@ namespace RTC return false; *volume = Utils::Byte::Get1Byte(extenValue, 0); - *voice = (*volume & (1 << 7)) ? true : false; + *voice = (*volume & (1 << 7)) ? true : false; *volume &= ~(1 << 7); return true; } - inline - bool RtpPacket::ReadAbsSendTime(uint32_t* time) const + inline bool RtpPacket::ReadAbsSendTime(uint32_t* time) const { uint8_t extenLen; uint8_t* extenValue; @@ -350,14 +330,12 @@ namespace RTC return true; } - inline - uint8_t* RtpPacket::GetPayload() const + inline uint8_t* RtpPacket::GetPayload() const { return this->payload; } - inline - size_t RtpPacket::GetPayloadLength() const + inline size_t RtpPacket::GetPayloadLength() const { return this->payloadLength; } diff --git a/worker/include/RTC/RtpReceiver.hpp b/worker/include/RTC/RtpReceiver.hpp index 636cc80dd2..86bc3d9e90 100644 --- a/worker/include/RTC/RtpReceiver.hpp +++ b/worker/include/RTC/RtpReceiver.hpp @@ -2,17 +2,17 @@ #define MS_RTC_RTP_RECEIVER_HPP #include "common.hpp" +#include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" +#include "RTC/RTCP/CompoundPacket.hpp" +#include "RTC/RTCP/Feedback.hpp" +#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RtpDictionaries.hpp" #include "RTC/RtpPacket.hpp" #include "RTC/RtpStreamRecv.hpp" -#include "RTC/RTCP/ReceiverReport.hpp" -#include "RTC/RTCP/Feedback.hpp" -#include "RTC/RTCP/CompoundPacket.hpp" -#include "Channel/Request.hpp" -#include "Channel/Notifier.hpp" -#include -#include #include +#include +#include namespace RTC { @@ -20,8 +20,7 @@ namespace RTC // the corresponding header files. class Transport; - class RtpReceiver : - public RtpStreamRecv::Listener + class RtpReceiver : public RtpStreamRecv::Listener { public: /** @@ -30,17 +29,15 @@ namespace RTC class Listener { public: - virtual void onRtpReceiverParameters(RtpReceiver* rtpReceiver) = 0; - virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0; - virtual void onRtpPacket(RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; - virtual void onRtpReceiverClosed(const RtpReceiver* rtpReceiver) = 0; + virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) = 0; + virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0; + virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; + virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) = 0; }; - private: - static uint8_t rtcpBuffer[]; - public: - RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind); + RtpReceiver( + Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind); private: virtual ~RtpReceiver(); @@ -55,7 +52,7 @@ namespace RTC RTC::RtpParameters* GetParameters() const; void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); - void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now); + void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const; void RequestFullFrame() const; @@ -64,9 +61,10 @@ namespace RTC void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void ClearRtpStreams(); - /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ + /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ public: - virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector& seqNumbers) override; + virtual void onNackRequired( + RTC::RtpStreamRecv* rtpStream, const std::vector& seqNumbers) override; virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override; public: @@ -76,14 +74,14 @@ namespace RTC private: // Passed by argument. - Listener* listener = nullptr; + Listener* listener = nullptr; Channel::Notifier* notifier = nullptr; - RTC::Transport* transport = nullptr; + RTC::Transport* transport = nullptr; // Allocated by this. RTC::RtpParameters* rtpParameters = nullptr; std::map rtpStreams; // Others. - bool rtpRawEventEnabled = false; + bool rtpRawEventEnabled = false; bool rtpObjectEventEnabled = false; // Timestamp when last RTCP was sent. uint64_t lastRtcpSentTime = 0; @@ -92,36 +90,30 @@ namespace RTC /* Inline methods. */ - inline - void RtpReceiver::SetTransport(RTC::Transport* transport) + inline void RtpReceiver::SetTransport(RTC::Transport* transport) { this->transport = transport; } - inline - RTC::Transport* RtpReceiver::GetTransport() const + inline RTC::Transport* RtpReceiver::GetTransport() const { return this->transport; } - inline - void RtpReceiver::RemoveTransport(RTC::Transport* transport) + inline void RtpReceiver::RemoveTransport(RTC::Transport* transport) { if (this->transport == transport) this->transport = nullptr; } - inline - RTC::RtpParameters* RtpReceiver::GetParameters() const + inline RTC::RtpParameters* RtpReceiver::GetParameters() const { return this->rtpParameters; } - inline - void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report) + inline void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report) { auto it = this->rtpStreams.find(report->GetSsrc()); - if (it != this->rtpStreams.end()) { auto rtpStream = it->second; diff --git a/worker/include/RTC/RtpSender.hpp b/worker/include/RTC/RtpSender.hpp index 8fb291f1fd..6a7c5cb84d 100644 --- a/worker/include/RTC/RtpSender.hpp +++ b/worker/include/RTC/RtpSender.hpp @@ -2,19 +2,19 @@ #define MS_RTC_RTP_SENDER_HPP #include "common.hpp" -#include "RTC/Transport.hpp" -#include "RTC/RtpStreamSend.hpp" +#include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" +#include "RTC/RTCP/CompoundPacket.hpp" +#include "RTC/RTCP/FeedbackRtpNack.hpp" +#include "RTC/RTCP/ReceiverReport.hpp" +#include "RTC/RTCP/Sdes.hpp" +#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpDictionaries.hpp" #include "RTC/RtpPacket.hpp" -#include "RTC/RtpDataCounter.hpp" -#include "RTC/RTCP/Sdes.hpp" -#include "RTC/RTCP/ReceiverReport.hpp" -#include "RTC/RTCP/FeedbackRtpNack.hpp" -#include "RTC/RTCP/CompoundPacket.hpp" -#include "Channel/Request.hpp" -#include "Channel/Notifier.hpp" -#include +#include "RTC/RtpStreamSend.hpp" +#include "RTC/Transport.hpp" #include +#include namespace RTC { @@ -31,7 +31,8 @@ namespace RTC }; public: - RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind); + RtpSender( + Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind); private: virtual ~RtpSender(); @@ -48,7 +49,7 @@ namespace RTC RTC::RtpParameters* GetParameters() const; bool GetActive() const; void SendRtpPacket(RTC::RtpPacket* packet); - void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now); + void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); uint32_t GetTransmissionRate(uint64_t now); @@ -65,13 +66,13 @@ namespace RTC private: // Passed by argument. - Listener* listener = nullptr; - Channel::Notifier* notifier = nullptr; - RTC::Transport* transport = nullptr; + Listener* listener = nullptr; + Channel::Notifier* notifier = nullptr; + RTC::Transport* transport = nullptr; RTC::RtpCapabilities* peerCapabilities = nullptr; // Allocated by this. RTC::RtpParameters* rtpParameters = nullptr; - RTC::RtpStreamSend* rtpStream = nullptr; + RTC::RtpStreamSend* rtpStream = nullptr; // Others. std::unordered_set supportedPayloadTypes; // Whether this RtpSender is valid according to Peer capabilities. @@ -89,8 +90,7 @@ namespace RTC /* Inline methods. */ - inline - void RtpSender::SetTransport(RTC::Transport* transport) + inline void RtpSender::SetTransport(RTC::Transport* transport) { bool wasActive = this->GetActive(); @@ -100,14 +100,12 @@ namespace RTC EmitActiveChange(); } - inline - RTC::Transport* RtpSender::GetTransport() const + inline RTC::Transport* RtpSender::GetTransport() const { return this->transport; } - inline - void RtpSender::RemoveTransport(RTC::Transport* transport) + inline void RtpSender::RemoveTransport(RTC::Transport* transport) { bool wasActive = this->GetActive(); @@ -118,20 +116,17 @@ namespace RTC EmitActiveChange(); } - inline - RTC::RtpParameters* RtpSender::GetParameters() const + inline RTC::RtpParameters* RtpSender::GetParameters() const { return this->rtpParameters; } - inline - bool RtpSender::GetActive() const + inline bool RtpSender::GetActive() const { return (this->available && this->transport && !this->disabled); } - inline - uint32_t RtpSender::GetTransmissionRate(uint64_t now) + inline uint32_t RtpSender::GetTransmissionRate(uint64_t now) { return this->transmittedCounter.GetRate(now); } diff --git a/worker/include/RTC/RtpStream.hpp b/worker/include/RTC/RtpStream.hpp index 533c6a58ce..1a9e6be1b1 100644 --- a/worker/include/RTC/RtpStream.hpp +++ b/worker/include/RTC/RtpStream.hpp @@ -2,8 +2,8 @@ #define MS_RTC_RTP_STREAM_HPP #include "common.hpp" -#include "RTC/RtpPacket.hpp" #include "RTC/RtpDictionaries.hpp" +#include "RTC/RtpPacket.hpp" #include namespace RTC @@ -15,13 +15,13 @@ namespace RTC { Json::Value toJson() const; - uint32_t ssrc = 0; - uint8_t payloadType = 0; + uint32_t ssrc = 0; + uint8_t payloadType = 0; RTC::RtpCodecMime mime; - uint32_t clockRate = 0; - bool useNack = false; - bool usePli = false; - uint8_t absSendTimeId = 0; // 0 means no abs-send-time id. + uint32_t clockRate = 0; + bool useNack = false; + bool usePli = false; + uint8_t absSendTimeId = 0; // 0 means no abs-send-time id. }; public: @@ -36,7 +36,7 @@ namespace RTC void InitSeq(uint16_t seq); bool UpdateSeq(RTC::RtpPacket* packet); - /* Pure virtual methods that must be implemented by the subclass. */ + /* Pure virtual methods that must be implemented by the subclass. */ protected: virtual void onInitSeq() = 0; @@ -46,12 +46,12 @@ namespace RTC // Others. bool started = false; // Whether at least a RTP packet has been received. // https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff. - uint16_t maxSeq = 0; // Highest seq. number seen. - uint32_t cycles = 0; // Shifted count of seq. number cycles. - uint32_t baseSeq = 0; // Base seq number. - uint32_t badSeq = 0; // Last 'bad' seq number + 1. - uint32_t probation = 0; // Seq. packets till source is valid. - uint32_t received = 0; // Packets received. + uint16_t maxSeq = 0; // Highest seq. number seen. + uint32_t cycles = 0; // Shifted count of seq. number cycles. + uint32_t baseSeq = 0; // Base seq number. + uint32_t badSeq = 0; // Last 'bad' seq number + 1. + uint32_t probation = 0; // Seq. packets till source is valid. + uint32_t received = 0; // Packets received. uint32_t expectedPrior = 0; // Packet expected at last interval. uint32_t receivedPrior = 0; // Packet received at last interval. // Others. @@ -60,8 +60,7 @@ namespace RTC /* Inline instance methods. */ - inline - uint32_t RtpStream::GetSsrc() + inline uint32_t RtpStream::GetSsrc() { return this->params.ssrc; } diff --git a/worker/include/RTC/RtpStreamRecv.hpp b/worker/include/RTC/RtpStreamRecv.hpp index f09583a4ba..7ce236a898 100644 --- a/worker/include/RTC/RtpStreamRecv.hpp +++ b/worker/include/RTC/RtpStreamRecv.hpp @@ -1,23 +1,22 @@ #ifndef MS_RTC_RTP_STREAM_RECV_HPP #define MS_RTC_RTP_STREAM_RECV_HPP -#include "RTC/RtpStream.hpp" +#include "RTC/NackGenerator.hpp" #include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/SenderReport.hpp" -#include "RTC/NackGenerator.hpp" +#include "RTC/RtpStream.hpp" namespace RTC { - class RtpStreamRecv : - public RtpStream, - public RTC::NackGenerator::Listener + class RtpStreamRecv : public RtpStream, public RTC::NackGenerator::Listener { public: class Listener { public: - virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector& seqNumbers) = 0; - virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; + virtual void onNackRequired( + RTC::RtpStreamRecv* rtpStream, const std::vector& seqNumbers) = 0; + virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; }; public: @@ -33,11 +32,11 @@ namespace RTC private: void CalculateJitter(uint32_t rtpTimestamp); - /* Pure virtual methods inherited from RtpStream. */ + /* Pure virtual methods inherited from RtpStream. */ protected: virtual void onInitSeq() override; - /* Pure virtual methods inherited from RTC::NackGenerator. */ + /* Pure virtual methods inherited from RTC::NackGenerator. */ protected: virtual void onNackRequired(const std::vector& seqNumbers) override; virtual void onFullFrameRequired() override; @@ -46,10 +45,12 @@ namespace RTC // Passed by argument. Listener* listener = nullptr; // Others. - uint32_t lastSrTimestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in the most recent sender report. - uint64_t lastSrReceived = 0; // Wallclock time representing the most recent sender report arrival. + uint32_t lastSrTimestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in + // the most recent sender report. + uint64_t lastSrReceived = + 0; // Wallclock time representing the most recent sender report arrival. uint32_t transit = 0; // Relative trans time for prev pkt. - uint32_t jitter = 0; // Estimated jitter. + uint32_t jitter = 0; // Estimated jitter. std::unique_ptr nackGenerator; }; } diff --git a/worker/include/RTC/RtpStreamSend.hpp b/worker/include/RTC/RtpStreamSend.hpp index 15da8ed787..a0cb4ca193 100644 --- a/worker/include/RTC/RtpStreamSend.hpp +++ b/worker/include/RTC/RtpStreamSend.hpp @@ -1,16 +1,15 @@ #ifndef MS_RTC_RTP_STREAM_SEND_HPP #define MS_RTC_RTP_STREAM_SEND_HPP -#include "RTC/RtpStream.hpp" -#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp" -#include +#include "RTC/RTCP/SenderReport.hpp" +#include "RTC/RtpStream.hpp" #include +#include namespace RTC { - class RtpStreamSend : - public RtpStream + class RtpStreamSend : public RtpStream { private: struct StorageItem @@ -21,8 +20,8 @@ namespace RTC private: struct BufferItem { - uint32_t seq32 = 0; // RTP seq in 32 bytes plus 16 bits cycles. - uint64_t resentAtTime = 0; + uint32_t seq32 = 0; // RTP seq in 32 bytes plus 16 bits cycles. + uint64_t resentAtTime = 0; RTC::RtpPacket* packet = nullptr; }; @@ -33,7 +32,8 @@ namespace RTC virtual Json::Value toJson() const override; bool ReceivePacket(RTC::RtpPacket* packet) override; void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); - void RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector& container); + void RequestRtpRetransmission( + uint16_t seq, uint16_t bitmask, std::vector& container); RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now); uint32_t GetRtt() const; @@ -41,7 +41,7 @@ namespace RTC void ClearBuffer(); void StorePacket(RTC::RtpPacket* packet); - /* Pure virtual methods inherited from RtpStream. */ + /* Pure virtual methods inherited from RtpStream. */ protected: virtual void onInitSeq() override; @@ -51,14 +51,13 @@ namespace RTC Buffer buffer; private: - size_t receivedBytes = 0; // Bytes received. - uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received. + size_t receivedBytes = 0; // Bytes received. + uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received. uint32_t lastPacketRtpTimestamp = 0; // RTP Timestamp of the last packet. - uint32_t rtt = 0; // Round trip time. + uint32_t rtt = 0; // Round trip time. }; - inline - uint32_t RtpStreamSend::GetRtt() const + inline uint32_t RtpStreamSend::GetRtt() const { return this->rtt; } diff --git a/worker/include/RTC/SrtpSession.hpp b/worker/include/RTC/SrtpSession.hpp index af5f6abfe6..a288a71705 100644 --- a/worker/include/RTC/SrtpSession.hpp +++ b/worker/include/RTC/SrtpSession.hpp @@ -50,8 +50,7 @@ namespace RTC /* Inline instance methods. */ - inline - void SrtpSession::RemoveStream(uint32_t ssrc) + inline void SrtpSession::RemoveStream(uint32_t ssrc) { srtp_remove_stream(this->session, htonl(ssrc)); } diff --git a/worker/include/RTC/StunMessage.hpp b/worker/include/RTC/StunMessage.hpp index f1a0cb99a2..c08578176b 100644 --- a/worker/include/RTC/StunMessage.hpp +++ b/worker/include/RTC/StunMessage.hpp @@ -60,7 +60,8 @@ namespace RTC static const uint8_t magicCookie[]; public: - StunMessage(Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size); + StunMessage( + Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size); ~StunMessage(); void Dump() const; @@ -85,180 +86,157 @@ namespace RTC uint16_t GetErrorCode() const; bool HasMessageIntegrity() const; bool HasFingerprint() const; - Authentication CheckAuthentication(const std::string &localUsername, const std::string &localPassword); + Authentication CheckAuthentication( + const std::string& localUsername, const std::string& localPassword); StunMessage* CreateSuccessResponse(); StunMessage* CreateErrorResponse(uint16_t errorCode); - void Authenticate(const std::string &password); + void Authenticate(const std::string& password); void Serialize(uint8_t* buffer); private: // Passed by argument. - Class klass; // 2 bytes. - Method method; // 2 bytes. + Class klass; // 2 bytes. + Method method; // 2 bytes. const uint8_t* transactionId = nullptr; // 12 bytes. - uint8_t* data = nullptr; // Pointer to binary data. - size_t size = 0; // The full message size (including header). + uint8_t* data = nullptr; // Pointer to binary data. + size_t size = 0; // The full message size (including header). // STUN attributes. - std::string username; // Less than 513 bytes. - uint32_t priority = 0; // 4 bytes unsigned integer. - uint64_t iceControlling = 0; // 8 bytes unsigned integer. - uint64_t iceControlled = 0; // 8 bytes unsigned integer. - bool hasUseCandidate = false; // 0 bytes. - const uint8_t* messageIntegrity = nullptr; // 20 bytes. - bool hasFingerprint = false; // 4 bytes. + std::string username; // Less than 513 bytes. + uint32_t priority = 0; // 4 bytes unsigned integer. + uint64_t iceControlling = 0; // 8 bytes unsigned integer. + uint64_t iceControlled = 0; // 8 bytes unsigned integer. + bool hasUseCandidate = false; // 0 bytes. + const uint8_t* messageIntegrity = nullptr; // 20 bytes. + bool hasFingerprint = false; // 4 bytes. const struct sockaddr* xorMappedAddress = nullptr; // 8 or 20 bytes. - uint16_t errorCode = 0; // 4 bytes (no reason phrase). + uint16_t errorCode = 0; // 4 bytes (no reason phrase). std::string password; }; /* Inline class methods. */ - inline - bool StunMessage::IsStun(const uint8_t* data, size_t len) + inline bool StunMessage::IsStun(const uint8_t* data, size_t len) { return ( - // STUN headers are 20 bytes. - (len >= 20) && - // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes - (data[0] < 3) && - // Magic cookie must match. - (data[4] == StunMessage::magicCookie[0]) && - (data[5] == StunMessage::magicCookie[1]) && - (data[6] == StunMessage::magicCookie[2]) && - (data[7] == StunMessage::magicCookie[3]) - ); + // STUN headers are 20 bytes. + (len >= 20) && + // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes + (data[0] < 3) && + // Magic cookie must match. + (data[4] == StunMessage::magicCookie[0]) && + (data[5] == StunMessage::magicCookie[1]) && (data[6] == StunMessage::magicCookie[2]) && + (data[7] == StunMessage::magicCookie[3])); } /* Inline instance methods. */ - inline - StunMessage::Class StunMessage::GetClass() const + inline StunMessage::Class StunMessage::GetClass() const { return this->klass; } - inline - StunMessage::Method StunMessage::GetMethod() const + inline StunMessage::Method StunMessage::GetMethod() const { return this->method; } - inline - const uint8_t* StunMessage::GetData() const + inline const uint8_t* StunMessage::GetData() const { return this->data; } - inline - size_t StunMessage::GetSize() const + inline size_t StunMessage::GetSize() const { return this->size; } - inline - void StunMessage::SetUsername(const char* username, size_t len) + inline void StunMessage::SetUsername(const char* username, size_t len) { if (this->username.empty()) this->username = std::string(username, len); } - inline - void StunMessage::SetPriority(const uint32_t priority) + inline void StunMessage::SetPriority(const uint32_t priority) { if (!this->priority) this->priority = priority; } - inline - void StunMessage::SetIceControlling(const uint64_t iceControlling) + inline void StunMessage::SetIceControlling(const uint64_t iceControlling) { if (!this->iceControlling) this->iceControlling = iceControlling; } - inline - void StunMessage::SetIceControlled(const uint64_t iceControlled) + inline void StunMessage::SetIceControlled(const uint64_t iceControlled) { if (!this->iceControlled) this->iceControlled = iceControlled; } - inline - void StunMessage::SetUseCandidate() + inline void StunMessage::SetUseCandidate() { this->hasUseCandidate = true; } - inline - void StunMessage::SetXorMappedAddress(const struct sockaddr* xorMappedAddress) + inline void StunMessage::SetXorMappedAddress(const struct sockaddr* xorMappedAddress) { if (!this->xorMappedAddress) this->xorMappedAddress = xorMappedAddress; } - inline - void StunMessage::SetErrorCode(uint16_t errorCode) + inline void StunMessage::SetErrorCode(uint16_t errorCode) { this->errorCode = errorCode; } - inline - void StunMessage::SetMessageIntegrity(const uint8_t* messageIntegrity) + inline void StunMessage::SetMessageIntegrity(const uint8_t* messageIntegrity) { if (!this->messageIntegrity) this->messageIntegrity = messageIntegrity; } - inline - void StunMessage::SetFingerprint() + inline void StunMessage::SetFingerprint() { this->hasFingerprint = true; } - inline - const std::string& StunMessage::GetUsername() const + inline const std::string& StunMessage::GetUsername() const { return this->username; } - inline - uint32_t StunMessage::GetPriority() const + inline uint32_t StunMessage::GetPriority() const { return this->priority; } - inline - uint64_t StunMessage::GetIceControlling() const + inline uint64_t StunMessage::GetIceControlling() const { return this->iceControlling; } - inline - uint64_t StunMessage::GetIceControlled() const + inline uint64_t StunMessage::GetIceControlled() const { return this->iceControlled; } - inline - bool StunMessage::HasUseCandidate() const + inline bool StunMessage::HasUseCandidate() const { return this->hasUseCandidate; } - inline - uint16_t StunMessage::GetErrorCode() const + inline uint16_t StunMessage::GetErrorCode() const { return this->errorCode; } - inline - bool StunMessage::HasMessageIntegrity() const + inline bool StunMessage::HasMessageIntegrity() const { return (this->messageIntegrity ? true : false); } - inline - bool StunMessage::HasFingerprint() const + inline bool StunMessage::HasFingerprint() const { return this->hasFingerprint; } diff --git a/worker/include/RTC/TcpConnection.hpp b/worker/include/RTC/TcpConnection.hpp index 5c719d8b9e..108ac90412 100644 --- a/worker/include/RTC/TcpConnection.hpp +++ b/worker/include/RTC/TcpConnection.hpp @@ -6,26 +6,25 @@ namespace RTC { - class TcpConnection : - public ::TcpConnection + class TcpConnection : public ::TcpConnection { public: class Listener { public: - virtual void onPacketRecv(RTC::TcpConnection *connection, const uint8_t* data, size_t len) = 0; + virtual void onPacketRecv(RTC::TcpConnection* connection, const uint8_t* data, size_t len) = 0; }; public: TcpConnection(Listener* listener, size_t bufferSize); private: - virtual ~TcpConnection() {}; + virtual ~TcpConnection(){}; public: void Send(const uint8_t* data, size_t len); - /* Pure virtual methods inherited from ::TcpConnection. */ + /* Pure virtual methods inherited from ::TcpConnection. */ public: virtual void userOnTcpConnectionRead() override; diff --git a/worker/include/RTC/TcpServer.hpp b/worker/include/RTC/TcpServer.hpp index fce1fe46b4..b29ba2656a 100644 --- a/worker/include/RTC/TcpServer.hpp +++ b/worker/include/RTC/TcpServer.hpp @@ -2,32 +2,32 @@ #define MS_RTC_TCP_SERVER_HPP #include "common.hpp" -#include "handles/TcpServer.hpp" -#include "handles/TcpConnection.hpp" #include "RTC/TcpConnection.hpp" -#include +#include "handles/TcpConnection.hpp" +#include "handles/TcpServer.hpp" #include +#include namespace RTC { - class TcpServer : - public ::TcpServer + class TcpServer : public ::TcpServer { public: class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: - virtual void onRtcTcpConnectionClosed(RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool is_closed_by_peer) = 0; + virtual void onRtcTcpConnectionClosed( + RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) = 0; }; public: static void ClassInit(); private: - static uv_tcp_t* GetRandomPort(int address_family); + static uv_tcp_t* GetRandomPort(int addressFamily); private: static struct sockaddr_storage sockaddrStorageIPv4; @@ -38,21 +38,21 @@ namespace RTC static std::unordered_map availableIPv6Ports; public: - TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int address_family); + TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int addressFamily); private: - virtual ~TcpServer() {}; + virtual ~TcpServer(){}; - /* Pure virtual methods inherited from ::TcpServer. */ + /* Pure virtual methods inherited from ::TcpServer. */ public: virtual void userOnTcpConnectionAlloc(::TcpConnection** connection) override; virtual void userOnNewTcpConnection(::TcpConnection* connection) override; - virtual void userOnTcpConnectionClosed(::TcpConnection* connection, bool is_closed_by_peer) override; + virtual void userOnTcpConnectionClosed(::TcpConnection* connection, bool isClosedByPeer) override; virtual void userOnTcpServerClosed() override; private: // Passed by argument. - Listener* listener = nullptr; + Listener* listener = nullptr; RTC::TcpConnection::Listener* connListener = nullptr; }; } diff --git a/worker/include/RTC/Transport.hpp b/worker/include/RTC/Transport.hpp index 99409a20a7..0ce16ec095 100644 --- a/worker/include/RTC/Transport.hpp +++ b/worker/include/RTC/Transport.hpp @@ -2,50 +2,46 @@ #define MS_RTC_TRANSPORT_HPP #include "common.hpp" -#include "RTC/UdpSocket.hpp" -#include "RTC/TcpServer.hpp" -#include "RTC/TcpConnection.hpp" +#include "Channel/Notifier.hpp" +#include "Channel/Request.hpp" +#include "RTC/DtlsTransport.hpp" #include "RTC/IceCandidate.hpp" #include "RTC/IceServer.hpp" -#include "RTC/StunMessage.hpp" -#include "RTC/TransportTuple.hpp" -#include "RTC/DtlsTransport.hpp" -#include "RTC/SrtpSession.hpp" -#include "RTC/RtpListener.hpp" -#include "RTC/RtpReceiver.hpp" -#include "RTC/RtpPacket.hpp" -#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/CompoundPacket.hpp" +#include "RTC/RTCP/Packet.hpp" #include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp" -#include "Channel/Request.hpp" -#include "Channel/Notifier.hpp" +#include "RTC/RtpListener.hpp" +#include "RTC/RtpPacket.hpp" +#include "RTC/RtpReceiver.hpp" +#include "RTC/SrtpSession.hpp" +#include "RTC/StunMessage.hpp" +#include "RTC/TcpConnection.hpp" +#include "RTC/TcpServer.hpp" +#include "RTC/TransportTuple.hpp" +#include "RTC/UdpSocket.hpp" +#include #include #include -#include namespace RTC { - class Transport : - public RTC::UdpSocket::Listener, - public RTC::TcpServer::Listener, - public RTC::TcpConnection::Listener, - public RTC::IceServer::Listener, - public RTC::DtlsTransport::Listener, - public RTC::RemoteBitrateEstimator::Listener + class Transport : public RTC::UdpSocket::Listener, + public RTC::TcpServer::Listener, + public RTC::TcpConnection::Listener, + public RTC::IceServer::Listener, + public RTC::DtlsTransport::Listener, + public RTC::RemoteBitrateEstimator::Listener { public: class Listener { public: - virtual void onTransportConnected(RTC::Transport* transport) = 0; - virtual void onTransportClosed(RTC::Transport* transport) = 0; + virtual void onTransportConnected(RTC::Transport* transport) = 0; + virtual void onTransportClosed(RTC::Transport* transport) = 0; virtual void onTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) = 0; - virtual void onTransportFullFrameRequired(RTC::Transport* transport) = 0; + virtual void onTransportFullFrameRequired(RTC::Transport* transport) = 0; }; - private: - static uint8_t rtcpBuffer[]; - public: Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data); @@ -68,7 +64,7 @@ namespace RTC private: void MayRunDtlsTransport(); - /* Private methods to unify UDP and TCP behavior. */ + /* Private methods to unify UDP and TCP behavior. */ private: void onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); void onStunDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); @@ -76,36 +72,53 @@ namespace RTC void onRtpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); void onRtcpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); - /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ + /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ public: - virtual void onPacketRecv(RTC::UdpSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr) override; + virtual void onPacketRecv( + RTC::UdpSocket* socket, + const uint8_t* data, + size_t len, + const struct sockaddr* remoteAddr) override; - /* Pure virtual methods inherited from RTC::TcpServer::Listener. */ + /* Pure virtual methods inherited from RTC::TcpServer::Listener. */ public: - virtual void onRtcTcpConnectionClosed(RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool is_closed_by_peer) override; + virtual void onRtcTcpConnectionClosed( + RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) override; - /* Pure virtual methods inherited from RTC::TcpConnection::Listener. */ + /* Pure virtual methods inherited from RTC::TcpConnection::Listener. */ public: - virtual void onPacketRecv(RTC::TcpConnection *connection, const uint8_t* data, size_t len) override; + virtual void onPacketRecv(RTC::TcpConnection* connection, const uint8_t* data, size_t len) override; - /* Pure virtual methods inherited from RTC::IceServer::Listener. */ + /* Pure virtual methods inherited from RTC::IceServer::Listener. */ public: - virtual void onOutgoingStunMessage(const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) override; - virtual void onIceSelectedTuple(const IceServer* iceServer, RTC::TransportTuple* tuple) override; - virtual void onIceConnected(const IceServer* iceServer) override; - virtual void onIceCompleted(const IceServer* iceServer) override; - virtual void onIceDisconnected(const IceServer* iceServer) override; - - /* Pure virtual methods inherited from RTC::DtlsTransport::Listener. */ + virtual void onOutgoingStunMessage( + const RTC::IceServer* iceServer, + const RTC::StunMessage* msg, + RTC::TransportTuple* tuple) override; + virtual void onIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) override; + virtual void onIceConnected(const RTC::IceServer* iceServer) override; + virtual void onIceCompleted(const RTC::IceServer* iceServer) override; + virtual void onIceDisconnected(const RTC::IceServer* iceServer) override; + + /* Pure virtual methods inherited from RTC::DtlsTransport::Listener. */ public: - virtual void onDtlsConnecting(const DtlsTransport* dtlsTransport) override; - virtual void onDtlsConnected(const DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) override; - virtual void onDtlsFailed(const DtlsTransport* dtlsTransport) override; - virtual void onDtlsClosed(const DtlsTransport* dtlsTransport) override; - virtual void onOutgoingDtlsData(const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; - virtual void onDtlsApplicationData(const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; - - /* Pure virtual methods inherited from RTC::RemoteBitrateEstimator::Listener. */ + virtual void onDtlsConnecting(const RTC::DtlsTransport* dtlsTransport) override; + virtual void onDtlsConnected( + const RTC::DtlsTransport* dtlsTransport, + RTC::SrtpSession::Profile srtpProfile, + uint8_t* srtpLocalKey, + size_t srtpLocalKeyLen, + uint8_t* srtpRemoteKey, + size_t srtpRemoteKeyLen, + std::string& remoteCert) override; + virtual void onDtlsFailed(const RTC::DtlsTransport* dtlsTransport) override; + virtual void onDtlsClosed(const RTC::DtlsTransport* dtlsTransport) override; + virtual void onOutgoingDtlsData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; + virtual void onDtlsApplicationData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; + + /* Pure virtual methods inherited from RTC::RemoteBitrateEstimator::Listener. */ public: virtual void onReceiveBitrateChanged(const std::vector& ssrcs, uint32_t bitrate) override; @@ -115,7 +128,7 @@ namespace RTC private: // Passed by argument. - Listener* listener = nullptr; + Listener* listener = nullptr; Channel::Notifier* notifier = nullptr; // Allocated by this. RTC::IceServer* iceServer = nullptr; @@ -130,50 +143,44 @@ namespace RTC std::vector iceLocalCandidates; RTC::TransportTuple* selectedTuple = nullptr; // Others (DTLS). - bool remoteDtlsParametersGiven = false; + bool remoteDtlsParametersGiven = false; RTC::DtlsTransport::Role dtlsLocalRole = RTC::DtlsTransport::Role::AUTO; // Others (RtpListener). RtpListener rtpListener; // REMB and bitrate stuff. - std::unique_ptr remoteBitrateEstimator; - uint32_t maxBitrate = 0; - uint32_t effectiveMaxBitrate = 0; + std::unique_ptr remoteBitrateEstimator; + uint32_t maxBitrate = 0; + uint32_t effectiveMaxBitrate = 0; uint64_t lastEffectiveMaxBitrateAt = 0; }; /* Inline instance methods. */ - inline - void Transport::AddRtpReceiver(RTC::RtpReceiver* rtpReceiver) + inline void Transport::AddRtpReceiver(RTC::RtpReceiver* rtpReceiver) { this->rtpListener.AddRtpReceiver(rtpReceiver); } - inline - void Transport::RemoveRtpReceiver(const RTC::RtpReceiver* rtpReceiver) + inline void Transport::RemoveRtpReceiver(const RTC::RtpReceiver* rtpReceiver) { this->rtpListener.RemoveRtpReceiver(rtpReceiver); } - inline - RTC::RtpReceiver* Transport::GetRtpReceiver(uint32_t ssrc) + inline RTC::RtpReceiver* Transport::GetRtpReceiver(uint32_t ssrc) { return this->rtpListener.GetRtpReceiver(ssrc); } - inline - bool Transport::IsConnected() const + inline bool Transport::IsConnected() const { return this->dtlsTransport->GetState() == RTC::DtlsTransport::DtlsState::CONNECTED; } - inline - void Transport::EnableRemb() + inline void Transport::EnableRemb() { if (!this->remoteBitrateEstimator) { - this->remoteBitrateEstimator.reset( - new RTC::RemoteBitrateEstimatorAbsSendTime(this)); + this->remoteBitrateEstimator.reset(new RTC::RemoteBitrateEstimatorAbsSendTime(this)); } } } diff --git a/worker/include/RTC/TransportTuple.hpp b/worker/include/RTC/TransportTuple.hpp index 594b5f9d9d..bb24ae6cb1 100644 --- a/worker/include/RTC/TransportTuple.hpp +++ b/worker/include/RTC/TransportTuple.hpp @@ -2,9 +2,9 @@ #define MS_RTC_TRANSPORT_TUPLE_HPP #include "common.hpp" -#include "RTC/UdpSocket.hpp" -#include "RTC/TcpConnection.hpp" #include "Utils.hpp" +#include "RTC/TcpConnection.hpp" +#include "RTC/UdpSocket.hpp" #include namespace RTC @@ -33,7 +33,7 @@ namespace RTC private: // Passed by argument. - RTC::UdpSocket* udpSocket = nullptr; + RTC::UdpSocket* udpSocket = nullptr; struct sockaddr* udpRemoteAddr = nullptr; sockaddr_storage udpRemoteAddrStorage; RTC::TcpConnection* tcpConnection = nullptr; @@ -43,40 +43,39 @@ namespace RTC /* Inline methods. */ - inline - TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) : - udpSocket(udpSocket), - udpRemoteAddr((struct sockaddr*)udpRemoteAddr), - protocol(Protocol::UDP) - {} + inline TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) + : udpSocket(udpSocket) + , udpRemoteAddr((struct sockaddr*)udpRemoteAddr) + , protocol(Protocol::UDP) + { + } - inline - TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection) : - tcpConnection(tcpConnection), - protocol(Protocol::TCP) - {} + inline TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection) + : tcpConnection(tcpConnection) + , protocol(Protocol::TCP) + { + } - inline - void TransportTuple::StoreUdpRemoteAddress() + inline void TransportTuple::StoreUdpRemoteAddress() { // Clone the given address into our address storage and make the sockaddr // pointer point to it. this->udpRemoteAddrStorage = Utils::IP::CopyAddress(udpRemoteAddr); - this->udpRemoteAddr = (struct sockaddr*)&this->udpRemoteAddrStorage; + this->udpRemoteAddr = (struct sockaddr*)&this->udpRemoteAddrStorage; } - inline - TransportTuple::Protocol TransportTuple::GetProtocol() const + inline TransportTuple::Protocol TransportTuple::GetProtocol() const { return this->protocol; } - inline - bool TransportTuple::Compare(const TransportTuple* tuple) const + inline bool TransportTuple::Compare(const TransportTuple* tuple) const { if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP) { - return (this->udpSocket == tuple->udpSocket && Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress())); + return ( + this->udpSocket == tuple->udpSocket && + Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress())); } else if (this->protocol == Protocol::TCP && tuple->GetProtocol() == Protocol::TCP) { @@ -88,8 +87,7 @@ namespace RTC } } - inline - void TransportTuple::Send(const uint8_t* data, size_t len) + inline void TransportTuple::Send(const uint8_t* data, size_t len) { if (this->protocol == Protocol::UDP) this->udpSocket->Send(data, len, this->udpRemoteAddr); @@ -97,8 +95,7 @@ namespace RTC this->tcpConnection->Send(data, len); } - inline - const struct sockaddr* TransportTuple::GetLocalAddress() const + inline const struct sockaddr* TransportTuple::GetLocalAddress() const { if (this->protocol == Protocol::UDP) return this->udpSocket->GetLocalAddress(); @@ -106,8 +103,7 @@ namespace RTC return this->tcpConnection->GetLocalAddress(); } - inline - const struct sockaddr* TransportTuple::GetRemoteAddress() const + inline const struct sockaddr* TransportTuple::GetRemoteAddress() const { if (this->protocol == Protocol::UDP) return (const struct sockaddr*)this->udpRemoteAddr; diff --git a/worker/include/RTC/UdpSocket.hpp b/worker/include/RTC/UdpSocket.hpp index 56f4b57a86..a08eadbd65 100644 --- a/worker/include/RTC/UdpSocket.hpp +++ b/worker/include/RTC/UdpSocket.hpp @@ -3,29 +3,32 @@ #include "common.hpp" #include "handles/UdpSocket.hpp" -#include #include +#include namespace RTC { - class UdpSocket : - public ::UdpSocket + class UdpSocket : public ::UdpSocket { public: class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: - virtual void onPacketRecv(RTC::UdpSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr) = 0; + virtual void onPacketRecv( + RTC::UdpSocket* socket, + const uint8_t* data, + size_t len, + const struct sockaddr* remoteAddr) = 0; }; public: static void ClassInit(); private: - static uv_udp_t* GetRandomPort(int address_family); + static uv_udp_t* GetRandomPort(int addressFamily); private: static struct sockaddr_storage sockaddrStorageIPv4; @@ -36,14 +39,15 @@ namespace RTC static std::unordered_map availableIPv6Ports; public: - UdpSocket(Listener* listener, int address_family); + UdpSocket(Listener* listener, int addressFamily); private: - virtual ~UdpSocket() {}; + virtual ~UdpSocket(){}; - /* Pure virtual methods inherited from ::UdpSocket. */ + /* Pure virtual methods inherited from ::UdpSocket. */ public: - virtual void userOnUdpDatagramRecv(const uint8_t* data, size_t len, const struct sockaddr* addr) override; + virtual void userOnUdpDatagramRecv( + const uint8_t* data, size_t len, const struct sockaddr* addr) override; virtual void userOnUdpSocketClosed() override; private: diff --git a/worker/include/Settings.hpp b/worker/include/Settings.hpp index 7bcbc13bf6..d2e76ec097 100644 --- a/worker/include/Settings.hpp +++ b/worker/include/Settings.hpp @@ -1,5 +1,5 @@ #ifndef MS_SETTINGS_HPP -#define MS_SETTINGS_HPP +#define MS_SETTINGS_HPP #include "common.hpp" #include "LogLevel.hpp" @@ -13,36 +13,35 @@ class Settings public: struct LogTags { - bool info { false }; - bool ice { false }; - bool dtls { false }; - bool rtp { false }; - bool srtp { false }; - bool rtcp { false }; - bool rtx { false }; - bool rbe { false }; - // TODO: Add more tags (here and in Settings.cpp). + bool info{false}; + bool ice{false}; + bool dtls{false}; + bool rtp{false}; + bool srtp{false}; + bool rtcp{false}; + bool rtx{false}; + bool rbe{false}; }; public: // Struct holding the configuration. struct Configuration { - LogLevel logLevel { LogLevel::LOG_DEBUG }; + LogLevel logLevel{LogLevel::LOG_DEBUG}; struct LogTags logTags; - std::string rtcIPv4; - std::string rtcIPv6; - std::string rtcAnnouncedIPv4; - std::string rtcAnnouncedIPv6; - uint16_t rtcMinPort { 10000 }; - uint16_t rtcMaxPort { 59999 }; - std::string dtlsCertificateFile; - std::string dtlsPrivateKeyFile; + std::string rtcIPv4; + std::string rtcIPv6; + std::string rtcAnnouncedIPv4; + std::string rtcAnnouncedIPv6; + uint16_t rtcMinPort{10000}; + uint16_t rtcMaxPort{59999}; + std::string dtlsCertificateFile; + std::string dtlsPrivateKeyFile; // Private fields. - bool hasIPv4 { false }; - bool hasIPv6 { false }; - bool hasAnnouncedIPv4 { false }; - bool hasAnnouncedIPv6 { false }; + bool hasIPv4{false}; + bool hasIPv6{false}; + bool hasAnnouncedIPv4{false}; + bool hasAnnouncedIPv6{false}; }; public: @@ -51,10 +50,10 @@ class Settings static void HandleRequest(Channel::Request* request); private: - static void SetDefaultRtcIP(int requested_family); - static void SetLogLevel(std::string &level); - static void SetRtcIPv4(const std::string &ip); - static void SetRtcIPv6(const std::string &ip); + static void SetDefaultRtcIP(int requestedFamily); + static void SetLogLevel(std::string& level); + static void SetRtcIPv4(const std::string& ip); + static void SetRtcIPv6(const std::string& ip); static void SetRtcPorts(); static void SetDtlsCertificateAndPrivateKeyFiles(); static void SetLogTags(std::vector& tags); diff --git a/worker/include/Utils.hpp b/worker/include/Utils.hpp index 24566f67d9..8be23f9cc9 100644 --- a/worker/include/Utils.hpp +++ b/worker/include/Utils.hpp @@ -1,10 +1,10 @@ #ifndef MS_UTILS_HPP -#define MS_UTILS_HPP +#define MS_UTILS_HPP #include "common.hpp" -#include -#include // std::memcmp(), std::memcpy() #include +#include // std::memcmp(), std::memcpy() +#include #include // gettimeofday namespace Utils @@ -12,27 +12,28 @@ namespace Utils class IP { public: - static int GetFamily(const char *ip, size_t ip_len); - static int GetFamily(const std::string &ip); - static void GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, uint16_t* port); + static int GetFamily(const char* ip, size_t ipLen); + static int GetFamily(const std::string& ip); + static void GetAddressInfo(const struct sockaddr* addr, int* family, std::string& ip, uint16_t* port); static bool CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2); static struct sockaddr_storage CopyAddress(const struct sockaddr* addr); }; /* Inline static methods. */ - inline - int IP::GetFamily(const std::string &ip) + inline int IP::GetFamily(const std::string& ip) { return GetFamily(ip.c_str(), ip.size()); } - inline - bool IP::CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2) + inline bool IP::CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2) { // Compare family. - if (addr1->sa_family != addr2->sa_family || (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6)) + if (addr1->sa_family != addr2->sa_family || + (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6)) + { return false; + } // Compare port. if (((struct sockaddr_in*)addr1)->sin_port != ((struct sockaddr_in*)addr2)->sin_port) @@ -42,12 +43,21 @@ namespace Utils switch (addr1->sa_family) { case AF_INET: - if (std::memcmp(&((struct sockaddr_in*)addr1)->sin_addr, &((struct sockaddr_in*)addr2)->sin_addr, 4) == 0) + if (std::memcmp( + &((struct sockaddr_in*)addr1)->sin_addr, &((struct sockaddr_in*)addr2)->sin_addr, 4) == + 0) + { return true; + } break; case AF_INET6: - if (std::memcmp(&((struct sockaddr_in6*)addr1)->sin6_addr, &((struct sockaddr_in6*)addr2)->sin6_addr, 16) == 0) + if (std::memcmp( + &((struct sockaddr_in6*)addr1)->sin6_addr, + &((struct sockaddr_in6*)addr2)->sin6_addr, + 16) == 0) + { return true; + } break; default: return false; @@ -56,22 +66,21 @@ namespace Utils return false; } - inline - struct sockaddr_storage IP::CopyAddress(const struct sockaddr* addr) + inline struct sockaddr_storage IP::CopyAddress(const struct sockaddr* addr) { - struct sockaddr_storage copied_addr; + struct sockaddr_storage copiedAddr; switch (addr->sa_family) { case AF_INET: - std::memcpy(&copied_addr, addr, sizeof(struct sockaddr_in)); + std::memcpy(&copiedAddr, addr, sizeof(struct sockaddr_in)); break; case AF_INET6: - std::memcpy(&copied_addr, addr, sizeof(struct sockaddr_in6)); + std::memcpy(&copiedAddr, addr, sizeof(struct sockaddr_in6)); break; } - return copied_addr; + return copiedAddr; } class File @@ -103,81 +112,71 @@ namespace Utils /* Inline static methods. */ - inline - uint8_t Byte::Get1Byte(const uint8_t* data, size_t i) + inline uint8_t Byte::Get1Byte(const uint8_t* data, size_t i) { return data[i]; } - inline - uint16_t Byte::Get2Bytes(const uint8_t* data, size_t i) + inline uint16_t Byte::Get2Bytes(const uint8_t* data, size_t i) { - return (uint16_t)(data[i+1]) | ((uint16_t)(data[i]))<<8; + return (uint16_t)(data[i + 1]) | ((uint16_t)(data[i])) << 8; } - inline - uint32_t Byte::Get3Bytes(const uint8_t* data, size_t i) + inline uint32_t Byte::Get3Bytes(const uint8_t* data, size_t i) { - return (uint32_t)(data[i+2]) | ((uint32_t)(data[i+1]))<<8 | ((uint32_t)(data[i]))<<16; + return (uint32_t)(data[i + 2]) | ((uint32_t)(data[i + 1])) << 8 | ((uint32_t)(data[i])) << 16; } - inline - uint32_t Byte::Get4Bytes(const uint8_t* data, size_t i) + inline uint32_t Byte::Get4Bytes(const uint8_t* data, size_t i) { - return (uint32_t)(data[i+3]) | ((uint32_t)(data[i+2]))<<8 | ((uint32_t)(data[i+1]))<<16 | ((uint32_t)(data[i]))<<24; + return (uint32_t)(data[i + 3]) | ((uint32_t)(data[i + 2])) << 8 | + ((uint32_t)(data[i + 1])) << 16 | ((uint32_t)(data[i])) << 24; } - inline - uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i) + inline uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i) { - return ((uint64_t)Byte::Get4Bytes(data,i))<<32 | Byte::Get4Bytes(data,i+4); + return ((uint64_t)Byte::Get4Bytes(data, i)) << 32 | Byte::Get4Bytes(data, i + 4); } - inline - void Byte::Set1Byte(uint8_t* data, size_t i, uint8_t value) + inline void Byte::Set1Byte(uint8_t* data, size_t i, uint8_t value) { data[i] = value; } - inline - void Byte::Set2Bytes(uint8_t* data, size_t i, uint16_t value) + inline void Byte::Set2Bytes(uint8_t* data, size_t i, uint16_t value) { - data[i+1] = (uint8_t)(value); - data[i] = (uint8_t)(value>>8); + data[i + 1] = (uint8_t)(value); + data[i] = (uint8_t)(value >> 8); } - inline - void Byte::Set3Bytes(uint8_t* data, size_t i, uint32_t value) + inline void Byte::Set3Bytes(uint8_t* data, size_t i, uint32_t value) { - data[i+2] = (uint8_t)(value); - data[i+1] = (uint8_t)(value>>8); - data[i] = (uint8_t)(value>>16); + data[i + 2] = (uint8_t)(value); + data[i + 1] = (uint8_t)(value >> 8); + data[i] = (uint8_t)(value >> 16); } - inline - void Byte::Set4Bytes(uint8_t* data, size_t i, uint32_t value) + inline void Byte::Set4Bytes(uint8_t* data, size_t i, uint32_t value) { - data[i+3] = (uint8_t)(value); - data[i+2] = (uint8_t)(value>>8); - data[i+1] = (uint8_t)(value>>16); - data[i] = (uint8_t)(value>>24); + data[i + 3] = (uint8_t)(value); + data[i + 2] = (uint8_t)(value >> 8); + data[i + 1] = (uint8_t)(value >> 16); + data[i] = (uint8_t)(value >> 24); } - inline - void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value) + inline void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value) { - data[i+7] = (uint8_t)(value); - data[i+6] = (uint8_t)(value>>8); - data[i+5] = (uint8_t)(value>>16); - data[i+4] = (uint8_t)(value>>24); - data[i+3] = (uint8_t)(value>>32); - data[i+2] = (uint8_t)(value>>40); - data[i+1] = (uint8_t)(value>>48); - data[i] = (uint8_t)(value>>56); + data[i + 7] = (uint8_t)(value); + data[i + 6] = (uint8_t)(value >> 8); + data[i + 5] = (uint8_t)(value >> 16); + data[i + 4] = (uint8_t)(value >> 24); + data[i + 3] = (uint8_t)(value >> 32); + data[i + 2] = (uint8_t)(value >> 40); + data[i + 1] = (uint8_t)(value >> 48); + data[i] = (uint8_t)(value >> 56); } - inline - uint16_t Byte::PadTo4Bytes(uint16_t size) + inline uint16_t Byte::PadTo4Bytes(uint16_t size) { // If size is not multiple of 32 bits then pad it. if (size & 0x03) @@ -186,8 +185,7 @@ namespace Utils return size; } - inline - uint32_t Byte::PadTo4Bytes(uint32_t size) + inline uint32_t Byte::PadTo4Bytes(uint32_t size) { // If size is not multiple of 32 bits then pad it. if (size & 0x03) @@ -204,7 +202,7 @@ namespace Utils static uint32_t GetRandomUInt(uint32_t min, uint32_t max); static const std::string GetRandomString(size_t len); static uint32_t GetCRC32(const uint8_t* data, size_t size); - static const uint8_t* GetHMAC_SHA1(const std::string &key, const uint8_t* data, size_t len); + static const uint8_t* GetHMAC_SHA1(const std::string& key, const uint8_t* data, size_t len); private: static uint32_t seed; @@ -215,8 +213,7 @@ namespace Utils /* Inline static methods. */ - inline - uint32_t Crypto::GetRandomUInt(uint32_t min, uint32_t max) + inline uint32_t Crypto::GetRandomUInt(uint32_t min, uint32_t max) { // NOTE: This is the original, but produces very small values. // Crypto::seed = (214013 * Crypto::seed) + 2531011; @@ -224,20 +221,15 @@ namespace Utils // This seems to produce better results. Crypto::seed = (uint32_t)((214013 * Crypto::seed) + 2531011); - return (((Crypto::seed>>4)&0x7FFF7FFF) % (max - min + 1)) + min; + return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min; } - inline - const std::string Crypto::GetRandomString(size_t len) + inline const std::string Crypto::GetRandomString(size_t len) { static char buffer[64]; - static const char chars[] = - { - '0','1','2','3','4','5','6','7','8','9', - 'a','b','c','d','e','f','g','h','i','j', - 'k','l','m','n','o','p','q','r','s','t', - 'u','v','w','x','y','z' - }; + static const char chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; if (len > 64) len = 64; @@ -248,10 +240,9 @@ namespace Utils return std::string(buffer, len); } - inline - uint32_t Crypto::GetCRC32(const uint8_t* data, size_t size) + inline uint32_t Crypto::GetCRC32(const uint8_t* data, size_t size) { - uint32_t crc = 0xFFFFFFFF; + uint32_t crc = 0xFFFFFFFF; const uint8_t* p = data; while (size--) @@ -266,8 +257,7 @@ namespace Utils static void ToLowerCase(std::string& str); }; - inline - void String::ToLowerCase(std::string& str) + inline void String::ToLowerCase(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), ::tolower); } @@ -277,7 +267,7 @@ namespace Utils // Seconds from Jan 1, 1900 to Jan 1, 1970. static constexpr uint32_t UnixNtpOffset = 0x83AA7E80; // NTP fractional unit. - static constexpr double NtpFractionalUnit = 1LL<<32; + static constexpr double NtpFractionalUnit = 1LL << 32; public: struct Ntp @@ -287,36 +277,34 @@ namespace Utils }; static void CurrentTimeNtp(Ntp& ntp); - static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prev_timestamp); + static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp); static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2); }; - inline - void Time::CurrentTimeNtp(Ntp& ntp) + inline void Time::CurrentTimeNtp(Ntp& ntp) { struct timeval tv; + gettimeofday(&tv, nullptr); - ntp.seconds = tv.tv_sec + UnixNtpOffset; + ntp.seconds = tv.tv_sec + UnixNtpOffset; ntp.fractions = (uint32_t)((double)(tv.tv_usec) * NtpFractionalUnit * 1.0e-6); } - inline - bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prev_timestamp) + inline bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp) { // Distinguish between elements that are exactly 0x80000000 apart. // If t1>t2 and |t1-t2| = 0x80000000: IsNewer(t1,t2)=true, // IsNewer(t2,t1)=false // rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false. - if (static_cast(timestamp - prev_timestamp) == 0x80000000) { - return timestamp > prev_timestamp; - } - return timestamp != prev_timestamp && - static_cast(timestamp - prev_timestamp) < 0x80000000; + if (static_cast(timestamp - prevTimestamp) == 0x80000000) + return timestamp > prevTimestamp; + + return timestamp != prevTimestamp && + static_cast(timestamp - prevTimestamp) < 0x80000000; } - inline - uint32_t Time::LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2) + inline uint32_t Time::LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2) { return IsNewerTimestamp(timestamp1, timestamp2) ? timestamp1 : timestamp2; } diff --git a/worker/include/common.hpp b/worker/include/common.hpp index 984b944fa6..d106f9962c 100644 --- a/worker/include/common.hpp +++ b/worker/include/common.hpp @@ -1,16 +1,13 @@ #ifndef MS_COMMON_HPP #define MS_COMMON_HPP -#include // std::addressof() -#include // std::transform(), std::find(), std::min(), std::max() -#include // size_t -#include // uint8_t, etc -#include // PRIu64, etc -#include // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6 +#include // std::transform(), std::find(), std::min(), std::max() +#include // htonl(), htons(), ntohl(), ntohs() +#include // PRIu64, etc +#include // size_t +#include // uint8_t, etc +#include // std::addressof() #include // sockaddr_in, sockaddr_in6 -#include // htonl(), htons(), ntohl(), ntohs() - -#define MS_APP_NAME "mediasoup" -#define MS_PROCESS_NAME "mediasoup-worker" +#include // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6 #endif diff --git a/worker/include/handles/SignalsHandler.hpp b/worker/include/handles/SignalsHandler.hpp index 07efff369d..929d03ed9e 100644 --- a/worker/include/handles/SignalsHandler.hpp +++ b/worker/include/handles/SignalsHandler.hpp @@ -1,9 +1,9 @@ #ifndef MS_SIGNALS_HANDLER_HPP -#define MS_SIGNALS_HANDLER_HPP +#define MS_SIGNALS_HANDLER_HPP -#include -#include #include +#include +#include class SignalsHandler { @@ -11,7 +11,7 @@ class SignalsHandler class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: virtual void onSignal(SignalsHandler* signalsHandler, int signum) = 0; @@ -21,13 +21,13 @@ class SignalsHandler explicit SignalsHandler(Listener* listener); private: - ~SignalsHandler() {}; + ~SignalsHandler(){}; public: void Destroy(); void AddSignal(int signum, std::string name); -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: void onUvSignal(int signum); diff --git a/worker/include/handles/TcpConnection.hpp b/worker/include/handles/TcpConnection.hpp index bcc555fb7f..09e18408d7 100644 --- a/worker/include/handles/TcpConnection.hpp +++ b/worker/include/handles/TcpConnection.hpp @@ -2,8 +2,8 @@ #define MS_TCP_CONNECTION_HPP #include "common.hpp" -#include #include +#include // Avoid cyclic #include problem by declaring classes instead of including // the corresponding header files. @@ -15,10 +15,10 @@ class TcpConnection class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: - virtual void onTcpConnectionClosed(TcpConnection* connection, bool is_closed_by_peer) = 0; + virtual void onTcpConnectionClosed(TcpConnection* connection, bool isClosedByPeer) = 0; }; public: @@ -26,17 +26,17 @@ class TcpConnection struct UvWriteData { TcpConnection* connection; - uv_write_t req; - uint8_t store[1]; + uv_write_t req; + uint8_t store[1]; }; -// Let the TcpServer class directly call the destructor of TcpConnection. -friend class TcpServer; + // Let the TcpServer class directly call the destructor of TcpConnection. + friend class TcpServer; public: explicit TcpConnection(size_t bufferSize); TcpConnection& operator=(const TcpConnection&) = delete; - TcpConnection(const TcpConnection&) = delete; + TcpConnection(const TcpConnection&) = delete; protected: virtual ~TcpConnection(); @@ -44,13 +44,17 @@ friend class TcpServer; public: void Destroy(); virtual void Dump() const; - void Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort); + void Setup( + Listener* listener, + struct sockaddr_storage* localAddr, + const std::string& localIP, + uint16_t localPort); bool IsClosing() const; uv_tcp_t* GetUvHandle() const; void Start(); void Write(const uint8_t* data, size_t len); void Write(const uint8_t* data1, size_t len1, const uint8_t* data2, size_t len2); - void Write(const std::string &data); + void Write(const std::string& data); const struct sockaddr* GetLocalAddress() const; int GetLocalFamily() const; const std::string& GetLocalIP() const; @@ -62,15 +66,15 @@ friend class TcpServer; private: bool SetPeerAddress(); -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: - void onUvReadAlloc(size_t suggested_size, uv_buf_t* buf); + void onUvReadAlloc(size_t suggestedSize, uv_buf_t* buf); void onUvRead(ssize_t nread, const uv_buf_t* buf); void onUvWriteError(int error); void onUvShutdown(uv_shutdown_t* req, int status); void onUvClosed(); -/* Pure virtual methods that must be implemented by the subclass. */ + /* Pure virtual methods that must be implemented by the subclass. */ protected: virtual void userOnTcpConnectionRead() = 0; @@ -81,9 +85,9 @@ friend class TcpServer; uv_tcp_t* uvHandle = nullptr; // Others. struct sockaddr_storage* localAddr = nullptr; - bool isClosing = false; - bool isClosedByPeer = false; - bool hasError = false; + bool isClosing = false; + bool isClosedByPeer = false; + bool hasError = false; protected: // Passed by argument. @@ -101,62 +105,52 @@ friend class TcpServer; /* Inline methods. */ -inline -bool TcpConnection::IsClosing() const +inline bool TcpConnection::IsClosing() const { return this->isClosing; } -inline -uv_tcp_t* TcpConnection::GetUvHandle() const +inline uv_tcp_t* TcpConnection::GetUvHandle() const { return this->uvHandle; } -inline -void TcpConnection::Write(const std::string &data) +inline void TcpConnection::Write(const std::string& data) { Write((const uint8_t*)data.c_str(), data.size()); } -inline -const struct sockaddr* TcpConnection::GetLocalAddress() const +inline const struct sockaddr* TcpConnection::GetLocalAddress() const { return (const struct sockaddr*)this->localAddr; } -inline -int TcpConnection::GetLocalFamily() const +inline int TcpConnection::GetLocalFamily() const { return ((const struct sockaddr*)&this->localAddr)->sa_family; } -inline -const std::string& TcpConnection::GetLocalIP() const +inline const std::string& TcpConnection::GetLocalIP() const { return this->localIP; } -inline -uint16_t TcpConnection::GetLocalPort() const +inline uint16_t TcpConnection::GetLocalPort() const { return this->localPort; } -inline -const struct sockaddr* TcpConnection::GetPeerAddress() const +inline const struct sockaddr* TcpConnection::GetPeerAddress() const { return (const struct sockaddr*)&this->peerAddr; } -inline -const std::string& TcpConnection::GetPeerIP() const +inline const std::string& TcpConnection::GetPeerIP() const { return this->peerIP; } -inline -uint16_t TcpConnection::GetPeerPort() const +inline uint16_t TcpConnection::GetPeerPort() const { return this->peerPort; } diff --git a/worker/include/handles/TcpServer.hpp b/worker/include/handles/TcpServer.hpp index 578d2a5863..6f42a3e063 100644 --- a/worker/include/handles/TcpServer.hpp +++ b/worker/include/handles/TcpServer.hpp @@ -3,14 +3,14 @@ #include "common.hpp" #include "handles/TcpConnection.hpp" +#include #include #include -#include class TcpServer : public TcpConnection::Listener { public: - TcpServer(const std::string &ip, uint16_t port, int backlog); + TcpServer(const std::string& ip, uint16_t port, int backlog); /** * uvHandle must be an already initialized and binded uv_tcp_t pointer. */ @@ -32,21 +32,21 @@ class TcpServer : public TcpConnection::Listener private: bool SetLocalAddress(); -/* Pure virtual methods that must be implemented by the subclass. */ + /* Pure virtual methods that must be implemented by the subclass. */ protected: - virtual void userOnTcpConnectionAlloc(TcpConnection** connection) = 0; - virtual void userOnNewTcpConnection(TcpConnection* connection) = 0; - virtual void userOnTcpConnectionClosed(TcpConnection* connection, bool is_closed_by_peer) = 0; - virtual void userOnTcpServerClosed() = 0; + virtual void userOnTcpConnectionAlloc(TcpConnection** connection) = 0; + virtual void userOnNewTcpConnection(TcpConnection* connection) = 0; + virtual void userOnTcpConnectionClosed(TcpConnection* connection, bool isClosedByPeer) = 0; + virtual void userOnTcpServerClosed() = 0; -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: void onUvConnection(int status); void onUvClosed(); -/* Methods inherited from TcpConnection::Listener. */ + /* Methods inherited from TcpConnection::Listener. */ public: - virtual void onTcpConnectionClosed(TcpConnection* connection, bool is_closed_by_peer); + virtual void onTcpConnectionClosed(TcpConnection* connection, bool isClosedByPeer); private: // Allocated by this (may be passed by argument). @@ -63,41 +63,34 @@ class TcpServer : public TcpConnection::Listener /* Inline methods. */ -inline -bool TcpServer::IsClosing() const +inline bool TcpServer::IsClosing() const { return this->isClosing; } -inline -size_t TcpServer::GetNumConnections() const +inline size_t TcpServer::GetNumConnections() const { return this->connections.size(); } -inline -const struct sockaddr* TcpServer::GetLocalAddress() const +inline const struct sockaddr* TcpServer::GetLocalAddress() const { return (const struct sockaddr*)&this->localAddr; } -inline -int TcpServer::GetLocalFamily() const +inline int TcpServer::GetLocalFamily() const { return ((const struct sockaddr*)&this->localAddr)->sa_family; } -inline -const std::string& TcpServer::GetLocalIP() const +inline const std::string& TcpServer::GetLocalIP() const { return this->localIP; } -inline -uint16_t TcpServer::GetLocalPort() const +inline uint16_t TcpServer::GetLocalPort() const { return this->localPort; } - #endif diff --git a/worker/include/handles/Timer.hpp b/worker/include/handles/Timer.hpp index a5009e724d..d2b6d9327b 100644 --- a/worker/include/handles/Timer.hpp +++ b/worker/include/handles/Timer.hpp @@ -1,5 +1,5 @@ #ifndef MS_TIMER_HPP -#define MS_TIMER_HPP +#define MS_TIMER_HPP #include "common.hpp" #include @@ -10,7 +10,7 @@ class Timer class Listener { public: - virtual ~Listener() {}; + virtual ~Listener(){}; public: virtual void onTimer(Timer* timer) = 0; @@ -19,17 +19,17 @@ class Timer public: explicit Timer(Listener* listener); Timer& operator=(const Timer&) = delete; - Timer(const Timer&) = delete; + Timer(const Timer&) = delete; private: - ~Timer() {}; + ~Timer(){}; public: void Destroy(); void Start(uint64_t timeout); void Stop(); -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: void onUvTimer(); diff --git a/worker/include/handles/UdpSocket.hpp b/worker/include/handles/UdpSocket.hpp index feb0c2316f..8b6d360125 100644 --- a/worker/include/handles/UdpSocket.hpp +++ b/worker/include/handles/UdpSocket.hpp @@ -2,8 +2,8 @@ #define MS_UDP_SOCKET_HPP #include "common.hpp" -#include #include +#include class UdpSocket { @@ -11,22 +11,19 @@ class UdpSocket /* Struct for the data field of uv_req_t when sending a datagram. */ struct UvSendData { - UdpSocket* socket; + UdpSocket* socket; uv_udp_send_t req; - uint8_t store[1]; + uint8_t store[1]; }; -private: - static uint8_t readBuffer[]; - public: - UdpSocket(const std::string &ip, uint16_t port); + UdpSocket(const std::string& ip, uint16_t port); /** * uvHandle must be an already initialized and binded uv_udp_t pointer. */ explicit UdpSocket(uv_udp_t* uvHandle); UdpSocket& operator=(const UdpSocket&) = delete; - UdpSocket(const UdpSocket&) = delete; + UdpSocket(const UdpSocket&) = delete; protected: virtual ~UdpSocket(); @@ -35,9 +32,9 @@ class UdpSocket void Destroy(); virtual void Dump() const; void Send(const uint8_t* data, size_t len, const struct sockaddr* addr); - void Send(const std::string &data, const struct sockaddr* addr); - void Send(const uint8_t* data, size_t len, const std::string &ip, uint16_t port); - void Send(const std::string &data, const std::string &ip, uint16_t port); + void Send(const std::string& data, const struct sockaddr* addr); + void Send(const uint8_t* data, size_t len, const std::string& ip, uint16_t port); + void Send(const std::string& data, const std::string& ip, uint16_t port); const struct sockaddr* GetLocalAddress() const; int GetLocalFamily() const; const std::string& GetLocalIP() const; @@ -46,14 +43,14 @@ class UdpSocket private: bool SetLocalAddress(); -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: - void onUvRecvAlloc(size_t suggested_size, uv_buf_t* buf); + void onUvRecvAlloc(size_t suggestedSize, uv_buf_t* buf); void onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags); void onUvSendError(int error); void onUvClosed(); -/* Pure virtual methods that must be implemented by the subclass. */ + /* Pure virtual methods that must be implemented by the subclass. */ protected: virtual void userOnUdpDatagramRecv(const uint8_t* data, size_t len, const struct sockaddr* addr) = 0; virtual void userOnUdpSocketClosed() = 0; @@ -72,38 +69,32 @@ class UdpSocket /* Inline methods. */ -inline -void UdpSocket::Send(const std::string &data, const struct sockaddr* addr) +inline void UdpSocket::Send(const std::string& data, const struct sockaddr* addr) { Send((const uint8_t*)data.c_str(), data.size(), addr); } -inline -void UdpSocket::Send(const std::string &data, const std::string &ip, uint16_t port) +inline void UdpSocket::Send(const std::string& data, const std::string& ip, uint16_t port) { Send((const uint8_t*)data.c_str(), data.size(), ip, port); } -inline -const struct sockaddr* UdpSocket::GetLocalAddress() const +inline const struct sockaddr* UdpSocket::GetLocalAddress() const { return (const struct sockaddr*)&this->localAddr; } -inline -int UdpSocket::GetLocalFamily() const +inline int UdpSocket::GetLocalFamily() const { return ((const struct sockaddr*)&this->localAddr)->sa_family; } -inline -const std::string& UdpSocket::GetLocalIP() const +inline const std::string& UdpSocket::GetLocalIP() const { return this->localIP; } -inline -uint16_t UdpSocket::GetLocalPort() const +inline uint16_t UdpSocket::GetLocalPort() const { return this->localPort; } diff --git a/worker/include/handles/UnixStreamSocket.hpp b/worker/include/handles/UnixStreamSocket.hpp index 6cd03d820c..cf8e271d1c 100644 --- a/worker/include/handles/UnixStreamSocket.hpp +++ b/worker/include/handles/UnixStreamSocket.hpp @@ -2,8 +2,8 @@ #define MS_UNIX_STREAM_SOCKET_HPP #include "common.hpp" -#include #include +#include class UnixStreamSocket { @@ -12,14 +12,14 @@ class UnixStreamSocket struct UvWriteData { UnixStreamSocket* socket; - uv_write_t req; - uint8_t store[1]; + uv_write_t req; + uint8_t store[1]; }; public: UnixStreamSocket(int fd, size_t bufferSize); UnixStreamSocket& operator=(const UnixStreamSocket&) = delete; - UnixStreamSocket(const UnixStreamSocket&) = delete; + UnixStreamSocket(const UnixStreamSocket&) = delete; protected: virtual ~UnixStreamSocket(); @@ -28,9 +28,9 @@ class UnixStreamSocket void Destroy(); bool IsClosing() const; void Write(const uint8_t* data, size_t len); - void Write(const std::string &data); + void Write(const std::string& data); -/* Callbacks fired by UV events. */ + /* Callbacks fired by UV events. */ public: void onUvReadAlloc(size_t suggested_size, uv_buf_t* buf); void onUvRead(ssize_t nread, const uv_buf_t* buf); @@ -38,18 +38,18 @@ class UnixStreamSocket void onUvShutdown(uv_shutdown_t* req, int status); void onUvClosed(); -/* Pure virtual methods that must be implemented by the subclass. */ + /* Pure virtual methods that must be implemented by the subclass. */ protected: - virtual void userOnUnixStreamRead() = 0; - virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) = 0; + virtual void userOnUnixStreamRead() = 0; + virtual void userOnUnixStreamSocketClosed(bool isClosedByPeer) = 0; private: // Allocated by this. uv_pipe_t* uvHandle = nullptr; // Others. - bool isClosing = false; + bool isClosing = false; bool isClosedByPeer = false; - bool hasError = false; + bool hasError = false; protected: // Passed by argument. @@ -62,14 +62,12 @@ class UnixStreamSocket /* Inline methods. */ -inline -bool UnixStreamSocket::IsClosing() const +inline bool UnixStreamSocket::IsClosing() const { return this->isClosing; } -inline -void UnixStreamSocket::Write(const std::string &data) +inline void UnixStreamSocket::Write(const std::string& data) { Write((const uint8_t*)data.c_str(), data.size()); } diff --git a/worker/src/Channel/Notifier.cpp b/worker/src/Channel/Notifier.cpp index 0a72c6762f..258750f631 100644 --- a/worker/src/Channel/Notifier.cpp +++ b/worker/src/Channel/Notifier.cpp @@ -8,8 +8,8 @@ namespace Channel { /* Instance methods. */ - Notifier::Notifier(Channel::UnixStreamSocket* channel) : - channel(channel) + Notifier::Notifier(Channel::UnixStreamSocket* channel) + : channel(channel) { MS_TRACE(); } @@ -24,12 +24,12 @@ namespace Channel Json::Value json(Json::objectValue); json[k_targetId] = (Json::UInt)targetId; - json[k_event] = event; + json[k_event] = event; this->channel->Send(json); } - void Notifier::Emit(uint32_t targetId, std::string event, Json::Value &data) + void Notifier::Emit(uint32_t targetId, std::string event, Json::Value& data) { MS_TRACE(); @@ -40,13 +40,14 @@ namespace Channel Json::Value json(Json::objectValue); json[k_targetId] = (Json::UInt)targetId; - json[k_event] = event; - json[k_data] = data; + json[k_event] = event; + json[k_data] = data; this->channel->Send(json); } - void Notifier::EmitWithBinary(uint32_t targetId, std::string event, Json::Value& data, const uint8_t* binary_data, size_t binary_len) + void Notifier::EmitWithBinary( + uint32_t targetId, std::string event, Json::Value& data, const uint8_t* binaryData, size_t binaryLen) { MS_TRACE(); @@ -58,11 +59,11 @@ namespace Channel Json::Value json(Json::objectValue); json[k_targetId] = (Json::UInt)targetId; - json[k_event] = event; - json[k_data] = data; - json[k_binary] = true; + json[k_event] = event; + json[k_data] = data; + json[k_binary] = true; this->channel->Send(json); - this->channel->SendBinary(binary_data, binary_len); + this->channel->SendBinary(binaryData, binaryLen); } } diff --git a/worker/src/Channel/Request.cpp b/worker/src/Channel/Request.cpp index 8a4a79c999..ef9edbb069 100644 --- a/worker/src/Channel/Request.cpp +++ b/worker/src/Channel/Request.cpp @@ -2,13 +2,14 @@ // #define MS_LOG_DEV #include "Channel/Request.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" namespace Channel { /* Class variables. */ + // clang-format off std::unordered_map Request::string2MethodId = { { "worker.dump", Request::MethodId::worker_dump }, @@ -35,11 +36,12 @@ namespace Channel { "rtpSender.setTransport", Request::MethodId::rtpSender_setTransport }, { "rtpSender.disable", Request::MethodId::rtpSender_disable } }; + // clang-format on /* Instance methods. */ - Request::Request(Channel::UnixStreamSocket* channel, Json::Value& json) : - channel(channel) + Request::Request(Channel::UnixStreamSocket* channel, Json::Value& json) + : channel(channel) { MS_TRACE(); @@ -91,32 +93,33 @@ namespace Channel { MS_TRACE(); - static Json::Value empty_data(Json::objectValue); + static Json::Value EmptyData(Json::objectValue); - Accept(empty_data); + Accept(EmptyData); } - void Request::Accept(Json::Value &data) + void Request::Accept(Json::Value& data) { MS_TRACE(); - static Json::Value empty_data(Json::objectValue); + static Json::Value EmptyData(Json::objectValue); static const Json::StaticString k_id("id"); static const Json::StaticString k_accepted("accepted"); static const Json::StaticString k_data("data"); MS_ASSERT(this->replied == false, "Request already replied"); + this->replied = true; Json::Value json(Json::objectValue); - json[k_id] = (Json::UInt)this->id; + json[k_id] = (Json::UInt)this->id; json[k_accepted] = true; if (data.isObject()) json[k_data] = data; else - json[k_data] = empty_data; + json[k_data] = EmptyData; this->channel->Send(json); } @@ -141,11 +144,12 @@ namespace Channel static const Json::StaticString k_reason("reason"); MS_ASSERT(this->replied == false, "Request already replied"); + this->replied = true; Json::Value json(Json::objectValue); - json[k_id] = (Json::UInt)this->id; + json[k_id] = (Json::UInt)this->id; json[k_rejected] = true; if (reason) diff --git a/worker/src/Channel/UnixStreamSocket.cpp b/worker/src/Channel/UnixStreamSocket.cpp index 7750ec537b..9864e209f3 100644 --- a/worker/src/Channel/UnixStreamSocket.cpp +++ b/worker/src/Channel/UnixStreamSocket.cpp @@ -4,29 +4,27 @@ #include "Channel/UnixStreamSocket.hpp" #include "Logger.hpp" #include "MediaSoupError.hpp" -#include // std::ostringstream +#include // std::ceil() +#include // sprintf() #include // std::memmove() -#include // std::ceil() -#include // sprintf() -extern "C" -{ - #include +#include // std::ostringstream +extern "C" { +#include } -// netstring length for a 65536 bytes payload -#define NS_MAX_SIZE 65543 -#define MESSAGE_MAX_SIZE 65536 - namespace Channel { - /* Class variables. */ + /* Static. */ - uint8_t UnixStreamSocket::writeBuffer[NS_MAX_SIZE]; + // netstring length for a 65536 bytes payload. + static constexpr size_t MaxSize = 65543; + static constexpr size_t MessageMaxSize = 65536; + static uint8_t WriteBuffer[MaxSize]; /* Instance methods. */ - UnixStreamSocket::UnixStreamSocket(int fd) : - ::UnixStreamSocket::UnixStreamSocket(fd, NS_MAX_SIZE) + UnixStreamSocket::UnixStreamSocket(int fd) + : ::UnixStreamSocket::UnixStreamSocket(fd, MaxSize) { MS_TRACE_STD(); @@ -34,11 +32,11 @@ namespace Channel { Json::CharReaderBuilder builder; Json::Value settings = Json::nullValue; - Json::Value invalid_settings; + Json::Value invalidSettings; builder.strictMode(&settings); - MS_ASSERT(builder.validate(&invalid_settings), "invalid Json::CharReaderBuilder"); + MS_ASSERT(builder.validate(&invalidSettings), "invalid Json::CharReaderBuilder"); this->jsonReader = builder.newCharReader(); } @@ -46,14 +44,14 @@ namespace Channel // Create the JSON writer. { Json::StreamWriterBuilder builder; - Json::Value invalid_settings; + Json::Value invalidSettings; - builder["commentStyle"] = "None"; - builder["indentation"] = ""; + builder["commentStyle"] = "None"; + builder["indentation"] = ""; builder["enableYAMLCompatibility"] = false; - builder["dropNullPlaceholders"] = false; + builder["dropNullPlaceholders"] = false; - MS_ASSERT(builder.validate(&invalid_settings), "invalid Json::StreamWriterBuilder"); + MS_ASSERT(builder.validate(&invalidSettings), "invalid Json::StreamWriterBuilder"); this->jsonWriter = builder.newStreamWriter(); } @@ -74,7 +72,7 @@ namespace Channel this->listener = listener; } - void UnixStreamSocket::Send(Json::Value &msg) + void UnixStreamSocket::Send(Json::Value& msg) { if (this->closed) return; @@ -82,112 +80,112 @@ namespace Channel // MS_TRACE_STD(); std::ostringstream stream; - std::string ns_payload; - size_t ns_payload_len; - size_t ns_num_len; - size_t ns_len; + std::string nsPayload; + size_t nsPayloadLen; + size_t nsNumLen; + size_t nsLen; this->jsonWriter->write(msg, &stream); - ns_payload = stream.str(); - ns_payload_len = ns_payload.length(); + nsPayload = stream.str(); + nsPayloadLen = nsPayload.length(); - if (ns_payload_len > MESSAGE_MAX_SIZE) + if (nsPayloadLen > MessageMaxSize) { MS_ERROR_STD("mesage too big"); return; } - if (ns_payload_len == 0) + if (nsPayloadLen == 0) { - ns_num_len = 1; - UnixStreamSocket::writeBuffer[0] = '0'; - UnixStreamSocket::writeBuffer[1] = ':'; - UnixStreamSocket::writeBuffer[2] = ','; + nsNumLen = 1; + WriteBuffer[0] = '0'; + WriteBuffer[1] = ':'; + WriteBuffer[2] = ','; } else { - ns_num_len = (size_t)std::ceil(std::log10((double)ns_payload_len + 1)); - std::sprintf((char*)UnixStreamSocket::writeBuffer, "%zu:", ns_payload_len); - std::memcpy(UnixStreamSocket::writeBuffer + ns_num_len + 1, ns_payload.c_str(), ns_payload_len); - UnixStreamSocket::writeBuffer[ns_num_len + ns_payload_len + 1] = ','; + nsNumLen = (size_t)std::ceil(std::log10((double)nsPayloadLen + 1)); + std::sprintf((char*)WriteBuffer, "%zu:", nsPayloadLen); + std::memcpy(WriteBuffer + nsNumLen + 1, nsPayload.c_str(), nsPayloadLen); + WriteBuffer[nsNumLen + nsPayloadLen + 1] = ','; } - ns_len = ns_num_len + ns_payload_len + 2; + nsLen = nsNumLen + nsPayloadLen + 2; - Write(UnixStreamSocket::writeBuffer, ns_len); + Write(WriteBuffer, nsLen); } - void UnixStreamSocket::SendLog(char* ns_payload, size_t ns_payload_len) + void UnixStreamSocket::SendLog(char* nsPayload, size_t nsPayloadLen) { if (this->closed) return; // MS_TRACE_STD(); - size_t ns_num_len; - size_t ns_len; + size_t nsNumLen; + size_t nsLen; - if (ns_payload_len > MESSAGE_MAX_SIZE) + if (nsPayloadLen > MessageMaxSize) { MS_ERROR_STD("mesage too big"); return; } - if (ns_payload_len == 0) + if (nsPayloadLen == 0) { - ns_num_len = 1; - UnixStreamSocket::writeBuffer[0] = '0'; - UnixStreamSocket::writeBuffer[1] = ':'; - UnixStreamSocket::writeBuffer[2] = ','; + nsNumLen = 1; + WriteBuffer[0] = '0'; + WriteBuffer[1] = ':'; + WriteBuffer[2] = ','; } else { - ns_num_len = (size_t)std::ceil(std::log10((double)ns_payload_len + 1)); - std::sprintf((char*)UnixStreamSocket::writeBuffer, "%zu:", ns_payload_len); - std::memcpy(UnixStreamSocket::writeBuffer + ns_num_len + 1, ns_payload, ns_payload_len); - UnixStreamSocket::writeBuffer[ns_num_len + ns_payload_len + 1] = ','; + nsNumLen = (size_t)std::ceil(std::log10((double)nsPayloadLen + 1)); + std::sprintf((char*)WriteBuffer, "%zu:", nsPayloadLen); + std::memcpy(WriteBuffer + nsNumLen + 1, nsPayload, nsPayloadLen); + WriteBuffer[nsNumLen + nsPayloadLen + 1] = ','; } - ns_len = ns_num_len + ns_payload_len + 2; + nsLen = nsNumLen + nsPayloadLen + 2; - Write(UnixStreamSocket::writeBuffer, ns_len); + Write(WriteBuffer, nsLen); } - void UnixStreamSocket::SendBinary(const uint8_t* ns_payload, size_t ns_payload_len) + void UnixStreamSocket::SendBinary(const uint8_t* nsPayload, size_t nsPayloadLen) { if (this->closed) return; - size_t ns_num_len; - size_t ns_len; + size_t nsNumLen; + size_t nsLen; - if (ns_payload_len > MESSAGE_MAX_SIZE) + if (nsPayloadLen > MessageMaxSize) { MS_ERROR_STD("mesage too big"); return; } - if (ns_payload_len == 0) + if (nsPayloadLen == 0) { - ns_num_len = 1; - UnixStreamSocket::writeBuffer[0] = '0'; - UnixStreamSocket::writeBuffer[1] = ':'; - UnixStreamSocket::writeBuffer[2] = ','; + nsNumLen = 1; + WriteBuffer[0] = '0'; + WriteBuffer[1] = ':'; + WriteBuffer[2] = ','; } else { - ns_num_len = (size_t)std::ceil(std::log10((double)ns_payload_len + 1)); - std::sprintf((char*)UnixStreamSocket::writeBuffer, "%zu:", ns_payload_len); - std::memcpy(UnixStreamSocket::writeBuffer + ns_num_len + 1, ns_payload, ns_payload_len); - UnixStreamSocket::writeBuffer[ns_num_len + ns_payload_len + 1] = ','; + nsNumLen = (size_t)std::ceil(std::log10((double)nsPayloadLen + 1)); + std::sprintf((char*)WriteBuffer, "%zu:", nsPayloadLen); + std::memcpy(WriteBuffer + nsNumLen + 1, nsPayload, nsPayloadLen); + WriteBuffer[nsNumLen + nsPayloadLen + 1] = ','; } - ns_len = ns_num_len + ns_payload_len + 2; + nsLen = nsNumLen + nsPayloadLen + 2; - Write(UnixStreamSocket::writeBuffer, ns_len); + Write(WriteBuffer, nsLen); } void UnixStreamSocket::userOnUnixStreamRead() @@ -200,15 +198,15 @@ namespace Channel if (IsClosing()) return; - size_t read_len = this->bufferDataLen - this->msgStart; - char* json_start = nullptr; - size_t json_len; - int ns_ret = netstring_read((char*)(this->buffer + this->msgStart), read_len, - &json_start, &json_len); + size_t readLen = this->bufferDataLen - this->msgStart; + char* jsonStart = nullptr; + size_t jsonLen; + int nsRet = + netstring_read((char*)(this->buffer + this->msgStart), readLen, &jsonStart, &jsonLen); - if (ns_ret != 0) + if (nsRet != 0) { - switch (ns_ret) + switch (nsRet) { case NETSTRING_ERROR_TOO_SHORT: // Check if the buffer is full. @@ -218,17 +216,19 @@ namespace Channel // the buffer, so move the incomplete message to the position 0. if (this->msgStart != 0) { - std::memmove(this->buffer, this->buffer + this->msgStart, read_len); - this->msgStart = 0; - this->bufferDataLen = read_len; + std::memmove(this->buffer, this->buffer + this->msgStart, readLen); + this->msgStart = 0; + this->bufferDataLen = readLen; } // Second case: the incomplete message begins at position 0 of the buffer. // The message is too big, so discard it. else { - MS_ERROR_STD("no more space in the buffer for the unfinished message being parsed, discarding it"); + MS_ERROR_STD( + "no more space in the buffer for the unfinished message being parsed, " + "discarding it"); - this->msgStart = 0; + this->msgStart = 0; this->bufferDataLen = 0; } } @@ -259,20 +259,21 @@ namespace Channel } // Error, so reset and exit the parsing loop. - this->msgStart = 0; + this->msgStart = 0; this->bufferDataLen = 0; return; } - // If here it means that json_start points to the beginning of a JSON string - // with json_len bytes length, so recalculate read_len. - read_len = (const uint8_t*)json_start - (this->buffer + this->msgStart) + json_len + 1; + // If here it means that jsonStart points to the beginning of a JSON string + // with jsonLen bytes length, so recalculate readLen. + readLen = (const uint8_t*)jsonStart - (this->buffer + this->msgStart) + jsonLen + 1; Json::Value json; - std::string json_parse_error; + std::string jsonParseError; - if (this->jsonReader->parse((const char*)json_start, (const char*)json_start + json_len, &json, &json_parse_error)) + if (this->jsonReader->parse( + (const char*)jsonStart, (const char*)jsonStart + jsonLen, &json, &jsonParseError)) { Channel::Request* request = nullptr; @@ -280,7 +281,7 @@ namespace Channel { request = new Channel::Request(this, json); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR_STD("discarding wrong Channel request"); } @@ -296,21 +297,21 @@ namespace Channel } else { - MS_ERROR_STD("JSON parsing error: %s", json_parse_error.c_str()); + MS_ERROR_STD("JSON parsing error: %s", jsonParseError.c_str()); } // If there is no more space available in the buffer and that is because // the latest parsed message filled it, then empty the full buffer. - if ((this->msgStart + read_len) == this->bufferSize) + if ((this->msgStart + readLen) == this->bufferSize) { - this->msgStart = 0; + this->msgStart = 0; this->bufferDataLen = 0; } // If there is still space in the buffer, set the beginning of the next // parsing to the next position after the parsed message. else { - this->msgStart += read_len; + this->msgStart += readLen; } // If there is more data in the buffer after the parsed message @@ -326,13 +327,13 @@ namespace Channel } } - void UnixStreamSocket::userOnUnixStreamSocketClosed(bool is_closed_by_peer) + void UnixStreamSocket::userOnUnixStreamSocketClosed(bool isClosedByPeer) { MS_TRACE_STD(); this->closed = true; - if (is_closed_by_peer) + if (isClosedByPeer) { // Notify the listener. this->listener->onChannelUnixStreamSocketRemotelyClosed(this); diff --git a/worker/src/DepLibSRTP.cpp b/worker/src/DepLibSRTP.cpp index 59b714c180..d9654dc993 100644 --- a/worker/src/DepLibSRTP.cpp +++ b/worker/src/DepLibSRTP.cpp @@ -2,40 +2,38 @@ // #define MS_LOG_DEV #include "DepLibSRTP.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" /* Static variables. */ -std::vector DepLibSRTP::errors = -{ - // From 0 (srtp_err_status_ok) to 24 (srtp_err_status_pfkey_err). - "success (srtp_err_status_ok)", - "unspecified failure (srtp_err_status_fail)", - "unsupported parameter (srtp_err_status_bad_param)", - "couldn't allocate memory (srtp_err_status_alloc_fail)", - "couldn't deallocate memory (srtp_err_status_dealloc_fail)", - "couldn't initialize (srtp_err_status_init_fail)", - "can’t process as much data as requested (srtp_err_status_terminus)", - "authentication failure (srtp_err_status_auth_fail)", - "cipher failure (srtp_err_status_cipher_fail)", - "replay check failed (bad index) (srtp_err_status_replay_fail)", - "replay check failed (index too old) (srtp_err_status_replay_old)", - "algorithm failed test routine (srtp_err_status_algo_fail)", - "unsupported operation (srtp_err_status_no_such_op)", - "no appropriate context found (srtp_err_status_no_ctx)", - "unable to perform desired validation (srtp_err_status_cant_check)", - "can’t use key any more (srtp_err_status_key_expired)", - "error in use of socket (srtp_err_status_socket_err)", - "error in use POSIX signals (srtp_err_status_signal_err)", - "nonce check failed (srtp_err_status_nonce_bad)", - "couldn’t read data (srtp_err_status_read_fail)", - "couldn’t write data (srtp_err_status_write_fail)", - "error parsing data (srtp_err_status_parse_err)", - "error encoding data (srtp_err_status_encode_err)", - "error while using semaphores (srtp_err_status_semaphore_err)", - "error while using pfkey (srtp_err_status_pfkey_err)" -}; +std::vector DepLibSRTP::errors = { + // From 0 (srtp_err_status_ok) to 24 (srtp_err_status_pfkey_err). + "success (srtp_err_status_ok)", + "unspecified failure (srtp_err_status_fail)", + "unsupported parameter (srtp_err_status_bad_param)", + "couldn't allocate memory (srtp_err_status_alloc_fail)", + "couldn't deallocate memory (srtp_err_status_dealloc_fail)", + "couldn't initialize (srtp_err_status_init_fail)", + "can’t process as much data as requested (srtp_err_status_terminus)", + "authentication failure (srtp_err_status_auth_fail)", + "cipher failure (srtp_err_status_cipher_fail)", + "replay check failed (bad index) (srtp_err_status_replay_fail)", + "replay check failed (index too old) (srtp_err_status_replay_old)", + "algorithm failed test routine (srtp_err_status_algo_fail)", + "unsupported operation (srtp_err_status_no_such_op)", + "no appropriate context found (srtp_err_status_no_ctx)", + "unable to perform desired validation (srtp_err_status_cant_check)", + "can’t use key any more (srtp_err_status_key_expired)", + "error in use of socket (srtp_err_status_socket_err)", + "error in use POSIX signals (srtp_err_status_signal_err)", + "nonce check failed (srtp_err_status_nonce_bad)", + "couldn’t read data (srtp_err_status_read_fail)", + "couldn’t write data (srtp_err_status_write_fail)", + "error parsing data (srtp_err_status_parse_err)", + "error encoding data (srtp_err_status_encode_err)", + "error while using semaphores (srtp_err_status_semaphore_err)", + "error while using pfkey (srtp_err_status_pfkey_err)"}; /* Static methods. */ diff --git a/worker/src/DepLibUV.cpp b/worker/src/DepLibUV.cpp index 988af1d977..e8a94289f5 100644 --- a/worker/src/DepLibUV.cpp +++ b/worker/src/DepLibUV.cpp @@ -18,7 +18,7 @@ void DepLibUV::ClassInit() int err; DepLibUV::loop = new uv_loop_t; - err = uv_loop_init(DepLibUV::loop); + err = uv_loop_init(DepLibUV::loop); if (err) MS_ABORT("libuv initialization failed"); } diff --git a/worker/src/DepOpenSSL.cpp b/worker/src/DepOpenSSL.cpp index b452896af3..af6f91f04f 100644 --- a/worker/src/DepOpenSSL.cpp +++ b/worker/src/DepOpenSSL.cpp @@ -2,10 +2,10 @@ // #define MS_LOG_DEV #include "DepOpenSSL.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" -#include +#include "MediaSoupError.hpp" #include // ENGINE_cleanup() +#include /* Static attributes. */ @@ -91,7 +91,7 @@ void DepOpenSSL::SetThreadId(CRYPTO_THREADID* id) CRYPTO_THREADID_set_numeric(id, (unsigned long)uv_thread_self()); } -void DepOpenSSL::LockingFunction(int mode, int n, const char *file, int line) +void DepOpenSSL::LockingFunction(int mode, int n, const char* file, int line) { // MS_TRACE(); diff --git a/worker/src/Logger.cpp b/worker/src/Logger.cpp index 417225f22b..ee6f81563f 100644 --- a/worker/src/Logger.cpp +++ b/worker/src/Logger.cpp @@ -5,21 +5,21 @@ /* Class variables. */ -std::string Logger::id = "unset"; +std::string Logger::id = "unset"; Channel::UnixStreamSocket* Logger::channel = nullptr; -char Logger::buffer[MS_LOGGER_BUFFER_SIZE]; +char Logger::buffer[Logger::bufferSize]; /* Class methods. */ -void Logger::Init(const std::string &id, Channel::UnixStreamSocket* channel) +void Logger::Init(const std::string& id, Channel::UnixStreamSocket* channel) { - Logger::id = id; + Logger::id = id; Logger::channel = channel; MS_TRACE(); } -void Logger::Init(const std::string &id) +void Logger::Init(const std::string& id) { Logger::id = id; diff --git a/worker/src/Loop.cpp b/worker/src/Loop.cpp index a3382b861d..fcbcb23d6d 100644 --- a/worker/src/Loop.cpp +++ b/worker/src/Loop.cpp @@ -3,19 +3,19 @@ #include "Loop.hpp" #include "DepLibUV.hpp" -#include "Settings.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" -#include -#include // std::pair() +#include "MediaSoupError.hpp" +#include "Settings.hpp" +#include #include #include // std::cout, std::cerr -#include +#include +#include // std::pair() /* Instance methods. */ -Loop::Loop(Channel::UnixStreamSocket* channel) : - channel(channel) +Loop::Loop(Channel::UnixStreamSocket* channel) + : channel(channel) { MS_TRACE(); @@ -124,8 +124,7 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum) break; default: - MS_WARN_DEV("received a signal (with signum %d) for which there is no handling code", - signum); + MS_WARN_DEV("received a signal (with signum %d) for which there is no handling code", signum); } } @@ -143,7 +142,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request static const Json::StaticString k_rooms("rooms"); Json::Value json(Json::objectValue); - Json::Value json_rooms(Json::arrayValue); + Json::Value jsonRooms(Json::arrayValue); json[k_workerId] = Logger::id; @@ -151,10 +150,10 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request { auto room = kv.second; - json_rooms.append(room->toJson()); + jsonRooms.append(room->toJson()); } - json[k_rooms] = json_rooms; + json[k_rooms] = jsonRooms; request->Accept(json); @@ -179,7 +178,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request { room = GetRoomFromRequest(request, &roomId); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -197,7 +196,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request { room = new RTC::Room(this, this->notifier, roomId, request->data); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -245,7 +244,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request { room = GetRoomFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); diff --git a/worker/src/RTC/DtlsTransport.cpp b/worker/src/RTC/DtlsTransport.cpp index c91be68576..a11137a8b6 100644 --- a/worker/src/RTC/DtlsTransport.cpp +++ b/worker/src/RTC/DtlsTransport.cpp @@ -2,40 +2,38 @@ // #define MS_LOG_DEV #include "RTC/DtlsTransport.hpp" +#include "Logger.hpp" +#include "MediaSoupError.hpp" #include "Settings.hpp" #include "Utils.hpp" -#include "MediaSoupError.hpp" -#include "Logger.hpp" -#include // std::sprintf(), std::fopen() -#include // std::memcpy(), std::strcmp() -#include // struct timeval -#include +#include #include +#include #include #include -#include - -#define LOG_OPENSSL_ERROR(desc) \ - do \ - { \ - if (ERR_peek_error() == 0) \ - MS_ERROR("OpenSSL error [desc:'%s']", desc); \ - else \ - { \ - unsigned long err; \ - while ((err = ERR_get_error()) != 0) \ - { \ - MS_ERROR("OpenSSL error [desc:'%s', error:'%s']", desc, ERR_error_string(err, nullptr)); \ - } \ - ERR_clear_error(); \ - } \ - } \ - while (0) +#include // std::sprintf(), std::fopen() +#include // std::memcpy(), std::strcmp() +#include // struct timeval + +#define LOG_OPENSSL_ERROR(desc) \ + do \ + { \ + if (ERR_peek_error() == 0) \ + MS_ERROR("OpenSSL error [desc:'%s']", desc); \ + else \ + { \ + unsigned long err; \ + while ((err = ERR_get_error()) != 0) \ + { \ + MS_ERROR("OpenSSL error [desc:'%s', error:'%s']", desc, ERR_error_string(err, nullptr)); \ + } \ + ERR_clear_error(); \ + } \ + } while (0) /* Static methods for OpenSSL callbacks. */ -static inline -int on_ssl_certificate_verify(int preverifyOk, X509_STORE_CTX* ctx) +inline static int onSslCertificate_verify(int preverifyOk, X509_STORE_CTX* ctx) { MS_TRACE(); @@ -43,8 +41,7 @@ int on_ssl_certificate_verify(int preverifyOk, X509_STORE_CTX* ctx) return 1; } -static inline -void on_ssl_info(const SSL* ssl, int where, int ret) +inline static void onSslInfo(const SSL* ssl, int where, int ret) { static_cast(SSL_get_ex_data(ssl, 0))->onSSLInfo(where, ret); } @@ -56,16 +53,17 @@ namespace RTC static constexpr int SslReadBufferSize = 65536; // NOTE: Those values are hardcoded as we just use AES_CM_128_HMAC_SHA1_80 and // AES_CM_128_HMAC_SHA1_32 which share same length values for key and salt. - static constexpr size_t SrtpMasterKeyLength = 16; + static constexpr size_t SrtpMasterKeyLength = 16; static constexpr size_t SrtpMasterSaltLength = 14; - static constexpr size_t SrtpMasterLength = SrtpMasterKeyLength + SrtpMasterSaltLength; + static constexpr size_t SrtpMasterLength = SrtpMasterKeyLength + SrtpMasterSaltLength; /* Class variables. */ - X509* DtlsTransport::certificate = nullptr; + X509* DtlsTransport::certificate = nullptr; EVP_PKEY* DtlsTransport::privateKey = nullptr; - SSL_CTX* DtlsTransport::sslCtx = nullptr; + SSL_CTX* DtlsTransport::sslCtx = nullptr; uint8_t DtlsTransport::sslReadBuffer[SslReadBufferSize]; + // clang-format off std::map DtlsTransport::string2FingerprintAlgorithm = { { "sha-1", DtlsTransport::FingerprintAlgorithm::SHA1 }, @@ -80,12 +78,15 @@ namespace RTC { "client", DtlsTransport::Role::CLIENT }, { "server", DtlsTransport::Role::SERVER } }; + // clang-format on Json::Value DtlsTransport::localFingerprints = Json::Value(Json::objectValue); + // clang-format off std::vector DtlsTransport::srtpProfiles = { { RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" }, { RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" } }; + // clang-format on /* Class methods. */ @@ -94,9 +95,8 @@ namespace RTC MS_TRACE(); // Generate a X509 certificate and private key (unless PEM files are provided). - if ( - Settings::configuration.dtlsCertificateFile.empty() || - Settings::configuration.dtlsPrivateKeyFile.empty()) + if (Settings::configuration.dtlsCertificateFile.empty() || + Settings::configuration.dtlsPrivateKeyFile.empty()) { GenerateCertificateAndPrivateKey(); } @@ -128,10 +128,10 @@ namespace RTC { MS_TRACE(); - int ret = 0; - BIGNUM* bne = nullptr; - RSA* rsaKey = nullptr; - int numBits = 1024; + int ret = 0; + BIGNUM* bne = nullptr; + RSA* rsaKey = nullptr; + int numBits = 1024; X509_NAME* certName = nullptr; // Create a big number object. @@ -194,12 +194,15 @@ namespace RTC X509_set_version(DtlsTransport::certificate, 2); // Set serial number (avoid default 0). - ASN1_INTEGER_set(X509_get_serialNumber(DtlsTransport::certificate), - (long)Utils::Crypto::GetRandomUInt(1000000, 9999999)); + ASN1_INTEGER_set( + X509_get_serialNumber(DtlsTransport::certificate), + (long)Utils::Crypto::GetRandomUInt(1000000, 9999999)); // Set valid period. - X509_gmtime_adj(X509_get_notBefore(DtlsTransport::certificate), -1*60*60*24*365*10); // -10 years. - X509_gmtime_adj(X509_get_notAfter(DtlsTransport::certificate), 60*60*24*365*10); // 10 years. + X509_gmtime_adj( + X509_get_notBefore(DtlsTransport::certificate), -1 * 60 * 60 * 24 * 365 * 10); // -10 years. + X509_gmtime_adj( + X509_get_notAfter(DtlsTransport::certificate), 60 * 60 * 24 * 365 * 10); // 10 years. // Set the public key for the certificate using the key. ret = X509_set_pubkey(DtlsTransport::certificate, DtlsTransport::privateKey); @@ -216,8 +219,8 @@ namespace RTC LOG_OPENSSL_ERROR("X509_get_subject_name() failed"); goto error; } - X509_NAME_add_entry_by_txt(certName, "O", MBSTRING_ASC, (uint8_t*)MS_APP_NAME, -1, -1, 0); - X509_NAME_add_entry_by_txt(certName, "CN", MBSTRING_ASC, (uint8_t*)MS_APP_NAME, -1, -1, 0); + X509_NAME_add_entry_by_txt(certName, "O", MBSTRING_ASC, (uint8_t*)"mediasoup", -1, -1, 0); + X509_NAME_add_entry_by_txt(certName, "CN", MBSTRING_ASC, (uint8_t*)"mediasoup", -1, -1, 0); // It is self-signed so set the issuer name to be the same as the subject. ret = X509_set_issuer_name(DtlsTransport::certificate, certName); @@ -305,17 +308,17 @@ namespace RTC EC_KEY* ecdh = nullptr; int ret; - /* Set the global DTLS context. */ +/* Set the global DTLS context. */ - // - Both DTLS 1.0 and 1.2 (requires OpenSSL >= 1.1.0). - #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) +// - Both DTLS 1.0 and 1.2 (requires OpenSSL >= 1.1.0). +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) DtlsTransport::sslCtx = SSL_CTX_new(DTLS_method()); - // - Just DTLS 1.0 (requires OpenSSL >= 1.0.1). - #elif (OPENSSL_VERSION_NUMBER >= 0x10001000L) +// - Just DTLS 1.0 (requires OpenSSL >= 1.0.1). +#elif (OPENSSL_VERSION_NUMBER >= 0x10001000L) DtlsTransport::sslCtx = SSL_CTX_new(DTLSv1_method()); - #else - #error "too old OpenSSL version" - #endif +#else +#error "too old OpenSSL version" +#endif if (!DtlsTransport::sslCtx) { @@ -345,7 +348,9 @@ namespace RTC } // Set options. - SSL_CTX_set_options(DtlsTransport::sslCtx, SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET | SSL_OP_SINGLE_ECDH_USE); + SSL_CTX_set_options( + DtlsTransport::sslCtx, + SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET | SSL_OP_SINGLE_ECDH_USE); // Don't use sessions cache. SSL_CTX_set_session_cache_mode(DtlsTransport::sslCtx, SSL_SESS_CACHE_OFF); @@ -358,27 +363,30 @@ namespace RTC SSL_CTX_set_verify_depth(DtlsTransport::sslCtx, 4); // Require certificate from peer. - SSL_CTX_set_verify(DtlsTransport::sslCtx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, on_ssl_certificate_verify); + SSL_CTX_set_verify( + DtlsTransport::sslCtx, + SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, + onSslCertificate_verify); // Set SSL info callback. - SSL_CTX_set_info_callback(DtlsTransport::sslCtx, on_ssl_info); + SSL_CTX_set_info_callback(DtlsTransport::sslCtx, onSslInfo); // Set ciphers. - ret = SSL_CTX_set_cipher_list(DtlsTransport::sslCtx, - "ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH"); + ret = SSL_CTX_set_cipher_list( + DtlsTransport::sslCtx, "ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH"); if (ret == 0) { LOG_OPENSSL_ERROR("SSL_CTX_set_cipher_list() failed"); goto error; } - // Enable ECDH ciphers. - // DOC: http://en.wikibooks.org/wiki/OpenSSL/Diffie-Hellman_parameters - // NOTE: https://code.google.com/p/chromium/issues/detail?id=406458 - // For OpenSSL >= 1.0.2: - #if (OPENSSL_VERSION_NUMBER >= 0x10002000L) +// Enable ECDH ciphers. +// DOC: http://en.wikibooks.org/wiki/OpenSSL/Diffie-Hellman_parameters +// NOTE: https://code.google.com/p/chromium/issues/detail?id=406458 +// For OpenSSL >= 1.0.2: +#if (OPENSSL_VERSION_NUMBER >= 0x10002000L) SSL_CTX_set_ecdh_auto(DtlsTransport::sslCtx, 1); - #else +#else ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); if (!ecdh) @@ -395,7 +403,7 @@ namespace RTC EC_KEY_free(ecdh); ecdh = nullptr; - #endif +#endif // Set the "use_srtp" DTLS extension. { @@ -405,8 +413,8 @@ namespace RTC if (it != DtlsTransport::srtpProfiles.begin()) dtlsSrtpProfiles += ":"; - SrtpProfileMapEntry* profile_entry = &(*it); - dtlsSrtpProfiles += profile_entry->name; + SrtpProfileMapEntry* profileEntry = &(*it); + dtlsSrtpProfiles += profileEntry->name; } } @@ -443,7 +451,7 @@ namespace RTC auto it = DtlsTransport::string2FingerprintAlgorithm.begin(); for (; it != DtlsTransport::string2FingerprintAlgorithm.end(); ++it) { - std::string algorithmString = it->first; + std::string algorithmString = it->first; FingerprintAlgorithm algorithm = it->second; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; unsigned int size = 0; @@ -495,8 +503,8 @@ namespace RTC /* Instance methods. */ - DtlsTransport::DtlsTransport(Listener* listener) : - listener(listener) + DtlsTransport::DtlsTransport(Listener* listener) + : listener(listener) { MS_TRACE(); @@ -559,9 +567,9 @@ namespace RTC if (this->ssl) { SSL_free(this->ssl); - this->ssl = nullptr; + this->ssl = nullptr; this->sslBioFromNetwork = nullptr; - this->sslBioToNetwork = nullptr; + this->sslBioToNetwork = nullptr; } } @@ -587,11 +595,13 @@ namespace RTC MS_TRACE(); MS_DUMP(""); - MS_DUMP(" [role:%s, running:%s, handshake done:%s, connected:%s]", - (this->localRole == Role::SERVER ? "server" : (this->localRole == Role::CLIENT ? "client" : "none")), - IsRunning() ? "yes" : "no", - this->handshakeDone ? "yes" : "no", - this->state == DtlsState::CONNECTED ? "yes" : "no"); + MS_DUMP( + " [role:%s, running:%s, handshake done:%s, connected:%s]", + (this->localRole == Role::SERVER ? "server" + : (this->localRole == Role::CLIENT ? "client" : "none")), + IsRunning() ? "yes" : "no", + this->handshakeDone ? "yes" : "no", + this->state == DtlsState::CONNECTED ? "yes" : "no"); MS_DUMP(""); } @@ -599,8 +609,9 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(localRole == Role::CLIENT || localRole == Role::SERVER, - "local DTLS role must be 'client' or 'server'"); + MS_ASSERT( + localRole == Role::CLIENT || localRole == Role::SERVER, + "local DTLS role must be 'client' or 'server'"); Role previousLocalRole = this->localRole; @@ -653,8 +664,8 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(fingerprint.algorithm != FingerprintAlgorithm::NONE, - "no fingerprint algorithm provided"); + MS_ASSERT( + fingerprint.algorithm != FingerprintAlgorithm::NONE, "no fingerprint algorithm provided"); this->remoteFingerprint = fingerprint; @@ -686,8 +697,11 @@ namespace RTC written = BIO_write(this->sslBioFromNetwork, (const void*)data, (int)len); if (written != (int)len) { - MS_WARN_TAG(dtls, "OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)", - (size_t)written, len); + MS_WARN_TAG( + dtls, + "OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)", + (size_t)written, + len); } // Must call SSL_read() to process received DTLS data. @@ -716,8 +730,8 @@ namespace RTC } // Notify the listener. - this->listener->onDtlsApplicationData(this, (uint8_t*)DtlsTransport::sslReadBuffer, - (size_t)read); + this->listener->onDtlsApplicationData( + this, (uint8_t*)DtlsTransport::sslReadBuffer, (size_t)read); } } @@ -751,8 +765,8 @@ namespace RTC } else if (written != (int)len) { - MS_WARN_TAG(dtls, "OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)", - written, len); + MS_WARN_TAG( + dtls, "OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)", written, len); } // Send data. @@ -778,9 +792,9 @@ namespace RTC // SendPendingOutgoingDTLSData(). SSL_shutdown(this->ssl); - this->localRole = Role::NONE; - this->state = DtlsState::NEW; - this->handshakeDone = false; + this->localRole = Role::NONE; + this->state = DtlsState::NEW; + this->handshakeDone = false; this->handshakeDoneNow = false; // Reset SSL status. @@ -792,8 +806,7 @@ namespace RTC ERR_clear_error(); } - inline - bool DtlsTransport::CheckStatus(int return_code) + inline bool DtlsTransport::CheckStatus(int return_code) { MS_TRACE(); @@ -835,7 +848,7 @@ namespace RTC if (this->handshakeDoneNow) { this->handshakeDoneNow = false; - this->handshakeDone = true; + this->handshakeDone = true; // Stop the timer. this->timer->Stop(); @@ -845,10 +858,7 @@ namespace RTC ProcessHandshake(); } // Check if the peer sent close alert or a fatal error happened. - else if ( - (SSL_get_shutdown(this->ssl) & SSL_RECEIVED_SHUTDOWN) || - err == SSL_ERROR_SSL - || err == SSL_ERROR_SYSCALL) + else if ((SSL_get_shutdown(this->ssl) & SSL_RECEIVED_SHUTDOWN) || err == SSL_ERROR_SSL || err == SSL_ERROR_SYSCALL) { if (this->state == DtlsState::CONNECTED) { @@ -877,8 +887,7 @@ namespace RTC return true; } - inline - void DtlsTransport::SendPendingOutgoingDtlsData() + inline void DtlsTransport::SendPendingOutgoingDtlsData() { MS_TRACE(); @@ -902,8 +911,7 @@ namespace RTC (void)BIO_reset(this->sslBioToNetwork); } - inline - bool DtlsTransport::SetTimeout() + inline bool DtlsTransport::SetTimeout() { MS_TRACE(); @@ -945,8 +953,7 @@ namespace RTC } } - inline - void DtlsTransport::ProcessHandshake() + inline void DtlsTransport::ProcessHandshake() { MS_TRACE(); @@ -974,13 +981,13 @@ namespace RTC } // Get the negotiated SRTP profile. - RTC::SrtpSession::Profile srtp_profile; - srtp_profile = GetNegotiatedSrtpProfile(); + RTC::SrtpSession::Profile srtpProfile; + srtpProfile = GetNegotiatedSrtpProfile(); - if (srtp_profile != RTC::SrtpSession::Profile::NONE) + if (srtpProfile != RTC::SrtpSession::Profile::NONE) { // Extract the SRTP keys (will notify the listener with them). - ExtractSrtpKeys(srtp_profile); + ExtractSrtpKeys(srtpProfile); } else { @@ -996,12 +1003,13 @@ namespace RTC } } - inline - bool DtlsTransport::CheckRemoteFingerprint() + inline bool DtlsTransport::CheckRemoteFingerprint() { MS_TRACE(); - MS_ASSERT(this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set"); + MS_ASSERT( + this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, + "remote fingerprint not set"); X509* certificate; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; @@ -1060,9 +1068,11 @@ namespace RTC if (this->remoteFingerprint.value.compare(hexFingerprint) != 0) { - MS_WARN_TAG(dtls, - "fingerprint in the remote certificate (%s) does not match the announced one (%s)", - hexFingerprint, this->remoteFingerprint.value.c_str()); + MS_WARN_TAG( + dtls, + "fingerprint in the remote certificate (%s) does not match the announced one (%s)", + hexFingerprint, + this->remoteFingerprint.value.c_str()); X509_free(certificate); @@ -1112,8 +1122,7 @@ namespace RTC return true; } - inline - void DtlsTransport::ExtractSrtpKeys(RTC::SrtpSession::Profile srtp_profile) + inline void DtlsTransport::ExtractSrtpKeys(RTC::SrtpSession::Profile srtpProfile) { MS_TRACE(); @@ -1126,23 +1135,23 @@ namespace RTC uint8_t srtpRemoteMasterKey[SrtpMasterLength]; int ret; - ret = SSL_export_keying_material(this->ssl, srtpMaterial, SrtpMasterLength * 2, - "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0); + ret = SSL_export_keying_material( + this->ssl, srtpMaterial, SrtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0); MS_ASSERT(ret != 0, "SSL_export_keying_material() failed"); switch (this->localRole) { case Role::SERVER: - srtpRemoteKey = srtpMaterial; - srtpLocalKey = srtpRemoteKey + SrtpMasterKeyLength; + srtpRemoteKey = srtpMaterial; + srtpLocalKey = srtpRemoteKey + SrtpMasterKeyLength; srtpRemoteSalt = srtpLocalKey + SrtpMasterKeyLength; - srtpLocalSalt = srtpRemoteSalt + SrtpMasterSaltLength; + srtpLocalSalt = srtpRemoteSalt + SrtpMasterSaltLength; break; case Role::CLIENT: - srtpLocalKey = srtpMaterial; - srtpRemoteKey = srtpLocalKey + SrtpMasterKeyLength; - srtpLocalSalt = srtpRemoteKey + SrtpMasterKeyLength; + srtpLocalKey = srtpMaterial; + srtpRemoteKey = srtpLocalKey + SrtpMasterKeyLength; + srtpLocalSalt = srtpRemoteKey + SrtpMasterKeyLength; srtpRemoteSalt = srtpLocalSalt + SrtpMasterSaltLength; break; default: @@ -1159,12 +1168,17 @@ namespace RTC // Set state and notify the listener. this->state = DtlsState::CONNECTED; - this->listener->onDtlsConnected(this, srtp_profile, srtpLocalMasterKey, SrtpMasterLength, - srtpRemoteMasterKey, SrtpMasterLength, this->remoteCert); + this->listener->onDtlsConnected( + this, + srtpProfile, + srtpLocalMasterKey, + SrtpMasterLength, + srtpRemoteMasterKey, + SrtpMasterLength, + this->remoteCert); } - inline - RTC::SrtpSession::Profile DtlsTransport::GetNegotiatedSrtpProfile() + inline RTC::SrtpSession::Profile DtlsTransport::GetNegotiatedSrtpProfile() { MS_TRACE(); @@ -1181,32 +1195,36 @@ namespace RTC auto it = DtlsTransport::srtpProfiles.begin(); for (; it != DtlsTransport::srtpProfiles.end(); ++it) { - SrtpProfileMapEntry* profile_entry = &(*it); + SrtpProfileMapEntry* profileEntry = &(*it); - if (std::strcmp(ssl_srtp_profile->name, profile_entry->name) == 0) + if (std::strcmp(ssl_srtp_profile->name, profileEntry->name) == 0) { - MS_DEBUG_TAG(dtls, "chosen SRTP profile: %s", profile_entry->name); + MS_DEBUG_TAG(dtls, "chosen SRTP profile: %s", profileEntry->name); - negotiatedSrtpProfile = profile_entry->profile; + negotiatedSrtpProfile = profileEntry->profile; } } - MS_ASSERT(negotiatedSrtpProfile != RTC::SrtpSession::Profile::NONE, "chosen SRTP profile is not an available one"); + MS_ASSERT( + negotiatedSrtpProfile != RTC::SrtpSession::Profile::NONE, + "chosen SRTP profile is not an available one"); return negotiatedSrtpProfile; } - inline - void DtlsTransport::onSSLInfo(int where, int ret) + inline void DtlsTransport::onSSLInfo(int where, int ret) { MS_TRACE(); int w = where & -SSL_ST_MASK; const char* role; - if (w & SSL_ST_CONNECT) role = "client"; - else if (w & SSL_ST_ACCEPT) role = "server"; - else role = "undefined"; + if (w & SSL_ST_CONNECT) + role = "client"; + else if (w & SSL_ST_ACCEPT) + role = "server"; + else + role = "undefined"; if (where & SSL_CB_LOOP) { @@ -1214,29 +1232,31 @@ namespace RTC } else if (where & SSL_CB_ALERT) { - const char* alert_type; + const char* alertType; switch (*SSL_alert_type_string(ret)) { - case 'W': alert_type = "warning"; break; - case 'F': alert_type = "fatal"; break; - default: alert_type = "undefined"; + case 'W': + alertType = "warning"; + break; + case 'F': + alertType = "fatal"; + break; + default: + alertType = "undefined"; } if (where & SSL_CB_READ) { - MS_WARN_TAG(dtls, "received DTLS %s alert: %s", - alert_type, SSL_alert_desc_string_long(ret)); + MS_WARN_TAG(dtls, "received DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); } else if (where & SSL_CB_WRITE) { - MS_DEBUG_TAG(dtls, "sending DTLS %s alert: %s", - alert_type, SSL_alert_desc_string_long(ret)); + MS_DEBUG_TAG(dtls, "sending DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); } else { - MS_DEBUG_TAG(dtls, "DTLS %s alert: %s", - alert_type, SSL_alert_desc_string_long(ret)); + MS_DEBUG_TAG(dtls, "DTLS %s alert: %s", alertType, SSL_alert_desc_string_long(ret)); } } else if (where & SSL_CB_EXIT) @@ -1261,8 +1281,7 @@ namespace RTC // receipt of a close alert does not work (the flag is set after this callback). } - inline - void DtlsTransport::onTimer(Timer* timer) + inline void DtlsTransport::onTimer(Timer* timer) { MS_TRACE(); diff --git a/worker/src/RTC/IceCandidate.cpp b/worker/src/RTC/IceCandidate.cpp index b70fe57954..7f53b5a624 100644 --- a/worker/src/RTC/IceCandidate.cpp +++ b/worker/src/RTC/IceCandidate.cpp @@ -8,13 +8,13 @@ namespace RTC { /* Instance methods. */ - IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority) : - foundation("udpcandidate"), - priority(priority), - family(udpSocket->GetLocalFamily()), - protocol(Protocol::UDP), - port(udpSocket->GetLocalPort()), - type(CandidateType::HOST) + IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority) + : foundation("udpcandidate") + , priority(priority) + , family(udpSocket->GetLocalFamily()) + , protocol(Protocol::UDP) + , port(udpSocket->GetLocalPort()) + , type(CandidateType::HOST) { switch (this->family) { @@ -40,14 +40,14 @@ namespace RTC } } - IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority) : - foundation("tcpcandidate"), - priority(priority), - family(tcpServer->GetLocalFamily()), - protocol(Protocol::TCP), - port(tcpServer->GetLocalPort()), - type(CandidateType::HOST), - tcpType(TcpCandidateType::PASSIVE) + IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority) + : foundation("tcpcandidate") + , priority(priority) + , family(tcpServer->GetLocalFamily()) + , protocol(Protocol::TCP) + , port(tcpServer->GetLocalPort()) + , type(CandidateType::HOST) + , tcpType(TcpCandidateType::PASSIVE) { switch (this->family) { @@ -106,8 +106,8 @@ namespace RTC } json[k_priority] = (Json::UInt)this->priority; - json[k_ip] = this->ip; - json[k_port] = (Json::UInt)this->port; + json[k_ip] = this->ip; + json[k_port] = (Json::UInt)this->port; switch (this->type) { diff --git a/worker/src/RTC/IceServer.cpp b/worker/src/RTC/IceServer.cpp index e9db7d59fb..d93ac6f2dc 100644 --- a/worker/src/RTC/IceServer.cpp +++ b/worker/src/RTC/IceServer.cpp @@ -13,15 +13,18 @@ namespace RTC /* Instance methods. */ - IceServer::IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password) : - listener(listener), - usernameFragment(usernameFragment), - password(password) + IceServer::IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password) + : listener(listener) + , usernameFragment(usernameFragment) + , password(password) { MS_TRACE(); - MS_DEBUG_TAG(ice, "[usernameFragment:%s, password:%s]", - this->usernameFragment.c_str(), this->password.c_str()); + MS_DEBUG_TAG( + ice, + "[usernameFragment:%s, password:%s]", + this->usernameFragment.c_str(), + this->password.c_str()); } void IceServer::Destroy() @@ -40,8 +43,8 @@ namespace RTC { if (msg->GetClass() == RTC::StunMessage::Class::Request) { - MS_WARN_TAG(ice, "unknown method %#.3x in STUN Request => 400", - (unsigned int)msg->GetMethod()); + MS_WARN_TAG( + ice, "unknown method %#.3x in STUN Request => 400", (unsigned int)msg->GetMethod()); // Reply 400. RTC::StunMessage* response = msg->CreateErrorResponse(400); @@ -52,8 +55,10 @@ namespace RTC } else { - MS_WARN_TAG(ice, "ignoring STUN Indication or Response with unknown method %#.3x", - (unsigned int)msg->GetMethod()); + MS_WARN_TAG( + ice, + "ignoring STUN Indication or Response with unknown method %#.3x", + (unsigned int)msg->GetMethod()); } return; @@ -150,9 +155,11 @@ namespace RTC return; } - MS_DEBUG_TAG(ice, - "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", - (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false"); + MS_DEBUG_TAG( + ice, + "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", + (uint32_t)msg->GetPriority(), + msg->HasUseCandidate() ? "true" : "false"); // Create a success response. RTC::StunMessage* response = msg->CreateSuccessResponse(); @@ -258,13 +265,15 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->selectedTuple != nullptr, - "cannot force the selected tuple if there was not a selected tuple"); + MS_ASSERT( + this->selectedTuple != nullptr, + "cannot force the selected tuple if there was not a selected tuple"); auto storedTuple = HasTuple(tuple); - MS_ASSERT(storedTuple, - "cannot force the selected tuple if the given tuple was not already a valid tuple"); + MS_ASSERT( + storedTuple, + "cannot force the selected tuple if the given tuple was not already a valid tuple"); // Mark it as selected tuple. SetSelectedTuple(storedTuple); @@ -279,12 +288,11 @@ namespace RTC case IceState::NEW: { // There should be no tuples. - MS_ASSERT(this->tuples.size() == 0, "state is 'new' but there are %zu tuples", - this->tuples.size()); + MS_ASSERT( + this->tuples.size() == 0, "state is 'new' but there are %zu tuples", this->tuples.size()); // There shouldn't be a selected tuple. - MS_ASSERT(this->selectedTuple == nullptr, - "state is 'new' but there is selected tuple"); + MS_ASSERT(this->selectedTuple == nullptr, "state is 'new' but there is selected tuple"); if (!hasUseCandidate) { @@ -321,12 +329,14 @@ namespace RTC case IceState::DISCONNECTED: { // There should be no tuples. - MS_ASSERT(this->tuples.size() == 0, - "state is 'disconnected' but there are %zu tuples", this->tuples.size()); + MS_ASSERT( + this->tuples.size() == 0, + "state is 'disconnected' but there are %zu tuples", + this->tuples.size()); // There shouldn't be a selected tuple. - MS_ASSERT(this->selectedTuple == nullptr, - "state is 'disconnected' but there is selected tuple"); + MS_ASSERT( + this->selectedTuple == nullptr, "state is 'disconnected' but there is selected tuple"); if (!hasUseCandidate) { @@ -363,12 +373,11 @@ namespace RTC case IceState::CONNECTED: { // There should be some tuples. - MS_ASSERT(this->tuples.size() > 0, - "state is 'connected' but there are no tuples"); + MS_ASSERT(this->tuples.size() > 0, "state is 'connected' but there are no tuples"); // There should be a selected tuple. - MS_ASSERT(this->selectedTuple != nullptr, - "state is 'connected' but there is not selected tuple"); + MS_ASSERT( + this->selectedTuple != nullptr, "state is 'connected' but there is not selected tuple"); if (!hasUseCandidate) { @@ -403,8 +412,8 @@ namespace RTC MS_ASSERT(this->tuples.size() > 0, "state is 'completed' but there are no tuples"); // There should be a selected tuple. - MS_ASSERT(this->selectedTuple != nullptr, - "state is 'completed' but there is not selected tuple"); + MS_ASSERT( + this->selectedTuple != nullptr, "state is 'completed' but there is not selected tuple"); if (!hasUseCandidate) { @@ -429,8 +438,7 @@ namespace RTC } } - inline - RTC::TransportTuple* IceServer::AddTuple(RTC::TransportTuple* tuple) + inline RTC::TransportTuple* IceServer::AddTuple(RTC::TransportTuple* tuple) { MS_TRACE(); @@ -448,8 +456,7 @@ namespace RTC return storedTuple; } - inline - RTC::TransportTuple* IceServer::HasTuple(const RTC::TransportTuple* tuple) const + inline RTC::TransportTuple* IceServer::HasTuple(const RTC::TransportTuple* tuple) const { MS_TRACE(); @@ -474,8 +481,7 @@ namespace RTC return nullptr; } - inline - void IceServer::SetSelectedTuple(RTC::TransportTuple* storedTuple) + inline void IceServer::SetSelectedTuple(RTC::TransportTuple* storedTuple) { MS_TRACE(); diff --git a/worker/src/RTC/NackGenerator.cpp b/worker/src/RTC/NackGenerator.cpp index 2e85dd0490..441eb8bfc1 100644 --- a/worker/src/RTC/NackGenerator.cpp +++ b/worker/src/RTC/NackGenerator.cpp @@ -9,17 +9,17 @@ namespace RTC { /* Static. */ - constexpr uint32_t MaxPacketAge = 10000; - constexpr size_t MaxNackPackets = 500; - constexpr uint32_t DefaultRtt = 100; + constexpr uint32_t MaxPacketAge = 10000; + constexpr size_t MaxNackPackets = 500; + constexpr uint32_t DefaultRtt = 100; constexpr uint8_t MaxNackRetries = 8; constexpr uint64_t TimerInterval = 25; /* Instance methods. */ - NackGenerator::NackGenerator(Listener* listener) : - listener(listener), - rtt(DefaultRtt) + NackGenerator::NackGenerator(Listener* listener) + : listener(listener) + , rtt(DefaultRtt) { MS_TRACE(); @@ -44,7 +44,7 @@ namespace RTC if (!this->started) { this->lastSeq32 = seq32; - this->started = true; + this->started = true; return; } @@ -69,18 +69,22 @@ namespace RTC // It was a nacked packet. if (it != this->nackList.end()) { - MS_DEBUG_TAG(rtx, - "nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_DEBUG_TAG( + rtx, + "nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); this->nackList.erase(it); } // Out of order packet. else { - MS_DEBUG_TAG(rtx, - "out of order packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_DEBUG_TAG( + rtx, + "out of order packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); } return; @@ -130,8 +134,8 @@ namespace RTC NackInfo nackInfo(seq32, sendAtSeqNum); - MS_ASSERT(this->nackList.find(seq32) == this->nackList.end(), - "packet already in the NACK list"); + MS_ASSERT( + this->nackList.find(seq32) == this->nackList.end(), "packet already in the NACK list"); this->nackList[seq32] = nackInfo; } @@ -146,21 +150,20 @@ namespace RTC while (it != this->nackList.end()) { NackInfo& nackInfo = it->second; - uint16_t seq = nackInfo.seq32 % (1<<16); + uint16_t seq = nackInfo.seq32 % (1 << 16); - if ( - filter == NackFilter::SEQ && - nackInfo.sentAtTime == 0 && - this->lastSeq32 >= nackInfo.sendAtSeqNum) + if (filter == NackFilter::SEQ && nackInfo.sentAtTime == 0 && + this->lastSeq32 >= nackInfo.sendAtSeqNum) { nackInfo.retries++; nackInfo.sentAtTime = now; if (nackInfo.retries >= MaxNackRetries) { - MS_WARN_TAG(rtx, - "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", - seq); + MS_WARN_TAG( + rtx, + "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", + seq); it = this->nackList.erase(it); } @@ -173,18 +176,17 @@ namespace RTC continue; } - if ( - filter == NackFilter::TIME && - nackInfo.sentAtTime + this->rtt < now) + if (filter == NackFilter::TIME && nackInfo.sentAtTime + this->rtt < now) { nackInfo.retries++; nackInfo.sentAtTime = now; if (nackInfo.retries >= MaxNackRetries) { - MS_WARN_TAG(rtx, - "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", - seq); + MS_WARN_TAG( + rtx, + "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", + seq); it = this->nackList.erase(it); } @@ -203,15 +205,13 @@ namespace RTC return nackBatch; } - inline - void NackGenerator::MayRunTimer() const + inline void NackGenerator::MayRunTimer() const { if (this->nackList.size() > 0) this->timer->Start(TimerInterval); } - inline - void NackGenerator::onTimer(Timer* timer) + inline void NackGenerator::onTimer(Timer* timer) { MS_TRACE(); diff --git a/worker/src/RTC/Peer.cpp b/worker/src/RTC/Peer.cpp index 7a9121d0a1..03b4f89be7 100644 --- a/worker/src/RTC/Peer.cpp +++ b/worker/src/RTC/Peer.cpp @@ -2,35 +2,31 @@ // #define MS_LOG_DEV #include "RTC/Peer.hpp" -#include "RTC/RtpDictionaries.hpp" +#include "DepLibUV.hpp" +#include "Logger.hpp" +#include "MediaSoupError.hpp" #include "RTC/RTCP/CompoundPacket.hpp" -#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/FeedbackPsRemb.hpp" +#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/Sdes.hpp" -#include "MediaSoupError.hpp" -#include "Logger.hpp" -#include "DepLibUV.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { - /* Class variables. */ - - uint8_t Peer::rtcpBuffer[MS_RTCP_BUFFER_SIZE]; - /* Instance methods. */ - Peer::Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName) : - peerId(peerId), - peerName(peerName), - listener(listener), - notifier(notifier) + Peer::Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName) + : peerId(peerId) + , peerName(peerName) + , listener(listener) + , notifier(notifier) { MS_TRACE(); this->timer = new Timer(this); // Start the RTCP timer. - this->timer->Start(uint64_t(RTC::RTCP::MAX_VIDEO_INTERVAL_MS / 2)); + this->timer->Start(uint64_t(RTC::RTCP::maxVideoIntervalMs / 2)); } Peer::~Peer() @@ -152,9 +148,9 @@ namespace RTC { case Channel::Request::MethodId::peer_close: { - #ifdef MS_LOG_DEV +#ifdef MS_LOG_DEV uint32_t peerId = this->peerId; - #endif +#endif Destroy(); @@ -188,7 +184,7 @@ namespace RTC { this->capabilities = RTC::RtpCapabilities(request->data, RTC::Scope::PEER_CAPABILITY); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -222,7 +218,7 @@ namespace RTC { transport = GetTransportFromRequest(request, &transportId); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -240,7 +236,7 @@ namespace RTC { transport = new RTC::Transport(this, this->notifier, transportId, request->data); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -278,7 +274,7 @@ namespace RTC { rtpReceiver = GetRtpReceiverFromRequest(request, &rtpReceiverId); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -296,7 +292,7 @@ namespace RTC { transport = GetTransportFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -320,10 +316,10 @@ namespace RTC // Create a RtpReceiver instance. try { - rtpReceiver = new RTC::RtpReceiver(this, this->notifier, rtpReceiverId, - RTC::Media::GetKind(kind)); + rtpReceiver = + new RTC::RtpReceiver(this, this->notifier, rtpReceiverId, RTC::Media::GetKind(kind)); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -353,7 +349,7 @@ namespace RTC { transport = GetTransportFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -384,7 +380,7 @@ namespace RTC { rtpReceiver = GetRtpReceiverFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -411,7 +407,7 @@ namespace RTC { rtpSender = GetRtpSenderFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -438,7 +434,7 @@ namespace RTC { rtpSender = GetRtpSenderFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -458,7 +454,7 @@ namespace RTC { transport = GetTransportFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -487,7 +483,7 @@ namespace RTC { rtpSender = GetRtpSenderFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -515,15 +511,17 @@ namespace RTC } } - void Peer::AddRtpSender(RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters) + void Peer::AddRtpSender( + RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters) { MS_TRACE(); static const Json::StaticString k_class("class"); static const Json::StaticString k_peerName("peerName"); - MS_ASSERT(this->rtpSenders.find(rtpSender->rtpSenderId) == this->rtpSenders.end(), - "given RtpSender already exists in this Peer"); + MS_ASSERT( + this->rtpSenders.find(rtpSender->rtpSenderId) == this->rtpSenders.end(), + "given RtpSender already exists in this Peer"); // Provide the RtpSender with peer's capabilities. rtpSender->SetPeerCapabilities(std::addressof(this->capabilities)); @@ -537,7 +535,7 @@ namespace RTC // Notify. Json::Value eventData = rtpSender->toJson(); - eventData[k_class] = "Peer"; + eventData[k_class] = "Peer"; eventData[k_peerName] = peerName; this->notifier->Emit(this->peerId, "newrtpsender", eventData); @@ -550,7 +548,7 @@ namespace RTC auto it = this->rtpSenders.begin(); for (; it != this->rtpSenders.end(); ++it) { - auto rtpSender = it->second; + auto rtpSender = it->second; auto rtpParameters = rtpSender->GetParameters(); if (!rtpParameters) @@ -600,15 +598,14 @@ namespace RTC if (packet->GetSenderReportCount()) { // Ensure that the RTCP packet fits into the RTCP buffer. - if (packet->GetSize() > MS_RTCP_BUFFER_SIZE) + if (packet->GetSize() > RTC::RTCP::bufferSize) { - MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", - packet->GetSize()); + MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", packet->GetSize()); return; } - packet->Serialize(Peer::rtcpBuffer); + packet->Serialize(RTC::RTCP::buffer); transport->SendRtcpCompoundPacket(packet.get()); // Reset the Compound packet. packet.reset(new RTC::RTCP::CompoundPacket()); @@ -629,15 +626,14 @@ namespace RTC if (packet->GetReceiverReportCount()) { // Ensure that the RTCP packet fits into the RTCP buffer. - if (packet->GetSize() > MS_RTCP_BUFFER_SIZE) + if (packet->GetSize() > RTC::RTCP::bufferSize) { - MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", - packet->GetSize()); + MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", packet->GetSize()); return; } - packet->Serialize(Peer::rtcpBuffer); + packet->Serialize(RTC::RTCP::buffer); transport->SendRtcpCompoundPacket(packet.get()); } } @@ -734,9 +730,7 @@ namespace RTC { RTC::RtpSender* rtpSender = kv.second; - if ( - rtpSender->kind != RTC::Media::Kind::VIDEO && - rtpSender->kind != RTC::Media::Kind::DEPTH) + if (rtpSender->kind != RTC::Media::Kind::VIDEO && rtpSender->kind != RTC::Media::Kind::DEPTH) { continue; } @@ -781,9 +775,7 @@ namespace RTC { RTC::RtpReceiver* rtpReceiver = kv.second; - if ( - rtpReceiver->kind != RTC::Media::Kind::VIDEO && - rtpReceiver->kind != RTC::Media::Kind::DEPTH) + if (rtpReceiver->kind != RTC::Media::Kind::VIDEO && rtpReceiver->kind != RTC::Media::Kind::DEPTH) { continue; } @@ -838,7 +830,8 @@ namespace RTC { switch (packet->GetType()) { - /* RTCP coming from a remote receiver which must be forwarded to the corresponding remote sender. */ + /* RTCP coming from a remote receiver which must be forwarded to the corresponding remote + * sender. */ case RTCP::Type::RR: { @@ -847,7 +840,7 @@ namespace RTC for (; it != rr->End(); ++it) { - auto& report = (*it); + auto& report = (*it); RTC::RtpSender* rtpSender = this->GetRtpSender(report->GetSsrc()); if (rtpSender) @@ -856,9 +849,10 @@ namespace RTC } else { - MS_WARN_TAG(rtcp, - "no RtpSender found for received Receiver Report [ssrc:%" PRIu32 "]", - report->GetSsrc()); + MS_WARN_TAG( + rtcp, + "no RtpSender found for received Receiver Report [ssrc:%" PRIu32 "]", + report->GetSsrc()); } } @@ -891,19 +885,20 @@ namespace RTC { if (feedback->GetMessageType() == RTCP::FeedbackPs::MessageType::PLI) { - MS_DEBUG_TAG(rtx, "PLI received [media_ssrc:%" PRIu32 "]", - feedback->GetMediaSsrc()); + MS_DEBUG_TAG(rtx, "PLI received [media ssrc:%" PRIu32 "]", feedback->GetMediaSsrc()); } this->listener->onPeerRtcpFeedback(this, rtpSender, feedback); } else { - MS_WARN_TAG(rtcp, - "no RtpSender found for received %s Feedback packet " - "[sender_ssrc:%" PRIu32 ", media_ssrc:%" PRIu32 "]", - RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), - feedback->GetMediaSsrc(), feedback->GetMediaSsrc()); + MS_WARN_TAG( + rtcp, + "no RtpSender found for received %s Feedback packet " + "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", + RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), + feedback->GetMediaSsrc(), + feedback->GetMediaSsrc()); } break; @@ -917,11 +912,13 @@ namespace RTC case RTCP::FeedbackPs::MessageType::EXT: default: { - MS_WARN_TAG(rtcp, - "ignoring unsupported %s Feedback packet " - "[sender_ssrc:%" PRIu32 ", media_ssrc:%" PRIu32 "]", - RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), - feedback->GetMediaSsrc(), feedback->GetMediaSsrc()); + MS_WARN_TAG( + rtcp, + "ignoring unsupported %s Feedback packet " + "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", + RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), + feedback->GetMediaSsrc(), + feedback->GetMediaSsrc()); break; } @@ -943,16 +940,18 @@ namespace RTC if (rtpSender) { RTC::RTCP::FeedbackRtpNackPacket* nackPacket = - static_cast(packet); + static_cast(packet); rtpSender->ReceiveNack(nackPacket); } else { - MS_WARN_TAG(rtcp, - "no RtpSender found for received NACK Feedback packet " - "[sender_ssrc:%" PRIu32 ", media_ssrc:%" PRIu32 "]", - feedback->GetMediaSsrc(), feedback->GetMediaSsrc()); + MS_WARN_TAG( + rtcp, + "no RtpSender found for received NACK Feedback packet " + "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", + feedback->GetMediaSsrc(), + feedback->GetMediaSsrc()); } break; @@ -968,11 +967,13 @@ namespace RTC case RTCP::FeedbackRtp::MessageType::EXT: default: { - MS_WARN_TAG(rtcp, - "ignoring unsupported %s Feedback packet " - "[sender_ssrc:%" PRIu32 ", media_ssrc:%" PRIu32 "]", - RTCP::FeedbackRtpPacket::MessageType2String(feedback->GetMessageType()).c_str(), - feedback->GetMediaSsrc(), feedback->GetMediaSsrc()); + MS_WARN_TAG( + rtcp, + "ignoring unsupported %s Feedback packet " + "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", + RTCP::FeedbackRtpPacket::MessageType2String(feedback->GetMessageType()).c_str(), + feedback->GetMediaSsrc(), + feedback->GetMediaSsrc()); break; } @@ -981,11 +982,12 @@ namespace RTC break; } - /* RTCP coming from a remote sender which must be forwarded to the corresponding remote receivers. */ + /* RTCP coming from a remote sender which must be forwarded to the corresponding remote + * receivers. */ case RTCP::Type::SR: { - RTCP::SenderReportPacket* sr = static_cast(packet); + RTCP::SenderReportPacket* sr = static_cast(packet); RTCP::SenderReportPacket::Iterator it = sr->Begin(); // Even if Sender Report packet can only contain one report.. @@ -1001,9 +1003,10 @@ namespace RTC } else { - MS_WARN_TAG(rtcp, - "no RtpReceiver found for received Sender Report [ssrc:%" PRIu32 "]", - report->GetSsrc()); + MS_WARN_TAG( + rtcp, + "no RtpReceiver found for received Sender Report [ssrc:%" PRIu32 "]", + report->GetSsrc()); } } @@ -1012,7 +1015,7 @@ namespace RTC case RTCP::Type::SDES: { - RTCP::SdesPacket* sdes = static_cast(packet); + RTCP::SdesPacket* sdes = static_cast(packet); RTCP::SdesPacket::Iterator it = sdes->Begin(); for (; it != sdes->End(); ++it) @@ -1023,8 +1026,8 @@ namespace RTC if (!rtpReceiver) { - MS_WARN_TAG(rtcp, "no RtpReceiver for received SDES chunk [ssrc:%" PRIu32 "]", - chunk->GetSsrc()); + MS_WARN_TAG( + rtcp, "no RtpReceiver for received SDES chunk [ssrc:%" PRIu32 "]", chunk->GetSsrc()); } } @@ -1040,8 +1043,8 @@ namespace RTC default: { - MS_WARN_TAG(rtcp, "unhandled RTCP type received [type:%" PRIu8 "]", - (uint8_t)packet->GetType()); + MS_WARN_TAG( + rtcp, "unhandled RTCP type received [type:%" PRIu8 "]", (uint8_t)packet->GetType()); } } @@ -1081,8 +1084,8 @@ namespace RTC void Peer::onTimer(Timer* timer) { - uint64_t interval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS; - uint32_t now = DepLibUV::GetTime(); + uint64_t interval = RTC::RTCP::maxVideoIntervalMs; + uint32_t now = DepLibUV::GetTime(); this->SendRtcp(now); @@ -1104,8 +1107,8 @@ namespace RTC if (rate) interval = 360000 / rate; - if (interval > RTC::RTCP::MAX_VIDEO_INTERVAL_MS) - interval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS; + if (interval > RTC::RTCP::maxVideoIntervalMs) + interval = RTC::RTCP::maxVideoIntervalMs; } /* diff --git a/worker/src/RTC/RTCP/Bye.cpp b/worker/src/RTC/RTCP/Bye.cpp index 06cc2009d0..36dcbfc165 100644 --- a/worker/src/RTC/RTCP/Bye.cpp +++ b/worker/src/RTC/RTCP/Bye.cpp @@ -2,99 +2,102 @@ // #define MS_LOG_DEV #include "RTC/RTCP/Bye.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - ByePacket* ByePacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ + + ByePacket* ByePacket::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); - // Get the header. - Packet::CommonHeader* header = (Packet::CommonHeader*)data; + // Get the header. + Packet::CommonHeader* header = (Packet::CommonHeader*)data; - std::unique_ptr packet(new ByePacket()); + std::unique_ptr packet(new ByePacket()); - size_t offset = sizeof(Packet::CommonHeader); + size_t offset = sizeof(Packet::CommonHeader); - uint8_t count = header->count; - while ((count--) && (len - offset > 0)) - { - if (sizeof(uint32_t) > len-offset) + uint8_t count = header->count; + while ((count--) && (len - offset > 0)) { - MS_WARN_TAG(rtcp, "not enough space for SSRC in RTCP Bye message"); + if (sizeof(uint32_t) > len - offset) + { + MS_WARN_TAG(rtcp, "not enough space for SSRC in RTCP Bye message"); - return nullptr; - } + return nullptr; + } - packet->AddSsrc(Utils::Byte::Get4Bytes(data, offset)); - offset += sizeof(uint32_t); - } + packet->AddSsrc(Utils::Byte::Get4Bytes(data, offset)); + offset += sizeof(uint32_t); + } - if (len - offset > 0) - { - size_t length = size_t(Utils::Byte::Get1Byte(data, offset)); - offset += sizeof(uint8_t); - if (length <= len-offset) + if (len - offset > 0) { - packet->SetReason(std::string((char*)data+offset, length)); + size_t length = size_t(Utils::Byte::Get1Byte(data, offset)); + offset += sizeof(uint8_t); + if (length <= len - offset) + { + packet->SetReason(std::string((char*)data + offset, length)); + } } + + return packet.release(); } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + size_t ByePacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t ByePacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t offset = Packet::Serialize(buffer); + + // SSRCs. + for (auto ssrc : this->ssrcs) + { + Utils::Byte::Set4Bytes(buffer, offset, ssrc); + offset += sizeof(uint32_t); + } - size_t offset = Packet::Serialize(buffer); + if (!this->reason.empty()) + { + // Length field. + Utils::Byte::Set1Byte(buffer, offset, this->reason.length()); + offset += sizeof(uint8_t); - // SSRCs. - for (auto ssrc : this->ssrcs) - { - Utils::Byte::Set4Bytes(buffer, offset, ssrc); - offset += sizeof(uint32_t); - } + // Reason field. + std::memcpy(buffer + offset, this->reason.c_str(), this->reason.length()); + offset += this->reason.length(); + } - if (!this->reason.empty()) - { - // Length field. - Utils::Byte::Set1Byte(buffer, offset, this->reason.length()); - offset += sizeof(uint8_t); + // 32 bits padding. + size_t padding = (-offset) & 3; + for (size_t i = 0; i < padding; ++i) + { + buffer[offset + i] = 0; + } - // Reason field. - std::memcpy(buffer+offset, this->reason.c_str(), this->reason.length()); - offset += this->reason.length(); + return offset + padding; } - // 32 bits padding. - size_t padding = (-offset) & 3; - for (size_t i = 0; i < padding; ++i) + void ByePacket::Dump() const { - buffer[offset+i] = 0; - } - - return offset+padding; - } - - void ByePacket::Dump() const - { - MS_TRACE(); + MS_TRACE(); - MS_DUMP(""); - for (auto ssrc : this->ssrcs) - { - MS_DUMP(" ssrc : %" PRIu32, ssrc); + MS_DUMP(""); + for (auto ssrc : this->ssrcs) + { + MS_DUMP(" ssrc : %" PRIu32, ssrc); + } + if (!this->reason.empty()) + MS_DUMP(" reason : %s", this->reason.c_str()); + MS_DUMP(""); } - if (!this->reason.empty()) - MS_DUMP(" reason : %s", this->reason.c_str()); - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RTCP/CompoundPacket.cpp b/worker/src/RTC/RTCP/CompoundPacket.cpp index 3495fcfcf3..2ff160f6ab 100644 --- a/worker/src/RTC/RTCP/CompoundPacket.cpp +++ b/worker/src/RTC/RTCP/CompoundPacket.cpp @@ -4,102 +4,110 @@ #include "RTC/RTCP/CompoundPacket.hpp" #include "Logger.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Instance methods. */ - - void CompoundPacket::Serialize(uint8_t* data) + namespace RTCP { - MS_TRACE(); - - this->header = data; + /* Instance methods. */ - // Calculate the total required size for the entire message. - if (this->senderReportPacket.GetCount()) + void CompoundPacket::Serialize(uint8_t* data) { - this->size = this->senderReportPacket.GetSize(); + MS_TRACE(); - if (this->receiverReportPacket.GetCount()) - this->size += sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount(); - } - // If no sender nor receiver reports are present send an empty Receiver Report - // packet as the head of the compound packet. - else - { - this->size = this->receiverReportPacket.GetSize(); - } + this->header = data; - if (this->sdesPacket.GetCount()) - this->size += this->sdesPacket.GetSize(); + // Calculate the total required size for the entire message. + if (this->senderReportPacket.GetCount()) + { + this->size = this->senderReportPacket.GetSize(); - // Fill it. - size_t offset = 0; + if (this->receiverReportPacket.GetCount()) + { + this->size += sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount(); + } + } + // If no sender nor receiver reports are present send an empty Receiver Report + // packet as the head of the compound packet. + else + { + this->size = this->receiverReportPacket.GetSize(); + } - if (this->senderReportPacket.GetCount()) - { - this->senderReportPacket.Serialize(this->header); - offset = this->senderReportPacket.GetSize(); + if (this->sdesPacket.GetCount()) + this->size += this->sdesPacket.GetSize(); - // Fix header count field. - Packet::CommonHeader* header = reinterpret_cast(this->header); - header->count = 0; + // Fill it. + size_t offset = 0; - if (this->receiverReportPacket.GetCount()) + if (this->senderReportPacket.GetCount()) { - // Fix header length field. - size_t length = ((sizeof(SenderReport::Header) + (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount())) / 4); - - header->length = htons(length); + this->senderReportPacket.Serialize(this->header); + offset = this->senderReportPacket.GetSize(); // Fix header count field. - header->count = this->receiverReportPacket.GetCount(); + Packet::CommonHeader* header = reinterpret_cast(this->header); + header->count = 0; - ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin(); - for (; it != this->receiverReportPacket.End(); ++it) + if (this->receiverReportPacket.GetCount()) { - ReceiverReport* report = (*it); + // Fix header length field. + size_t length = + ((sizeof(SenderReport::Header) + + (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount())) / + 4); - report->Serialize(this->header + offset); - offset += sizeof(ReceiverReport::Header); + header->length = htons(length); + + // Fix header count field. + header->count = this->receiverReportPacket.GetCount(); + + ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin(); + for (; it != this->receiverReportPacket.End(); ++it) + { + ReceiverReport* report = (*it); + + report->Serialize(this->header + offset); + offset += sizeof(ReceiverReport::Header); + } } } - } - else - { - this->receiverReportPacket.Serialize(this->header); - offset = this->receiverReportPacket.GetSize(); - } + else + { + this->receiverReportPacket.Serialize(this->header); + offset = this->receiverReportPacket.GetSize(); + } - if (this->sdesPacket.GetCount()) - this->sdesPacket.Serialize(this->header + offset); - } + if (this->sdesPacket.GetCount()) + this->sdesPacket.Serialize(this->header + offset); + } - void CompoundPacket::Dump() const - { - MS_TRACE(); + void CompoundPacket::Dump() const + { + MS_TRACE(); - MS_DUMP(""); + MS_DUMP(""); - if (this->senderReportPacket.GetCount()) - { - this->senderReportPacket.Dump(); + if (this->senderReportPacket.GetCount()) + { + this->senderReportPacket.Dump(); - if (this->receiverReportPacket.GetCount()) + if (this->receiverReportPacket.GetCount()) + this->receiverReportPacket.Dump(); + } + else this->receiverReportPacket.Dump(); - } - else - this->receiverReportPacket.Dump(); - if (this->sdesPacket.GetCount()) - this->sdesPacket.Dump(); + if (this->sdesPacket.GetCount()) + this->sdesPacket.Dump(); - MS_DUMP(""); - } + MS_DUMP(""); + } - void CompoundPacket::AddSenderReport(SenderReport* report) - { - MS_ASSERT(this->senderReportPacket.GetCount() == 0, "a sender report is already present"); + void CompoundPacket::AddSenderReport(SenderReport* report) + { + MS_ASSERT(this->senderReportPacket.GetCount() == 0, "a sender report is already present"); - this->senderReportPacket.AddReport(report); + this->senderReportPacket.AddReport(report); + } } -}} +} diff --git a/worker/src/RTC/RTCP/Feedback.cpp b/worker/src/RTC/RTCP/Feedback.cpp index b8c89d009d..dc96de0faa 100644 --- a/worker/src/RTC/RTCP/Feedback.cpp +++ b/worker/src/RTC/RTCP/Feedback.cpp @@ -3,260 +3,268 @@ #include "RTC/RTCP/Feedback.hpp" // Feedback RTP. +#include "RTC/RTCP/FeedbackRtpEcn.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp" -#include "RTC/RTCP/FeedbackRtpTmmb.hpp" #include "RTC/RTCP/FeedbackRtpSrReq.hpp" #include "RTC/RTCP/FeedbackRtpTllei.hpp" -#include "RTC/RTCP/FeedbackRtpEcn.hpp" +#include "RTC/RTCP/FeedbackRtpTmmb.hpp" // Feedback PS. +#include "Logger.hpp" +#include "Utils.hpp" +#include "RTC/RTCP/FeedbackPsAfb.hpp" +#include "RTC/RTCP/FeedbackPsFir.hpp" +#include "RTC/RTCP/FeedbackPsLei.hpp" #include "RTC/RTCP/FeedbackPsPli.hpp" -#include "RTC/RTCP/FeedbackPsSli.hpp" #include "RTC/RTCP/FeedbackPsRpsi.hpp" -#include "RTC/RTCP/FeedbackPsFir.hpp" +#include "RTC/RTCP/FeedbackPsSli.hpp" #include "RTC/RTCP/FeedbackPsTst.hpp" #include "RTC/RTCP/FeedbackPsVbcm.hpp" -#include "RTC/RTCP/FeedbackPsLei.hpp" -#include "RTC/RTCP/FeedbackPsAfb.hpp" -#include "Utils.hpp" -#include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - template - const std::string& FeedbackPacket::MessageType2String(typename T::MessageType type) + namespace RTCP { - static const std::string unknown("UNKNOWN"); - - if (FeedbackPacket::type2String.find(type) == FeedbackPacket::type2String.end()) - return unknown; + /* Class methods. */ - return FeedbackPacket::type2String[type]; - } - - /* Instance methods. */ - - template - FeedbackPacket::FeedbackPacket(CommonHeader* commonHeader): - Packet(RTCP::Type(commonHeader->packet_type)), - messageType(typename T::MessageType(commonHeader->count)) - { - this->header = reinterpret_cast(reinterpret_cast(commonHeader) + sizeof(CommonHeader)); - } + template + const std::string& FeedbackPacket::MessageType2String(typename T::MessageType type) + { + static const std::string unknown("UNKNOWN"); - template - FeedbackPacket::FeedbackPacket(typename T::MessageType messageType, uint32_t sender_ssrc, uint32_t media_ssrc): - Packet(RtcpType), - messageType(messageType) - { - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); - this->header->s_ssrc = htonl(sender_ssrc); - this->header->m_ssrc = htonl(media_ssrc); - } + if (FeedbackPacket::type2String.find(type) == FeedbackPacket::type2String.end()) + return unknown; - template - FeedbackPacket::~FeedbackPacket() - { - if (this->raw) - delete this->raw; - } - - /* Instance methods. */ + return FeedbackPacket::type2String[type]; + } - template - size_t FeedbackPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + /* Instance methods. */ - size_t offset = Packet::Serialize(buffer); + template + FeedbackPacket::FeedbackPacket(CommonHeader* commonHeader) + : Packet(RTCP::Type(commonHeader->packetType)) + , messageType(typename T::MessageType(commonHeader->count)) + { + this->header = + reinterpret_cast(reinterpret_cast(commonHeader) + sizeof(CommonHeader)); + } - // Copy the header. - std::memcpy(buffer+offset, this->header, sizeof(Header)); + template + FeedbackPacket::FeedbackPacket( + typename T::MessageType messageType, uint32_t senderSsrc, uint32_t mediaSsrc) + : Packet(RtcpType) + , messageType(messageType) + { + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); + this->header->senderSsrc = htonl(senderSsrc); + this->header->mediaSsrc = htonl(mediaSsrc); + } - return offset + sizeof(Header); - } + template + FeedbackPacket::~FeedbackPacket() + { + if (this->raw) + delete this->raw; + } - template - void FeedbackPacket::Dump() const - { - MS_TRACE(); + /* Instance methods. */ - MS_DUMP(" sender ssrc : %" PRIu32, (uint32_t)ntohl(this->header->s_ssrc)); - MS_DUMP(" media ssrc : %" PRIu32, (uint32_t)ntohl(this->header->m_ssrc)); - MS_DUMP(" size : %zu", this->GetSize()); - } + template + size_t FeedbackPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - /* Specialization for Ps class. */ + size_t offset = Packet::Serialize(buffer); - template<> - Type FeedbackPacket::RtcpType = RTCP::Type::PSFB; + // Copy the header. + std::memcpy(buffer + offset, this->header, sizeof(Header)); - template<> - std::map FeedbackPacket::type2String = - { - { FeedbackPs::MessageType::PLI, "PLI" }, - { FeedbackPs::MessageType::SLI, "SLI" }, - { FeedbackPs::MessageType::RPSI, "RPSI" }, - { FeedbackPs::MessageType::FIR, "FIR" }, - { FeedbackPs::MessageType::TSTR, "TSTR" }, - { FeedbackPs::MessageType::TSTN, "TSTN" }, - { FeedbackPs::MessageType::VBCM, "VBCM" }, - { FeedbackPs::MessageType::PSLEI, "PSLEI" }, - { FeedbackPs::MessageType::ROI, "ROI" }, - { FeedbackPs::MessageType::AFB, "AFB" }, - { FeedbackPs::MessageType::EXT, "EXT" } - }; - - template<> - FeedbackPacket* FeedbackPacket::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + return offset + sizeof(Header); + } - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + template + void FeedbackPacket::Dump() const { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; + MS_DUMP(" sender ssrc : %" PRIu32, GetSenderSsrc()); + MS_DUMP(" media ssrc : %" PRIu32, GetMediaSsrc()); + MS_DUMP(" size : %zu", this->GetSize()); } - CommonHeader* commonHeader = const_cast(reinterpret_cast(data)); - FeedbackPsPacket* packet = nullptr; - - switch (FeedbackPs::MessageType(commonHeader->count)) + /* Specialization for Ps class. */ + + template<> + Type FeedbackPacket::RtcpType = RTCP::Type::PSFB; + + template<> + std::map FeedbackPacket::type2String = { + {FeedbackPs::MessageType::PLI, "PLI"}, + {FeedbackPs::MessageType::SLI, "SLI"}, + {FeedbackPs::MessageType::RPSI, "RPSI"}, + {FeedbackPs::MessageType::FIR, "FIR"}, + {FeedbackPs::MessageType::TSTR, "TSTR"}, + {FeedbackPs::MessageType::TSTN, "TSTN"}, + {FeedbackPs::MessageType::VBCM, "VBCM"}, + {FeedbackPs::MessageType::PSLEI, "PSLEI"}, + {FeedbackPs::MessageType::ROI, "ROI"}, + {FeedbackPs::MessageType::AFB, "AFB"}, + {FeedbackPs::MessageType::EXT, "EXT"}}; + + template<> + FeedbackPacket* FeedbackPacket::Parse(const uint8_t* data, size_t len) { - case FeedbackPs::MessageType::PLI: - packet = FeedbackPsPliPacket::Parse(data, len); - break; - - case FeedbackPs::MessageType::SLI: - packet = FeedbackPsSliPacket::Parse(data, len); - break; - - case FeedbackPs::MessageType::RPSI: - packet = FeedbackPsRpsiPacket::Parse(data, len); - break; - - case FeedbackPs::MessageType::FIR: - packet = FeedbackPsFirPacket::Parse(data, len); - break; - - case FeedbackPs::MessageType::TSTR: - packet = FeedbackPsTstrPacket::Parse(data, len); - break; - - case FeedbackPs::MessageType::TSTN: - packet = FeedbackPsTstnPacket::Parse(data, len); - break; + MS_TRACE(); - case FeedbackPs::MessageType::VBCM: - packet = FeedbackPsVbcmPacket::Parse(data, len); - break; + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - case FeedbackPs::MessageType::PSLEI: - packet = FeedbackPsLeiPacket::Parse(data, len); - break; + return nullptr; + } - case FeedbackPs::MessageType::ROI: - break; + CommonHeader* commonHeader = + const_cast(reinterpret_cast(data)); + FeedbackPsPacket* packet = nullptr; - case FeedbackPs::MessageType::AFB: + switch (FeedbackPs::MessageType(commonHeader->count)) { - packet = FeedbackPsAfbPacket::Parse(data, len); - break; + case FeedbackPs::MessageType::PLI: + packet = FeedbackPsPliPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::SLI: + packet = FeedbackPsSliPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::RPSI: + packet = FeedbackPsRpsiPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::FIR: + packet = FeedbackPsFirPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::TSTR: + packet = FeedbackPsTstrPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::TSTN: + packet = FeedbackPsTstnPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::VBCM: + packet = FeedbackPsVbcmPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::PSLEI: + packet = FeedbackPsLeiPacket::Parse(data, len); + break; + + case FeedbackPs::MessageType::ROI: + break; + + case FeedbackPs::MessageType::AFB: + { + packet = FeedbackPsAfbPacket::Parse(data, len); + break; + } + + case FeedbackPs::MessageType::EXT: + break; + + default: + MS_WARN_TAG( + rtcp, + "unknown RTCP PS Feedback message type [packetType:%" PRIu8 "]", + commonHeader->count); } - case FeedbackPs::MessageType::EXT: - break; - - default: - MS_WARN_TAG(rtcp, "unknown RTCP PS Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count); + return packet; } - return packet; - } + /* Specialization for Rtcp class. */ - /* Specialization for Rtcp class. */ + template<> + Type FeedbackPacket::RtcpType = RTCP::Type::RTPFB; - template<> - Type FeedbackPacket::RtcpType = RTCP::Type::RTPFB; + template<> + std::map FeedbackPacket::type2String = { + {FeedbackRtp::MessageType::NACK, "NACK"}, + {FeedbackRtp::MessageType::TMMBR, "TMMBR"}, + {FeedbackRtp::MessageType::TMMBN, "TMMBN"}, + {FeedbackRtp::MessageType::SR_REQ, "SR_REQ"}, + {FeedbackRtp::MessageType::RAMS, "RAMS"}, + {FeedbackRtp::MessageType::TLLEI, "TLLEI"}, + {FeedbackRtp::MessageType::ECN, "ECN"}, + {FeedbackRtp::MessageType::PS, "PS"}, + {FeedbackRtp::MessageType::EXT, "EXT"}}; - template<> - std::map FeedbackPacket::type2String = - { - { FeedbackRtp::MessageType::NACK, "NACK" }, - { FeedbackRtp::MessageType::TMMBR, "TMMBR" }, - { FeedbackRtp::MessageType::TMMBN, "TMMBN" }, - { FeedbackRtp::MessageType::SR_REQ, "SR_REQ" }, - { FeedbackRtp::MessageType::RAMS, "RAMS" }, - { FeedbackRtp::MessageType::TLLEI, "TLLEI" }, - { FeedbackRtp::MessageType::ECN, "ECN" }, - { FeedbackRtp::MessageType::PS, "PS" }, - { FeedbackRtp::MessageType::EXT, "EXT" } - }; - - /* Class methods. */ - - template<> - FeedbackPacket* FeedbackPacket::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + template<> + FeedbackPacket* FeedbackPacket::Parse(const uint8_t* data, size_t len) { + MS_TRACE(); + + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); return nullptr; - } + } - CommonHeader* commonHeader = (CommonHeader*)data; - FeedbackRtpPacket* packet = nullptr; + CommonHeader* commonHeader = (CommonHeader*)data; + FeedbackRtpPacket* packet = nullptr; - switch (FeedbackRtp::MessageType(commonHeader->count)) - { - case FeedbackRtp::MessageType::NACK: - packet = FeedbackRtpNackPacket::Parse(data, len); - break; + switch (FeedbackRtp::MessageType(commonHeader->count)) + { + case FeedbackRtp::MessageType::NACK: + packet = FeedbackRtpNackPacket::Parse(data, len); + break; + + case FeedbackRtp::MessageType::TMMBR: + packet = FeedbackRtpTmmbrPacket::Parse(data, len); + break; - case FeedbackRtp::MessageType::TMMBR: - packet = FeedbackRtpTmmbrPacket::Parse(data, len); - break; + case FeedbackRtp::MessageType::TMMBN: + packet = FeedbackRtpTmmbnPacket::Parse(data, len); + break; - case FeedbackRtp::MessageType::TMMBN: - packet = FeedbackRtpTmmbnPacket::Parse(data, len); - break; + case FeedbackRtp::MessageType::SR_REQ: + packet = FeedbackRtpSrReqPacket::Parse(data, len); + break; - case FeedbackRtp::MessageType::SR_REQ: - packet = FeedbackRtpSrReqPacket::Parse(data, len); - break; + case FeedbackRtp::MessageType::RAMS: + break; - case FeedbackRtp::MessageType::RAMS: - break; + case FeedbackRtp::MessageType::TLLEI: + packet = FeedbackRtpTlleiPacket::Parse(data, len); + break; - case FeedbackRtp::MessageType::TLLEI: - packet = FeedbackRtpTlleiPacket::Parse(data, len); - break; + case FeedbackRtp::MessageType::ECN: + packet = FeedbackRtpEcnPacket::Parse(data, len); + break; - case FeedbackRtp::MessageType::ECN: - packet = FeedbackRtpEcnPacket::Parse(data, len); - break; + case FeedbackRtp::MessageType::PS: + break; - case FeedbackRtp::MessageType::PS: - break; + case FeedbackRtp::MessageType::EXT: + break; - case FeedbackRtp::MessageType::EXT: - break; + default: + MS_WARN_TAG( + rtcp, + "unknown RTCP RTP Feedback message type [packetType:%" PRIu8 "]", + commonHeader->count); + } - default: - MS_WARN_TAG(rtcp, "unknown RTCP RTP Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count); + return packet; } - return packet; + // Explicit instantiation to have all FeedbackPacket definitions in this file. + template class FeedbackPacket; + template class FeedbackPacket; } - - // Explicit instantiation to have all FeedbackPacket definitions in this file. - template class FeedbackPacket; - template class FeedbackPacket; -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPs.cpp b/worker/src/RTC/RTCP/FeedbackPs.cpp index 2d447e8fb3..83ede86314 100644 --- a/worker/src/RTC/RTCP/FeedbackPs.cpp +++ b/worker/src/RTC/RTCP/FeedbackPs.cpp @@ -2,90 +2,96 @@ // #define MS_LOG_DEV #include "RTC/RTCP/FeedbackPs.hpp" -#include "RTC/RTCP/FeedbackPsSli.hpp" -#include "RTC/RTCP/FeedbackPsRpsi.hpp" +#include "Logger.hpp" #include "RTC/RTCP/FeedbackPsFir.hpp" +#include "RTC/RTCP/FeedbackPsLei.hpp" +#include "RTC/RTCP/FeedbackPsRpsi.hpp" +#include "RTC/RTCP/FeedbackPsSli.hpp" #include "RTC/RTCP/FeedbackPsTst.hpp" #include "RTC/RTCP/FeedbackPsVbcm.hpp" -#include "RTC/RTCP/FeedbackPsLei.hpp" -#include "Logger.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - template - FeedbackPsItemsPacket* FeedbackPsItemsPacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + template + FeedbackPsItemsPacket* FeedbackPsItemsPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + + return nullptr; + } - CommonHeader* commonHeader = const_cast(reinterpret_cast(data)); - std::unique_ptr> packet(new FeedbackPsItemsPacket(commonHeader)); + CommonHeader* commonHeader = + const_cast(reinterpret_cast(data)); - size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); + std::unique_ptr> packet( + new FeedbackPsItemsPacket(commonHeader)); - while (len - offset > 0) - { - Item* item = Item::Parse(data+offset, len-offset); + size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); - if (item) - { - packet->AddItem(item); - offset += item->GetSize(); - } - else + while (len - offset > 0) { - break; + Item* item = Item::Parse(data + offset, len - offset); + + if (item) + { + packet->AddItem(item); + offset += item->GetSize(); + } + else + { + break; + } } + + return packet.release(); } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + template + size_t FeedbackPsItemsPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - template - size_t FeedbackPsItemsPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t offset = FeedbackPacket::Serialize(buffer); - size_t offset = FeedbackPacket::Serialize(buffer); + for (auto item : this->items) + { + offset += item->Serialize(buffer + offset); + } - for (auto item : this->items) - { - offset += item->Serialize(buffer + offset); + return offset; } - return offset; - } - - template - void FeedbackPsItemsPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP("<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str()); - FeedbackPsPacket::Dump(); - for (auto item : this->items) + template + void FeedbackPsItemsPacket::Dump() const { - item->Dump(); + MS_TRACE(); + + MS_DUMP("<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str()); + FeedbackPsPacket::Dump(); + for (auto item : this->items) + { + item->Dump(); + } + MS_DUMP("", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str()); } - MS_DUMP("", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str()); - } - // explicit instantiation to have all FeedbackRtpPacket definitions in this file. - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; - template class FeedbackPsItemsPacket; -}} + // explicit instantiation to have all FeedbackRtpPacket definitions in this file. + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + template class FeedbackPsItemsPacket; + } +} diff --git a/worker/src/RTC/RTCP/FeedbackPsAfb.cpp b/worker/src/RTC/RTCP/FeedbackPsAfb.cpp index 40a97459b3..1866657c6c 100644 --- a/worker/src/RTC/RTCP/FeedbackPsAfb.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsAfb.cpp @@ -2,61 +2,66 @@ // #define MS_LOG_DEV #include "RTC/RTCP/FeedbackPsAfb.hpp" -#include "RTC/RTCP/FeedbackPsRemb.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" +#include "RTC/RTCP/FeedbackPsRemb.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsAfbPacket* FeedbackPsAfbPacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + FeedbackPsAfbPacket* FeedbackPsAfbPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - CommonHeader* commonHeader = const_cast(reinterpret_cast(data)); + return nullptr; + } - std::unique_ptr packet; + CommonHeader* commonHeader = + const_cast(reinterpret_cast(data)); - constexpr size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); - if (Utils::Byte::Get4Bytes(data, offset) == FeedbackPsRembPacket::UniqueIdentifier) - { - packet.reset(FeedbackPsRembPacket::Parse(data, len)); - } + std::unique_ptr packet; - else { - packet.reset(new FeedbackPsAfbPacket(commonHeader)); - } + constexpr size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); + if (Utils::Byte::Get4Bytes(data, offset) == FeedbackPsRembPacket::UniqueIdentifier) + { + packet.reset(FeedbackPsRembPacket::Parse(data, len)); + } - return packet.release(); - } + else + { + packet.reset(new FeedbackPsAfbPacket(commonHeader)); + } - size_t FeedbackPsAfbPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + return packet.release(); + } - size_t offset = FeedbackPsPacket::Serialize(buffer); + size_t FeedbackPsAfbPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - // Copy the content. - std::memcpy(buffer+offset, this->data, this->size); + size_t offset = FeedbackPsPacket::Serialize(buffer); - return offset + this->size; - } + // Copy the content. + std::memcpy(buffer + offset, this->data, this->size); - void FeedbackPsAfbPacket::Dump() const - { - MS_TRACE(); + return offset + this->size; + } + + void FeedbackPsAfbPacket::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - FeedbackPsPacket::Dump(); - MS_DUMP(""); + MS_DUMP(""); + FeedbackPsPacket::Dump(); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsFir.cpp b/worker/src/RTC/RTCP/FeedbackPsFir.cpp index 5286aee92a..6da11b4c12 100644 --- a/worker/src/RTC/RTCP/FeedbackPsFir.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsFir.cpp @@ -6,59 +6,62 @@ #include #include // std::memset() -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsFirItem* FeedbackPsFirItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header. - if (sizeof(Header) > len) + FeedbackPsFirItem* FeedbackPsFirItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Fir item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Fir item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackPsFirItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - /* Instance methods. */ + return new FeedbackPsFirItem(header); + } - FeedbackPsFirItem::FeedbackPsFirItem(uint32_t ssrc, uint8_t sequence_number) - { - MS_TRACE(); + /* Instance methods. */ - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); + FeedbackPsFirItem::FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber) + { + MS_TRACE(); - // Set reserved bits to zero. - std::memset(this->header, 0, sizeof(Header)); + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); - this->header->ssrc = htonl(ssrc); - this->header->sequence_number = sequence_number; - } + // Set reserved bits to zero. + std::memset(this->header, 0, sizeof(Header)); - size_t FeedbackPsFirItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->header->ssrc = htonl(ssrc); + this->header->sequenceNumber = sequenceNumber; + } - std::memcpy(buffer, this->header, sizeof(Header)); + size_t FeedbackPsFirItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - return sizeof(Header); - } + std::memcpy(buffer, this->header, sizeof(Header)); - void FeedbackPsFirItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } + + void FeedbackPsFirItem::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber()); - MS_DUMP(""); + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsLei.cpp b/worker/src/RTC/RTCP/FeedbackPsLei.cpp index ef4854f2c7..0da95b33b8 100644 --- a/worker/src/RTC/RTCP/FeedbackPsLei.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsLei.cpp @@ -5,53 +5,56 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsLeiItem* FeedbackPsLeiItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackPsLeiItem* FeedbackPsLeiItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for PsLei item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for PsLei item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackPsLeiItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - /* Instance methods. */ - FeedbackPsLeiItem::FeedbackPsLeiItem(uint32_t ssrc) - { - MS_TRACE(); + return new FeedbackPsLeiItem(header); + } - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); - this->header->ssrc = htonl(ssrc); - } + /* Instance methods. */ + FeedbackPsLeiItem::FeedbackPsLeiItem(uint32_t ssrc) + { + MS_TRACE(); - size_t FeedbackPsLeiItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); + this->header->ssrc = htonl(ssrc); + } - // Add minimum header. - std::memcpy(buffer, this->header, sizeof(Header)); + size_t FeedbackPsLeiItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - return sizeof(Header); - } + // Add minimum header. + std::memcpy(buffer, this->header, sizeof(Header)); - void FeedbackPsLeiItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } + + void FeedbackPsLeiItem::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(""); + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsPli.cpp b/worker/src/RTC/RTCP/FeedbackPsPli.cpp index 8bde7b7299..dd43d1aae8 100644 --- a/worker/src/RTC/RTCP/FeedbackPsPli.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsPli.cpp @@ -4,33 +4,38 @@ #include "RTC/RTCP/FeedbackPsPli.hpp" #include "Logger.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsPliPacket* FeedbackPsPliPacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + FeedbackPsPliPacket* FeedbackPsPliPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - CommonHeader* commonHeader = const_cast(reinterpret_cast(data)); - std::unique_ptr packet(new FeedbackPsPliPacket(commonHeader)); + return nullptr; + } - return packet.release(); - } + CommonHeader* commonHeader = + const_cast(reinterpret_cast(data)); - void FeedbackPsPliPacket::Dump() const - { - MS_TRACE(); + std::unique_ptr packet(new FeedbackPsPliPacket(commonHeader)); - MS_DUMP(""); - FeedbackPsPacket::Dump(); - MS_DUMP(""); + return packet.release(); + } + + void FeedbackPsPliPacket::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + FeedbackPsPacket::Dump(); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsRemb.cpp b/worker/src/RTC/RTCP/FeedbackPsRemb.cpp index a247d71146..7c65650bd0 100644 --- a/worker/src/RTC/RTCP/FeedbackPsRemb.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsRemb.cpp @@ -2,127 +2,141 @@ // #define MS_LOG_DEV #include "RTC/RTCP/FeedbackPsRemb.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class variables. */ - - uint32_t FeedbackPsRembPacket::UniqueIdentifier = 0x52454D42; + namespace RTCP + { + /* Class variables. */ - /* Class methods. */ + uint32_t FeedbackPsRembPacket::UniqueIdentifier = 0x52454D42; - FeedbackPsRembPacket* FeedbackPsRembPacket::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + FeedbackPsRembPacket* FeedbackPsRembPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - CommonHeader* commonHeader = const_cast(reinterpret_cast(data)); - std::unique_ptr packet(new FeedbackPsRembPacket(commonHeader)); + return nullptr; + } - if (!packet->IsCorrect()) - return nullptr; + CommonHeader* commonHeader = + const_cast(reinterpret_cast(data)); - return packet.release(); - } + std::unique_ptr packet(new FeedbackPsRembPacket(commonHeader)); - FeedbackPsRembPacket::FeedbackPsRembPacket(CommonHeader* commonHeader): - FeedbackPsAfbPacket(commonHeader, FeedbackPsAfbPacket::REMB) - { - uint8_t* data = reinterpret_cast(commonHeader+1); + if (!packet->IsCorrect()) + return nullptr; - if (Utils::Byte::Get4Bytes(data, 8) != UniqueIdentifier) - { - MS_WARN_TAG(rtcp, "invalid unique indentifier in REMB packet"); - this->isCorrect = false; - return; + return packet.release(); } - size_t numSsrcs = data[12]; - - uint8_t exponent = data[13] >> 2; - - uint64_t mantissa = (static_cast(data[13] & 0x03) << 16) | Utils::Byte::Get2Bytes(data, 14); - - this->bitrate = (mantissa << exponent); - if ((this->bitrate >> exponent) != mantissa) + FeedbackPsRembPacket::FeedbackPsRembPacket(CommonHeader* commonHeader) + : FeedbackPsAfbPacket(commonHeader, FeedbackPsAfbPacket::REMB) { - MS_WARN_TAG(rtcp, "invalid REMB bitrate value : %" PRIu64" *2^%u", mantissa, exponent); - this->isCorrect = false; - return; + uint8_t* data = reinterpret_cast(commonHeader + 1); + + if (Utils::Byte::Get4Bytes(data, 8) != UniqueIdentifier) + { + MS_WARN_TAG(rtcp, "invalid unique indentifier in REMB packet"); + this->isCorrect = false; + return; + } + + size_t numSsrcs = data[12]; + + uint8_t exponent = data[13] >> 2; + + uint64_t mantissa = + (static_cast(data[13] & 0x03) << 16) | Utils::Byte::Get2Bytes(data, 14); + + this->bitrate = (mantissa << exponent); + if ((this->bitrate >> exponent) != mantissa) + { + MS_WARN_TAG(rtcp, "invalid REMB bitrate value : %" PRIu64 " *2^%u", mantissa, exponent); + + this->isCorrect = false; + return; + } + + // Check length. + size_t len = (size_t)(ntohs(commonHeader->length) + 1) * 4; + if (len != sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) + sizeof(Header) + + (numSsrcs * sizeof(uint32_t))) + { + MS_WARN_TAG( + rtcp, + "invalid payload size: %zu for the given number of ssrcs: " + "%zu", + len, + numSsrcs); + + this->isCorrect = false; + return; + } + + size_t index = 16; + this->ssrcs.reserve(numSsrcs); + for (size_t n = 0; n < numSsrcs; ++n) + { + this->ssrcs.push_back(Utils::Byte::Get4Bytes(data, index)); + index += sizeof(uint32_t); + } } - // Check length. - size_t len = (size_t)(ntohs(commonHeader->length) + 1) * 4; - if (len != sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) + sizeof(Header) + (numSsrcs * sizeof(uint32_t))) + size_t FeedbackPsRembPacket::Serialize(uint8_t* buffer) { - MS_WARN_TAG(rtcp, "invalid payload size: %zu for the given number of ssrcs: %zu", len, numSsrcs); + MS_TRACE(); - this->isCorrect = false; - return; - } - - size_t index = 16; - this->ssrcs.reserve(numSsrcs); - for (size_t n=0; nssrcs.push_back(Utils::Byte::Get4Bytes(data, index)); - index += sizeof(uint32_t); - } - } + size_t offset = FeedbackPsPacket::Serialize(buffer); - size_t FeedbackPsRembPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + uint64_t mantissa = this->bitrate; + uint8_t exponent = 0; - size_t offset = FeedbackPsPacket::Serialize(buffer); + while (mantissa > 0x3FFFF /* max mantissa (18 bits) */) + { + mantissa >>= 1; + ++exponent; + } - uint64_t mantissa = this->bitrate; - uint8_t exponent = 0; + Utils::Byte::Set4Bytes(buffer, offset, UniqueIdentifier); + offset += sizeof(UniqueIdentifier); - while (mantissa > 0x3FFFF /* max mantissa (18 bits) */) { - mantissa >>= 1; - ++exponent; - } + buffer[offset] = this->ssrcs.size(); + offset += 1; - Utils::Byte::Set4Bytes(buffer, offset, UniqueIdentifier); - offset += sizeof(UniqueIdentifier); + buffer[offset] = (exponent << 2) | (mantissa >> 16); + offset += 1; - buffer[offset] = this->ssrcs.size(); - offset+=1; + Utils::Byte::Set2Bytes(buffer, offset, mantissa & 0xFFFF); + offset += 2; - buffer[offset] = (exponent << 2) | (mantissa >> 16); - offset+=1; + for (auto ssrc : this->ssrcs) + { + Utils::Byte::Set4Bytes(buffer, offset, ssrc); + offset += sizeof(ssrc); + } - Utils::Byte::Set2Bytes(buffer, offset, mantissa & 0xFFFF); - offset+=2; + return offset; + } - for (auto ssrc : this->ssrcs) + void FeedbackPsRembPacket::Dump() const { - Utils::Byte::Set4Bytes(buffer, offset, ssrc); - offset += sizeof(ssrc); + MS_TRACE(); + + MS_DUMP(""); + FeedbackPsPacket::Dump(); + MS_DUMP("\t bitrate (bps): %" PRIu64, this->bitrate); + for (auto ssrc : this->ssrcs) + MS_DUMP("\t ssrc: %" PRIu32, ssrc); + MS_DUMP(""); } - - return offset; - } - - void FeedbackPsRembPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - FeedbackPsPacket::Dump(); - MS_DUMP("\t bitrate (bps): %" PRIu64, this->bitrate); - for (auto ssrc : this->ssrcs) - MS_DUMP("\t ssrc: %" PRIu32, ssrc); - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp b/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp index 9108c44920..cd892250b2 100644 --- a/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp @@ -5,100 +5,105 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsRpsiItem* FeedbackPsRpsiItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header. - if (sizeof(Header) > len) + FeedbackPsRpsiItem* FeedbackPsRpsiItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Rpsi item, discarded"); - - return nullptr; - } + MS_TRACE(); - Header* header = const_cast(reinterpret_cast(data)); - std::unique_ptr item(new FeedbackPsRpsiItem(header)); + // data size must be >= header. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Rpsi item, discarded"); - if (item->IsCorrect()) - return item.release(); - else - return nullptr; - } + return nullptr; + } - /* Instance methods. */ + Header* header = const_cast(reinterpret_cast(data)); + std::unique_ptr item(new FeedbackPsRpsiItem(header)); - FeedbackPsRpsiItem::FeedbackPsRpsiItem(Header* header) - { - MS_TRACE(); + if (item->IsCorrect()) + return item.release(); + else + return nullptr; + } - this->header = header; + /* Instance methods. */ - // Calculate bit_string length. - if (this->header->padding_bits % 8 != 0) + FeedbackPsRpsiItem::FeedbackPsRpsiItem(Header* header) { - MS_WARN_TAG(rtcp, "invalid Rpsi packet with fractional padding bytes value"); + MS_TRACE(); - isCorrect = false; - } + this->header = header; - size_t paddingBytes = this->header->padding_bits / 8; + // Calculate bitString length. + if (this->header->paddingBits % 8 != 0) + { + MS_WARN_TAG(rtcp, "invalid Rpsi packet with fractional padding bytes value"); - if (paddingBytes > FeedbackPsRpsiItem::MaxBitStringSize) - { - MS_WARN_TAG(rtcp, "invalid Rpsi packet with too many padding bytes"); + isCorrect = false; + } - isCorrect = false; - } + size_t paddingBytes = this->header->paddingBits / 8; - this->length = FeedbackPsRpsiItem::MaxBitStringSize - paddingBytes; - } + if (paddingBytes > FeedbackPsRpsiItem::MaxBitStringSize) + { + MS_WARN_TAG(rtcp, "invalid Rpsi packet with too many padding bytes"); - FeedbackPsRpsiItem::FeedbackPsRpsiItem(uint8_t payload_type, uint8_t* bit_string, size_t length) - { - MS_TRACE(); + isCorrect = false; + } + + this->length = FeedbackPsRpsiItem::MaxBitStringSize - paddingBytes; + } - MS_ASSERT(payload_type <= 0x7f, "rpsi payload type exceeds the maximum value"); - MS_ASSERT(length <= FeedbackPsRpsiItem::MaxBitStringSize, "rpsi bit string length exceeds the maximum value"); + FeedbackPsRpsiItem::FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length) + { + MS_TRACE(); - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); + MS_ASSERT(payloadType <= 0x7f, "rpsi payload type exceeds the maximum value"); + MS_ASSERT( + length <= FeedbackPsRpsiItem::MaxBitStringSize, + "rpsi bit string length exceeds the maximum value"); - // 32 bits padding. - size_t padding = (-length) & 3; + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); - this->header->padding_bits = padding * 8; - this->header->zero = 0; - std::memcpy(this->header->bit_string, bit_string, length); + // 32 bits padding. + size_t padding = (-length) & 3; - // Fill padding. - for (size_t i = 0; i < padding; ++i) - { - this->raw[sizeof(Header)+i-1] = 0; + this->header->paddingBits = padding * 8; + this->header->zero = 0; + std::memcpy(this->header->bitString, bitString, length); + + // Fill padding. + for (size_t i = 0; i < padding; ++i) + { + this->raw[sizeof(Header) + i - 1] = 0; + } } - } - size_t FeedbackPsRpsiItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t FeedbackPsRpsiItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - std::memcpy(buffer, this->header, sizeof(Header)); + std::memcpy(buffer, this->header, sizeof(Header)); - return sizeof(Header); - } + return sizeof(Header); + } - void FeedbackPsRpsiItem::Dump() const - { - MS_TRACE(); + void FeedbackPsRpsiItem::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - MS_DUMP(" padding bits : %" PRIu8, this->header->padding_bits); - MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType()); - MS_DUMP(" length : %zu", this->GetLength()); - MS_DUMP(""); + MS_DUMP(""); + MS_DUMP(" padding bits : %" PRIu8, this->header->paddingBits); + MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType()); + MS_DUMP(" length : %zu", this->GetLength()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackPsSli.cpp b/worker/src/RTC/RTCP/FeedbackPsSli.cpp index d3dc0e5336..df0f87f848 100644 --- a/worker/src/RTC/RTCP/FeedbackPsSli.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsSli.cpp @@ -5,62 +5,64 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsSliItem* FeedbackPsSliItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackPsSliItem* FeedbackPsSliItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Sli item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Sli item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackPsSliItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - /* Instance methods. */ + return new FeedbackPsSliItem(header); + } - FeedbackPsSliItem::FeedbackPsSliItem(Header* header) - { - MS_TRACE(); + /* Instance methods. */ - this->header = header; + FeedbackPsSliItem::FeedbackPsSliItem(Header* header) + { + MS_TRACE(); - uint32_t compact = (uint32_t)ntohl(header->compact); + this->header = header; - this->first = compact >> 19; /* first 13 bits */ - this->number = (compact >> 6) & 0x1fff; /* next 13 bits */ - this->pictureId = compact & 0x3f; /* last 6 bits */ - } + uint32_t compact = (uint32_t)ntohl(header->compact); - size_t FeedbackPsSliItem::Serialize(uint8_t* buffer) - { - uint32_t compact = (this->first << 19) | (this->number << 6) | this->pictureId; - Header* header = reinterpret_cast(buffer); + this->first = compact >> 19; /* first 13 bits */ + this->number = (compact >> 6) & 0x1fff; /* next 13 bits */ + this->pictureId = compact & 0x3f; /* last 6 bits */ + } - header->compact = htonl(compact); - std::memcpy(buffer, header, sizeof(Header)); + size_t FeedbackPsSliItem::Serialize(uint8_t* buffer) + { + uint32_t compact = (this->first << 19) | (this->number << 6) | this->pictureId; + Header* header = reinterpret_cast(buffer); - return sizeof(Header); - } + header->compact = htonl(compact); + std::memcpy(buffer, header, sizeof(Header)); - void FeedbackPsSliItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } - MS_DUMP(""); - MS_DUMP(" first : %" PRIu16, this->first); - MS_DUMP(" number : %" PRIu16, this->number); - MS_DUMP(" picture id : %" PRIu8, this->pictureId); - MS_DUMP(""); - } -}} + void FeedbackPsSliItem::Dump() const + { + MS_TRACE(); + MS_DUMP(""); + MS_DUMP(" first : %" PRIu16, this->first); + MS_DUMP(" number : %" PRIu16, this->number); + MS_DUMP(" picture id : %" PRIu8, this->pictureId); + MS_DUMP(""); + } + } +} diff --git a/worker/src/RTC/RTCP/FeedbackPsTst.cpp b/worker/src/RTC/RTCP/FeedbackPsTst.cpp index 68f74e2ee8..d323fe8c62 100644 --- a/worker/src/RTC/RTCP/FeedbackPsTst.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsTst.cpp @@ -5,77 +5,82 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - template - FeedbackPsTstItem* FeedbackPsTstItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + template + FeedbackPsTstItem* FeedbackPsTstItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Tst item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Tst item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackPsTstItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - template - FeedbackPsTstItem::FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index) - { - MS_TRACE(); + return new FeedbackPsTstItem(header); + } - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); + template + FeedbackPsTstItem::FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index) + { + MS_TRACE(); - // Set reserved bits to zero. - std::memset(this->header, 0, sizeof(Header)); + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); - this->header->ssrc = htonl(ssrc); - this->header->sequence_number = sequenceNumber; - this->header->index = index; - } + // Set reserved bits to zero. + std::memset(this->header, 0, sizeof(Header)); - template - size_t FeedbackPsTstItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->header->ssrc = htonl(ssrc); + this->header->sequenceNumber = sequenceNumber; + this->header->index = index; + } - std::memcpy(buffer, this->header, sizeof(Header)); + template + size_t FeedbackPsTstItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - return sizeof(Header); - } + std::memcpy(buffer, this->header, sizeof(Header)); - template - void FeedbackPsTstItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber()); - MS_DUMP(" index : %" PRIu32, this->GetIndex()); - MS_DUMP(""); - } + template + void FeedbackPsTstItem::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber()); + MS_DUMP(" index : %" PRIu32, this->GetIndex()); + MS_DUMP(""); + } - /* Specialization for Tstr class. */ + /* Specialization for Tstr class. */ - template<> - const FeedbackPs::MessageType FeedbackPsTstItem::MessageType = FeedbackPs::MessageType::TSTR; + template<> + const FeedbackPs::MessageType FeedbackPsTstItem::MessageType = + FeedbackPs::MessageType::TSTR; - /* Specialization for Tstn class. */ + /* Specialization for Tstn class. */ - template<> - const FeedbackPs::MessageType FeedbackPsTstItem::MessageType = FeedbackPs::MessageType::TSTN; + template<> + const FeedbackPs::MessageType FeedbackPsTstItem::MessageType = + FeedbackPs::MessageType::TSTN; - // Explicit instantiation to have all definitions in this file. - template class FeedbackPsTstItem; - template class FeedbackPsTstItem; -}} + // Explicit instantiation to have all definitions in this file. + template class FeedbackPsTstItem; + template class FeedbackPsTstItem; + } +} diff --git a/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp b/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp index f9dba75f09..b8c6cfc493 100644 --- a/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp +++ b/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp @@ -5,72 +5,76 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackPsVbcmItem* FeedbackPsVbcmItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackPsVbcmItem* FeedbackPsVbcmItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Vbcm item, discarded"); + MS_TRACE(); + + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Vbcm item, discarded"); + + return nullptr; + } + + Header* header = const_cast(reinterpret_cast(data)); - return nullptr; + return new FeedbackPsVbcmItem(header); } - Header* header = const_cast(reinterpret_cast(data)); + /* Instance methods. */ + FeedbackPsVbcmItem::FeedbackPsVbcmItem( + uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value) + { + this->raw = new uint8_t[8 + length]; + this->header = reinterpret_cast(this->raw); + + this->header->ssrc = htonl(ssrc); + this->header->sequenceNumber = sequenceNumber; + this->header->zero = 0; + this->header->payloadType = payloadType; + this->header->length = htons(length); + std::memcpy(this->header->value, value, sizeof(length)); + } - return new FeedbackPsVbcmItem(header); - } + size_t FeedbackPsVbcmItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - /* Instance methods. */ - FeedbackPsVbcmItem::FeedbackPsVbcmItem(uint32_t ssrc, uint8_t sequence_number, uint8_t payload_type, uint16_t length, uint8_t* value) - { - this->raw = new uint8_t[8 + length]; - this->header = reinterpret_cast(this->raw); - - this->header->ssrc = htonl(ssrc); - this->header->sequence_number = sequence_number; - this->header->zero = 0; - this->header->payload_type = payload_type; - this->header->length = htons(length); - std::memcpy(this->header->value, value, sizeof(length)); - } + // Add minimum header. + std::memcpy(buffer, this->header, 8); - size_t FeedbackPsVbcmItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + // Copy the content. + std::memcpy(buffer + 8, this->header->value, this->header->length); - // Add minimum header. - std::memcpy(buffer, this->header, 8); + size_t offset = 8 + this->header->length; - // Copy the content. - std::memcpy(buffer+8, this->header->value, this->header->length); + // 32 bits padding. + size_t padding = (-offset) & 3; + for (size_t i = 0; i < padding; ++i) + { + buffer[offset + i] = 0; + } - size_t offset = 8+this->header->length; + return offset + padding; + } - // 32 bits padding. - size_t padding = (-offset) & 3; - for (size_t i = 0; i < padding; ++i) + void FeedbackPsVbcmItem::Dump() const { - buffer[offset+i] = 0; + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber()); + MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType()); + MS_DUMP(" length : %" PRIu16, this->GetLength()); + MS_DUMP(""); } - - return offset+padding; - } - - void FeedbackPsVbcmItem::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber()); - MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType()); - MS_DUMP(" length : %" PRIu16, this->GetLength()); - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackRtp.cpp b/worker/src/RTC/RTCP/FeedbackRtp.cpp index fadb81b8eb..43182befeb 100644 --- a/worker/src/RTC/RTCP/FeedbackRtp.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtp.cpp @@ -2,86 +2,90 @@ // #define MS_LOG_DEV #include "RTC/RTCP/FeedbackRtp.hpp" +#include "Logger.hpp" +#include "RTC/RTCP/FeedbackRtpEcn.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp" -#include "RTC/RTCP/FeedbackRtpTmmb.hpp" #include "RTC/RTCP/FeedbackRtpTllei.hpp" -#include "RTC/RTCP/FeedbackRtpEcn.hpp" -#include "Logger.hpp" +#include "RTC/RTCP/FeedbackRtpTmmb.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - template - FeedbackRtpItemsPacket* FeedbackRtpItemsPacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + template + FeedbackRtpItemsPacket* FeedbackRtpItemsPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - CommonHeader* commonHeader = (CommonHeader*)data; - std::unique_ptr> packet(new FeedbackRtpItemsPacket(commonHeader)); + return nullptr; + } - size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); + CommonHeader* commonHeader = (CommonHeader*)data; + std::unique_ptr> packet( + new FeedbackRtpItemsPacket(commonHeader)); - while (len - offset > 0) - { - Item* item = Item::Parse(data+offset, len-offset); + size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); - if (item) + while (len - offset > 0) { - packet->AddItem(item); - offset += item->GetSize(); - } - else - { - break; + Item* item = Item::Parse(data + offset, len - offset); + + if (item) + { + packet->AddItem(item); + offset += item->GetSize(); + } + else + { + break; + } } + + return packet.release(); } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + template + size_t FeedbackRtpItemsPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - template - size_t FeedbackRtpItemsPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t offset = FeedbackPacket::Serialize(buffer); - size_t offset = FeedbackPacket::Serialize(buffer); + for (auto item : this->items) + { + offset += item->Serialize(buffer + offset); + } - for (auto item : this->items) - { - offset += item->Serialize(buffer + offset); + return offset; } - return offset; - } - - template - void FeedbackRtpItemsPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP("<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str()); - FeedbackRtpPacket::Dump(); - for (auto item : this->items) + template + void FeedbackRtpItemsPacket::Dump() const { - item->Dump(); + MS_TRACE(); + + MS_DUMP("<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str()); + FeedbackRtpPacket::Dump(); + for (auto item : this->items) + { + item->Dump(); + } + MS_DUMP("", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str()); } - MS_DUMP("", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str()); - } - // Explicit instantiation to have all FeedbackRtpPacket definitions in this file. - template class FeedbackRtpItemsPacket; - template class FeedbackRtpItemsPacket; - template class FeedbackRtpItemsPacket; - template class FeedbackRtpItemsPacket; - template class FeedbackRtpItemsPacket; -}} + // Explicit instantiation to have all FeedbackRtpPacket definitions in this file. + template class FeedbackRtpItemsPacket; + template class FeedbackRtpItemsPacket; + template class FeedbackRtpItemsPacket; + template class FeedbackRtpItemsPacket; + template class FeedbackRtpItemsPacket; + } +} diff --git a/worker/src/RTC/RTCP/FeedbackRtpEcn.cpp b/worker/src/RTC/RTCP/FeedbackRtpEcn.cpp index a9f2a37657..9e1bf93b35 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpEcn.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpEcn.cpp @@ -5,49 +5,52 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackRtpEcnItem* FeedbackRtpEcnItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackRtpEcnItem* FeedbackRtpEcnItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Ecn item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Ecn item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackRtpEcnItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - size_t FeedbackRtpEcnItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + return new FeedbackRtpEcnItem(header); + } + + size_t FeedbackRtpEcnItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - // Add minimum header. - std::memcpy(buffer, this->header, sizeof(Header)); + // Add minimum header. + std::memcpy(buffer, this->header, sizeof(Header)); - return sizeof(Header); - } + return sizeof(Header); + } - void FeedbackRtpEcnItem::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber()); - MS_DUMP(" ect0 counter : %" PRIu32, this->GetEct0Counter()); - MS_DUMP(" ect1 counter : %" PRIu32, this->GetEct1Counter()); - MS_DUMP(" ecn ce counter : %" PRIu16, this->GetEcnCeCounter()); - MS_DUMP(" not ect counter : %" PRIu16, this->GetNotEctCounter()); - MS_DUMP(" lost packets : %" PRIu16, this->GetLostPackets()); - MS_DUMP(" duplicated packets : %" PRIu16, this->GetDuplicatedPackets()); - MS_DUMP(""); + void FeedbackRtpEcnItem::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber()); + MS_DUMP(" ect0 counter : %" PRIu32, this->GetEct0Counter()); + MS_DUMP(" ect1 counter : %" PRIu32, this->GetEct1Counter()); + MS_DUMP(" ecn ce counter : %" PRIu16, this->GetEcnCeCounter()); + MS_DUMP(" not ect counter : %" PRIu16, this->GetNotEctCounter()); + MS_DUMP(" lost packets : %" PRIu16, this->GetLostPackets()); + MS_DUMP(" duplicated packets : %" PRIu16, this->GetDuplicatedPackets()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackRtpNack.cpp b/worker/src/RTC/RTCP/FeedbackRtpNack.cpp index 4e32a216a2..0d6973b657 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpNack.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpNack.cpp @@ -3,59 +3,62 @@ #include "RTC/RTCP/FeedbackRtpNack.hpp" #include "Logger.hpp" -#include #include // std::bitset() +#include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackRtpNackItem* FeedbackRtpNackItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackRtpNackItem* FeedbackRtpNackItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Nack item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Nack item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackRtpNackItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - /* Instance methods. */ - FeedbackRtpNackItem::FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask) - { - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); + return new FeedbackRtpNackItem(header); + } - this->header->packet_id = htons(packetId); - this->header->lost_packet_bitmask = htons(lostPacketBitmask); - } + /* Instance methods. */ + FeedbackRtpNackItem::FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask) + { + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); - size_t FeedbackRtpNackItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->header->packetId = htons(packetId); + this->header->lostPacketBitmask = htons(lostPacketBitmask); + } - // Add minimum header. - std::memcpy(buffer, this->header, sizeof(Header)); + size_t FeedbackRtpNackItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - return sizeof(Header); - } + // Add minimum header. + std::memcpy(buffer, this->header, sizeof(Header)); - void FeedbackRtpNackItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } + + void FeedbackRtpNackItem::Dump() const + { + MS_TRACE(); - std::bitset<16> nack_bitset(this->GetLostPacketBitmask()); + std::bitset<16> nackBitset(this->GetLostPacketBitmask()); - MS_DUMP(""); - MS_DUMP(" pid : %" PRIu16, this->GetPacketId()); - MS_DUMP(" bpl : %s", nack_bitset.to_string().c_str()); - MS_DUMP(""); + MS_DUMP(""); + MS_DUMP(" pid : %" PRIu16, this->GetPacketId()); + MS_DUMP(" bpl : %s", nackBitset.to_string().c_str()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp b/worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp index da93328aa8..2a077ea070 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp @@ -4,32 +4,35 @@ #include "RTC/RTCP/FeedbackRtpSrReq.hpp" #include "Logger.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackRtpSrReqPacket* FeedbackRtpSrReqPacket::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + FeedbackRtpSrReqPacket* FeedbackRtpSrReqPacket::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); + MS_TRACE(); - return nullptr; - } + if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded"); - CommonHeader* commonHeader = (CommonHeader*)data; + return nullptr; + } - return new FeedbackRtpSrReqPacket(commonHeader); - } + CommonHeader* commonHeader = (CommonHeader*)data; - void FeedbackRtpSrReqPacket::Dump() const - { - MS_TRACE(); + return new FeedbackRtpSrReqPacket(commonHeader); + } + + void FeedbackRtpSrReqPacket::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - FeedbackRtpPacket::Dump(); - MS_DUMP(""); + MS_DUMP(""); + FeedbackRtpPacket::Dump(); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackRtpTllei.cpp b/worker/src/RTC/RTCP/FeedbackRtpTllei.cpp index fd51d3dcf5..7ce738cc24 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpTllei.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpTllei.cpp @@ -5,54 +5,57 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - FeedbackRtpTlleiItem* FeedbackRtpTlleiItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(Header) > len) + FeedbackRtpTlleiItem* FeedbackRtpTlleiItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Tllei item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for Tllei item, discarded"); - Header* header = const_cast(reinterpret_cast(data)); + return nullptr; + } - return new FeedbackRtpTlleiItem(header); - } + Header* header = const_cast(reinterpret_cast(data)); - /* Instance methods. */ - FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask) - { - this->raw = new uint8_t[sizeof(Header)]; - this->header = reinterpret_cast(this->raw); + return new FeedbackRtpTlleiItem(header); + } - this->header->packet_id = htons(packetId); - this->header->lost_packet_bitmask = htons(lostPacketBitmask); - } + /* Instance methods. */ + FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask) + { + this->raw = new uint8_t[sizeof(Header)]; + this->header = reinterpret_cast(this->raw); - size_t FeedbackRtpTlleiItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->header->packetId = htons(packetId); + this->header->lostPacketBitmask = htons(lostPacketBitmask); + } - // Add minimum header. - std::memcpy(buffer, this->header, sizeof(Header)); + size_t FeedbackRtpTlleiItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - return sizeof(Header); - } + // Add minimum header. + std::memcpy(buffer, this->header, sizeof(Header)); - void FeedbackRtpTlleiItem::Dump() const - { - MS_TRACE(); + return sizeof(Header); + } + + void FeedbackRtpTlleiItem::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - MS_DUMP(" pid: %" PRIu16, this->GetPacketId()); - MS_DUMP(" bpl: %" PRIu16, this->GetLostPacketBitmask()); - MS_DUMP(""); + MS_DUMP(""); + MS_DUMP(" pid: %" PRIu16, this->GetPacketId()); + MS_DUMP(" bpl: %" PRIu16, this->GetLostPacketBitmask()); + MS_DUMP(""); + } } -}} +} diff --git a/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp b/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp index f9d53c9f1b..1a00cffbe3 100644 --- a/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp +++ b/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp @@ -6,101 +6,106 @@ #include "Utils.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - template - FeedbackRtpTmmbItem* FeedbackRtpTmmbItem::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); - - // data size must be >= header + length value. - if (HeaderSize > len) + /* Class methods. */ + template + FeedbackRtpTmmbItem* FeedbackRtpTmmbItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for Tmmb item, discarded"); + MS_TRACE(); - return nullptr; - } + // data size must be >= header + length value. + if (HeaderSize > len) + { + MS_WARN_TAG(rtcp, "not enough space for Tmmb item, discarded"); - std::unique_ptr item(new FeedbackRtpTmmbItem(data)); + return nullptr; + } - if (!item->IsCorrect()) - return nullptr; + std::unique_ptr item(new FeedbackRtpTmmbItem(data)); - return item.release(); - } + if (!item->IsCorrect()) + return nullptr; - /* Instance methods. */ - template - FeedbackRtpTmmbItem::FeedbackRtpTmmbItem(const uint8_t* data) - { - this->ssrc = Utils::Byte::Get4Bytes(data, 0); + return item.release(); + } - // Read the 4 bytes block. - uint32_t compact = Utils::Byte::Get4Bytes(data, 4); - // Read each component. - uint8_t exponent = compact >> 26; // 6 bits. - uint64_t mantissa = (compact >> 9) & 0x1ffff; // 17 bits. + /* Instance methods. */ + template + FeedbackRtpTmmbItem::FeedbackRtpTmmbItem(const uint8_t* data) + { + this->ssrc = Utils::Byte::Get4Bytes(data, 0); - this->overhead = compact & 0x1ff; // 9 bits. + // Read the 4 bytes block. + uint32_t compact = Utils::Byte::Get4Bytes(data, 4); + // Read each component. + uint8_t exponent = compact >> 26; // 6 bits. + uint64_t mantissa = (compact >> 9) & 0x1ffff; // 17 bits. - // Get the bitrate out of exponent and mantissa. - this->bitrate = (mantissa << exponent); + this->overhead = compact & 0x1ff; // 9 bits. - if ((this->bitrate >> exponent) != mantissa) - { - MS_WARN_TAG(rtcp, "invalid TMMB bitrate value : %" PRIu64" x 2^%" PRIu8, mantissa, exponent); + // Get the bitrate out of exponent and mantissa. + this->bitrate = (mantissa << exponent); + + if ((this->bitrate >> exponent) != mantissa) + { + MS_WARN_TAG(rtcp, "invalid TMMB bitrate value : %" PRIu64 " x 2^%" PRIu8, mantissa, exponent); - this->isCorrect = false; + this->isCorrect = false; + } } - } - template - size_t FeedbackRtpTmmbItem::Serialize(uint8_t* buffer) - { - static constexpr uint32_t MaxMantissa = 0x1ffff; // 17 bits. + template + size_t FeedbackRtpTmmbItem::Serialize(uint8_t* buffer) + { + static constexpr uint32_t MaxMantissa = 0x1ffff; // 17 bits. - uint64_t mantissa = this->bitrate; - uint32_t exponent = 0; + uint64_t mantissa = this->bitrate; + uint32_t exponent = 0; - while (mantissa > MaxMantissa) - { - mantissa >>= 1; - ++exponent; - } + while (mantissa > MaxMantissa) + { + mantissa >>= 1; + ++exponent; + } - Utils::Byte::Set4Bytes(buffer, 0, this->ssrc); + Utils::Byte::Set4Bytes(buffer, 0, this->ssrc); - uint32_t compact = (exponent << 26) | (mantissa << 9) | this->overhead; + uint32_t compact = (exponent << 26) | (mantissa << 9) | this->overhead; - Utils::Byte::Set4Bytes(buffer, 4, compact); + Utils::Byte::Set4Bytes(buffer, 4, compact); - return HeaderSize; - } + return HeaderSize; + } - template - void FeedbackRtpTmmbItem::Dump() const - { - MS_TRACE(); + template + void FeedbackRtpTmmbItem::Dump() const + { + MS_TRACE(); - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" bitrate : %" PRIu64, this->GetBitrate()); - MS_DUMP(" overhead : %" PRIu16, this->GetOverhead()); - MS_DUMP(""); - } + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" bitrate : %" PRIu64, this->GetBitrate()); + MS_DUMP(" overhead : %" PRIu16, this->GetOverhead()); + MS_DUMP(""); + } - /* Specialization for Tmmbr class. */ + /* Specialization for Tmmbr class. */ - template<> - const FeedbackRtp::MessageType FeedbackRtpTmmbItem::MessageType = FeedbackRtp::MessageType::TMMBR; + template<> + const FeedbackRtp::MessageType FeedbackRtpTmmbItem::MessageType = + FeedbackRtp::MessageType::TMMBR; - /* Specialization for Tmmbn class. */ + /* Specialization for Tmmbn class. */ - template<> - const FeedbackRtp::MessageType FeedbackRtpTmmbItem::MessageType = FeedbackRtp::MessageType::TMMBN; + template<> + const FeedbackRtp::MessageType FeedbackRtpTmmbItem::MessageType = + FeedbackRtp::MessageType::TMMBN; - // Explicit instantiation to have all FeedbackRtpTmmbItem definitions in this file. - template class FeedbackRtpTmmbItem; - template class FeedbackRtpTmmbItem; -}} + // Explicit instantiation to have all FeedbackRtpTmmbItem definitions in this file. + template class FeedbackRtpTmmbItem; + template class FeedbackRtpTmmbItem; + } +} diff --git a/worker/src/RTC/RTCP/Packet.cpp b/worker/src/RTC/RTCP/Packet.cpp index 904c12b86c..7b1d98ad34 100644 --- a/worker/src/RTC/RTCP/Packet.cpp +++ b/worker/src/RTC/RTCP/Packet.cpp @@ -2,17 +2,24 @@ // #define MS_LOG_DEV #include "RTC/RTCP/Packet.hpp" -#include "RTC/RTCP/ReceiverReport.hpp" -#include "RTC/RTCP/SenderReport.hpp" -#include "RTC/RTCP/Sdes.hpp" +#include "Logger.hpp" #include "RTC/RTCP/Bye.hpp" #include "RTC/RTCP/Feedback.hpp" -#include "Logger.hpp" +#include "RTC/RTCP/ReceiverReport.hpp" +#include "RTC/RTCP/Sdes.hpp" +#include "RTC/RTCP/SenderReport.hpp" -namespace RTC { namespace RTCP +namespace RTC { - /* Class variables. */ + namespace RTCP + { + /* Namespace variables. */ + + uint8_t buffer[bufferSize]; + /* Class variables. */ + + // clang-format off std::map Packet::type2String = { { Type::FIR, "FIR" }, @@ -25,156 +32,171 @@ namespace RTC { namespace RTCP { Type::RTPFB, "RTPFB" }, { Type::PSFB, "PSFB" } }; + // clang-format on - /* Class methods. */ + /* Class methods. */ - Packet* Packet::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + Packet* Packet::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); - // First, Currently parsing and Last RTCP packets in the compound packet. - Packet *first, *current, *last; - first = current = last = nullptr; + // First, Currently parsing and Last RTCP packets in the compound packet. + Packet *first, *current, *last; - while (int(len) > 0) - { - if (!Packet::IsRtcp(data, len)) + first = current = last = nullptr; + + while (int(len) > 0) { - MS_WARN_TAG(rtcp, "data is not a RTCP packet"); + if (!Packet::IsRtcp(data, len)) + { + MS_WARN_TAG(rtcp, "data is not a RTCP packet"); - return first; - } + return first; + } - CommonHeader* header = const_cast(reinterpret_cast(data)); - size_t packet_len = (size_t)(ntohs(header->length) + 1) * 4; + CommonHeader* header = const_cast(reinterpret_cast(data)); - if (len < packet_len) - { - MS_WARN_TAG(rtcp, "packet length exceeds remaining data [len:%zu, packet_len:%zu]", len, packet_len); + size_t packetLlen = (size_t)(ntohs(header->length) + 1) * 4; - return first; - } + if (len < packetLlen) + { + MS_WARN_TAG( + rtcp, + "packet length exceeds remaining data [len:%zu, " + "packet len:%zu]", + len, + packetLlen); + + return first; + } - switch (Type(header->packet_type)) - { - case Type::SR: + switch (Type(header->packetType)) { - current = SenderReportPacket::Parse(data, len); + case Type::SR: + { + current = SenderReportPacket::Parse(data, len); + + if (!current) + break; + + if ((uint8_t)header->count > 0) + { + Packet* rr = ReceiverReportPacket::Parse(data, len, current->GetSize()); + if (!rr) + break; + + current->SetNext(rr); + } - if (!current) break; + } - if ((uint8_t)header->count > 0) + case Type::RR: { - Packet* rr = ReceiverReportPacket::Parse(data, len, current->GetSize()); - if (!rr) - break; + current = ReceiverReportPacket::Parse(data, len); + break; + } - current->SetNext(rr); + case Type::SDES: + { + current = SdesPacket::Parse(data, len); + break; } - break; - } + case Type::BYE: + { + current = ByePacket::Parse(data, len); + break; + } - case Type::RR: - { - current = ReceiverReportPacket::Parse(data, len); - break; - } + case Type::APP: + { + current = nullptr; + break; + } - case Type::SDES: - { - current = SdesPacket::Parse(data, len); - break; - } + case Type::PSFB: + { + current = FeedbackPsPacket::Parse(data, len); + break; + } - case Type::BYE: - { - current = ByePacket::Parse(data, len); - break; - } + case Type::RTPFB: + { + current = FeedbackRtpPacket::Parse(data, len); + break; + } - case Type::APP: - { - current = nullptr; - break; - } + default: + { + MS_WARN_TAG(rtcp, "unknown RTCP packet type [packetType:%" PRIu8 "]", header->packetType); - case Type::PSFB: - { - current = FeedbackPsPacket::Parse(data, len); - break; + current = nullptr; + } } - case Type::RTPFB: + if (!current) { - current = FeedbackRtpPacket::Parse(data, len); - break; - } + std::string packetType = Type2String(Type(header->packetType)); - default: - { - MS_WARN_TAG(rtcp, "unknown RTCP packet type [packet_type:%" PRIu8 "]", header->packet_type); + if (Type(header->packetType) == Type::PSFB) + { + packetType += + " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count)); + } + else if (Type(header->packetType) == Type::RTPFB) + { + packetType += + " " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count)); + } - current = nullptr; - } - } + MS_WARN_TAG(rtcp, "error parsing %s Packet", packetType.c_str()); - if (!current) - { - std::string packetType = Type2String(Type(header->packet_type)); + return first; + } - if (Type(header->packet_type) == Type::PSFB) - packetType += " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count)); - else if (Type(header->packet_type) == Type::RTPFB) - packetType += " " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count)); + data += packetLlen; + len -= packetLlen; - MS_WARN_TAG(rtcp, "error parsing %s Packet", packetType.c_str()); + if (!first) + first = current; + else + last->SetNext(current); - return first; + last = current->GetNext() ? current->GetNext() : current; } - data += packet_len; - len -= packet_len; - - if (!first) - first = current; - else - last->SetNext(current); - - last = current->GetNext() ? current->GetNext() : current; + return first; } - return first; - } - - const std::string& Packet::Type2String(Type type) - { - static const std::string unknown("UNKNOWN"); + const std::string& Packet::Type2String(Type type) + { + static const std::string unknown("UNKNOWN"); - if (Packet::type2String.find(type) == Packet::type2String.end()) - return unknown; + if (Packet::type2String.find(type) == Packet::type2String.end()) + return unknown; - return Packet::type2String[type]; - } + return Packet::type2String[type]; + } - /* Instance methods. */ + /* Instance methods. */ - size_t Packet::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t Packet::Serialize(uint8_t* buffer) + { + MS_TRACE(); - this->header = reinterpret_cast(buffer); + this->header = reinterpret_cast(buffer); - size_t length = (this->GetSize() / 4) - 1; + size_t length = (this->GetSize() / 4) - 1; - // Fill the common header. - this->header->version = 2; - this->header->padding = 0; - this->header->count = (uint8_t)this->GetCount(); - this->header->packet_type = (uint8_t)this->type; - this->header->length = htons(length); + // Fill the common header. + this->header->version = 2; + this->header->padding = 0; + this->header->count = (uint8_t)this->GetCount(); + this->header->packetType = (uint8_t)this->type; + this->header->length = htons(length); - return sizeof(CommonHeader); + return sizeof(CommonHeader); + } } -}} +} diff --git a/worker/src/RTC/RTCP/ReceiverReport.cpp b/worker/src/RTC/RTCP/ReceiverReport.cpp index fee6639443..365d3190bd 100644 --- a/worker/src/RTC/RTCP/ReceiverReport.cpp +++ b/worker/src/RTC/RTCP/ReceiverReport.cpp @@ -2,129 +2,132 @@ #define MS_LOG_DEV #include "RTC/RTCP/ReceiverReport.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - ReceiverReport* ReceiverReport::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ - // Get the header. - Header* header = const_cast(reinterpret_cast(data)); - - // Packet size must be >= header size. - if (sizeof(Header) > len) + ReceiverReport* ReceiverReport::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for receiver report, packet discarded"); + MS_TRACE(); - return nullptr; - } + // Get the header. + Header* header = const_cast(reinterpret_cast(data)); - return new ReceiverReport(header); - } + // Packet size must be >= header size. + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for receiver report, packet discarded"); - /* Instance methods. */ + return nullptr; + } - void ReceiverReport::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" fraction lost : %" PRIu32, this->GetFractionLost()); - MS_DUMP(" total lost : %" PRIu32, this->GetTotalLost()); - MS_DUMP(" last seq : %" PRIu32, this->GetLastSeq()); - MS_DUMP(" jitter : %" PRIu32, this->GetJitter()); - MS_DUMP(" lsr : %" PRIu32, this->GetLastSenderReport()); - MS_DUMP(" dlsr : %" PRIu32, this->GetDelaySinceLastSenderReport()); - MS_DUMP(""); - } + return new ReceiverReport(header); + } - size_t ReceiverReport::Serialize(uint8_t* buffer) - { - MS_TRACE(); + /* Instance methods. */ - // Copy the header. - std::memcpy(buffer, this->header, sizeof(Header)); + void ReceiverReport::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" fraction lost : %" PRIu32, this->GetFractionLost()); + MS_DUMP(" total lost : %" PRIu32, this->GetTotalLost()); + MS_DUMP(" last seq : %" PRIu32, this->GetLastSeq()); + MS_DUMP(" jitter : %" PRIu32, this->GetJitter()); + MS_DUMP(" lsr : %" PRIu32, this->GetLastSenderReport()); + MS_DUMP(" dlsr : %" PRIu32, this->GetDelaySinceLastSenderReport()); + MS_DUMP(""); + } - return sizeof(Header); - } + size_t ReceiverReport::Serialize(uint8_t* buffer) + { + MS_TRACE(); - /* Class methods. */ + // Copy the header. + std::memcpy(buffer, this->header, sizeof(Header)); - /** - * ReceiverReportPacket::Parse() - * @param data - Points to the begining of the incoming RTCP packet. - * @param len - Total length of the packet. - * @param offset - points to the first Receiver Report if the incoming packet. - */ - ReceiverReportPacket* ReceiverReportPacket::Parse(const uint8_t* data, size_t len, size_t offset) - { - MS_TRACE(); + return sizeof(Header); + } + + /* Class methods. */ - // Get the header. - Packet::CommonHeader* header = (Packet::CommonHeader*)data; - std::unique_ptr packet(new ReceiverReportPacket()); + /** + * ReceiverReportPacket::Parse() + * @param data - Points to the begining of the incoming RTCP packet. + * @param len - Total length of the packet. + * @param offset - points to the first Receiver Report if the incoming packet. + */ + ReceiverReportPacket* ReceiverReportPacket::Parse(const uint8_t* data, size_t len, size_t offset) + { + MS_TRACE(); - packet->SetSsrc(Utils::Byte::Get4Bytes((uint8_t*)header, sizeof(CommonHeader))); + // Get the header. + Packet::CommonHeader* header = (Packet::CommonHeader*)data; + std::unique_ptr packet(new ReceiverReportPacket()); - if (offset == 0) - offset = sizeof(Packet::CommonHeader) + sizeof(uint32_t) /* ssrc */; + packet->SetSsrc(Utils::Byte::Get4Bytes((uint8_t*)header, sizeof(CommonHeader))); - uint8_t count = header->count; - while ((count--) && (len - offset > 0)) - { - ReceiverReport* report = ReceiverReport::Parse(data+offset, len-offset); - if (report) - { - packet->AddReport(report); - offset += report->GetSize(); - } - else + if (offset == 0) + offset = sizeof(Packet::CommonHeader) + sizeof(uint32_t) /* ssrc */; + + uint8_t count = header->count; + while ((count--) && (len - offset > 0)) { - return packet.release(); + ReceiverReport* report = ReceiverReport::Parse(data + offset, len - offset); + if (report) + { + packet->AddReport(report); + offset += report->GetSize(); + } + else + { + return packet.release(); + } } + + return packet.release(); } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + size_t ReceiverReportPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t ReceiverReportPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t offset = Packet::Serialize(buffer); - size_t offset = Packet::Serialize(buffer); + // Copy the SSRC. + std::memcpy(buffer + sizeof(Packet::CommonHeader), &this->ssrc, sizeof(this->ssrc)); + offset += sizeof(this->ssrc); - // Copy the SSRC. - std::memcpy(buffer + sizeof(Packet::CommonHeader), &this->ssrc, sizeof(this->ssrc)); - offset += sizeof(this->ssrc); + // Serialize reports. + for (auto report : this->reports) + { + offset += report->Serialize(buffer + offset); + } - // Serialize reports. - for (auto report : this->reports) - { - offset += report->Serialize(buffer + offset); + return offset; } - return offset; - } - - void ReceiverReportPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" ssrc: %" PRIu32, (uint32_t)ntohl(this->ssrc)); - for (auto report : this->reports) + void ReceiverReportPacket::Dump() const { - report->Dump(); + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc: %" PRIu32, (uint32_t)ntohl(this->ssrc)); + for (auto report : this->reports) + { + report->Dump(); + } + MS_DUMP(""); } - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RTCP/Sdes.cpp b/worker/src/RTC/RTCP/Sdes.cpp index 6cc7c9b548..2eef82db4d 100644 --- a/worker/src/RTC/RTCP/Sdes.cpp +++ b/worker/src/RTC/RTCP/Sdes.cpp @@ -2,14 +2,17 @@ #define MS_LOG_DEV #include "RTC/RTCP/Sdes.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Item Class variables. */ + namespace RTCP + { + /* Item Class variables. */ + // clang-format off std::map SdesItem::type2String = { { SdesItem::Type::END, "END" }, @@ -22,210 +25,212 @@ namespace RTC { namespace RTCP { SdesItem::Type::NOTE, "NOTE" }, { SdesItem::Type::PRIV, "PRIV" } }; + // clang-format on - /* Class methods. */ - - SdesItem* SdesItem::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); - - // Get the header. - Header* header = const_cast(reinterpret_cast(data)); + /* Class methods. */ - // data size must be >= header + length value. - if (sizeof(uint8_t)*2 + header->length > len) + SdesItem* SdesItem::Parse(const uint8_t* data, size_t len) { - MS_WARN_TAG(rtcp, "not enough space for SDES item, discarded"); + MS_TRACE(); - return nullptr; - } + // Get the header. + Header* header = const_cast(reinterpret_cast(data)); - return new SdesItem(header); - } - - const std::string& SdesItem::Type2String(SdesItem::Type type) - { - static const std::string unknown("UNKNOWN"); - - if (type2String.find(type) == type2String.end()) - return unknown; + // data size must be >= header + length value. + if (sizeof(uint8_t) * 2 + header->length > len) + { + MS_WARN_TAG(rtcp, "not enough space for SDES item, discarded"); - return type2String[type]; - } + return nullptr; + } - /* Instance methods. */ + return new SdesItem(header); + } - SdesItem::SdesItem(SdesItem::Type type, size_t len, const char* value) - { - MS_TRACE(); + const std::string& SdesItem::Type2String(SdesItem::Type type) + { + static const std::string unknown("UNKNOWN"); - // Allocate memory. - this->raw.reset(new uint8_t[2 + len]); + if (type2String.find(type) == type2String.end()) + return unknown; - // Update the header pointer. - this->header = reinterpret_cast(this->raw.get()); + return type2String[type]; + } - this->header->type = type; - this->header->length = len; + /* Instance methods. */ - // Copy the value into raw. - std::memcpy(this->header->value, value, this->header->length); - } + SdesItem::SdesItem(SdesItem::Type type, size_t len, const char* value) + { + MS_TRACE(); - void SdesItem::Dump() const - { - MS_TRACE(); + // Allocate memory. + this->raw.reset(new uint8_t[2 + len]); - MS_DUMP(""); - MS_DUMP(" type : %s", SdesItem::Type2String(this->GetType()).c_str()); - MS_DUMP(" length : %" PRIu8, this->header->length); - MS_DUMP(" value : %.*s", this->header->length, this->header->value); - MS_DUMP(""); - } + // Update the header pointer. + this->header = reinterpret_cast(this->raw.get()); - size_t SdesItem::Serialize(uint8_t* buffer) - { - MS_TRACE(); + this->header->type = type; + this->header->length = len; - // Add minimum header. - std::memcpy(buffer, this->header, 2); + // Copy the value into raw. + std::memcpy(this->header->value, value, this->header->length); + } - // Copy the content. - std::memcpy(buffer+2, this->header->value, this->header->length); + void SdesItem::Dump() const + { + MS_TRACE(); - return 2 + this->header->length; - } + MS_DUMP(""); + MS_DUMP(" type : %s", SdesItem::Type2String(this->GetType()).c_str()); + MS_DUMP(" length : %" PRIu8, this->header->length); + MS_DUMP(" value : %.*s", this->header->length, this->header->value); + MS_DUMP(""); + } - /* Class methods. */ + size_t SdesItem::Serialize(uint8_t* buffer) + { + MS_TRACE(); - SdesChunk* SdesChunk::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + // Add minimum header. + std::memcpy(buffer, this->header, 2); - // data size must be > SSRC field. - if (sizeof(uint32_t) /* ssrc */ > len) - { - MS_WARN_TAG(rtcp, "not enough space for SDES chunk, discarded"); + // Copy the content. + std::memcpy(buffer + 2, this->header->value, this->header->length); - return nullptr; + return 2 + this->header->length; } - std::unique_ptr chunk(new SdesChunk(Utils::Byte::Get4Bytes(data, 0))); - - size_t offset = sizeof(uint32_t) /* ssrc */; + /* Class methods. */ - while (len - offset > 0) + SdesChunk* SdesChunk::Parse(const uint8_t* data, size_t len) { - SdesItem* item = SdesItem::Parse(data+offset, len-offset); - if (item) + MS_TRACE(); + + // data size must be > SSRC field. + if (sizeof(uint32_t) /* ssrc */ > len) { - if (item->GetType() == SdesItem::Type::END) - return chunk.release(); + MS_WARN_TAG(rtcp, "not enough space for SDES chunk, discarded"); - chunk->AddItem(item); - offset += item->GetSize(); + return nullptr; } - else + + std::unique_ptr chunk(new SdesChunk(Utils::Byte::Get4Bytes(data, 0))); + + size_t offset = sizeof(uint32_t) /* ssrc */; + + while (len - offset > 0) { - return chunk.release(); + SdesItem* item = SdesItem::Parse(data + offset, len - offset); + if (item) + { + if (item->GetType() == SdesItem::Type::END) + return chunk.release(); + + chunk->AddItem(item); + offset += item->GetSize(); + } + else + { + return chunk.release(); + } } + + return chunk.release(); } - return chunk.release(); - } + /* Instance methods. */ - /* Instance methods. */ + size_t SdesChunk::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t SdesChunk::Serialize(uint8_t* buffer) - { - MS_TRACE(); + std::memcpy(buffer, &this->ssrc, sizeof(this->ssrc)); - std::memcpy(buffer, &this->ssrc, sizeof(this->ssrc)); + size_t offset = sizeof(this->ssrc); - size_t offset = sizeof(this->ssrc); + for (auto item : this->items) + { + offset += item->Serialize(buffer + offset); + } - for (auto item : this->items) - { - offset += item->Serialize(buffer + offset); - } + // 32 bits padding. + size_t padding = (-offset) & 3; + for (size_t i = 0; i < padding; ++i) + { + buffer[offset + i] = 0; + } - // 32 bits padding. - size_t padding = (-offset) & 3; - for (size_t i = 0; i < padding; ++i) - { - buffer[offset+i] = 0; + return offset + padding; } - return offset+padding; - } - - void SdesChunk::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, (uint32_t)ntohl(this->ssrc)); - for (auto item : this->items) + void SdesChunk::Dump() const { - item->Dump(); + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, (uint32_t)ntohl(this->ssrc)); + for (auto item : this->items) + { + item->Dump(); + } + MS_DUMP(""); } - MS_DUMP(""); - } - /* Class methods. */ + /* Class methods. */ - SdesPacket* SdesPacket::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + SdesPacket* SdesPacket::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); - // Get the header. - Packet::CommonHeader* header = (Packet::CommonHeader*)data; - std::unique_ptr packet(new SdesPacket()); - size_t offset = sizeof(Packet::CommonHeader); - uint8_t count = header->count; + // Get the header. + Packet::CommonHeader* header = (Packet::CommonHeader*)data; + std::unique_ptr packet(new SdesPacket()); + size_t offset = sizeof(Packet::CommonHeader); + uint8_t count = header->count; - while ((count--) && (len - offset > 0)) - { - SdesChunk* chunk = SdesChunk::Parse(data+offset, len-offset); - if (chunk) + while ((count--) && (len - offset > 0)) { - packet->AddChunk(chunk); - offset += chunk->GetSize(); - } - else - { - return packet.release(); + SdesChunk* chunk = SdesChunk::Parse(data + offset, len - offset); + if (chunk) + { + packet->AddChunk(chunk); + offset += chunk->GetSize(); + } + else + { + return packet.release(); + } } + + return packet.release(); } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + size_t SdesPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t SdesPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + size_t offset = Packet::Serialize(buffer); - size_t offset = Packet::Serialize(buffer); + for (auto chunk : this->chunks) + { + offset += chunk->Serialize(buffer + offset); + } - for (auto chunk : this->chunks) - { - offset += chunk->Serialize(buffer + offset); + return offset; } - return offset; - } - - void SdesPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - for (auto chunk : this->chunks) + void SdesPacket::Dump() const { - chunk->Dump(); + MS_TRACE(); + + MS_DUMP(""); + for (auto chunk : this->chunks) + { + chunk->Dump(); + } + MS_DUMP(""); } - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RTCP/SenderReport.cpp b/worker/src/RTC/RTCP/SenderReport.cpp index 85f75c084f..bfc21b5b40 100644 --- a/worker/src/RTC/RTCP/SenderReport.cpp +++ b/worker/src/RTC/RTCP/SenderReport.cpp @@ -5,100 +5,103 @@ #include "Logger.hpp" #include -namespace RTC { namespace RTCP +namespace RTC { - /* Class methods. */ - - SenderReport* SenderReport::Parse(const uint8_t* data, size_t len) + namespace RTCP { - MS_TRACE(); + /* Class methods. */ + + SenderReport* SenderReport::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); - // Get the header. - Header* header = const_cast(reinterpret_cast(data)); + // Get the header. + Header* header = const_cast(reinterpret_cast(data)); // Packet size must be >= header size. - if (sizeof(Header) > len) - { - MS_WARN_TAG(rtcp, "not enough space for sender report, packet discarded"); + if (sizeof(Header) > len) + { + MS_WARN_TAG(rtcp, "not enough space for sender report, packet discarded"); - return nullptr; + return nullptr; + } + + return new SenderReport(header); } - return new SenderReport(header); - } + /* Instance methods. */ - /* Instance methods. */ + void SenderReport::Dump() const + { + MS_TRACE(); + + MS_DUMP(""); + MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); + MS_DUMP(" ntp sec : %" PRIu32, this->GetNtpSec()); + MS_DUMP(" ntp frac : %" PRIu32, this->GetNtpFrac()); + MS_DUMP(" rtp ts : %" PRIu32, this->GetRtpTs()); + MS_DUMP(" packet count : %" PRIu32, this->GetPacketCount()); + MS_DUMP(" octet count : %" PRIu32, this->GetOctetCount()); + MS_DUMP(""); + } - void SenderReport::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc()); - MS_DUMP(" ntp sec : %" PRIu32, this->GetNtpSec()); - MS_DUMP(" ntp frac : %" PRIu32, this->GetNtpFrac()); - MS_DUMP(" rtp ts : %" PRIu32, this->GetRtpTs()); - MS_DUMP(" packet count : %" PRIu32, this->GetPacketCount()); - MS_DUMP(" octet count : %" PRIu32, this->GetOctetCount()); - MS_DUMP(""); - } + size_t SenderReport::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t SenderReport::Serialize(uint8_t* buffer) - { - MS_TRACE(); + // Copy the header. + std::memcpy(buffer, this->header, sizeof(Header)); - // Copy the header. - std::memcpy(buffer, this->header, sizeof(Header)); + return sizeof(Header); + } - return sizeof(Header); - } + /* Class methods. */ - /* Class methods. */ + SenderReportPacket* SenderReportPacket::Parse(const uint8_t* data, size_t len) + { + MS_TRACE(); - SenderReportPacket* SenderReportPacket::Parse(const uint8_t* data, size_t len) - { - MS_TRACE(); + std::unique_ptr packet(new SenderReportPacket()); + size_t offset = sizeof(Packet::CommonHeader); - std::unique_ptr packet(new SenderReportPacket()); - size_t offset = sizeof(Packet::CommonHeader); + SenderReport* report = SenderReport::Parse(data + offset, len - offset); + if (report) + packet->AddReport(report); + else + return packet.release(); - SenderReport* report = SenderReport::Parse(data+offset, len-offset); - if (report) - packet->AddReport(report); - else return packet.release(); + } - return packet.release(); - } + /* Instance methods. */ - /* Instance methods. */ + size_t SenderReportPacket::Serialize(uint8_t* buffer) + { + MS_TRACE(); - size_t SenderReportPacket::Serialize(uint8_t* buffer) - { - MS_TRACE(); + MS_ASSERT(this->reports.size() == 1, "invalid number of sender reports"); - MS_ASSERT(this->reports.size() == 1, "invalid number of sender reports"); + size_t offset = Packet::Serialize(buffer); - size_t offset = Packet::Serialize(buffer); + // Serialize reports. + for (auto report : this->reports) + { + offset += report->Serialize(buffer + offset); + } - // Serialize reports. - for (auto report : this->reports) - { - offset += report->Serialize(buffer + offset); + return offset; } - return offset; - } - - void SenderReportPacket::Dump() const - { - MS_TRACE(); - - MS_DUMP(""); - for (auto report : this->reports) + void SenderReportPacket::Dump() const { - report->Dump(); + MS_TRACE(); + + MS_DUMP(""); + for (auto report : this->reports) + { + report->Dump(); + } + MS_DUMP(""); } - MS_DUMP(""); } -}} +} diff --git a/worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp b/worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp index a0488dc03d..95003e4ce0 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp @@ -8,13 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ - #define MS_CLASS "AimdRateControl" // #define MS_LOG_DEV #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" -#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include "Logger.hpp" +#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include #include @@ -22,7 +21,6 @@ static constexpr int64_t kMaxFeedbackIntervalMs = 1000; namespace RTC { - int64_t AimdRateControl::GetFeedbackInterval() const { MS_TRACE(); @@ -30,7 +28,8 @@ namespace RTC // Estimate how often we can send RTCP if we allocate up to 5% of bandwidth // to feedback. static const int kRtcpSize = 80; - int64_t interval = static_cast(kRtcpSize * 8.0 * 1000.0 / (0.05 * this->currentBitrateBps) + 0.5); + int64_t interval = + static_cast(kRtcpSize * 8.0 * 1000.0 / (0.05 * this->currentBitrateBps) + 0.5); const int64_t kMinFeedbackIntervalMs = 200; return std::min(std::max(interval, kMinFeedbackIntervalMs), kMaxFeedbackIntervalMs); @@ -78,7 +77,7 @@ namespace RTC } else if (nowMs - this->timeFirstIncomingEstimate > kInitializationTimeMs && input->incomingBitrate) { - this->currentBitrateBps = input->incomingBitrate; + this->currentBitrateBps = input->incomingBitrate; this->bitrateIsInitialized = true; } } @@ -87,12 +86,12 @@ namespace RTC { // Only update delay factor and incoming bit rate. We always want to react // on an over-use. - this->currentInput.noiseVar = input->noiseVar; + this->currentInput.noiseVar = input->noiseVar; this->currentInput.incomingBitrate = input->incomingBitrate; } else { - this->updated = true; + this->updated = true; this->currentInput = *input; } } @@ -103,18 +102,18 @@ namespace RTC // MS_ASSERT(this->currentBitrateBps > 0); - double bitsPerFrame = static_cast(this->currentBitrateBps) / 30.0; - double packetsPerFrame = std::ceil(bitsPerFrame / (8.0 * 1200.0)); + double bitsPerFrame = static_cast(this->currentBitrateBps) / 30.0; + double packetsPerFrame = std::ceil(bitsPerFrame / (8.0 * 1200.0)); double avgPacketSizeBits = bitsPerFrame / packetsPerFrame; // Approximate the over-use estimator delay to 100 ms. - const int64_t responseTime = (this->rtt + 100) * 2; + const int64_t responseTime = (this->rtt + 100) * 2; constexpr double kMinIncreaseRateBps = 4000; - return static_cast(std::max(kMinIncreaseRateBps, - (avgPacketSizeBits * 1000) / responseTime)); + return static_cast(std::max(kMinIncreaseRateBps, (avgPacketSizeBits * 1000) / responseTime)); } - uint32_t AimdRateControl::ChangeBitrate(uint32_t newBitrateBps, uint32_t incomingBitrateBps, int64_t nowMs) + uint32_t AimdRateControl::ChangeBitrate( + uint32_t newBitrateBps, uint32_t incomingBitrateBps, int64_t nowMs) { MS_TRACE(); @@ -142,7 +141,8 @@ namespace RTC break; case kRcIncrease: - if (this->avgMaxBitrateKbps >= 0 && incomingBitrateKbps > this->avgMaxBitrateKbps + 3 * stdMaxBitRate) + if (this->avgMaxBitrateKbps >= 0 && + incomingBitrateKbps > this->avgMaxBitrateKbps + 3 * stdMaxBitRate) { ChangeRegion(kRcMaxUnknown); this->avgMaxBitrateKbps = -1.0; @@ -155,7 +155,8 @@ namespace RTC } else { - uint32_t multiplicativeIncreaseBps = MultiplicativeRateIncrease(nowMs, this->timeLastBitrateChange, newBitrateBps); + uint32_t multiplicativeIncreaseBps = + MultiplicativeRateIncrease(nowMs, this->timeLastBitrateChange, newBitrateBps); newBitrateBps += multiplicativeIncreaseBps; } @@ -222,7 +223,8 @@ namespace RTC return newBitrateBps; } - uint32_t AimdRateControl::MultiplicativeRateIncrease(int64_t nowMs, int64_t lastMs, uint32_t currentBitrateBps) const + uint32_t AimdRateControl::MultiplicativeRateIncrease( + int64_t nowMs, int64_t lastMs, uint32_t currentBitrateBps) const { MS_TRACE(); @@ -260,7 +262,8 @@ namespace RTC const float norm = std::max(this->avgMaxBitrateKbps, 1.0f); this->varMaxBitrateKbps = (1 - alpha) * this->varMaxBitrateKbps + - alpha * (this->avgMaxBitrateKbps - incomingBitrateKbps) * (this->avgMaxBitrateKbps - incomingBitrateKbps) / norm; + alpha * (this->avgMaxBitrateKbps - incomingBitrateKbps) * + (this->avgMaxBitrateKbps - incomingBitrateKbps) / norm; // 0.4 ~= 14 kbit/s at 500 kbit/s if (this->varMaxBitrateKbps < 0.4f) diff --git a/worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp b/worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp index b028346936..91b3cbc2a6 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp @@ -20,59 +20,72 @@ namespace RTC { static const int kBurstDeltaThresholdMs = 5; - bool InterArrival::ComputeDeltas(uint32_t timestamp, int64_t arrival_time_ms, int64_t system_time_ms, size_t packet_size, uint32_t* timestamp_delta, - int64_t* arrival_time_delta_ms, int* packet_size_delta) + bool InterArrival::ComputeDeltas( + uint32_t timestamp, + int64_t arrivalTimeMs, + int64_t systemTimeMs, + size_t packetSize, + uint32_t* timestampDelta, + int64_t* arrivalTimeDeltaMs, + int* packetSizeDelta) { MS_TRACE(); - MS_ASSERT(timestamp_delta, "'timestamp_delta' missing"); - MS_ASSERT(arrival_time_delta_ms, "'arrival_time_delta_ms' missing"); - MS_ASSERT(packet_size_delta, "'packet_size_delta' missing"); + MS_ASSERT(timestampDelta, "'timestampDelta' missing"); + MS_ASSERT(arrivalTimeDeltaMs, "'arrivalTimeDeltaMs' missing"); + MS_ASSERT(packetSizeDelta, "'packetSizeDelta' missing"); - bool calculated_deltas = false; + bool calculatedDeltas = false; if (this->currentTimestampGroup.IsFirstPacket()) { // We don't have enough data to update the filter, so we store it until we // have two frames of data to process. - this->currentTimestampGroup.timestamp = timestamp; - this->currentTimestampGroup.first_timestamp = timestamp; + this->currentTimestampGroup.timestamp = timestamp; + this->currentTimestampGroup.firstTimestamp = timestamp; } else if (!PacketInOrder(timestamp)) { return false; } - else if (NewTimestampGroup(arrival_time_ms, timestamp)) + else if (NewTimestampGroup(arrivalTimeMs, timestamp)) { // First packet of a later frame, the previous frame sample is ready. - if (this->prevTimestampGroup.complete_time_ms >= 0) + if (this->prevTimestampGroup.completeTimeMs >= 0) { - *timestamp_delta = this->currentTimestampGroup.timestamp - this->prevTimestampGroup.timestamp; - *arrival_time_delta_ms = this->currentTimestampGroup.complete_time_ms - this->prevTimestampGroup.complete_time_ms; + *timestampDelta = this->currentTimestampGroup.timestamp - this->prevTimestampGroup.timestamp; + *arrivalTimeDeltaMs = + this->currentTimestampGroup.completeTimeMs - this->prevTimestampGroup.completeTimeMs; // Check system time differences to see if we have an unproportional jump // in arrival time. In that case reset the inter-arrival computations. - int64_t system_time_delta_ms = this->currentTimestampGroup.last_system_time_ms - this->prevTimestampGroup.last_system_time_ms; + int64_t systemTimeDeltaMs = + this->currentTimestampGroup.lastSystemTimeMs - this->prevTimestampGroup.lastSystemTimeMs; - if (*arrival_time_delta_ms - system_time_delta_ms >= kArrivalTimeOffsetThresholdMs) + if (*arrivalTimeDeltaMs - systemTimeDeltaMs >= kArrivalTimeOffsetThresholdMs) { - MS_WARN_TAG(rbe, "the arrival time clock offset has changed, resetting [diff:%" PRId64 "ms]", - *arrival_time_delta_ms - system_time_delta_ms); + MS_WARN_TAG( + rbe, + "the arrival time clock offset has changed, resetting" + "[diff:%" PRId64 "ms]", + *arrivalTimeDeltaMs - systemTimeDeltaMs); Reset(); return false; } - if (*arrival_time_delta_ms < 0) + if (*arrivalTimeDeltaMs < 0) { // The group of packets has been reordered since receiving its local // arrival timestamp. ++this->numConsecutiveReorderedPackets; if (this->numConsecutiveReorderedPackets >= kReorderedResetThreshold) { - MS_WARN_TAG(rbe, "packets are being reordered on the path from the " - "socket to the bandwidth estimator, ignoring this " - "packet for bandwidth estimation, resetting"); + MS_WARN_TAG( + rbe, + "packets are being reordered on the path from the " + "socket to the bandwidth estimator, ignoring this " + "packet for bandwidth estimation, resetting"); Reset(); } @@ -83,28 +96,30 @@ namespace RTC this->numConsecutiveReorderedPackets = 0; } - MS_ASSERT(*arrival_time_delta_ms >= 0, "invalid arrival_time_delta_ms value"); + MS_ASSERT(*arrivalTimeDeltaMs >= 0, "invalid arrivalTimeDeltaMs value"); - *packet_size_delta = static_cast(this->currentTimestampGroup.size) - static_cast(this->prevTimestampGroup.size); - calculated_deltas = true; + *packetSizeDelta = static_cast(this->currentTimestampGroup.size) - + static_cast(this->prevTimestampGroup.size); + calculatedDeltas = true; } this->prevTimestampGroup = this->currentTimestampGroup; // The new timestamp is now the current frame. - this->currentTimestampGroup.first_timestamp = timestamp; - this->currentTimestampGroup.timestamp = timestamp; - this->currentTimestampGroup.size = 0; + this->currentTimestampGroup.firstTimestamp = timestamp; + this->currentTimestampGroup.timestamp = timestamp; + this->currentTimestampGroup.size = 0; } else { - this->currentTimestampGroup.timestamp = Utils::Time::LatestTimestamp(this->currentTimestampGroup.timestamp, timestamp); + this->currentTimestampGroup.timestamp = + Utils::Time::LatestTimestamp(this->currentTimestampGroup.timestamp, timestamp); } // Accumulate the frame size. - this->currentTimestampGroup.size += packet_size; - this->currentTimestampGroup.complete_time_ms = arrival_time_ms; - this->currentTimestampGroup.last_system_time_ms = system_time_ms; + this->currentTimestampGroup.size += packetSize; + this->currentTimestampGroup.completeTimeMs = arrivalTimeMs; + this->currentTimestampGroup.lastSystemTimeMs = systemTimeMs; - return calculated_deltas; + return calculatedDeltas; } bool InterArrival::PacketInOrder(uint32_t timestamp) @@ -120,15 +135,15 @@ namespace RTC // Assume that a diff which is bigger than half the timestamp interval // (32 bits) must be due to reordering. This code is almost identical to // that in IsNewerTimestamp() in module_common_types.h. - uint32_t timestamp_diff = timestamp - this->currentTimestampGroup.first_timestamp; + uint32_t timestampDiff = timestamp - this->currentTimestampGroup.firstTimestamp; - return timestamp_diff < 0x80000000; + return timestampDiff < 0x80000000; } } // Assumes that |timestamp| is not reordered compared to // |this->currentTimestampGroup|. - bool InterArrival::NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const + bool InterArrival::NewTimestampGroup(int64_t arrivalTimeMs, uint32_t timestamp) const { MS_TRACE(); @@ -136,19 +151,19 @@ namespace RTC { return false; } - else if (BelongsToBurst(arrival_time_ms, timestamp)) + else if (BelongsToBurst(arrivalTimeMs, timestamp)) { return false; } else { - uint32_t timestamp_diff = timestamp - this->currentTimestampGroup.first_timestamp; + uint32_t timestampDiff = timestamp - this->currentTimestampGroup.firstTimestamp; - return timestamp_diff > kTimestampGroupLengthTicks; + return timestampDiff > kTimestampGroupLengthTicks; } } - bool InterArrival::BelongsToBurst(int64_t arrival_time_ms, uint32_t timestamp) const + bool InterArrival::BelongsToBurst(int64_t arrivalTimeMs, uint32_t timestamp) const { MS_TRACE(); @@ -157,18 +172,19 @@ namespace RTC return false; } - MS_ASSERT(this->currentTimestampGroup.complete_time_ms >= 0, "invalid complete_time_ms value"); + MS_ASSERT(this->currentTimestampGroup.completeTimeMs >= 0, "invalid completeTimeMs value"); - int64_t arrival_time_delta_ms = arrival_time_ms - this->currentTimestampGroup.complete_time_ms; - uint32_t timestamp_diff = timestamp - this->currentTimestampGroup.timestamp; - int64_t ts_delta_ms = this->timestampToMsCoeff * timestamp_diff + 0.5; + int64_t arrivalTimeDeltaMs = arrivalTimeMs - this->currentTimestampGroup.completeTimeMs; - if (ts_delta_ms == 0) + uint32_t timestampDiff = timestamp - this->currentTimestampGroup.timestamp; + int64_t tsDeltaMs = this->timestampToMsCoeff * timestampDiff + 0.5; + + if (tsDeltaMs == 0) return true; - int propagation_delta_ms = arrival_time_delta_ms - ts_delta_ms; + int propagationDeltaMs = arrivalTimeDeltaMs - tsDeltaMs; - return propagation_delta_ms < 0 && arrival_time_delta_ms <= kBurstDeltaThresholdMs; + return propagationDeltaMs < 0 && arrivalTimeDeltaMs <= kBurstDeltaThresholdMs; } void InterArrival::Reset() @@ -176,7 +192,7 @@ namespace RTC MS_TRACE(); this->numConsecutiveReorderedPackets = 0; - this->currentTimestampGroup = TimestampGroup(); - this->prevTimestampGroup = TimestampGroup(); + this->currentTimestampGroup = TimestampGroup(); + this->prevTimestampGroup = TimestampGroup(); } } diff --git a/worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp b/worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp index 7fb4e9ad10..20e2a327c7 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp @@ -13,16 +13,16 @@ #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" #include "Logger.hpp" -#include -#include #include +#include #include +#include #include namespace RTC { constexpr double kMaxAdaptOffsetMs = 15.0; - constexpr int kMinNumDeltas = 60; + constexpr int kMinNumDeltas = 60; BandwidthUsage OveruseDetector::Detect(double offset, double tsDelta, int numOfDeltas, int64_t nowMs) { @@ -52,23 +52,23 @@ namespace RTC { if (offset >= this->prevOffset) { - this->timeOverUsing = 0; + this->timeOverUsing = 0; this->overuseCounter = 0; - this->hypothesis = kBwOverusing; + this->hypothesis = kBwOverusing; } } } else if (T < -this->threshold) { - this->timeOverUsing = -1; + this->timeOverUsing = -1; this->overuseCounter = 0; - this->hypothesis = kBwUnderusing; + this->hypothesis = kBwUnderusing; } else { - this->timeOverUsing = -1; + this->timeOverUsing = -1; this->overuseCounter = 0; - this->hypothesis = kBwNormal; + this->hypothesis = kBwNormal; } this->prevOffset = offset; @@ -94,7 +94,7 @@ namespace RTC const double k = fabs(modifiedOffset) < this->threshold ? this->kDown : this->kUp; const int64_t kMaxTimeDeltaMs = 100; - int64_t timeDeltaMs = std::min(nowMs - this->lastUpdateMs, kMaxTimeDeltaMs); + int64_t timeDeltaMs = std::min(nowMs - this->lastUpdateMs, kMaxTimeDeltaMs); this->threshold += k * (fabs(modifiedOffset) - this->threshold) * timeDeltaMs; diff --git a/worker/src/RTC/RemoteBitrateEstimator/OveruseEstimator.cpp b/worker/src/RTC/RemoteBitrateEstimator/OveruseEstimator.cpp index 801fd08487..0a9de88187 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/OveruseEstimator.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/OveruseEstimator.cpp @@ -13,24 +13,25 @@ #include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" #include "Logger.hpp" +#include #include #include #include -#include namespace RTC { constexpr size_t kMinFramePeriodHistoryLength = 60; - constexpr uint16_t kDeltaCounterMax = 1000; + constexpr uint16_t kDeltaCounterMax = 1000; - void OveruseEstimator::Update(int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs) + void OveruseEstimator::Update( + int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs) { MS_TRACE(); (void)nowMs; const double minFramePeriod = UpdateMinFramePeriod(tsDelta); - const double tTsDelta = tDelta - tsDelta; - double fsDelta = sizeDelta; + const double tTsDelta = tDelta - tsDelta; + double fsDelta = sizeDelta; ++this->numOfDeltas; if (this->numOfDeltas > kDeltaCounterMax) @@ -48,9 +49,11 @@ namespace RTC this->E[1][1] += 10 * this->processNoise[1]; } - const double h[2] = {fsDelta, 1.0}; - const double Eh[2] = {this->E[0][0] * h[0] + this->E[0][1] * h[1], this->E[1][0] * h[0] + this->E[1][1] * h[1]}; - const double residual = tTsDelta - this->slope * h[0] - this->offset; + const double h[2] = {fsDelta, 1.0}; + const double Eh[2] = {this->E[0][0] * h[0] + this->E[0][1] * h[1], + this->E[1][0] * h[0] + this->E[1][1] * h[1]}; + + const double residual = tTsDelta - this->slope * h[0] - this->offset; const bool inStableState = (currentHypothesis == kBwNormal); const double maxResidual = 3.0 * sqrt(this->varNoise); @@ -65,9 +68,10 @@ namespace RTC UpdateNoiseEstimate(residual < 0 ? -maxResidual : maxResidual, minFramePeriod, inStableState); } - const double denom = this->varNoise + h[0] * Eh[0] + h[1] * Eh[1]; - const double K[2] = {Eh[0] / denom, Eh[1] / denom}; + const double denom = this->varNoise + h[0] * Eh[0] + h[1] * Eh[1]; + const double K[2] = {Eh[0] / denom, Eh[1] / denom}; const double IKh[2][2] = {{1.0 - K[0] * h[0], -K[0] * h[1]}, {-K[1] * h[0], 1.0 - K[1] * h[1]}}; + const double e00 = this->E[0][0]; const double e01 = this->E[0][1]; @@ -78,8 +82,9 @@ namespace RTC this->E[1][1] = e01 * IKh[1][0] + this->E[1][1] * IKh[1][1]; // The covariance matrix must be positive semi-definite. - bool positiveSemiDefinite = - this->E[0][0] + this->E[1][1] >= 0 && this->E[0][0] * this->E[1][1] - this->E[0][1] * this->E[1][0] >= 0 && this->E[0][0] >= 0; + bool positiveSemiDefinite = this->E[0][0] + this->E[1][1] >= 0 && + this->E[0][0] * this->E[1][1] - this->E[0][1] * this->E[1][0] >= 0 && + this->E[0][0] >= 0; MS_ASSERT(positiveSemiDefinite, "positiveSemiDefinite missing"); @@ -88,9 +93,9 @@ namespace RTC MS_ERROR("the over-use estimator's covariance matrix is no longer semi-definite"); } - this->slope = this->slope + K[0] * residual; + this->slope = this->slope + K[0] * residual; this->prevOffset = this->offset; - this->offset = this->offset + K[1] * residual; + this->offset = this->offset + K[1] * residual; } double OveruseEstimator::UpdateMinFramePeriod(double tsDelta) @@ -136,7 +141,8 @@ namespace RTC const double beta = pow(1 - alpha, tsDelta * 30.0 / 1000.0); this->avgNoise = beta * this->avgNoise + (1 - beta) * residual; - this->varNoise = beta * this->varNoise + (1 - beta) * (this->avgNoise - residual) * (this->avgNoise - residual); + this->varNoise = beta * this->varNoise + + (1 - beta) * (this->avgNoise - residual) * (this->avgNoise - residual); if (this->varNoise < 1) { this->varNoise = 1; diff --git a/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp b/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp index 2bd45dd8a1..458e2bd776 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp @@ -12,24 +12,24 @@ // #define MS_LOG_DEV #include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp" -#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include "DepLibUV.hpp" #include "Logger.hpp" -#include +#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp" #include +#include namespace RTC { enum { - kTimestampGroupLengthMs = 5, - kAbsSendTimeFraction = 18, + kTimestampGroupLengthMs = 5, + kAbsSendTimeFraction = 18, kAbsSendTimeInterArrivalUpshift = 8, - kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, - kInitialProbingIntervalMs = 2000, - kMinClusterSize = 4, - kMaxProbePackets = 15, - kExpectedNumberOfProbes = 3 + kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, + kInitialProbingIntervalMs = 2000, + kMinClusterSize = 4, + kMaxProbePackets = 15, + kExpectedNumberOfProbes = 3 }; static constexpr double kTimestampToMs = 1000.0 / static_cast(1 << kInterArrivalShift); @@ -41,7 +41,8 @@ namespace RTC keys.reserve(map.size()); - for (typename std::map::const_iterator it = map.begin(); it != map.end(); ++it) + typename std::map::const_iterator it = map.begin(); + for (; it != map.end(); ++it) { keys.push_back(it->first); } @@ -51,12 +52,15 @@ namespace RTC uint32_t ConvertMsTo24Bits(int64_t timeMs) { - uint32_t time_24Bits = static_cast(((static_cast(timeMs) << kAbsSendTimeFraction) + 500) / 1000) & 0x00FFFFFF; + uint32_t time_24Bits = + static_cast(((static_cast(timeMs) << kAbsSendTimeFraction) + 500) / 1000) & + 0x00FFFFFF; return time_24Bits; } - bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds(int sendDeltaMs, const Cluster& clusterAggregate) + bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds( + int sendDeltaMs, const Cluster& clusterAggregate) { MS_TRACE(); @@ -86,7 +90,8 @@ namespace RTC int64_t prevSendTime = -1; int64_t prevRecvTime = -1; - for (std::list::const_iterator it = this->probes.begin(); it != this->probes.end(); ++it) + std::list::const_iterator it = this->probes.begin(); + for (; it != this->probes.end(); ++it) { if (prevSendTime >= 0) { @@ -120,26 +125,29 @@ namespace RTC AddCluster(clusters, ¤t); } - std::list::const_iterator RemoteBitrateEstimatorAbsSendTime::FindBestProbe(const std::list& clusters) const + std::list::const_iterator RemoteBitrateEstimatorAbsSendTime::FindBestProbe( + const std::list& clusters) const { MS_TRACE(); - int highestProbeBitrateBps = 0; + int highestProbeBitrateBps = 0; std::list::const_iterator bestIt = clusters.end(); - for (std::list::const_iterator it = clusters.begin(); it != clusters.end(); ++it) + std::list::const_iterator it = clusters.begin(); + for (; it != clusters.end(); ++it) { if (it->sendMeanMs == 0 || it->recvMeanMs == 0) continue; - if (it->numAboveMinDelta > it->count / 2 && (it->recvMeanMs - it->sendMeanMs <= 2.0f && it->sendMeanMs - it->recvMeanMs <= 5.0f)) + if (it->numAboveMinDelta > it->count / 2 && + (it->recvMeanMs - it->sendMeanMs <= 2.0f && it->sendMeanMs - it->recvMeanMs <= 5.0f)) { int probeBitrateBps = std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); if (probeBitrateBps > highestProbeBitrateBps) { highestProbeBitrateBps = probeBitrateBps; - bestIt = it; + bestIt = it; } } else @@ -147,8 +155,15 @@ namespace RTC int sendBitrateBps = it->meanSize * 8 * 1000 / it->sendMeanMs; int recvBitrateBps = it->meanSize * 8 * 1000 / it->recvMeanMs; - MS_DEBUG_TAG(rbe, "probe failed, sent at %d bps, received at %d bps [mean send delta:%fms, mean recv delta:%fms, num probes:%d]", - sendBitrateBps, recvBitrateBps, it->sendMeanMs, it->recvMeanMs, it->count); + MS_DEBUG_TAG( + rbe, + "probe failed, sent at %d bps, received at %d bps [mean " + "send delta:%fms, mean recv delta:%fms, num probes:%d]", + sendBitrateBps, + recvBitrateBps, + it->sendMeanMs, + it->recvMeanMs, + it->count); break; } @@ -157,7 +172,8 @@ namespace RTC return bestIt; } - RemoteBitrateEstimatorAbsSendTime::ProbeResult RemoteBitrateEstimatorAbsSendTime::ProcessClusters(int64_t nowMs) + RemoteBitrateEstimatorAbsSendTime::ProbeResult RemoteBitrateEstimatorAbsSendTime::ProcessClusters( + int64_t nowMs) { MS_TRACE(); @@ -183,8 +199,16 @@ namespace RTC // reduce the estimate. if (IsBitrateImproving(probeBitrateBps)) { - MS_DEBUG_TAG(rbe, "probe successful, sent at %d bps, received at %d bps [mean send delta:%fms, mean recv delta: %f ms, num probes:%d", - bestIt->GetSendBitrateBps(), bestIt->GetRecvBitrateBps(), bestIt->sendMeanMs, bestIt->recvMeanMs, bestIt->count); + MS_DEBUG_TAG( + rbe, + "probe successful, sent at %d bps, received at %d bps " + "[mean send delta:%fms, mean recv delta: %f ms, " + "num probes:%d", + bestIt->GetSendBitrateBps(), + bestIt->GetRecvBitrateBps(), + bestIt->sendMeanMs, + bestIt->recvMeanMs, + bestIt->count); this->remoteRate.SetEstimate(probeBitrateBps, nowMs); @@ -204,21 +228,23 @@ namespace RTC { MS_TRACE(); - bool initialProbe = !this->remoteRate.ValidEstimate() && newBitrateBps > 0; + bool initialProbe = !this->remoteRate.ValidEstimate() && newBitrateBps > 0; bool bitrateAboveEstimate = this->remoteRate.ValidEstimate() && - newBitrateBps > static_cast(this->remoteRate.LatestEstimate()); + newBitrateBps > static_cast(this->remoteRate.LatestEstimate()); return initialProbe || bitrateAboveEstimate; } - void RemoteBitrateEstimatorAbsSendTime::IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime) + void RemoteBitrateEstimatorAbsSendTime::IncomingPacket( + int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime) { MS_TRACE(); IncomingPacketInfo(arrivalTimeMs, absSendTime, payloadSize, packet.GetSsrc()); } - void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo(int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc) + void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( + int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc) { MS_TRACE(); @@ -231,7 +257,7 @@ namespace RTC // so wrapping works properly. uint32_t timestamp = sendTime_24bits << kAbsSendTimeInterArrivalUpshift; int64_t sendTimeMs = static_cast(timestamp) * kTimestampToMs; - int64_t nowMs = DepLibUV::GetTime(); + int64_t nowMs = DepLibUV::GetTime(); // TODO(holmer): SSRCs are only needed for REMB, should be broken out from // here. // Check if incoming bitrate estimate is valid, and if it needs to be reset. @@ -255,10 +281,10 @@ namespace RTC if (this->firstPacketTimeMs == -1) this->firstPacketTimeMs = nowMs; - uint32_t tsDelta = 0; - int64_t tDelta = 0; - int sizeDelta = 0; - bool updateEstimate = false; + uint32_t tsDelta = 0; + int64_t tDelta = 0; + int sizeDelta = 0; + bool updateEstimate = false; uint32_t targetBitrateBps = 0; std::vector ssrcs; @@ -275,7 +301,9 @@ namespace RTC // the sender. const size_t kMinProbePacketSize = 200; - if (payloadSize > kMinProbePacketSize && (!this->remoteRate.ValidEstimate() || nowMs - this->firstPacketTimeMs < kInitialProbingIntervalMs)) + if (payloadSize > kMinProbePacketSize && + (!this->remoteRate.ValidEstimate() || + nowMs - this->firstPacketTimeMs < kInitialProbingIntervalMs)) { // TODO(holmer): Use a map instead to get correct order? if (this->totalProbesReceived < kMaxProbePackets) @@ -289,8 +317,15 @@ namespace RTC recvDeltaMs = arrivalTimeMs - this->probes.back().recvTimeMs; } - MS_DEBUG_TAG(rbe, - "probe packet received [send time:%" PRId64 "ms, recv time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]", sendTimeMs, arrivalTimeMs, sendDeltaMs, recvDeltaMs); + MS_DEBUG_TAG( + rbe, + "probe packet received [send time:%" PRId64 + "ms, recv " + "time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]", + sendTimeMs, + arrivalTimeMs, + sendDeltaMs, + recvDeltaMs); } this->probes.push_back(Probe(sendTimeMs, arrivalTimeMs, payloadSize)); @@ -302,21 +337,22 @@ namespace RTC updateEstimate = true; } - if (this->interArrival->ComputeDeltas(timestamp, arrivalTimeMs, nowMs, payloadSize, &tsDelta, &tDelta, &sizeDelta)) + if (this->interArrival->ComputeDeltas( + timestamp, arrivalTimeMs, nowMs, payloadSize, &tsDelta, &tDelta, &sizeDelta)) { double tsDeltaMs = (1000.0 * tsDelta) / (1 << kInterArrivalShift); this->estimator->Update(tDelta, tsDeltaMs, sizeDelta, this->detector.State(), arrivalTimeMs); - this->detector.Detect(this->estimator->GetOffset(), tsDeltaMs, this->estimator->GetNumOfDeltas(), arrivalTimeMs); + this->detector.Detect( + this->estimator->GetOffset(), tsDeltaMs, this->estimator->GetNumOfDeltas(), arrivalTimeMs); } if (!updateEstimate) { // Check if it's time for a periodic update or if we should update because // of an over-use. - if ( - this->lastUpdateMs == -1 || - nowMs - this->lastUpdateMs > this->remoteRate.GetFeedbackInterval()) + if (this->lastUpdateMs == -1 || + nowMs - this->lastUpdateMs > this->remoteRate.GetFeedbackInterval()) { updateEstimate = true; } @@ -335,13 +371,14 @@ namespace RTC // We also have to update the estimate immediately if we are overusing // and the target bitrate is too high compared to what we are receiving. const RateControlInput input( - this->detector.State(), this->incomingBitrate.GetRate(arrivalTimeMs), - this->estimator->GetVarNoise()); + this->detector.State(), + this->incomingBitrate.GetRate(arrivalTimeMs), + this->estimator->GetVarNoise()); this->remoteRate.Update(&input, nowMs); targetBitrateBps = this->remoteRate.UpdateBandwidthEstimate(nowMs); - updateEstimate = this->remoteRate.ValidEstimate(); - ssrcs = Keys(this->ssrcs); + updateEstimate = this->remoteRate.ValidEstimate(); + ssrcs = Keys(this->ssrcs); } } @@ -367,14 +404,16 @@ namespace RTC if (this->ssrcs.empty()) { // We can't update the estimate if we don't have any active streams. - this->interArrival.reset(new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, kTimestampToMs, true)); + this->interArrival.reset(new InterArrival( + (kTimestampGroupLengthMs << kInterArrivalShift) / 1000, kTimestampToMs, true)); this->estimator.reset(new OveruseEstimator(OverUseDetectorOptions())); // We deliberately don't reset the this->firstPacketTimeMs here for now since // we only probe for bandwidth in the beginning of a call right now. } } - bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate(std::vector* ssrcs, uint32_t* bitrateBps) const + bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate( + std::vector* ssrcs, uint32_t* bitrateBps) const { MS_TRACE(); diff --git a/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp b/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp index aba2c3a794..4b0bd0a5a8 100644 --- a/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp +++ b/worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp @@ -12,17 +12,21 @@ // #define MS_LOG_DEV #include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.hpp" +#include "DepLibUV.hpp" +#include "Logger.hpp" #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" #include "RTC/RemoteBitrateEstimator/InterArrival.hpp" #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" #include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" -#include "DepLibUV.hpp" -#include "Logger.hpp" -#include // std::make_pair +#include // std::make_pair() namespace RTC { - void RemoteBitrateEstimatorSingleStream::IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t transmissionTimeOffset) + void RemoteBitrateEstimatorSingleStream::IncomingPacket( + int64_t arrivalTimeMs, + size_t payloadSize, + const RtpPacket& packet, + const uint32_t transmissionTimeOffset) { MS_TRACE(); @@ -31,9 +35,9 @@ namespace RTC this->umaRecorded = true; } - uint32_t ssrc = packet.GetSsrc(); + uint32_t ssrc = packet.GetSsrc(); uint32_t rtpTimestamp = packet.GetTimestamp() + transmissionTimeOffset; - int64_t nowMs = DepLibUV::GetTime(); + int64_t nowMs = DepLibUV::GetTime(); SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.find(ssrc); if (it == this->overuseDetectors.end()) @@ -44,12 +48,12 @@ namespace RTC // callback will no longer be called for the old SSRC. This will be // automatically cleaned up when we have one RemoteBitrateEstimator per REMB // group. - std::pair insertResult = - this->overuseDetectors.insert(std::make_pair(ssrc, new Detector(nowMs, OverUseDetectorOptions(), true))); + std::pair insertResult = this->overuseDetectors.insert( + std::make_pair(ssrc, new Detector(nowMs, OverUseDetectorOptions(), true))); it = insertResult.first; } - Detector* estimator = it->second; + Detector* estimator = it->second; estimator->lastPacketTimeMs = nowMs; // Check if incoming bitrate estimate is valid, and if it needs to be reset. @@ -71,23 +75,31 @@ namespace RTC this->incomingBitrate.Update(payloadSize, nowMs); const BandwidthUsage priorState = estimator->detector.State(); - uint32_t timestampDelta = 0; - int64_t timeDelta = 0; - int sizeDelta = 0; + uint32_t timestampDelta = 0; + int64_t timeDelta = 0; + int sizeDelta = 0; - if (estimator->interArrival.ComputeDeltas(rtpTimestamp, arrivalTimeMs, nowMs, payloadSize, ×tampDelta, &timeDelta, &sizeDelta)) + if (estimator->interArrival.ComputeDeltas( + rtpTimestamp, arrivalTimeMs, nowMs, payloadSize, ×tampDelta, &timeDelta, &sizeDelta)) { double timestampDeltaMs = timestampDelta * kTimestampToMs; - estimator->estimator.Update(timeDelta, timestampDeltaMs, sizeDelta, estimator->detector.State(), nowMs); - estimator->detector.Detect(estimator->estimator.GetOffset(), timestampDeltaMs, estimator->estimator.GetNumOfDeltas(), nowMs); + estimator->estimator.Update( + timeDelta, timestampDeltaMs, sizeDelta, estimator->detector.State(), nowMs); + + estimator->detector.Detect( + estimator->estimator.GetOffset(), + timestampDeltaMs, + estimator->estimator.GetNumOfDeltas(), + nowMs); } if (estimator->detector.State() == kBwOverusing) { uint32_t incomingBitrateBps = this->incomingBitrate.GetRate(nowMs); - if (incomingBitrateBps && (priorState != kBwOverusing || GetRemoteRate()->TimeToReduceFurther(nowMs, incomingBitrateBps))) + if (incomingBitrateBps && (priorState != kBwOverusing || + GetRemoteRate()->TimeToReduceFurther(nowMs, incomingBitrateBps))) { // The first overuse should immediately trigger a new estimate. // We also have to update the estimate immediately if we are overusing @@ -112,8 +124,8 @@ namespace RTC { MS_TRACE(); - BandwidthUsage bwState = kBwNormal; - double sumVarNoise = 0.0; + BandwidthUsage bwState = kBwNormal; + double sumVarNoise = 0.0; SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.begin(); while (it != this->overuseDetectors.end()) @@ -145,7 +157,7 @@ namespace RTC } AimdRateControl* remoteRate = GetRemoteRate(); - double meanNoiseVar = sumVarNoise / static_cast(this->overuseDetectors.size()); + double meanNoiseVar = sumVarNoise / static_cast(this->overuseDetectors.size()); const RateControlInput input(bwState, this->incomingBitrate.GetRate(nowMs), meanNoiseVar); remoteRate->Update(&input, nowMs); @@ -155,6 +167,7 @@ namespace RTC if (remoteRate->ValidEstimate()) { this->processIntervalMs = remoteRate->GetFeedbackInterval(); + // MS_ASSERT(this->processIntervalMs > 0); std::vector ssrcs; @@ -164,7 +177,8 @@ namespace RTC } } - bool RemoteBitrateEstimatorSingleStream::LatestEstimate(std::vector* ssrcs, uint32_t* bitrateBps) const + bool RemoteBitrateEstimatorSingleStream::LatestEstimate( + std::vector* ssrcs, uint32_t* bitrateBps) const { MS_TRACE(); @@ -190,9 +204,10 @@ namespace RTC ssrcs->resize(this->overuseDetectors.size()); - int i = 0; + int i = 0; + SsrcOveruseEstimatorMap::const_iterator it = this->overuseDetectors.begin(); - for (SsrcOveruseEstimatorMap::const_iterator it = this->overuseDetectors.begin(); it != this->overuseDetectors.end(); ++it, ++i) + for (; it != this->overuseDetectors.end(); ++it, ++i) { (*ssrcs)[i] = it->first; } diff --git a/worker/src/RTC/Room.cpp b/worker/src/RTC/Room.cpp index 49d71d90ca..dc1f1c10a2 100644 --- a/worker/src/RTC/Room.cpp +++ b/worker/src/RTC/Room.cpp @@ -2,12 +2,12 @@ // #define MS_LOG_DEV #include "RTC/Room.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" #include "Utils.hpp" +#include #include #include -#include namespace RTC { @@ -31,18 +31,22 @@ namespace RTC Json::CharReader* jsonReader = builder.newCharReader(); // NOTE: These lines are auto-generated from data/supportedCapabilities.js. - const std::string supportedRtpCapabilities = R"({"codecs":[{"kind":"audio","name":"audio/opus","clockRate":48000,"numChannels":2,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})"; + const std::string supportedRtpCapabilities = + R"({"codecs":[{"kind":"audio","name":"audio/opus","clockRate":48000,"numChannels":2,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})"; Json::Value json; std::string jsonParseError; - if (!jsonReader->parse(supportedRtpCapabilities.c_str(), - supportedRtpCapabilities.c_str() + supportedRtpCapabilities.length(), &json, &jsonParseError)) + if (!jsonReader->parse( + supportedRtpCapabilities.c_str(), + supportedRtpCapabilities.c_str() + supportedRtpCapabilities.length(), + &json, + &jsonParseError)) { delete jsonReader; - MS_THROW_ERROR_STD("JSON parsing error in supported RTP capabilities: %s", - jsonParseError.c_str()); + MS_THROW_ERROR_STD( + "JSON parsing error in supported RTP capabilities: %s", jsonParseError.c_str()); } else { @@ -53,7 +57,7 @@ namespace RTC { Room::supportedRtpCapabilities = RTC::RtpCapabilities(json, RTC::Scope::ROOM_CAPABILITY); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_THROW_ERROR_STD("wrong supported RTP capabilities: %s", error.what()); } @@ -62,10 +66,10 @@ namespace RTC /* Instance methods. */ - Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data) : - roomId(roomId), - listener(listener), - notifier(notifier) + Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data) + : roomId(roomId) + , listener(listener) + , notifier(notifier) { MS_TRACE(); @@ -191,11 +195,11 @@ namespace RTC // Add `mapRtpSenderRtpReceiver`. for (auto& kv : this->mapRtpSenderRtpReceiver) { - auto rtpSender = kv.first; + auto rtpSender = kv.first; auto rtpReceiver = kv.second; jsonMapRtpSenderRtpReceiver[std::to_string(rtpSender->rtpSenderId)] = - std::to_string(rtpReceiver->rtpReceiverId); + std::to_string(rtpReceiver->rtpReceiverId); } json[k_mapRtpSenderRtpReceiver] = jsonMapRtpSenderRtpReceiver; @@ -210,9 +214,9 @@ namespace RTC { case Channel::Request::MethodId::room_close: { - #ifdef MS_LOG_DEV +#ifdef MS_LOG_DEV uint32_t roomId = this->roomId; - #endif +#endif Destroy(); @@ -244,7 +248,7 @@ namespace RTC { peer = GetPeerFromRequest(request, &peerId); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -271,7 +275,7 @@ namespace RTC { peer = new RTC::Peer(this, this->notifier, peerId, peerName); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -312,7 +316,7 @@ namespace RTC { peer = GetPeerFromRequest(request); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -375,19 +379,12 @@ namespace RTC // Set codecs. { // Available dynamic payload types. - static const std::vector dynamicPayloadTypes - { - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, - 96, 97, 98, 99, - 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, 93, 94, 95, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71 - }; + static const std::vector dynamicPayloadTypes{ + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, + 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 96, 97, 98, 99, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71}; // Iterator for available dynamic payload types. auto dynamicPayloadTypeIt = dynamicPayloadTypes.begin(); // Payload types used by the room. @@ -404,9 +401,8 @@ namespace RTC // Set unique PT. // If the codec has PT and it's not already used, let it untouched. - if ( - mediaCodec.hasPayloadType && - roomPayloadTypes.find(mediaCodec.payloadType) == roomPayloadTypes.end()) + if (mediaCodec.hasPayloadType && + roomPayloadTypes.find(mediaCodec.payloadType) == roomPayloadTypes.end()) { ; } @@ -422,7 +418,7 @@ namespace RTC if (roomPayloadTypes.find(payloadType) == roomPayloadTypes.end()) { // Assign PT. - mediaCodec.payloadType = payloadType; + mediaCodec.payloadType = payloadType; mediaCodec.hasPayloadType = true; break; @@ -466,7 +462,7 @@ namespace RTC for (auto it = capabilities->codecs.begin(); it != capabilities->codecs.end();) { auto& peerCodecCapability = *it; - auto it2 = this->capabilities.codecs.begin(); + auto it2 = this->capabilities.codecs.begin(); for (; it2 != this->capabilities.codecs.end(); ++it2) { @@ -475,7 +471,7 @@ namespace RTC if (roomCodecCapability.Matches(peerCodecCapability)) { // Set the same payload type. - peerCodecCapability.payloadType = roomCodecCapability.payloadType; + peerCodecCapability.payloadType = roomCodecCapability.payloadType; peerCodecCapability.hasPayloadType = true; // Remove the unsupported RTCP feedback from the given codec. @@ -510,8 +506,8 @@ namespace RTC continue; uint32_t rtpSenderId = Utils::Crypto::GetRandomUInt(10000000, 99999999); - RTC::RtpSender* rtpSender = new RTC::RtpSender(peer, this->notifier, rtpSenderId, - rtpReceiver->kind); + RTC::RtpSender* rtpSender = + new RTC::RtpSender(peer, this->notifier, rtpSenderId, rtpReceiver->kind); // Store into the maps. this->mapRtpReceiverRtpSenders[rtpReceiver].insert(rtpSender); @@ -550,8 +546,8 @@ namespace RTC // Create a RtpSender for the other Peer. uint32_t rtpSenderId = Utils::Crypto::GetRandomUInt(10000000, 99999999); - RTC::RtpSender* rtpSender = new RTC::RtpSender(senderPeer, this->notifier, rtpSenderId, - rtpReceiver->kind); + RTC::RtpSender* rtpSender = + new RTC::RtpSender(senderPeer, this->notifier, rtpSenderId, rtpReceiver->kind); // Store into the maps. this->mapRtpReceiverRtpSenders[rtpReceiver].insert(rtpSender); @@ -618,8 +614,9 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapRtpReceiverRtpSenders.find(rtpReceiver) != - this->mapRtpReceiverRtpSenders.end(), "RtpReceiver not present in the map"); + MS_ASSERT( + this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end(), + "RtpReceiver not present in the map"); auto& rtpSenders = this->mapRtpReceiverRtpSenders[rtpReceiver]; @@ -631,57 +628,66 @@ namespace RTC } } - void Room::onPeerRtcpReceiverReport(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) + void Room::onPeerRtcpReceiverReport( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) { MS_TRACE(); - MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != - this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map"); + MS_ASSERT( + this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), + "RtpSender not present in the map"); rtpSender->ReceiveRtcpReceiverReport(report); } - void Room::onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) + void Room::onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) { MS_TRACE(); - MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != - this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map"); + MS_ASSERT( + this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), + "RtpSender not present in the map"); auto& rtpReceiver = this->mapRtpSenderRtpReceiver[rtpSender]; rtpReceiver->ReceiveRtcpFeedback(packet); } - void Room::onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) + void Room::onPeerRtcpFeedback( + const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) { MS_TRACE(); - MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != - this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map"); + MS_ASSERT( + this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), + "RtpSender not present in the map"); auto& rtpReceiver = this->mapRtpSenderRtpReceiver[rtpSender]; rtpReceiver->ReceiveRtcpFeedback(packet); } - void Room::onPeerRtcpSenderReport(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) + void Room::onPeerRtcpSenderReport( + const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) { MS_TRACE(); // RtpReceiver needs the sender report in order to generate it's receiver report. rtpReceiver->ReceiveRtcpSenderReport(report); - MS_ASSERT(this->mapRtpReceiverRtpSenders.find(rtpReceiver) != - this->mapRtpReceiverRtpSenders.end(), "RtpReceiver not present in the map"); + MS_ASSERT( + this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end(), + "RtpReceiver not present in the map"); } void Room::onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) { MS_TRACE(); - MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != - this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map"); + MS_ASSERT( + this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), + "RtpSender not present in the map"); auto& rtpReceiver = this->mapRtpSenderRtpReceiver[rtpSender]; diff --git a/worker/src/RTC/RtpDataCounter.cpp b/worker/src/RTC/RtpDataCounter.cpp index 2a2d29913f..617e45d29b 100644 --- a/worker/src/RTC/RtpDataCounter.cpp +++ b/worker/src/RTC/RtpDataCounter.cpp @@ -18,7 +18,7 @@ namespace RTC // Set data in the index before the oldest index. uint32_t offset = this->windowSize - 1; - uint32_t index = this->oldestIndex + offset; + uint32_t index = this->oldestIndex + offset; if (index >= this->windowSize) index -= this->windowSize; @@ -34,7 +34,7 @@ namespace RTC this->RemoveOldData(now); int64_t nominalWindowSize = now - this->oldestTime; - float scale = this->scale / nominalWindowSize; + float scale = this->scale / nominalWindowSize; return static_cast(this->totalCount * scale + 0.5f); } diff --git a/worker/src/RTC/RtpDictionaries/Media.cpp b/worker/src/RTC/RtpDictionaries/Media.cpp index 3709d790a7..cb8c3b892c 100644 --- a/worker/src/RTC/RtpDictionaries/Media.cpp +++ b/worker/src/RTC/RtpDictionaries/Media.cpp @@ -1,15 +1,16 @@ #define MS_CLASS "RTC::Media" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { /* Class variables. */ + // clang-format off std::unordered_map Media::string2Kind = { { "", Media::Kind::ALL }, @@ -17,7 +18,6 @@ namespace RTC { "video", Media::Kind::VIDEO }, { "depth", Media::Kind::DEPTH } }; - std::map Media::kind2Json = { { Media::Kind::ALL, Json::StaticString("") }, @@ -25,6 +25,7 @@ namespace RTC { Media::Kind::VIDEO, Json::StaticString("video") }, { Media::Kind::DEPTH, Json::StaticString("depth") } }; + // clang-format on /* Class methods. */ diff --git a/worker/src/RTC/RtpDictionaries/Parameters.cpp b/worker/src/RTC/RtpDictionaries/Parameters.cpp index 8a047139d6..bedeb86395 100644 --- a/worker/src/RTC/RtpDictionaries/Parameters.cpp +++ b/worker/src/RTC/RtpDictionaries/Parameters.cpp @@ -16,7 +16,7 @@ namespace RTC for (auto& kv : this->mapKeyValues) { - auto& key = kv.first; + auto& key = kv.first; auto& value = kv.second; switch (value.type) @@ -74,7 +74,7 @@ namespace RTC for (Json::Value::iterator it = data.begin(); it != data.end(); ++it) { - std::string key = it.key().asString(); + std::string key = it.key().asString(); Json::Value value = (*it); switch (value.type()) @@ -141,8 +141,7 @@ namespace RTC break; } - default: - ; // Just ignore other value types. + default:; // Just ignore other value types. } } } @@ -151,8 +150,10 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapKeyValues.find(key) != this->mapKeyValues.end(), - "key does not exist [key:%s]", key.c_str()); + MS_ASSERT( + this->mapKeyValues.find(key) != this->mapKeyValues.end(), + "key does not exist [key:%s]", + key.c_str()); return this->mapKeyValues[key].booleanValue; } @@ -161,8 +162,10 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapKeyValues.find(key) != this->mapKeyValues.end(), - "key does not exist [key:%s]", key.c_str()); + MS_ASSERT( + this->mapKeyValues.find(key) != this->mapKeyValues.end(), + "key does not exist [key:%s]", + key.c_str()); return this->mapKeyValues[key].integerValue; } @@ -171,8 +174,10 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapKeyValues.find(key) != this->mapKeyValues.end(), - "key does not exist [key:%s]", key.c_str()); + MS_ASSERT( + this->mapKeyValues.find(key) != this->mapKeyValues.end(), + "key does not exist [key:%s]", + key.c_str()); return this->mapKeyValues[key].doubleValue; } @@ -181,8 +186,10 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapKeyValues.find(key) != this->mapKeyValues.end(), - "key does not exist [key:%s]", key.c_str()); + MS_ASSERT( + this->mapKeyValues.find(key) != this->mapKeyValues.end(), + "key does not exist [key:%s]", + key.c_str()); return this->mapKeyValues[key].stringValue; } @@ -191,8 +198,10 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->mapKeyValues.find(key) != this->mapKeyValues.end(), - "key does not exist [key:%s]", key.c_str()); + MS_ASSERT( + this->mapKeyValues.find(key) != this->mapKeyValues.end(), + "key does not exist [key:%s]", + key.c_str()); return this->mapKeyValues[key].arrayOfIntegers; } diff --git a/worker/src/RTC/RtpDictionaries/RtcpFeedback.cpp b/worker/src/RTC/RtpDictionaries/RtcpFeedback.cpp index 653f5ff304..f66fa1483e 100644 --- a/worker/src/RTC/RtpDictionaries/RtcpFeedback.cpp +++ b/worker/src/RTC/RtpDictionaries/RtcpFeedback.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtcpFeedback" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpDictionaries/RtcpParameters.cpp b/worker/src/RTC/RtpDictionaries/RtcpParameters.cpp index 3d59a879f7..f4a8c18d48 100644 --- a/worker/src/RTC/RtpDictionaries/RtcpParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtcpParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtcpParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp b/worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp index b0b8d98fe5..f2e4dcb095 100644 --- a/worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpCapabilities.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpCapabilities" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" #include namespace RTC @@ -21,11 +21,11 @@ namespace RTC // `codecs` is optional. if (data[k_codecs].isArray()) { - auto& json_codecs = data[k_codecs]; + auto& jsonCodecs = data[k_codecs]; - for (Json::UInt i = 0; i < json_codecs.size(); ++i) + for (Json::UInt i = 0; i < jsonCodecs.size(); ++i) { - RtpCodecParameters codec(json_codecs[i], scope); + RtpCodecParameters codec(jsonCodecs[i], scope); // Append to the codecs vector. this->codecs.push_back(codec); @@ -35,11 +35,11 @@ namespace RTC // `headerExtensions` is optional. if (data[k_headerExtensions].isArray()) { - auto& json_array = data[k_headerExtensions]; + auto& jsonArray = data[k_headerExtensions]; - for (Json::UInt i = 0; i < json_array.size(); ++i) + for (Json::UInt i = 0; i < jsonArray.size(); ++i) { - RtpHeaderExtension headerExtension(json_array[i]); + RtpHeaderExtension headerExtension(jsonArray[i]); // If a known header extension, append to the headerExtensions vector. if (headerExtension.type != RtpHeaderExtensionUri::Type::UNKNOWN) @@ -50,15 +50,15 @@ namespace RTC // `fecMechanisms` is optional. if (data[k_fecMechanisms].isArray()) { - auto& json_array = data[k_fecMechanisms]; + auto& jsonArray = data[k_fecMechanisms]; - for (Json::UInt i = 0; i < json_array.size(); ++i) + for (Json::UInt i = 0; i < jsonArray.size(); ++i) { - if (!json_array[i].isString()) + if (!jsonArray[i].isString()) MS_THROW_ERROR("invalid RtpCapabilities.fecMechanisms"); // Append to the fecMechanisms vector. - this->fecMechanisms.push_back(json_array[i].asString()); + this->fecMechanisms.push_back(jsonArray[i].asString()); } } @@ -104,7 +104,8 @@ namespace RTC return json; } - void RtpCapabilities::ReduceHeaderExtensions(std::vector& supportedHeaderExtensions) + void RtpCapabilities::ReduceHeaderExtensions( + std::vector& supportedHeaderExtensions) { MS_TRACE(); @@ -114,15 +115,12 @@ namespace RTC { for (auto& supportedHeaderExtension : supportedHeaderExtensions) { - if ( - headerExtension.type == supportedHeaderExtension.type && - ( - headerExtension.kind == supportedHeaderExtension.kind || - supportedHeaderExtension.kind == RTC::Media::Kind::ALL - )) + if (headerExtension.type == supportedHeaderExtension.type && + (headerExtension.kind == supportedHeaderExtension.kind || + supportedHeaderExtension.kind == RTC::Media::Kind::ALL)) { // Set the same id and other properties. - headerExtension.preferredId = supportedHeaderExtension.preferredId; + headerExtension.preferredId = supportedHeaderExtension.preferredId; headerExtension.preferredEncrypt = supportedHeaderExtension.preferredEncrypt; updatedHeaderExtensions.push_back(headerExtension); @@ -157,8 +155,7 @@ namespace RTC this->fecMechanisms = updatedFecMechanisms; } - inline - void RtpCapabilities::ValidateCodecs(RTC::Scope scope) + inline void RtpCapabilities::ValidateCodecs(RTC::Scope scope) { MS_TRACE(); diff --git a/worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp b/worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp index 98a7bd35e8..6b6bfe364c 100644 --- a/worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpCodecMime.cpp @@ -1,27 +1,26 @@ #define MS_CLASS "RTC::RtpCodecMime" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { /* Class variables. */ + // clang-format off std::unordered_map RtpCodecMime::string2Type = { { "audio", RtpCodecMime::Type::AUDIO }, { "video", RtpCodecMime::Type::VIDEO } }; - std::map RtpCodecMime::type2String = { { RtpCodecMime::Type::AUDIO, "audio" }, { RtpCodecMime::Type::VIDEO, "video" } }; - std::unordered_map RtpCodecMime::string2Subtype = { // Audio codecs: @@ -46,7 +45,6 @@ namespace RTC { "flexfec", RtpCodecMime::Subtype::FLEXFEC }, { "red", RtpCodecMime::Subtype::RED } }; - std::map RtpCodecMime::subtype2String = { // Audio codecs: @@ -71,6 +69,7 @@ namespace RTC { RtpCodecMime::Subtype::FLEXFEC, "flexfec" }, { RtpCodecMime::Subtype::RED, "red" } }; + // clang-format on /* Instance methods. */ @@ -78,13 +77,13 @@ namespace RTC { MS_TRACE(); - auto slash_pos = name.find('/'); + auto slashPos = name.find('/'); - if (slash_pos == std::string::npos || slash_pos == 0 || slash_pos == name.length() - 1) + if (slashPos == std::string::npos || slashPos == 0 || slashPos == name.length() - 1) MS_THROW_ERROR("wrong codec MIME"); - std::string type = name.substr(0, slash_pos); - std::string subtype = name.substr(slash_pos + 1); + std::string type = name.substr(0, slashPos); + std::string subtype = name.substr(slashPos + 1); // Force lowcase names. Utils::String::ToLowerCase(type); diff --git a/worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp index ae282d7555..17295b80c0 100644 --- a/worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp @@ -1,16 +1,16 @@ #define MS_CLASS "RTC::RtpCodecParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { /* Instance methods. */ - RtpCodecParameters::RtpCodecParameters(Json::Value& data, RTC::Scope scope) : - scope(scope) + RtpCodecParameters::RtpCodecParameters(Json::Value& data, RTC::Scope scope) + : scope(scope) { MS_TRACE(); @@ -27,9 +27,7 @@ namespace RTC if (!data.isObject()) MS_THROW_ERROR("RtpCodecParameters is not an object"); - if ( - this->scope == RTC::Scope::ROOM_CAPABILITY || - this->scope == RTC::Scope::PEER_CAPABILITY) + if (this->scope == RTC::Scope::ROOM_CAPABILITY || this->scope == RTC::Scope::PEER_CAPABILITY) { // `kind` is mandatory. if (!data[k_kind].isString()) @@ -53,7 +51,7 @@ namespace RTC if (data[k_payloadType].isUInt()) { - this->payloadType = (uint8_t)data[k_payloadType].asUInt(); + this->payloadType = (uint8_t)data[k_payloadType].asUInt(); this->hasPayloadType = true; } @@ -68,7 +66,7 @@ namespace RTC if (!data[k_payloadType].isUInt()) MS_THROW_ERROR("missing RtpCodecParameters.payloadType"); - this->payloadType = (uint8_t)data[k_payloadType].asUInt(); + this->payloadType = (uint8_t)data[k_payloadType].asUInt(); this->hasPayloadType = true; } @@ -97,11 +95,11 @@ namespace RTC // `rtcpFeedback` is optional. if (data[k_rtcpFeedback].isArray()) { - auto& json_rtcpFeedback = data[k_rtcpFeedback]; + auto& jsonRtcpFeedback = data[k_rtcpFeedback]; - for (Json::UInt i = 0; i < json_rtcpFeedback.size(); ++i) + for (Json::UInt i = 0; i < jsonRtcpFeedback.size(); ++i) { - RTC::RtcpFeedback rtcpFeedback(json_rtcpFeedback[i]); + RTC::RtcpFeedback rtcpFeedback(jsonRtcpFeedback[i]); // Append to the rtcpFeedback vector. this->rtcpFeedback.push_back(rtcpFeedback); @@ -128,9 +126,7 @@ namespace RTC Json::Value json(Json::objectValue); - if ( - this->scope == RTC::Scope::ROOM_CAPABILITY || - this->scope == RTC::Scope::PEER_CAPABILITY) + if (this->scope == RTC::Scope::ROOM_CAPABILITY || this->scope == RTC::Scope::PEER_CAPABILITY) { // Add `kind`. json[k_kind] = RTC::Media::GetJsonString(this->kind); @@ -206,8 +202,7 @@ namespace RTC break; } - default: - ; + default:; } // Per MIME checks. @@ -215,7 +210,7 @@ namespace RTC { case RTC::RtpCodecMime::Subtype::H264: { - int32_t packetizationMode = this->parameters.GetInteger(k_packetizationMode); + int32_t packetizationMode = this->parameters.GetInteger(k_packetizationMode); int32_t givenPacketizationMode = codec.parameters.GetInteger(k_packetizationMode); if (packetizationMode != givenPacketizationMode) @@ -224,8 +219,7 @@ namespace RTC break; } - default: - ; + default:; } return true; @@ -241,9 +235,8 @@ namespace RTC { for (auto& supportedRtcpFeedbackItem : supportedRtcpFeedback) { - if ( - rtcpFeedbackItem.type == supportedRtcpFeedbackItem.type && - rtcpFeedbackItem.parameter == supportedRtcpFeedbackItem.parameter) + if (rtcpFeedbackItem.type == supportedRtcpFeedbackItem.type && + rtcpFeedbackItem.parameter == supportedRtcpFeedbackItem.parameter) { updatedRtcpFeedback.push_back(supportedRtcpFeedbackItem); @@ -255,12 +248,11 @@ namespace RTC this->rtcpFeedback = updatedRtcpFeedback; } - inline - void RtpCodecParameters::CheckCodec() + inline void RtpCodecParameters::CheckCodec() { MS_TRACE(); - static std::string k_apt = "apt"; + static std::string k_apt = "apt"; static std::string k_packetizationMode = "packetizationMode"; // Check per MIME parameters and set default values. @@ -293,8 +285,7 @@ namespace RTC break; } - default: - ; + default:; } } } diff --git a/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp index 17a26f8dff..80636c09fc 100644 --- a/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpEncodingParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { @@ -30,7 +30,7 @@ namespace RTC // `codecPayloadType` is optional. if (data[k_codecPayloadType].isUInt()) { - this->codecPayloadType = (uint8_t)data[k_codecPayloadType].asUInt(); + this->codecPayloadType = (uint8_t)data[k_codecPayloadType].asUInt(); this->hasCodecPayloadType = true; } @@ -41,14 +41,14 @@ namespace RTC // `fec` is optional. if (data[k_fec].isObject()) { - this->fec = RtpFecParameters(data[k_fec]); + this->fec = RtpFecParameters(data[k_fec]); this->hasFec = true; } // `rtx` is optional. if (data[k_rtx].isObject()) { - this->rtx = RtpRtxParameters(data[k_rtx]); + this->rtx = RtpRtxParameters(data[k_rtx]); this->hasRtx = true; } @@ -75,11 +75,11 @@ namespace RTC // `dependencyEncodingIds` is optional. if (data[k_dependencyEncodingIds].isArray()) { - auto& json_array = data[k_dependencyEncodingIds]; + auto& jsonArray = data[k_dependencyEncodingIds]; - for (Json::UInt i = 0; i < json_array.size(); ++i) + for (Json::UInt i = 0; i < jsonArray.size(); ++i) { - auto& entry = json_array[i]; + auto& entry = jsonArray[i]; // Append to the dependencyEncodingIds vector. if (entry.isString()) diff --git a/worker/src/RTC/RtpDictionaries/RtpFecParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpFecParameters.cpp index 20571b3ef4..03e9fe21e7 100644 --- a/worker/src/RTC/RtpDictionaries/RtpFecParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpFecParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpFecParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpDictionaries/RtpHeaderExtension.cpp b/worker/src/RTC/RtpDictionaries/RtpHeaderExtension.cpp index 628e285947..25e40874ee 100644 --- a/worker/src/RTC/RtpDictionaries/RtpHeaderExtension.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpHeaderExtension.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpHeaderExtension" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp index 39b628301b..92afaa6d07 100644 --- a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpHeaderExtensionParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp index c9a8952b3e..da14c64f36 100644 --- a/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp @@ -1,14 +1,15 @@ #define MS_CLASS "RTC::RtpHeaderExtensionUri" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { /* Class variables. */ + // clang-format off std::unordered_map RtpHeaderExtensionUri::string2Type = { { "urn:ietf:params:rtp-hdrext:ssrc-audio-level", RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL }, @@ -17,6 +18,7 @@ namespace RTC { "urn:3gpp:video-orientation", RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION }, { "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id", RtpHeaderExtensionUri::Type::RTP_STREAM_ID } }; + // clang-format on /* Class methods. */ diff --git a/worker/src/RTC/RtpDictionaries/RtpParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpParameters.cpp index 64b0662ab8..1538bbdfdd 100644 --- a/worker/src/RTC/RtpDictionaries/RtpParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" #include namespace RTC @@ -33,11 +33,11 @@ namespace RTC // `codecs` is mandatory. if (data[k_codecs].isArray()) { - auto& json_codecs = data[k_codecs]; + auto& jsonCodecs = data[k_codecs]; - for (Json::UInt i = 0; i < json_codecs.size(); ++i) + for (Json::UInt i = 0; i < jsonCodecs.size(); ++i) { - RTC::RtpCodecParameters codec(json_codecs[i], RTC::Scope::RECEIVE); + RTC::RtpCodecParameters codec(jsonCodecs[i], RTC::Scope::RECEIVE); // Append to the codecs vector. this->codecs.push_back(codec); @@ -51,11 +51,11 @@ namespace RTC // `encodings` is optional. if (data[k_encodings].isArray()) { - auto& json_array = data[k_encodings]; + auto& jsonArray = data[k_encodings]; - for (Json::UInt i = 0; i < json_array.size(); ++i) + for (Json::UInt i = 0; i < jsonArray.size(); ++i) { - RTC::RtpEncodingParameters encoding(json_array[i]); + RTC::RtpEncodingParameters encoding(jsonArray[i]); // Append to the encodings vector. this->encodings.push_back(encoding); @@ -65,11 +65,11 @@ namespace RTC // `headerExtensions` is optional. if (data[k_headerExtensions].isArray()) { - auto& json_array = data[k_headerExtensions]; + auto& jsonArray = data[k_headerExtensions]; - for (Json::UInt i = 0; i < json_array.size(); ++i) + for (Json::UInt i = 0; i < jsonArray.size(); ++i) { - RTC::RtpHeaderExtensionParameters headerExtension(json_array[i]); + RTC::RtpHeaderExtensionParameters headerExtension(jsonArray[i]); // If a known header extension, append to the headerExtensions vector. if (headerExtension.type != RtpHeaderExtensionUri::Type::UNKNOWN) @@ -80,7 +80,7 @@ namespace RTC // `rtcp` is optional. if (data[k_rtcp].isObject()) { - this->rtcp = RTC::RtcpParameters(data[k_rtcp]); + this->rtcp = RTC::RtcpParameters(data[k_rtcp]); this->hasRtcp = true; } @@ -95,14 +95,14 @@ namespace RTC ValidateEncodings(); } - RtpParameters::RtpParameters(const RtpParameters* rtpParameters) : - muxId(rtpParameters->muxId), - codecs(rtpParameters->codecs), - encodings(rtpParameters->encodings), - headerExtensions(rtpParameters->headerExtensions), - rtcp(rtpParameters->rtcp), - hasRtcp(rtpParameters->hasRtcp), - userParameters(rtpParameters->userParameters) + RtpParameters::RtpParameters(const RtpParameters* rtpParameters) + : muxId(rtpParameters->muxId) + , codecs(rtpParameters->codecs) + , encodings(rtpParameters->encodings) + , headerExtensions(rtpParameters->headerExtensions) + , rtcp(rtpParameters->rtcp) + , hasRtcp(rtpParameters->hasRtcp) + , userParameters(rtpParameters->userParameters) { MS_TRACE(); } @@ -167,7 +167,7 @@ namespace RTC for (auto it = this->codecs.begin(); it != this->codecs.end();) { auto& codec = *it; - auto it2 = capabilities.codecs.begin(); + auto it2 = capabilities.codecs.begin(); for (; it2 != capabilities.codecs.end(); ++it2) { @@ -184,8 +184,10 @@ namespace RTC } if (it2 == capabilities.codecs.end()) { - MS_WARN_DEV("no matching peer codec capability found [payloadType:%" PRIu8 ", mime:%s]", - codec.payloadType, codec.mime.GetName().c_str()); + MS_WARN_DEV( + "no matching peer codec capability found [payloadType:%" PRIu8 ", mime:%s]", + codec.payloadType, + codec.mime.GetName().c_str()); removedCodecPayloadTypes.push_back(codec.payloadType); it = this->codecs.erase(it); @@ -196,7 +198,7 @@ namespace RTC for (auto it = this->encodings.begin(); it != this->encodings.end();) { auto& encoding = *it; - auto it2 = removedCodecPayloadTypes.begin(); + auto it2 = removedCodecPayloadTypes.begin(); for (; it2 != removedCodecPayloadTypes.end(); ++it2) { @@ -234,7 +236,7 @@ namespace RTC if (headerExtension.type == supportedHeaderExtension.type) { // Set the same id and other properties. - headerExtension.id = supportedHeaderExtension.preferredId; + headerExtension.id = supportedHeaderExtension.preferredId; headerExtension.encrypt = supportedHeaderExtension.preferredEncrypt; updatedHeaderExtensions.push_back(headerExtension); @@ -271,8 +273,7 @@ namespace RTC return fakeCodec; } - inline - void RtpParameters::ValidateCodecs() + inline void RtpParameters::ValidateCodecs() { MS_TRACE(); @@ -298,7 +299,7 @@ namespace RTC { // NOTE: RtpCodecParameters already asserted that there is 'apt' parameter. int32_t apt = codec.parameters.GetInteger(k_apt); - auto it = this->codecs.begin(); + auto it = this->codecs.begin(); for (; it != this->codecs.end(); ++it) { @@ -322,14 +323,12 @@ namespace RTC break; } - default: - ; + default:; } } } - inline - void RtpParameters::ValidateEncodings() + inline void RtpParameters::ValidateEncodings() { uint8_t firstMediaPayloadType; @@ -358,7 +357,7 @@ namespace RTC { RTC::RtpEncodingParameters encoding; - encoding.codecPayloadType = firstMediaPayloadType; + encoding.codecPayloadType = firstMediaPayloadType; encoding.hasCodecPayloadType = true; // Insert into the encodings vector. @@ -372,7 +371,7 @@ namespace RTC { if (!encoding.hasCodecPayloadType) { - encoding.codecPayloadType = firstMediaPayloadType; + encoding.codecPayloadType = firstMediaPayloadType; encoding.hasCodecPayloadType = true; } else diff --git a/worker/src/RTC/RtpDictionaries/RtpRtxParameters.cpp b/worker/src/RTC/RtpDictionaries/RtpRtxParameters.cpp index 2684e571c6..3dfe1ffdb1 100644 --- a/worker/src/RTC/RtpDictionaries/RtpRtxParameters.cpp +++ b/worker/src/RTC/RtpDictionaries/RtpRtxParameters.cpp @@ -1,9 +1,9 @@ #define MS_CLASS "RTC::RtpRtxParameters" // #define MS_LOG_DEV -#include "RTC/RtpDictionaries.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RtpDictionaries.hpp" namespace RTC { diff --git a/worker/src/RTC/RtpListener.cpp b/worker/src/RTC/RtpListener.cpp index 21f7157dc5..a3cd4095a2 100644 --- a/worker/src/RTC/RtpListener.cpp +++ b/worker/src/RTC/RtpListener.cpp @@ -2,8 +2,8 @@ // #define MS_LOG_DEV #include "RTC/RtpListener.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" namespace RTC { @@ -25,7 +25,7 @@ namespace RTC // Add `ssrcTable`. for (auto& kv : this->ssrcTable) { - auto ssrc = kv.first; + auto ssrc = kv.first; auto rtpReceiver = kv.second; jsonSsrcTable[std::to_string(ssrc)] = std::to_string(rtpReceiver->rtpReceiverId); @@ -35,7 +35,7 @@ namespace RTC // Add `muxIdTable`. for (auto& kv : this->muxIdTable) { - auto muxId = kv.first; + auto muxId = kv.first; auto rtpReceiver = kv.second; jsonMuxIdTable[muxId] = std::to_string(rtpReceiver->rtpReceiverId); @@ -71,7 +71,7 @@ namespace RTC for (auto& kv : this->ssrcTable) { - auto ssrc = kv.first; + auto ssrc = kv.first; auto& existingRtpReceiver = kv.second; if (existingRtpReceiver == rtpReceiver) @@ -80,7 +80,7 @@ namespace RTC for (auto& kv : this->muxIdTable) { - auto& muxId = kv.first; + auto& muxId = kv.first; auto& existingRtpReceiver = kv.second; if (existingRtpReceiver == rtpReceiver) @@ -92,7 +92,7 @@ namespace RTC for (auto& kv : this->ptTable) { - auto payloadType = kv.first; + auto payloadType = kv.first; auto& existingRtpReceiver = kv.second; if (existingRtpReceiver == rtpReceiver) @@ -199,10 +199,8 @@ namespace RTC { auto& encoding = *it; - if ( - !encoding.ssrc || - (encoding.hasRtx && !encoding.rtx.ssrc) || - (encoding.hasFec && !encoding.fec.ssrc)) + if (!encoding.ssrc || (encoding.hasRtx && !encoding.rtx.ssrc) || + (encoding.hasFec && !encoding.fec.ssrc)) { break; } @@ -223,7 +221,8 @@ namespace RTC RemoveRtpReceiver(rtpReceiver); RollbackRtpReceiver(rtpReceiver, previousSsrcs, previousMuxId, previousPayloadTypes); - MS_THROW_ERROR("payloadType already exists in RTP listener [payloadType:%" PRIu8 "]", payloadType); + MS_THROW_ERROR( + "payloadType already exists in RTP listener [payloadType:%" PRIu8 "]", payloadType); } } } @@ -272,7 +271,7 @@ namespace RTC if (it != this->ssrcTable.end()) { - auto rtpReceiver = it->second; + auto rtpReceiver = it->second; auto rtpParameters = rtpReceiver->GetParameters(); // Ensure the RTP PT is present in RtpParameters. @@ -284,8 +283,7 @@ namespace RTC } // RTP PT not present. - MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]", - packet->GetPayloadType()); + MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType()); // TODO: We may emit "unhandledrtp" event. return nullptr; @@ -331,7 +329,11 @@ namespace RTC return nullptr; } - void RtpListener::RollbackRtpReceiver(RTC::RtpReceiver* rtpReceiver, std::vector& previousSsrcs, std::string& previousMuxId, std::vector& previousPayloadTypes) + void RtpListener::RollbackRtpReceiver( + RTC::RtpReceiver* rtpReceiver, + std::vector& previousSsrcs, + std::string& previousMuxId, + std::vector& previousPayloadTypes) { MS_TRACE(); diff --git a/worker/src/RTC/RtpPacket.cpp b/worker/src/RTC/RtpPacket.cpp index fc4421f2d3..c96b3625c1 100644 --- a/worker/src/RTC/RtpPacket.cpp +++ b/worker/src/RTC/RtpPacket.cpp @@ -35,8 +35,7 @@ namespace RTC // Packet size must be >= header size + CSRC list. if (len < (ptr - data) + csrcListSize) { - MS_WARN_TAG(rtp, - "not enough space for the announced CSRC list, packet discarded"); + MS_WARN_TAG(rtp, "not enough space for the announced CSRC list, packet discarded"); return nullptr; } @@ -45,15 +44,14 @@ namespace RTC // Check header extension. ExtensionHeader* extensionHeader = nullptr; - size_t extensionValueSize = 0; + size_t extensionValueSize = 0; if (header->extension) { // The extension header is at least 4 bytes. if (len < size_t(ptr - data) + 4) { - MS_WARN_TAG(rtp, - "not enough space for the announced extension header, packet discarded"); + MS_WARN_TAG(rtp, "not enough space for the announced extension header, packet discarded"); return nullptr; } @@ -67,8 +65,8 @@ namespace RTC // Packet size must be >= header size + CSRC list + header extension size. if (len < (ptr - data) + 4 + extensionValueSize) { - MS_WARN_TAG(rtp, - "not enough space for the announced header extension value, packet discarded"); + MS_WARN_TAG( + rtp, "not enough space for the announced header extension value, packet discarded"); return nullptr; } @@ -76,8 +74,8 @@ namespace RTC } // Get payload. - uint8_t* payload = ptr; - size_t payloadLength = len - (ptr - data); + uint8_t* payload = ptr; + size_t payloadLength = len - (ptr - data); uint8_t payloadPadding = 0; MS_ASSERT(len >= size_t(ptr - data), "payload has negative size"); @@ -88,8 +86,7 @@ namespace RTC // Must be at least a single payload byte. if (payloadLength == 0) { - MS_WARN_TAG(rtp, - "padding bit is set but no space for a padding byte, packet discarded"); + MS_WARN_TAG(rtp, "padding bit is set but no space for a padding byte, packet discarded"); return nullptr; } @@ -104,8 +101,10 @@ namespace RTC if (payloadLength < (size_t)payloadPadding) { - MS_WARN_TAG(rtp, - "number of padding octets is greater than available space for payload, packet discarded"); + MS_WARN_TAG( + rtp, + "number of padding octets is greater than available space for payload, packet " + "discarded"); return nullptr; } @@ -115,12 +114,13 @@ namespace RTC if (payloadLength == 0) payload = nullptr; - MS_ASSERT(len == sizeof(Header) + csrcListSize + (extensionHeader ? 4 + - extensionValueSize : 0) + payloadLength + (size_t)payloadPadding, - "packet's computed size does not match received size"); + MS_ASSERT( + len == sizeof(Header) + csrcListSize + (extensionHeader ? 4 + extensionValueSize : 0) + + payloadLength + (size_t)payloadPadding, + "packet's computed size does not match received size"); - RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, payloadLength, - payloadPadding, len); + RtpPacket* packet = + new RtpPacket(header, extensionHeader, payload, payloadLength, payloadPadding, len); // Parse RFC 5285 extension header. packet->ParseExtensions(); @@ -130,13 +130,19 @@ namespace RTC /* Instance methods. */ - RtpPacket::RtpPacket(Header* header, ExtensionHeader* extensionHeader, const uint8_t* payload, size_t payloadLength, uint8_t payloadPadding, size_t size) : - header(header), - extensionHeader(extensionHeader), - payload((uint8_t*)payload), - payloadLength(payloadLength), - payloadPadding(payloadPadding), - size(size) + RtpPacket::RtpPacket( + Header* header, + ExtensionHeader* extensionHeader, + const uint8_t* payload, + size_t payloadLength, + uint8_t payloadPadding, + size_t size) + : header(header) + , extensionHeader(extensionHeader) + , payload((uint8_t*)payload) + , payloadLength(payloadLength) + , payloadPadding(payloadPadding) + , size(size) { MS_TRACE(); @@ -288,8 +294,8 @@ namespace RTC MS_ASSERT(size_t(ptr - buffer) == this->size, "size_t(ptr - buffer) == this->size"); // Create the new RtpPacket instance and return it. - RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, this->payloadLength, - this->payloadPadding, this->size); + RtpPacket* packet = new RtpPacket( + header, extensionHeader, payload, this->payloadLength, this->payloadPadding, this->size); // Parse RFC 5285 extension header. packet->ParseExtensions(); @@ -311,8 +317,8 @@ namespace RTC this->oneByteExtensions.clear(); uint8_t* extensionStart = (uint8_t*)this->extensionHeader + 4; - uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength(); - uint8_t* ptr = extensionStart; + uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength(); + uint8_t* ptr = extensionStart; while (ptr < extensionEnd) { @@ -321,8 +327,8 @@ namespace RTC if (ptr + 1 + len > extensionEnd) { - MS_WARN_TAG(rtp, - "not enough space for the announced One-Byte header extension element value"); + MS_WARN_TAG( + rtp, "not enough space for the announced One-Byte header extension element value"); break; } @@ -344,8 +350,8 @@ namespace RTC this->twoBytesExtensions.clear(); uint8_t* extensionStart = (uint8_t*)this->extensionHeader + 4; - uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength(); - uint8_t* ptr = extensionStart; + uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength(); + uint8_t* ptr = extensionStart; while (ptr < extensionEnd) { @@ -354,8 +360,8 @@ namespace RTC if (ptr + len > extensionEnd) { - MS_WARN_TAG(rtp, - "not enough space for the announced Two-Bytes header extension element value"); + MS_WARN_TAG( + rtp, "not enough space for the announced Two-Bytes header extension element value"); break; } diff --git a/worker/src/RTC/RtpReceiver.cpp b/worker/src/RTC/RtpReceiver.cpp index 03a6da6929..b8f9ae3953 100644 --- a/worker/src/RTC/RtpReceiver.cpp +++ b/worker/src/RTC/RtpReceiver.cpp @@ -2,33 +2,30 @@ // #define MS_LOG_DEV #include "RTC/RtpReceiver.hpp" -#include "RTC/Transport.hpp" +#include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "RTC/RTCP/FeedbackPsPli.hpp" #include "RTC/RTCP/FeedbackRtp.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp" -#include "RTC/RTCP/FeedbackPsPli.hpp" -#include "MediaSoupError.hpp" -#include "Logger.hpp" +#include "RTC/Transport.hpp" namespace RTC { - /* Class variables. */ - - uint8_t RtpReceiver::rtcpBuffer[MS_RTCP_BUFFER_SIZE]; - /* Instance methods. */ - RtpReceiver::RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind) : - rtpReceiverId(rtpReceiverId), - kind(kind), - listener(listener), - notifier(notifier) + RtpReceiver::RtpReceiver( + Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind) + : rtpReceiverId(rtpReceiverId) + , kind(kind) + , listener(listener) + , notifier(notifier) { MS_TRACE(); if (this->kind == RTC::Media::Kind::AUDIO) - this->maxRtcpInterval = RTC::RTCP::MAX_AUDIO_INTERVAL_MS; + this->maxRtcpInterval = RTC::RTCP::maxAudioIntervalMs; else - this->maxRtcpInterval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS; + this->maxRtcpInterval = RTC::RTCP::maxAudioIntervalMs; } RtpReceiver::~RtpReceiver() @@ -109,9 +106,9 @@ namespace RTC { case Channel::Request::MethodId::rtpReceiver_close: { - #ifdef MS_LOG_DEV +#ifdef MS_LOG_DEV uint32_t rtpReceiverId = this->rtpReceiverId; - #endif +#endif Destroy(); @@ -140,7 +137,7 @@ namespace RTC { this->rtpParameters = new RTC::RtpParameters(request->data); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -152,7 +149,7 @@ namespace RTC { this->listener->onRtpReceiverParameters(this); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { // Rollback previous parameters. this->rtpParameters = previousRtpParameters; @@ -272,8 +269,8 @@ namespace RTC eventData[k_class] = "RtpReceiver"; - this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpraw", eventData, - packet->GetData(), packet->GetSize()); + this->notifier->EmitWithBinary( + this->rtpReceiverId, "rtpraw", eventData, packet->GetData(), packet->GetSize()); } // Emit "rtpobject" is enabled. @@ -284,27 +281,27 @@ namespace RTC eventData[k_class] = "RtpReceiver"; - jsonObject[k_payloadType] = (Json::UInt)packet->GetPayloadType(); - jsonObject[k_marker] = packet->HasMarker(); + jsonObject[k_payloadType] = (Json::UInt)packet->GetPayloadType(); + jsonObject[k_marker] = packet->HasMarker(); jsonObject[k_sequenceNumber] = (Json::UInt)packet->GetSequenceNumber(); - jsonObject[k_timestamp] = (Json::UInt)packet->GetTimestamp(); - jsonObject[k_ssrc] = (Json::UInt)packet->GetSsrc(); + jsonObject[k_timestamp] = (Json::UInt)packet->GetTimestamp(); + jsonObject[k_ssrc] = (Json::UInt)packet->GetSsrc(); eventData[k_object] = jsonObject; - this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpobject", eventData, - packet->GetPayload(), packet->GetPayloadLength()); + this->notifier->EmitWithBinary( + this->rtpReceiverId, "rtpobject", eventData, packet->GetPayload(), packet->GetPayloadLength()); } } - void RtpReceiver::GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now) + void RtpReceiver::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) { if (static_cast((now - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval) return; for (auto& kv : this->rtpStreams) { - auto rtpStream = kv.second; + auto rtpStream = kv.second; RTC::RTCP::ReceiverReport* report = rtpStream->GetRtcpReceiverReport(); report->SetSsrc(rtpStream->GetSsrc()); @@ -322,15 +319,14 @@ namespace RTC return; // Ensure that the RTCP packet fits into the RTCP buffer. - if (packet->GetSize() > MS_RTCP_BUFFER_SIZE) + if (packet->GetSize() > RTC::RTCP::bufferSize) { - MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", - packet->GetSize()); + MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", packet->GetSize()); return; } - packet->Serialize(RtpReceiver::rtcpBuffer); + packet->Serialize(RTC::RTCP::buffer); this->transport->SendRtcpPacket(packet); } @@ -342,15 +338,14 @@ namespace RTC return; // Ensure that the RTCP packet fits into the RTCP buffer. - if (packet->GetSize() > MS_RTCP_BUFFER_SIZE) + if (packet->GetSize() > RTC::RTCP::bufferSize) { - MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", - packet->GetSize()); + MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)", packet->GetSize()); return; } - packet->Serialize(RtpReceiver::rtcpBuffer); + packet->Serialize(RTC::RTCP::buffer); this->transport->SendRtcpPacket(packet); } @@ -384,10 +379,10 @@ namespace RTC return; // Get the codec of the stream/encoding. - auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); - bool useNack = false; - bool usePli = false; - bool useRemb = false; + auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); + bool useNack = false; + bool usePli = false; + bool useRemb = false; uint8_t absSendTimeId = 0; for (auto& fb : codec.rtcpFeedback) @@ -423,12 +418,12 @@ namespace RTC // Create stream params. RTC::RtpStream::Params params; - params.ssrc = ssrc; - params.payloadType = codec.payloadType; - params.mime = codec.mime; - params.clockRate = codec.clockRate; - params.useNack = useNack; - params.usePli = usePli; + params.ssrc = ssrc; + params.payloadType = codec.payloadType; + params.mime = codec.mime; + params.clockRate = codec.clockRate; + params.useNack = useNack; + params.usePli = usePli; params.absSendTimeId = absSendTimeId; // Create a RtpStreamRecv for receiving a media stream. @@ -459,7 +454,7 @@ namespace RTC return; RTC::RTCP::FeedbackRtpNackPacket packet(0, rtpStream->GetSsrc()); - auto it = seqNumbers.begin(); + auto it = seqNumbers.begin(); const auto end = seqNumbers.end(); while (it != end) @@ -491,15 +486,14 @@ namespace RTC } // Ensure that the RTCP packet fits into the RTCP buffer. - if (packet.GetSize() > MS_RTCP_BUFFER_SIZE) + if (packet.GetSize() > RTC::RTCP::bufferSize) { - MS_WARN_TAG(rtx, "cannot send RTCP NACK packet, size too big (%zu bytes)", - packet.GetSize()); + MS_WARN_TAG(rtx, "cannot send RTCP NACK packet, size too big (%zu bytes)", packet.GetSize()); return; } - packet.Serialize(RtpReceiver::rtcpBuffer); + packet.Serialize(RTC::RTCP::buffer); this->transport->SendRtcpPacket(&packet); } @@ -510,7 +504,7 @@ namespace RTC RTC::RTCP::FeedbackPsPliPacket packet(0, rtpStream->GetSsrc()); - packet.Serialize(RtpReceiver::rtcpBuffer); + packet.Serialize(RTC::RTCP::buffer); // Send two, because it's free. this->transport->SendRtcpPacket(&packet); diff --git a/worker/src/RTC/RtpSender.cpp b/worker/src/RTC/RtpSender.cpp index 9a2b7b4f51..12a2285ecd 100644 --- a/worker/src/RTC/RtpSender.cpp +++ b/worker/src/RTC/RtpSender.cpp @@ -2,11 +2,11 @@ // #define MS_LOG_DEV #include "RTC/RtpSender.hpp" -#include "RTC/RTCP/SenderReport.hpp" -#include "RTC/RTCP/FeedbackRtpNack.hpp" -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" +#include "RTC/RTCP/FeedbackRtpNack.hpp" +#include "RTC/RTCP/SenderReport.hpp" #include namespace RTC @@ -17,18 +17,19 @@ namespace RTC /* Instance methods. */ - RtpSender::RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind) : - rtpSenderId(rtpSenderId), - kind(kind), - listener(listener), - notifier(notifier) + RtpSender::RtpSender( + Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind) + : rtpSenderId(rtpSenderId) + , kind(kind) + , listener(listener) + , notifier(notifier) { MS_TRACE(); if (this->kind == RTC::Media::Kind::AUDIO) - this->maxRtcpInterval = RTC::RTCP::MAX_AUDIO_INTERVAL_MS; + this->maxRtcpInterval = RTC::RTCP::maxAudioIntervalMs; else - this->maxRtcpInterval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS; + this->maxRtcpInterval = RTC::RTCP::maxVideoIntervalMs; } RtpSender::~RtpSender() @@ -200,7 +201,7 @@ namespace RTC for (auto it = codecs.begin(); it != this->rtpParameters->codecs.end();) { auto& codec = *it; - auto it2 = codecs.begin(); + auto it2 = codecs.begin(); for (; it2 != codecs.end(); ++it2) { @@ -272,9 +273,9 @@ namespace RTC { Json::Value eventData(Json::objectValue); - eventData[k_class] = "RtpSender"; + eventData[k_class] = "RtpSender"; eventData[k_rtpParameters] = this->rtpParameters->toJson(); - eventData[k_active] = this->GetActive(); + eventData[k_active] = this->GetActive(); this->notifier->Emit(this->rtpSenderId, "parameterschange", eventData); } @@ -294,15 +295,14 @@ namespace RTC // RTP parameters. if (packet->GetSsrc() != this->rtpParameters->encodings[0].ssrc) { - MS_WARN_TAG(rtp, "ignoring packet with unknown SSRC [ssrc:%" PRIu32 "]", - packet->GetSsrc()); + MS_WARN_TAG(rtp, "ignoring packet with unknown SSRC [ssrc:%" PRIu32 "]", packet->GetSsrc()); return; } // Map the payload type. uint8_t payloadType = packet->GetPayloadType(); - auto it = this->supportedPayloadTypes.find(payloadType); + auto it = this->supportedPayloadTypes.find(payloadType); // NOTE: This may happen if this peer supports just some codecs from the // given RtpParameters. @@ -327,7 +327,7 @@ namespace RTC this->transmittedCounter.Update(packet); } - void RtpSender::GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now) + void RtpSender::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) { if (!this->rtpStream) return; @@ -340,16 +340,16 @@ namespace RTC return; // NOTE: This assumes a single stream. - uint32_t ssrc = this->rtpParameters->encodings[0].ssrc; + uint32_t ssrc = this->rtpParameters->encodings[0].ssrc; std::string cname = this->rtpParameters->rtcp.cname; report->SetSsrc(ssrc); packet->AddSenderReport(report); // Build SDES chunk for this sender. - RTC::RTCP::SdesChunk *sdesChunk = new RTC::RTCP::SdesChunk(ssrc); - RTC::RTCP::SdesItem *sdesItem = - new RTC::RTCP::SdesItem(RTC::RTCP::SdesItem::Type::CNAME, cname.size(), cname.c_str()); + RTC::RTCP::SdesChunk* sdesChunk = new RTC::RTCP::SdesChunk(ssrc); + RTC::RTCP::SdesItem* sdesItem = + new RTC::RTCP::SdesItem(RTC::RTCP::SdesItem::Type::CNAME, cname.size(), cname.c_str()); sdesChunk->AddItem(sdesItem); packet->AddSdesChunk(sdesChunk); @@ -372,7 +372,8 @@ namespace RTC { RTC::RTCP::FeedbackRtpNackItem* item = *it; - this->rtpStream->RequestRtpRetransmission(item->GetPacketId(), item->GetLostPacketBitmask(), RtpRetransmissionContainer); + this->rtpStream->RequestRtpRetransmission( + item->GetPacketId(), item->GetLostPacketBitmask(), RtpRetransmissionContainer); auto it2 = RtpRetransmissionContainer.begin(); for (; it2 != RtpRetransmissionContainer.end(); ++it2) @@ -407,9 +408,9 @@ namespace RTC uint32_t ssrc = encoding.ssrc; // Get the codec of the stream/encoding. - auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); - bool useNack = false; - bool usePli = false; + auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); + bool useNack = false; + bool usePli = false; uint8_t absSendTimeId = 0; // 0 means no abs-send-time id. for (auto& fb : codec.rtcpFeedback) @@ -439,12 +440,12 @@ namespace RTC // Create stream params. RTC::RtpStream::Params params; - params.ssrc = ssrc; - params.payloadType = codec.payloadType; - params.mime = codec.mime; - params.clockRate = codec.clockRate; - params.useNack = useNack; - params.usePli = usePli; + params.ssrc = ssrc; + params.payloadType = codec.payloadType; + params.mime = codec.mime; + params.clockRate = codec.clockRate; + params.useNack = useNack; + params.usePli = usePli; params.absSendTimeId = absSendTimeId; // Create a RtpStreamSend for sending a single media stream. @@ -471,8 +472,7 @@ namespace RTC this->transport->SendRtpPacket(packet); } - inline - void RtpSender::EmitActiveChange() const + inline void RtpSender::EmitActiveChange() const { MS_TRACE(); @@ -481,7 +481,7 @@ namespace RTC Json::Value eventData(Json::objectValue); - eventData[k_class] = "RtpSender"; + eventData[k_class] = "RtpSender"; eventData[k_active] = this->GetActive(); this->notifier->Emit(this->rtpSenderId, "activechange", eventData); diff --git a/worker/src/RTC/RtpStream.cpp b/worker/src/RTC/RtpStream.cpp index 61e2adf311..2cd7a64fe7 100644 --- a/worker/src/RTC/RtpStream.cpp +++ b/worker/src/RTC/RtpStream.cpp @@ -11,14 +11,14 @@ namespace RTC /* Static. */ static constexpr uint32_t MinSequential = 0; - static constexpr uint16_t MaxDropout = 3000; - static constexpr uint16_t MaxMisorder = 100; - static constexpr uint32_t RtpSeqMod = 1<<16; + static constexpr uint16_t MaxDropout = 3000; + static constexpr uint16_t MaxMisorder = 100; + static constexpr uint32_t RtpSeqMod = 1 << 16; /* Instance methods. */ - RtpStream::RtpStream(RTC::RtpStream::Params& params) : - params(params) + RtpStream::RtpStream(RTC::RtpStream::Params& params) + : params(params) { MS_TRACE(); } @@ -38,8 +38,8 @@ namespace RTC if (!this->started) { InitSeq(seq); - this->started = true; - this->maxSeq = seq - 1; + this->started = true; + this->maxSeq = seq - 1; this->probation = MinSequential; } @@ -48,17 +48,18 @@ namespace RTC { if (!this->probation) { - MS_WARN_TAG(rtp, - "invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_WARN_TAG( + rtp, + "invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); } return false; } // Set the extended sequence number into the packet. - packet->SetExtendedSequenceNumber( - this->cycles + (uint32_t)packet->GetSequenceNumber()); + packet->SetExtendedSequenceNumber(this->cycles + (uint32_t)packet->GetSequenceNumber()); // Update highest seen RTP timestamp. if (packet->GetTimestamp() > this->maxTimestamp) @@ -72,11 +73,11 @@ namespace RTC MS_TRACE(); // Initialize/reset RTP counters. - this->baseSeq = seq; - this->maxSeq = seq; - this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false. - this->cycles = 0; - this->received = 0; + this->baseSeq = seq; + this->maxSeq = seq; + this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false. + this->cycles = 0; + this->received = 0; this->receivedPrior = 0; this->expectedPrior = 0; // Also reset the highest seen RTP timestamp. @@ -90,7 +91,7 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); + uint16_t seq = packet->GetSequenceNumber(); uint16_t udelta = seq - this->maxSeq; /* @@ -116,7 +117,7 @@ namespace RTC else { this->probation = MinSequential - 1; - this->maxSeq = seq; + this->maxSeq = seq; } return false; @@ -142,17 +143,21 @@ namespace RTC * restarted without telling us so just re-sync * (i.e., pretend this was the first packet). */ - MS_WARN_TAG(rtp, - "too bad sequence number, re-syncing RTP [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_WARN_TAG( + rtp, + "too bad sequence number, re-syncing RTP [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); InitSeq(seq); } else { - MS_WARN_TAG(rtp, - "bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_WARN_TAG( + rtp, + "bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); this->badSeq = (seq + 1) & (RtpSeqMod - 1); @@ -179,12 +184,12 @@ namespace RTC Json::Value json(Json::objectValue); - json[k_ssrc] = (Json::UInt)this->ssrc; - json[k_payloadType] = (Json::UInt)this->payloadType; - json[k_mime] = this->mime.name; - json[k_clockRate] = (Json::UInt)this->clockRate; - json[k_useNack] = this->useNack; - json[k_usePli] = this->usePli; + json[k_ssrc] = (Json::UInt)this->ssrc; + json[k_payloadType] = (Json::UInt)this->payloadType; + json[k_mime] = this->mime.name; + json[k_clockRate] = (Json::UInt)this->clockRate; + json[k_useNack] = this->useNack; + json[k_usePli] = this->usePli; json[k_absSendTimeId] = (Json::UInt)this->absSendTimeId; return json; diff --git a/worker/src/RTC/RtpStreamRecv.cpp b/worker/src/RTC/RtpStreamRecv.cpp index b6a9b579cb..5793fc13ed 100644 --- a/worker/src/RTC/RtpStreamRecv.cpp +++ b/worker/src/RTC/RtpStreamRecv.cpp @@ -9,9 +9,9 @@ namespace RTC { /* Instance methods. */ - RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params) : - RtpStream::RtpStream(params), - listener(listener) + RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params) + : RtpStream::RtpStream(params) + , listener(listener) { MS_TRACE(); } @@ -33,11 +33,11 @@ namespace RTC Json::Value json(Json::objectValue); - json[k_params] = this->params.toJson(); - json[k_received] = (Json::UInt)this->received; + json[k_params] = this->params.toJson(); + json[k_received] = (Json::UInt)this->received; json[k_maxTimestamp] = (Json::UInt)this->maxTimestamp; - json[k_transit] = (Json::UInt)this->transit; - json[k_jitter] = (Json::UInt)this->jitter; + json[k_transit] = (Json::UInt)this->transit; + json[k_jitter] = (Json::UInt)this->jitter; return json; } @@ -57,7 +57,7 @@ namespace RTC if (this->params.absSendTimeId) { packet->AddExtensionMapping( - RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->params.absSendTimeId); + RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->params.absSendTimeId); } // Pass the packet to the NackGenerator. @@ -126,7 +126,7 @@ namespace RTC { MS_TRACE(); - this->lastSrReceived = DepLibUV::GetTime(); + this->lastSrReceived = DepLibUV::GetTime(); this->lastSrTimestamp = report->GetNtpSec() << 16; this->lastSrTimestamp += report->GetNtpFrac() >> 16; } @@ -153,11 +153,12 @@ namespace RTC return; int transit = DepLibUV::GetTime() - (rtpTimestamp * 1000 / this->params.clockRate); - int d = transit - this->transit; + int d = transit - this->transit; this->transit = transit; - if (d < 0) d = -d; - this->jitter += (1./16.) * ((double)d - this->jitter); + if (d < 0) + d = -d; + this->jitter += (1. / 16.) * ((double)d - this->jitter); } void RtpStreamRecv::onInitSeq() @@ -184,9 +185,12 @@ namespace RTC MS_ASSERT(this->params.useNack, "NACK required but not supported"); - MS_WARN_TAG(rtx, - "triggering NACK [ssrc:%" PRIu32 ", first_seq:%" PRIu16 ", num_packets:%zu]", - this->params.ssrc, seqNumbers[0], seqNumbers.size()); + MS_WARN_TAG( + rtx, + "triggering NACK [ssrc:%" PRIu32 ", first seq:%" PRIu16 ", num packets:%zu]", + this->params.ssrc, + seqNumbers[0], + seqNumbers.size()); this->listener->onNackRequired(this, seqNumbers); } diff --git a/worker/src/RTC/RtpStreamSend.cpp b/worker/src/RTC/RtpStreamSend.cpp index 49b093681a..82d71b1caa 100644 --- a/worker/src/RTC/RtpStreamSend.cpp +++ b/worker/src/RTC/RtpStreamSend.cpp @@ -2,24 +2,24 @@ // #define MS_LOG_DEV #include "RTC/RtpStreamSend.hpp" -#include "Logger.hpp" #include "DepLibUV.hpp" +#include "Logger.hpp" #include "Utils.hpp" namespace RTC { /* Static. */ - static constexpr uint32_t RtpSeqMod = 1<<16; + static constexpr uint32_t RtpSeqMod = 1 << 16; // Don't retransmit packets older than this (ms). static constexpr uint32_t MaxRetransmissionAge = 500; - static constexpr uint32_t DefaultRtt = 100; + static constexpr uint32_t DefaultRtt = 100; /* Instance methods. */ - RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize) : - RtpStream::RtpStream(params), - storage(bufferSize) + RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize) + : RtpStream::RtpStream(params) + , storage(bufferSize) { MS_TRACE(); } @@ -44,11 +44,11 @@ namespace RTC Json::Value json(Json::objectValue); - json[k_params] = this->params.toJson(); - json[k_received] = (Json::UInt)this->received; - json[k_maxTimestamp] = (Json::UInt)this->maxTimestamp; + json[k_params] = this->params.toJson(); + json[k_received] = (Json::UInt)this->received; + json[k_maxTimestamp] = (Json::UInt)this->maxTimestamp; json[k_receivedBytes] = (Json::UInt)this->receivedBytes; - json[k_rtt] = (Json::UInt)this->rtt; + json[k_rtt] = (Json::UInt)this->rtt; return json; } @@ -69,7 +69,7 @@ namespace RTC this->receivedBytes += packet->GetPayloadLength(); // Record current time and RTP timestamp. - this->lastPacketTimeMs = DepLibUV::GetTime(); + this->lastPacketTimeMs = DepLibUV::GetTime(); this->lastPacketRtpTimestamp = packet->GetTimestamp(); return true; @@ -89,8 +89,7 @@ namespace RTC nowCompactNtp |= (nowNtp.fractions & 0xFFFF0000) >> 16; uint32_t lastSr = report->GetLastSenderReport(); - uint32_t dlsr = report->GetDelaySinceLastSenderReport(); - + uint32_t dlsr = report->GetDelaySinceLastSenderReport(); // RTT in 1/2^16 seconds. uint32_t rtt = nowCompactNtp - dlsr - lastSr; @@ -101,7 +100,8 @@ namespace RTC // This method looks for the requested RTP packets and inserts them into the // given container (and set to null the next container position). - void RtpStreamSend::RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector& container) + void RtpStreamSend::RequestRtpRetransmission( + uint16_t seq, uint16_t bitmask, std::vector& container) { MS_TRACE(); @@ -125,15 +125,15 @@ namespace RTC // Convert the given sequence numbers to 32 bits. uint32_t firstSeq32 = (uint32_t)seq + this->cycles; - uint32_t lastSeq32 = firstSeq32 + MaxRequestedPackets - 1; + uint32_t lastSeq32 = firstSeq32 + MaxRequestedPackets - 1; // Number of requested packets cannot be greater than the container size - 1. MS_ASSERT(container.size() - 1 >= MaxRequestedPackets, "RtpPacket container is too small"); - auto bufferIt = this->buffer.begin(); - auto bufferItReverse = this->buffer.rbegin(); + auto bufferIt = this->buffer.begin(); + auto bufferItReverse = this->buffer.rbegin(); uint32_t bufferFirstSeq32 = (*bufferIt).seq32; - uint32_t bufferLastSeq32 = (*bufferItReverse).seq32; + uint32_t bufferLastSeq32 = (*bufferItReverse).seq32; // Requested packet range not found. if (firstSeq32 > bufferLastSeq32 || lastSeq32 < bufferFirstSeq32) @@ -162,17 +162,17 @@ namespace RTC } // Look for each requested packet. - uint64_t now = DepLibUV::GetTime(); - uint32_t rtt = (this->rtt ? this->rtt : DefaultRtt); - uint32_t seq32 = firstSeq32; - bool requested = true; + uint64_t now = DepLibUV::GetTime(); + uint32_t rtt = (this->rtt ? this->rtt : DefaultRtt); + uint32_t seq32 = firstSeq32; + bool requested = true; size_t containerIdx = 0; // Some variables for debugging. - uint16_t origBitmask = bitmask; - uint16_t sentBitmask = 0b0000000000000000; - bool isFirstPacket = true; - bool firstPacketSent = false; + uint16_t origBitmask = bitmask; + uint16_t sentBitmask = 0b0000000000000000; + bool isFirstPacket = true; + bool firstPacketSent = false; uint8_t bitmaskCounter = 0; bool tooOldPacketFound = false; @@ -190,16 +190,21 @@ namespace RTC if (currentSeq32 == seq32) { auto currentPacket = (*bufferIt).packet; - uint32_t diff = (this->maxTimestamp - currentPacket->GetTimestamp()) * 1000 / this->params.clockRate; + uint32_t diff = + (this->maxTimestamp - currentPacket->GetTimestamp()) * 1000 / this->params.clockRate; // Just provide the packet if no older than MaxRetransmissionAge ms. if (diff > MaxRetransmissionAge) { if (!tooOldPacketFound) { - MS_WARN_TAG(rtx, - "ignoring retransmission for too old packet [seq:%" PRIu16 ", max_age:%" PRIu32 "ms, packet_age:%" PRIu32 "ms]", - currentPacket->GetSequenceNumber(), MaxRetransmissionAge, diff); + MS_WARN_TAG( + rtx, + "ignoring retransmission for too old packet " + "[seq:%" PRIu16 ", max age:%" PRIu32 "ms, packet age:%" PRIu32 "ms]", + currentPacket->GetSequenceNumber(), + MaxRetransmissionAge, + diff); tooOldPacketFound = true; } @@ -210,13 +215,14 @@ namespace RTC // Don't resent the packet if it was resent in the last RTT ms. uint32_t resentAtTime = (*bufferIt).resentAtTime; - if ( - resentAtTime && - now - resentAtTime < static_cast(rtt)) + if (resentAtTime && now - resentAtTime < static_cast(rtt)) { - MS_WARN_TAG(rtx, - "ignoring retransmission for a packet already resent in the last RTT ms [seq:%" PRIu16 ", rtt:%" PRIu32 "]", - currentPacket->GetSequenceNumber(), rtt); + MS_WARN_TAG( + rtx, + "ignoring retransmission for a packet already resent in the last RTT ms " + "[seq:%" PRIu16 ", rtt:%" PRIu32 "]", + currentPacket->GetSequenceNumber(), + rtt); break; } @@ -259,17 +265,23 @@ namespace RTC // If not all the requested packets was sent, log it. if (!firstPacketSent || origBitmask != sentBitmask) { - MS_DEBUG_TAG(rtx, - "could not resend all packets [seq:%" PRIu16 ", first:%s, " - "bitmask:" MS_UINT16_TO_BINARY_PATTERN ", sentBitmask:" MS_UINT16_TO_BINARY_PATTERN "]", - seq, firstPacketSent ? "yes" : "no", - MS_UINT16_TO_BINARY(origBitmask), MS_UINT16_TO_BINARY(sentBitmask)); + MS_DEBUG_TAG( + rtx, + "could not resend all packets [seq:%" PRIu16 + ", first:%s, " + "bitmask:" MS_UINT16_TO_BINARY_PATTERN ", sent bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", + seq, + firstPacketSent ? "yes" : "no", + MS_UINT16_TO_BINARY(origBitmask), + MS_UINT16_TO_BINARY(sentBitmask)); } else { - MS_DEBUG_TAG(rtx, - "all packets resent [seq:%" PRIu16 ", bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", - seq, MS_UINT16_TO_BINARY(origBitmask)); + MS_DEBUG_TAG( + rtx, + "all packets resent [seq:%" PRIu16 ", bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", + seq, + MS_UINT16_TO_BINARY(origBitmask)); } // Set the next container element to null. @@ -295,7 +307,7 @@ namespace RTC report->SetNtpFrac(ntp.fractions); // Calculate RTP timestamp diff between now and last received RTP packet. - uint32_t diffMs = now - this->lastPacketTimeMs; + uint32_t diffMs = now - this->lastPacketTimeMs; uint32_t diffRtpTimestamp = diffMs * this->params.clockRate / 1000; report->SetRtpTs(this->lastPacketRtpTimestamp + diffRtpTimestamp); @@ -317,8 +329,7 @@ namespace RTC this->buffer.clear(); } - inline - void RtpStreamSend::StorePacket(RTC::RtpPacket* packet) + inline void RtpStreamSend::StorePacket(RTC::RtpPacket* packet) { MS_TRACE(); @@ -366,9 +377,11 @@ namespace RTC // NOTE: This should never happen. if (bufferItReverse == this->buffer.rend()) { - MS_WARN_TAG(rtp, - "ignoring packet older than anything in the buffer [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetSequenceNumber()); + MS_WARN_TAG( + rtp, + "ignoring packet older than anything in the buffer [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetSequenceNumber()); return; } @@ -382,7 +395,7 @@ namespace RTC else { auto& firstBufferItem = *(this->buffer.begin()); - auto firstPacket = firstBufferItem.packet; + auto firstPacket = firstBufferItem.packet; // Store points to the store used by the first packet. store = (uint8_t*)firstPacket->GetData(); diff --git a/worker/src/RTC/SrtpSession.cpp b/worker/src/RTC/SrtpSession.cpp index f777c3e080..0c393e4e56 100644 --- a/worker/src/RTC/SrtpSession.cpp +++ b/worker/src/RTC/SrtpSession.cpp @@ -3,12 +3,10 @@ #include "RTC/SrtpSession.hpp" #include "DepLibSRTP.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" #include // std::memset(), std::memcpy() -#define MS_ENCRYPT_BUFFER_SIZE 65536 - namespace RTC { /* Static. */ @@ -76,8 +74,9 @@ namespace RTC MS_ABORT("unknown SRTP suite"); } - MS_ASSERT((int)keyLen == policy.rtp.cipher_key_len, - "given keyLen does not match policy.rtp.cipher_keyLen"); + MS_ASSERT( + (int)keyLen == policy.rtp.cipher_key_len, + "given keyLen does not match policy.rtp.cipher_keyLen"); switch (type) { @@ -90,11 +89,11 @@ namespace RTC } policy.ssrc.value = 0; - policy.key = key; + policy.key = key; // Required for sending RTP retransmission without RTX. policy.allow_repeat_tx = 1; - policy.window_size = 2048; - policy.next = nullptr; + policy.window_size = 2048; + policy.next = nullptr; // Set the SRTP session. err = srtp_create(&this->session, &policy); @@ -128,7 +127,7 @@ namespace RTC MS_TRACE(); // Ensure that the resulting SRTP packet fits into the encrypt buffer. - if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) + if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) { MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%zu bytes)", *len); @@ -175,7 +174,7 @@ namespace RTC MS_TRACE(); // Ensure that the resulting SRTCP packet fits into the encrypt buffer. - if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) + if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) { MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%zu bytes)", *len); diff --git a/worker/src/RTC/StunMessage.cpp b/worker/src/RTC/StunMessage.cpp index 28026ff086..a954a911af 100644 --- a/worker/src/RTC/StunMessage.cpp +++ b/worker/src/RTC/StunMessage.cpp @@ -2,16 +2,16 @@ // #define MS_LOG_DEV #include "RTC/StunMessage.hpp" -#include "Utils.hpp" #include "Logger.hpp" -#include // std::snprintf() +#include "Utils.hpp" +#include // std::snprintf() #include // std::memcmp(), std::memcpy() namespace RTC { /* Class variables. */ - const uint8_t StunMessage::magicCookie[] = { 0x21, 0x12, 0xA4, 0x42 }; + const uint8_t StunMessage::magicCookie[] = {0x21, 0x12, 0xA4, 0x42}; /* Class methods. */ @@ -23,17 +23,17 @@ namespace RTC return nullptr; /* - The message type field is decomposed further into the following + The message type field is decomposed further into the following structure: - 0 1 - 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + 0 1 + 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ |M |M |M|M|M|C|M|M|M|C|M|M|M|M| |11|10|9|8|7|1|6|5|4|0|3|2|1|0| +--+--+-+-+-+-+-+-+-+-+-+-+-+-+ - Figure 3: Format of STUN Message Type Field + Figure 3: Format of STUN Message Type Field Here the bits in the message type field are shown as most significant (M11) through least significant (M0). M11 through M0 represent a 12- @@ -50,15 +50,16 @@ namespace RTC // length field must be total size minus header's 20 bytes, and must be multiple of 4 Bytes. if (((size_t)msgLength != len - 20) || (msgLength & 0x03)) { - MS_WARN_TAG(ice, - "length field + 20 does not match total size (or it is not multiple of 4 bytes), " - "message discarded"); + MS_WARN_TAG( + ice, + "length field + 20 does not match total size (or it is not multiple of 4 bytes), " + "message discarded"); return nullptr; } // Get STUN method. - uint16_t msgMethod = (msgType & 0x000f) | ((msgType & 0x00e0)>>1) | ((msgType & 0x3E00)>>2); + uint16_t msgMethod = (msgType & 0x000f) | ((msgType & 0x00e0) >> 1) | ((msgType & 0x3E00) >> 2); // Get STUN class. uint16_t msgClass = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4); @@ -86,12 +87,11 @@ namespace RTC // Start looking for attributes after STUN header (Byte #20). size_t pos = 20; - // Flags (positions) for special MESSAGE-INTEGRITY and FINGERPRINT attributes. bool hasMessageIntegrity = false; - bool hasFingerprint = false; + bool hasFingerprint = false; size_t fingerprintAttrPos; // Will point to the beginning of the attribute. - uint32_t fingerprint; // Holds the value of the FINGERPRINT attribute. + uint32_t fingerprint; // Holds the value of the FINGERPRINT attribute. // Ensure there are at least 4 remaining bytes (attribute with 0 length). while (pos + 4 <= len) @@ -123,9 +123,10 @@ namespace RTC // After a MESSAGE-INTEGRITY attribute just FINGERPRINT is allowed. if (hasMessageIntegrity && attrType != Attribute::Fingerprint) { - MS_WARN_TAG(ice, - "attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, " - "message discarded"); + MS_WARN_TAG( + ice, + "attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, " + "message discarded"); delete msg; return nullptr; @@ -174,25 +175,24 @@ namespace RTC } case Attribute::Fingerprint: { - hasFingerprint = true; + hasFingerprint = true; fingerprintAttrPos = pos; - fingerprint = Utils::Byte::Get4Bytes(attrValuePos, 0); + fingerprint = Utils::Byte::Get4Bytes(attrValuePos, 0); msg->SetFingerprint(); break; } case Attribute::ErrorCode: { - uint8_t errorClass = Utils::Byte::Get1Byte(attrValuePos, 2); + uint8_t errorClass = Utils::Byte::Get1Byte(attrValuePos, 2); uint8_t errorNumber = Utils::Byte::Get1Byte(attrValuePos, 3); - uint16_t errorCode = (uint16_t)(errorClass * 100 + errorNumber); + uint16_t errorCode = (uint16_t)(errorClass * 100 + errorNumber); msg->SetErrorCode(errorCode); break; } - default: - ; + default:; } // Set next attribute position. @@ -213,15 +213,15 @@ namespace RTC { // Compute the CRC32 of the received message up to (but excluding) the // FINGERPRINT attribute and XOR it with 0x5354554e. - uint32_t computedFingerprint = - Utils::Crypto::GetCRC32(data, fingerprintAttrPos) ^ 0x5354554e; + uint32_t computedFingerprint = Utils::Crypto::GetCRC32(data, fingerprintAttrPos) ^ 0x5354554e; // Compare with the FINGERPRINT value in the message. if (fingerprint != computedFingerprint) { - MS_WARN_TAG(ice, - "computed FINGERPRINT value does not match the value in the message, " - "message discarded"); + MS_WARN_TAG( + ice, + "computed FINGERPRINT value does not match the value in the message, " + "message discarded"); delete msg; return nullptr; @@ -233,12 +233,13 @@ namespace RTC /* Instance methods. */ - StunMessage::StunMessage(Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size) : - klass(klass), - method(method), - transactionId(transactionId), - data((uint8_t*)data), - size(size) + StunMessage::StunMessage( + Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size) + : klass(klass) + , method(method) + , transactionId(transactionId) + , data((uint8_t*)data) + , size(size) { MS_TRACE(); } @@ -257,10 +258,18 @@ namespace RTC std::string klass; switch (this->klass) { - case Class::Request : klass = "Request"; break; - case Class::Indication : klass = "Indication"; break; - case Class::SuccessResponse : klass = "SuccessResponse"; break; - case Class::ErrorResponse : klass = "ErrorResponse"; break; + case Class::Request: + klass = "Request"; + break; + case Class::Indication: + klass = "Indication"; + break; + case Class::SuccessResponse: + klass = "SuccessResponse"; + break; + case Class::ErrorResponse: + klass = "ErrorResponse"; + break; } if (this->method == Method::Binding) { @@ -275,10 +284,10 @@ namespace RTC static char TransactionId[25]; - for (int i=0; i<12; ++i) + for (int i = 0; i < 12; ++i) { // NOTE: n must be 3 because snprintf adds a \0 after printed chars. - std::snprintf(TransactionId+(i*2), 3, "%.2x", this->transactionId[i]); + std::snprintf(TransactionId + (i * 2), 3, "%.2x", this->transactionId[i]); } MS_DUMP(" transactionId: %s", TransactionId); if (this->errorCode) @@ -307,9 +316,9 @@ namespace RTC { static char MessageIntegrity[41]; - for (int i=0; i<20; ++i) + for (int i = 0; i < 20; ++i) { - std::snprintf(MessageIntegrity+(i*2), 3, "%.2x", this->messageIntegrity[i]); + std::snprintf(MessageIntegrity + (i * 2), 3, "%.2x", this->messageIntegrity[i]); } MS_DUMP(" messageIntegrity: %s", MessageIntegrity); @@ -320,7 +329,8 @@ namespace RTC MS_DUMP(""); } - StunMessage::Authentication StunMessage::CheckAuthentication(const std::string &localUsername, const std::string &localPassword) + StunMessage::Authentication StunMessage::CheckAuthentication( + const std::string& localUsername, const std::string& localPassword) { MS_TRACE(); @@ -336,11 +346,9 @@ namespace RTC // Check that USERNAME attribute begins with our local username plus ":". size_t localUsernameLen = localUsername.length(); - if ( - this->username.length() <= localUsernameLen || - this->username.at(localUsernameLen) != ':' || - (this->username.compare(0, localUsernameLen, localUsername) != 0) - ) + if (this->username.length() <= localUsernameLen || + this->username.at(localUsernameLen) != ':' || + (this->username.compare(0, localUsernameLen, localUsername) != 0)) return Authentication::Unauthorized; break; @@ -363,8 +371,8 @@ namespace RTC Utils::Byte::Set2Bytes(this->data, 2, (uint16_t)(this->size - 20 - 8)); // Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules. - const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHMAC_SHA1(localPassword, - this->data, (this->messageIntegrity - 4) - this->data); + const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHMAC_SHA1( + localPassword, this->data, (this->messageIntegrity - 4) - this->data); Authentication result; @@ -385,8 +393,9 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->klass == Class::Request, - "attempt to create a success response for a non Request STUN message"); + MS_ASSERT( + this->klass == Class::Request, + "attempt to create a success response for a non Request STUN message"); return new StunMessage(Class::SuccessResponse, this->method, this->transactionId, nullptr, 0); } @@ -395,18 +404,19 @@ namespace RTC { MS_TRACE(); - MS_ASSERT(this->klass == Class::Request, - "attempt to create an error response for a non Request STUN message"); + MS_ASSERT( + this->klass == Class::Request, + "attempt to create an error response for a non Request STUN message"); - StunMessage* response = new StunMessage(Class::ErrorResponse, this->method, - this->transactionId, nullptr, 0); + StunMessage* response = + new StunMessage(Class::ErrorResponse, this->method, this->transactionId, nullptr, 0); response->SetErrorCode(errorCode); return response; } - void StunMessage::Authenticate(const std::string &password) + void StunMessage::Authenticate(const std::string& password) { // Just for Request, Indication and SuccessResponse messages. if (this->klass == Class::ErrorResponse) @@ -424,13 +434,14 @@ namespace RTC MS_TRACE(); // Some useful variables. - uint16_t usernamePaddedLen = 0; + uint16_t usernamePaddedLen = 0; uint16_t xorMappedAddressPaddedLen = 0; - bool addXorMappedAddress = (this->xorMappedAddress && - this->method == StunMessage::Method::Binding && this->klass == Class::SuccessResponse); - bool addErrorCode = (this->errorCode && this->klass == Class::ErrorResponse); + bool addXorMappedAddress = + (this->xorMappedAddress && this->method == StunMessage::Method::Binding && + this->klass == Class::SuccessResponse); + bool addErrorCode = (this->errorCode && this->klass == Class::ErrorResponse); bool addMessageIntegrity = (this->klass != Class::ErrorResponse && !this->password.empty()); - bool addFingerprint = true; // Do always. + bool addFingerprint = true; // Do always. // Update data pointer. this->data = buffer; @@ -568,26 +579,27 @@ namespace RTC Utils::Byte::Set2Bytes(buffer, pos, (uint16_t)Attribute::XorMappedAddress); Utils::Byte::Set2Bytes(buffer, pos + 2, xorMappedAddressPaddedLen); - uint8_t* attr_value = buffer + pos + 4; + uint8_t* attrValue = buffer + pos + 4; switch (this->xorMappedAddress->sa_family) { case AF_INET: { // Set first byte to 0. - attr_value[0] = 0; + attrValue[0] = 0; // Set inet family. - attr_value[1] = 0x01; + attrValue[1] = 0x01; // Set port and XOR it. - std::memcpy(attr_value + 2, &((const sockaddr_in*)(this->xorMappedAddress))->sin_port, 2); - attr_value[2] ^= StunMessage::magicCookie[0]; - attr_value[3] ^= StunMessage::magicCookie[1]; + std::memcpy(attrValue + 2, &((const sockaddr_in*)(this->xorMappedAddress))->sin_port, 2); + attrValue[2] ^= StunMessage::magicCookie[0]; + attrValue[3] ^= StunMessage::magicCookie[1]; // Set address and XOR it. - std::memcpy(attr_value + 4, &((const sockaddr_in*)this->xorMappedAddress)->sin_addr.s_addr, 4); - attr_value[4] ^= StunMessage::magicCookie[0]; - attr_value[5] ^= StunMessage::magicCookie[1]; - attr_value[6] ^= StunMessage::magicCookie[2]; - attr_value[7] ^= StunMessage::magicCookie[3]; + std::memcpy( + attrValue + 4, &((const sockaddr_in*)this->xorMappedAddress)->sin_addr.s_addr, 4); + attrValue[4] ^= StunMessage::magicCookie[0]; + attrValue[5] ^= StunMessage::magicCookie[1]; + attrValue[6] ^= StunMessage::magicCookie[2]; + attrValue[7] ^= StunMessage::magicCookie[3]; pos += 4 + 8; @@ -596,31 +608,32 @@ namespace RTC case AF_INET6: { // Set first byte to 0. - attr_value[0] = 0; + attrValue[0] = 0; // Set inet family. - attr_value[1] = 0x02; + attrValue[1] = 0x02; // Set port and XOR it. - std::memcpy(attr_value + 2, &((const sockaddr_in6*)(this->xorMappedAddress))->sin6_port, 2); - attr_value[2] ^= StunMessage::magicCookie[0]; - attr_value[3] ^= StunMessage::magicCookie[1]; + std::memcpy(attrValue + 2, &((const sockaddr_in6*)(this->xorMappedAddress))->sin6_port, 2); + attrValue[2] ^= StunMessage::magicCookie[0]; + attrValue[3] ^= StunMessage::magicCookie[1]; // Set address and XOR it. - std::memcpy(attr_value + 4, &((const sockaddr_in6*)this->xorMappedAddress)->sin6_addr.s6_addr, 16); - attr_value[4] ^= StunMessage::magicCookie[0]; - attr_value[5] ^= StunMessage::magicCookie[1]; - attr_value[6] ^= StunMessage::magicCookie[2]; - attr_value[7] ^= StunMessage::magicCookie[3]; - attr_value[8] ^= this->transactionId[0]; - attr_value[9] ^= this->transactionId[1]; - attr_value[10] ^= this->transactionId[2]; - attr_value[11] ^= this->transactionId[3]; - attr_value[12] ^= this->transactionId[4]; - attr_value[13] ^= this->transactionId[5]; - attr_value[14] ^= this->transactionId[6]; - attr_value[15] ^= this->transactionId[7]; - attr_value[16] ^= this->transactionId[8]; - attr_value[17] ^= this->transactionId[9]; - attr_value[18] ^= this->transactionId[10]; - attr_value[19] ^= this->transactionId[11]; + std::memcpy( + attrValue + 4, &((const sockaddr_in6*)this->xorMappedAddress)->sin6_addr.s6_addr, 16); + attrValue[4] ^= StunMessage::magicCookie[0]; + attrValue[5] ^= StunMessage::magicCookie[1]; + attrValue[6] ^= StunMessage::magicCookie[2]; + attrValue[7] ^= StunMessage::magicCookie[3]; + attrValue[8] ^= this->transactionId[0]; + attrValue[9] ^= this->transactionId[1]; + attrValue[10] ^= this->transactionId[2]; + attrValue[11] ^= this->transactionId[3]; + attrValue[12] ^= this->transactionId[4]; + attrValue[13] ^= this->transactionId[5]; + attrValue[14] ^= this->transactionId[6]; + attrValue[15] ^= this->transactionId[7]; + attrValue[16] ^= this->transactionId[8]; + attrValue[17] ^= this->transactionId[9]; + attrValue[18] ^= this->transactionId[10]; + attrValue[19] ^= this->transactionId[11]; pos += 4 + 20; @@ -635,7 +648,7 @@ namespace RTC Utils::Byte::Set2Bytes(buffer, pos, (uint16_t)Attribute::ErrorCode); Utils::Byte::Set2Bytes(buffer, pos + 2, 4); - uint8_t codeClass = (uint8_t)(this->errorCode / 100); + uint8_t codeClass = (uint8_t)(this->errorCode / 100); uint8_t codeNumber = (uint8_t)this->errorCode - (codeClass * 100); Utils::Byte::Set2Bytes(buffer, pos + 4, 0); @@ -652,7 +665,8 @@ namespace RTC Utils::Byte::Set2Bytes(buffer, 2, (uint16_t)(this->size - 20 - 8)); // Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules. - const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHMAC_SHA1(this->password, buffer, pos); + const uint8_t* computedMessageIntegrity = + Utils::Crypto::GetHMAC_SHA1(this->password, buffer, pos); Utils::Byte::Set2Bytes(buffer, pos, (uint16_t)Attribute::MessageIntegrity); Utils::Byte::Set2Bytes(buffer, pos + 2, 20); diff --git a/worker/src/RTC/TcpConnection.cpp b/worker/src/RTC/TcpConnection.cpp index eb257ac91d..4facce3cc8 100644 --- a/worker/src/RTC/TcpConnection.cpp +++ b/worker/src/RTC/TcpConnection.cpp @@ -2,17 +2,17 @@ // #define MS_LOG_DEV #include "RTC/TcpConnection.hpp" -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include // std::memmove() namespace RTC { /* Instance methods. */ - TcpConnection::TcpConnection(Listener* listener, size_t bufferSize) : - ::TcpConnection::TcpConnection(bufferSize), - listener(listener) + TcpConnection::TcpConnection(Listener* listener, size_t bufferSize) + : ::TcpConnection::TcpConnection(bufferSize) + , listener(listener) { MS_TRACE(); } @@ -21,8 +21,12 @@ namespace RTC { MS_TRACE(); - MS_DEBUG_DEV("data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", - GetLocalIP().c_str(), GetLocalPort(), GetPeerIP().c_str(), GetPeerPort()); + MS_DEBUG_DEV( + "data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", + GetLocalIP().c_str(), + GetLocalPort(), + GetPeerIP().c_str(), + GetPeerPort()); /* * Framing RFC 4571 @@ -70,7 +74,7 @@ namespace RTC { MS_DEBUG_DEV("no more space in the buffer, emptying the buffer data"); - this->frameStart = 0; + this->frameStart = 0; this->bufferDataLen = 0; } // If there is still space in the buffer, set the beginning of the next @@ -104,19 +108,22 @@ namespace RTC // the buffer, so move the frame to the position 0. if (this->frameStart != 0) { - MS_DEBUG_DEV("no more space in the buffer, moving parsed bytes to the beginning of " - "the buffer and wait for more data"); + MS_DEBUG_DEV( + "no more space in the buffer, moving parsed bytes to the beginning of " + "the buffer and wait for more data"); - std::memmove(this->buffer, this->buffer + this->frameStart, - this->bufferSize - this->frameStart); + std::memmove( + this->buffer, this->buffer + this->frameStart, this->bufferSize - this->frameStart); this->bufferDataLen = this->bufferSize - this->frameStart; - this->frameStart = 0; + this->frameStart = 0; } // Second case: the incomplete frame begins at position 0 of the buffer. // The frame is too big, so close the connection. else { - MS_WARN_DEV("no more space in the buffer for the unfinished frame being parsed, closing the connection"); + MS_WARN_DEV( + "no more space in the buffer for the unfinished frame being parsed, closing the " + "connection"); // Close the socket. Destroy(); diff --git a/worker/src/RTC/TcpServer.cpp b/worker/src/RTC/TcpServer.cpp index edb5db98aa..23c2755477 100644 --- a/worker/src/RTC/TcpServer.cpp +++ b/worker/src/RTC/TcpServer.cpp @@ -2,17 +2,16 @@ // #define MS_LOG_DEV #include "RTC/TcpServer.hpp" -#include "Settings.hpp" -#include "Utils.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Settings.hpp" +#include "Utils.hpp" #include /* Static methods for UV callbacks. */ -static inline -void on_error_close(uv_handle_t* handle) +static inline void on_error_close(uv_handle_t* handle) { delete handle; } @@ -21,7 +20,7 @@ namespace RTC { /* Static. */ - static constexpr uint16_t MaxBindAttempts = 20; + static constexpr uint16_t MaxBindAttempts = 20; static constexpr size_t MaxTcpConnectionsPerServer = 10; /* Class variables. */ @@ -43,8 +42,10 @@ namespace RTC if (!Settings::configuration.rtcIPv4.empty()) { - err = uv_ip4_addr(Settings::configuration.rtcIPv4.c_str(), 0, - (struct sockaddr_in*)&RTC::TcpServer::sockaddrStorageIPv4); + err = uv_ip4_addr( + Settings::configuration.rtcIPv4.c_str(), + 0, + (struct sockaddr_in*)&RTC::TcpServer::sockaddrStorageIPv4); if (err) MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err)); @@ -52,8 +53,10 @@ namespace RTC if (!Settings::configuration.rtcIPv6.empty()) { - err = uv_ip6_addr(Settings::configuration.rtcIPv6.c_str(), 0, - (struct sockaddr_in6*)&RTC::TcpServer::sockaddrStorageIPv6); + err = uv_ip6_addr( + Settings::configuration.rtcIPv6.c_str(), + 0, + (struct sockaddr_in6*)&RTC::TcpServer::sockaddrStorageIPv6); if (err) MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err)); @@ -68,8 +71,7 @@ namespace RTC { RTC::TcpServer::availableIPv4Ports[i] = true; RTC::TcpServer::availableIPv6Ports[i] = true; - } - while (i++ != RTC::TcpServer::maxPort); + } while (i++ != RTC::TcpServer::maxPort); } uv_tcp_t* TcpServer::GetRandomPort(int addressFamily) @@ -87,23 +89,23 @@ namespace RTC const char* listenIp; uint16_t initialPort; uint16_t iteratingPort; - uint16_t attempt = 0; + uint16_t attempt = 0; uint16_t bindAttempt = 0; - int flags = 0; + int flags = 0; std::unordered_map* availablePorts; switch (addressFamily) { case AF_INET: availablePorts = &RTC::TcpServer::availableIPv4Ports; - bindAddr = RTC::TcpServer::sockaddrStorageIPv4; - listenIp = Settings::configuration.rtcIPv4.c_str(); + bindAddr = RTC::TcpServer::sockaddrStorageIPv4; + listenIp = Settings::configuration.rtcIPv4.c_str(); break; case AF_INET6: availablePorts = &RTC::TcpServer::availableIPv6Ports; - bindAddr = RTC::TcpServer::sockaddrStorageIPv6; - listenIp = Settings::configuration.rtcIPv6.c_str(); + bindAddr = RTC::TcpServer::sockaddrStorageIPv6; + listenIp = Settings::configuration.rtcIPv6.c_str(); // Don't also bind into IPv4 when listening in IPv6. flags |= UV_TCP_IPV6ONLY; break; @@ -114,8 +116,8 @@ namespace RTC } // Choose a random first port to start from. - initialPort = (uint16_t)Utils::Crypto::GetRandomUInt((uint32_t)RTC::TcpServer::minPort, - (uint32_t)RTC::TcpServer::maxPort); + initialPort = (uint16_t)Utils::Crypto::GetRandomUInt( + (uint32_t)RTC::TcpServer::minPort, (uint32_t)RTC::TcpServer::maxPort); iteratingPort = initialPort; @@ -134,8 +136,10 @@ namespace RTC // Check whether the chosen port is available. if (!(*availablePorts)[iteratingPort]) { - MS_DEBUG_DEV("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", - iteratingPort, attempt); + MS_DEBUG_DEV( + "port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", + iteratingPort, + attempt); // If we have tried all the ports in the range raise an error. if (iteratingPort == initialPort) @@ -173,8 +177,11 @@ namespace RTC err = uv_tcp_bind(uvHandle, (const struct sockaddr*)&bindAddr, flags); if (err) { - MS_WARN_DEV("uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", - attempt, iteratingPort, uv_strerror(err)); + MS_WARN_DEV( + "uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", + attempt, + iteratingPort, + uv_strerror(err)); uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close); @@ -184,8 +191,8 @@ namespace RTC // If bind() fails for more that MaxBindAttempts then raise an error. if (bindAttempt > MaxBindAttempts) - MS_THROW_ERROR("uv_tcp_bind() fails more than %" PRIu16 " times for IP '%s'", - MaxBindAttempts, listenIp); + MS_THROW_ERROR( + "uv_tcp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp); // If we have tried all the ports in the range raise an error. if (iteratingPort == initialPort) @@ -197,8 +204,11 @@ namespace RTC // Set the port as unavailable. (*availablePorts)[iteratingPort] = false; - MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", - listenIp, iteratingPort, attempt); + MS_DEBUG_DEV( + "bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", + listenIp, + iteratingPort, + attempt); return uvHandle; }; @@ -206,13 +216,13 @@ namespace RTC /* Instance methods. */ - TcpServer::TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int addressFamily) : - // Provide the parent class constructor with a UDP uv handle. - // NOTE: This may throw a MediaSoupError exception if the address family is not available - // or there are no available ports. - ::TcpServer::TcpServer(GetRandomPort(addressFamily), 256), - listener(listener), - connListener(connListener) + TcpServer::TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int addressFamily) + : // Provide the parent class constructor with a UDP uv handle. + // NOTE: This may throw a MediaSoupError exception if the address family is not available + // or there are no available ports. + ::TcpServer::TcpServer(GetRandomPort(addressFamily), 256) + , listener(listener) + , connListener(connListener) { MS_TRACE(); } @@ -234,7 +244,7 @@ namespace RTC connection->Destroy(); } - void TcpServer::userOnTcpConnectionClosed(::TcpConnection* connection, bool is_closed_by_peer) + void TcpServer::userOnTcpConnectionClosed(::TcpConnection* connection, bool isClosedByPeer) { MS_TRACE(); @@ -243,8 +253,8 @@ namespace RTC // At the end, this is just called if the connection was remotely closed. if (!IsClosing()) { - this->listener->onRtcTcpConnectionClosed(this, static_cast(connection), - is_closed_by_peer); + this->listener->onRtcTcpConnectionClosed( + this, static_cast(connection), isClosedByPeer); } } diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index a215ccfeb2..1f6cdf5467 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -2,55 +2,50 @@ // #define MS_LOG_DEV #include "RTC/Transport.hpp" -#include "RTC/RTCP/FeedbackPsRemb.hpp" -#include "Settings.hpp" #include "DepLibUV.hpp" -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" -#include // std::ostringstream() +#include "MediaSoupError.hpp" +#include "Settings.hpp" +#include "Utils.hpp" +#include "RTC/RTCP/FeedbackPsRemb.hpp" +#include // std::pow() #include // std::ostream_iterator<>() -#include // std::pow() +#include // std::ostringstream + +/* Consts. */ -#define ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY 20000 -#define ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_FAMILY_INCREMENT 10000 -#define ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT 5000 +static constexpr uint16_t IceCandidateDefaultLocalPriority = 20000; +static constexpr uint16_t IceCandidateLocalPriorityPreferFamilyIncrement = 10000; +static constexpr uint16_t IceCandidateLocalPriorityPreferProtocolIncrement = 5000; +// We just provide "host" candidates so `type preference` is fixed. +static constexpr uint16_t IceTypePreference = 64; +// We do not support non rtcp-mux so `component` is always 1. +static constexpr uint16_t IceComponent = 1; /* Static helpers. */ -static inline -uint32_t generateIceCandidatePriority(uint16_t local_preference) +static inline uint32_t generateIceCandidatePriority(uint16_t localPreference) { MS_TRACE(); - // We just provide 'host' candidates so `type preference` is fixed. - static uint16_t type_preference = 64; - // We do not support non rtcp-mux so `component` is always 1. - static uint16_t component = 1; - - return - std::pow(2, 24) * type_preference + - std::pow(2, 8) * local_preference + - std::pow(2, 0) * (256 - component); + return std::pow(2, 24) * IceTypePreference + std::pow(2, 8) * localPreference + + std::pow(2, 0) * (256 - IceComponent); } namespace RTC { /* Consts. */ - static constexpr uint64_t EffectiveMaxBitrateCheckInterval = 2000; // In ms. - static constexpr double EffectiveMaxBitrateThresholdBeforeFullFrame = 0.6; // 0.0 - 1.0. - - /* Class variables. */ - - uint8_t Transport::rtcpBuffer[MS_RTCP_BUFFER_SIZE]; + static constexpr uint64_t EffectiveMaxBitrateCheckInterval = 2000; // In ms. + static constexpr double EffectiveMaxBitrateThresholdBeforeFullFrame = 0.6; // 0.0 - 1.0. /* Instance methods. */ - Transport::Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data) : - transportId(transportId), - listener(listener), - notifier(notifier) + Transport::Transport( + Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data) + : transportId(transportId) + , listener(listener) + , notifier(notifier) { MS_TRACE(); @@ -61,21 +56,21 @@ namespace RTC static const Json::StaticString k_preferUdp("preferUdp"); static const Json::StaticString k_preferTcp("preferTcp"); - bool try_IPv4_udp = true; - bool try_IPv6_udp = true; - bool try_IPv4_tcp = true; - bool try_IPv6_tcp = true; + bool tryIPv4udp = true; + bool tryIPv6udp = true; + bool tryIPv4tcp = true; + bool tryIPv6tcp = true; bool preferIPv4 = false; bool preferIPv6 = false; - bool preferUdp = false; - bool preferTcp = false; + bool preferUdp = false; + bool preferTcp = false; if (data[k_udp].isBool()) - try_IPv4_udp = try_IPv6_udp = data[k_udp].asBool(); + tryIPv4udp = tryIPv6udp = data[k_udp].asBool(); if (data[k_tcp].isBool()) - try_IPv4_tcp = try_IPv6_tcp = data[k_tcp].asBool(); + tryIPv4tcp = tryIPv6tcp = data[k_tcp].asBool(); if (data[k_preferIPv4].isBool()) preferIPv4 = data[k_preferIPv4].asBool(); @@ -87,21 +82,20 @@ namespace RTC preferTcp = data[k_preferTcp].asBool(); // Create a ICE server. - this->iceServer = new RTC::IceServer(this, - Utils::Crypto::GetRandomString(16), - Utils::Crypto::GetRandomString(32)); + this->iceServer = new RTC::IceServer( + this, Utils::Crypto::GetRandomString(16), Utils::Crypto::GetRandomString(32)); // Open a IPv4 UDP socket. - if (try_IPv4_udp && Settings::configuration.hasIPv4) + if (tryIPv4udp && Settings::configuration.hasIPv4) { - uint16_t local_preference = ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY; + uint16_t localPreference = IceCandidateDefaultLocalPriority; if (preferIPv4) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_FAMILY_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferFamilyIncrement; if (preferUdp) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferProtocolIncrement; - uint32_t priority = generateIceCandidatePriority(local_preference); + uint32_t priority = generateIceCandidatePriority(localPreference); try { @@ -111,23 +105,23 @@ namespace RTC this->udpSockets.push_back(udpSocket); this->iceLocalCandidates.push_back(iceCandidate); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error adding IPv4 UDP socket: %s", error.what()); } } // Open a IPv6 UDP socket. - if (try_IPv6_udp && Settings::configuration.hasIPv6) + if (tryIPv6udp && Settings::configuration.hasIPv6) { - uint16_t local_preference = ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY; + uint16_t localPreference = IceCandidateDefaultLocalPriority; if (preferIPv6) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_FAMILY_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferFamilyIncrement; if (preferUdp) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferProtocolIncrement; - uint32_t priority = generateIceCandidatePriority(local_preference); + uint32_t priority = generateIceCandidatePriority(localPreference); try { @@ -137,23 +131,23 @@ namespace RTC this->udpSockets.push_back(udpSocket); this->iceLocalCandidates.push_back(iceCandidate); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error adding IPv6 UDP socket: %s", error.what()); } } // Open a IPv4 TCP server. - if (try_IPv4_tcp && Settings::configuration.hasIPv4) + if (tryIPv4tcp && Settings::configuration.hasIPv4) { - uint16_t local_preference = ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY; + uint16_t localPreference = IceCandidateDefaultLocalPriority; if (preferIPv4) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_FAMILY_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferFamilyIncrement; if (preferTcp) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferProtocolIncrement; - uint32_t priority = generateIceCandidatePriority(local_preference); + uint32_t priority = generateIceCandidatePriority(localPreference); try { @@ -163,23 +157,23 @@ namespace RTC this->tcpServers.push_back(tcpServer); this->iceLocalCandidates.push_back(iceCandidate); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error adding IPv4 TCP server: %s", error.what()); } } // Open a IPv6 TCP server. - if (try_IPv6_tcp && Settings::configuration.hasIPv6) + if (tryIPv6tcp && Settings::configuration.hasIPv6) { - uint16_t local_preference = ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY; + uint16_t localPreference = IceCandidateDefaultLocalPriority; if (preferIPv6) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_FAMILY_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferFamilyIncrement; if (preferTcp) - local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT; + localPreference += IceCandidateLocalPriorityPreferProtocolIncrement; - uint32_t priority = generateIceCandidatePriority(local_preference); + uint32_t priority = generateIceCandidatePriority(localPreference); try { @@ -189,7 +183,7 @@ namespace RTC this->tcpServers.push_back(tcpServer); this->iceLocalCandidates.push_back(iceCandidate); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error adding IPv6 TCP server: %s", error.what()); } @@ -221,7 +215,7 @@ namespace RTC static const Json::StaticString k_class("class"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); if (this->srtpRecvSession) this->srtpRecvSession->Destroy(); @@ -246,8 +240,8 @@ namespace RTC this->selectedTuple = nullptr; // Notify. - event_data[k_class] = "Transport"; - this->notifier->Emit(this->transportId, "close", event_data); + eventData[k_class] = "Transport"; + this->notifier->Emit(this->transportId, "close", eventData); // If this was allocated (it did not throw in the constructor) notify the // listener and delete it. @@ -301,7 +295,7 @@ namespace RTC // Add `iceLocalParameters`. json[k_iceLocalParameters][k_usernameFragment] = this->iceServer->GetUsernameFragment(); - json[k_iceLocalParameters][k_password] = this->iceServer->GetPassword(); + json[k_iceLocalParameters][k_password] = this->iceServer->GetPassword(); // Add `iceLocalCandidates`. json[k_iceLocalCandidates] = Json::arrayValue; @@ -393,13 +387,14 @@ namespace RTC { case Channel::Request::MethodId::transport_close: { - #ifdef MS_LOG_DEV +#ifdef MS_LOG_DEV uint32_t transportId = this->transportId; - #endif +#endif Destroy(); MS_DEBUG_DEV("Transport closed [transportId:%" PRIu32 "]", transportId); + request->Accept(); break; @@ -424,14 +419,17 @@ namespace RTC static const Json::StaticString k_value("value"); RTC::DtlsTransport::Fingerprint remoteFingerprint; - RTC::DtlsTransport::Role remoteRole = RTC::DtlsTransport::Role::AUTO; // Default value if missing. + RTC::DtlsTransport::Role remoteRole = + RTC::DtlsTransport::Role::AUTO; // Default value if missing. // Ensure this method is not called twice. if (this->remoteDtlsParametersGiven) { request->Reject("method already called"); + return; } + this->remoteDtlsParametersGiven = true; // Validate request data. @@ -439,21 +437,25 @@ namespace RTC if (!request->data[k_fingerprint].isObject()) { request->Reject("missing data.fingerprint"); + return; } if (!request->data[k_fingerprint][k_algorithm].isString() || - !request->data[k_fingerprint][k_value].isString()) + !request->data[k_fingerprint][k_value].isString()) { request->Reject("missing data.fingerprint.algorithm and/or data.fingerprint.value"); + return; } - remoteFingerprint.algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(request->data[k_fingerprint][k_algorithm].asString()); + remoteFingerprint.algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm( + request->data[k_fingerprint][k_algorithm].asString()); if (remoteFingerprint.algorithm == RTC::DtlsTransport::FingerprintAlgorithm::NONE) { request->Reject("unsupported data.fingerprint.algorithm"); + return; } @@ -515,6 +517,7 @@ namespace RTC if (!request->data[k_bitrate].isUInt()) { request->Reject("missing data.bitrate"); + return; } @@ -525,8 +528,7 @@ namespace RTC this->maxBitrate = bitrate; - MS_DEBUG_TAG(rbe, "transport max bitrate set to %" PRIu32 "bps", - this->maxBitrate); + MS_DEBUG_TAG(rbe, "transport max bitrate set to %" PRIu32 "bps", this->maxBitrate); request->Accept(); @@ -559,7 +561,7 @@ namespace RTC } const uint8_t* data = packet->GetData(); - size_t len = packet->GetSize(); + size_t len = packet->GetSize(); if (!this->srtpSendSession->EncryptRtp(&data, &len)) return; @@ -584,7 +586,7 @@ namespace RTC } const uint8_t* data = packet->GetData(); - size_t len = packet->GetSize(); + size_t len = packet->GetSize(); if (!this->srtpSendSession->EncryptRtcp(&data, &len)) return; @@ -609,7 +611,7 @@ namespace RTC } const uint8_t* data = packet->GetData(); - size_t len = packet->GetSize(); + size_t len = packet->GetSize(); if (!this->srtpSendSession->EncryptRtcp(&data, &len)) return; @@ -617,8 +619,7 @@ namespace RTC this->selectedTuple->Send(data, len); } - inline - void Transport::MayRunDtlsTransport() + inline void Transport::MayRunDtlsTransport() { MS_TRACE(); @@ -636,7 +637,8 @@ namespace RTC if (this->iceServer->GetState() == RTC::IceServer::IceState::CONNECTED || this->iceServer->GetState() == RTC::IceServer::IceState::COMPLETED) { - MS_DEBUG_TAG(dtls, "transition from DTLS local role 'auto' to 'server' and running DTLS transport"); + MS_DEBUG_TAG( + dtls, "transition from DTLS local role 'auto' to 'server' and running DTLS transport"); this->dtlsLocalRole = RTC::DtlsTransport::Role::SERVER; this->dtlsTransport->Run(RTC::DtlsTransport::Role::SERVER); @@ -672,8 +674,7 @@ namespace RTC } } - inline - void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) + inline void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -703,8 +704,7 @@ namespace RTC } } - inline - void Transport::onStunDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) + inline void Transport::onStunDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -722,8 +722,7 @@ namespace RTC delete msg; } - inline - void Transport::onDtlsDataRecv(const RTC::TransportTuple* tuple, const uint8_t* data, size_t len) + inline void Transport::onDtlsDataRecv(const RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -748,15 +747,13 @@ namespace RTC } else { - MS_WARN_TAG(dtls, - "Transport is not 'connecting' or 'connected', ignoring received DTLS data"); + MS_WARN_TAG(dtls, "Transport is not 'connecting' or 'connected', ignoring received DTLS data"); return; } } - inline - void Transport::onRtpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) + inline void Transport::onRtpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -788,15 +785,19 @@ namespace RTC if (!this->srtpRecvSession->DecryptSrtp(data, &len)) { RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); + if (!packet) { MS_WARN_TAG(srtp, "DecryptSrtp() failed due to an invalid RTP packet"); } else { - MS_WARN_TAG(srtp, - "DecryptSrtp() failed [ssrc:%" PRIu32 ", payloadType:%" PRIu8 ", seq:%" PRIu16 "]", - packet->GetSsrc(), packet->GetPayloadType(), packet->GetSequenceNumber()); + MS_WARN_TAG( + srtp, + "DecryptSrtp() failed [ssrc:%" PRIu32 ", payloadType:%" PRIu8 ", seq:%" PRIu16 "]", + packet->GetSsrc(), + packet->GetPayloadType(), + packet->GetSequenceNumber()); delete packet; } @@ -805,6 +806,7 @@ namespace RTC } RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); + if (!packet) { MS_WARN_TAG(rtp, "received data is not a valid RTP packet"); @@ -812,22 +814,33 @@ namespace RTC return; } - MS_DEBUG_DEV("RTP packet received [ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]", packet->GetSsrc(), packet->GetPayloadType()); + MS_DEBUG_DEV( + "RTP packet received [ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]", + packet->GetSsrc(), + packet->GetPayloadType()); // Get the associated RtpReceiver. RTC::RtpReceiver* rtpReceiver = this->rtpListener.GetRtpReceiver(packet); if (!rtpReceiver) { - MS_WARN_TAG(rtp, - "no suitable RtpReceiver for received RTP packet [ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]", - packet->GetSsrc(), packet->GetPayloadType()); + MS_WARN_TAG( + rtp, + "no suitable RtpReceiver for received RTP packet [ssrc:%" PRIu32 ", payloadType:%" PRIu8 + "]", + packet->GetSsrc(), + packet->GetPayloadType()); delete packet; return; } - MS_DEBUG_DEV("valid RTP packet received [ssrc:%" PRIu32 ", payloadType:%" PRIu8 ", rtpReceiver:%" PRIu32 "]", packet->GetSsrc(), packet->GetPayloadType(), rtpReceiver->rtpReceiverId); + MS_DEBUG_DEV( + "valid RTP packet received [ssrc:%" PRIu32 ", payloadType:%" PRIu8 ", rtpReceiver:%" PRIu32 + "]", + packet->GetSsrc(), + packet->GetPayloadType(), + rtpReceiver->rtpReceiverId); // Trick for clients performing aggressive ICE regardless we are ICE-Lite. this->iceServer->ForceSelectedTuple(tuple); @@ -843,15 +856,14 @@ namespace RTC if (packet->ReadAbsSendTime(&absSendTime)) { this->remoteBitrateEstimator->IncomingPacket( - DepLibUV::GetTime(), packet->GetPayloadLength(), *packet, absSendTime); + DepLibUV::GetTime(), packet->GetPayloadLength(), *packet, absSendTime); } } delete packet; } - inline - void Transport::onRtcpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) + inline void Transport::onRtcpDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -884,6 +896,7 @@ namespace RTC return; RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); + if (!packet) { MS_WARN_TAG(rtcp, "received data is not a valid RTCP compound or single packet"); @@ -899,33 +912,35 @@ namespace RTC // Delete the whole packet. while (packet) { - RTC::RTCP::Packet* next_packet = packet->GetNext(); + RTC::RTCP::Packet* nextPacket = packet->GetNext(); delete packet; - packet = next_packet; + packet = nextPacket; } } - void Transport::onPacketRecv(RTC::UdpSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr) + void Transport::onPacketRecv( + RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr) { MS_TRACE(); - RTC::TransportTuple tuple(socket, remote_addr); + RTC::TransportTuple tuple(socket, remoteAddr); onPacketRecv(&tuple, data, len); } - void Transport::onRtcTcpConnectionClosed(RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool is_closed_by_peer) + void Transport::onRtcTcpConnectionClosed( + RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) { MS_TRACE(); RTC::TransportTuple tuple(connection); - if (is_closed_by_peer) + if (isClosedByPeer) this->iceServer->RemoveTuple(&tuple); } - void Transport::onPacketRecv(RTC::TcpConnection *connection, const uint8_t* data, size_t len) + void Transport::onPacketRecv(RTC::TcpConnection* connection, const uint8_t* data, size_t len) { MS_TRACE(); @@ -934,7 +949,8 @@ namespace RTC onPacketRecv(&tuple, data, len); } - void Transport::onOutgoingStunMessage(const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) + void Transport::onOutgoingStunMessage( + const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) { MS_TRACE(); @@ -949,7 +965,7 @@ namespace RTC static const Json::StaticString k_class("class"); static const Json::StaticString k_iceSelectedTuple("iceSelectedTuple"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); /* * RFC 5245 section 11.2 "Receiving Media": @@ -962,9 +978,9 @@ namespace RTC this->selectedTuple = tuple; // Notify. - event_data[k_class] = "Transport"; - event_data[k_iceSelectedTuple] = tuple->toJson(); - this->notifier->Emit(this->transportId, "iceselectedtuplechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_iceSelectedTuple] = tuple->toJson(); + this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData); } void Transport::onIceConnected(const RTC::IceServer* iceServer) @@ -975,14 +991,14 @@ namespace RTC static const Json::StaticString k_iceState("iceState"); static const Json::StaticString v_connected("connected"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(ice, "ICE connected"); // Notify. - event_data[k_class] = "Transport"; - event_data[k_iceState] = v_connected; - this->notifier->Emit(this->transportId, "icestatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_iceState] = v_connected; + this->notifier->Emit(this->transportId, "icestatechange", eventData); // If ready, run the DTLS handler. MayRunDtlsTransport(); @@ -996,14 +1012,14 @@ namespace RTC static const Json::StaticString k_iceState("iceState"); static const Json::StaticString v_completed("completed"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(ice, "ICE completed"); // Notify. - event_data[k_class] = "Transport"; - event_data[k_iceState] = v_completed; - this->notifier->Emit(this->transportId, "icestatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_iceState] = v_completed; + this->notifier->Emit(this->transportId, "icestatechange", eventData); // If ready, run the DTLS handler. MayRunDtlsTransport(); @@ -1017,7 +1033,7 @@ namespace RTC static const Json::StaticString k_iceState("iceState"); static const Json::StaticString v_disconnected("disconnected"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(ice, "ICE disconnected"); @@ -1025,9 +1041,9 @@ namespace RTC this->selectedTuple = nullptr; // Notify. - event_data[k_class] = "Transport"; - event_data[k_iceState] = v_disconnected; - this->notifier->Emit(this->transportId, "icestatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_iceState] = v_disconnected; + this->notifier->Emit(this->transportId, "icestatechange", eventData); // This is a fatal error so close the transport. Destroy(); @@ -1041,17 +1057,24 @@ namespace RTC static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString v_connecting("connecting"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(dtls, "DTLS connecting"); // Notify. - event_data[k_class] = "Transport"; - event_data[k_dtlsState] = v_connecting; - this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_dtlsState] = v_connecting; + this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); } - void Transport::onDtlsConnected(const RTC::DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) + void Transport::onDtlsConnected( + const RTC::DtlsTransport* dtlsTransport, + RTC::SrtpSession::Profile srtp_profile, + uint8_t* srtp_local_key, + size_t srtp_local_key_len, + uint8_t* srtp_remote_key, + size_t srtp_remote_key_len, + std::string& remoteCert) { MS_TRACE(); @@ -1060,7 +1083,7 @@ namespace RTC static const Json::StaticString v_connected("connected"); static const Json::StaticString k_dtlsRemoteCert("dtlsRemoteCert"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(dtls, "DTLS connected"); @@ -1078,20 +1101,20 @@ namespace RTC try { - this->srtpSendSession = new RTC::SrtpSession(RTC::SrtpSession::Type::OUTBOUND, - srtp_profile, srtp_local_key, srtp_local_key_len); + this->srtpSendSession = new RTC::SrtpSession( + RTC::SrtpSession::Type::OUTBOUND, srtp_profile, srtp_local_key, srtp_local_key_len); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error creating SRTP sending session: %s", error.what()); } try { - this->srtpRecvSession = new RTC::SrtpSession(SrtpSession::Type::INBOUND, - srtp_profile, srtp_remote_key, srtp_remote_key_len); + this->srtpRecvSession = new RTC::SrtpSession( + SrtpSession::Type::INBOUND, srtp_profile, srtp_remote_key, srtp_remote_key_len); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("error creating SRTP receiving session: %s", error.what()); @@ -1100,10 +1123,10 @@ namespace RTC } // Notify. - event_data[k_class] = "Transport"; - event_data[k_dtlsState] = v_connected; - event_data[k_dtlsRemoteCert] = remoteCert; - this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_dtlsState] = v_connected; + eventData[k_dtlsRemoteCert] = remoteCert; + this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->listener->onTransportConnected(this); } @@ -1116,14 +1139,14 @@ namespace RTC static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString v_failed("failed"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_WARN_TAG(dtls, "DTLS failed"); // Notify. - event_data[k_class] = "Transport"; - event_data[k_dtlsState] = v_failed; - this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_dtlsState] = v_failed; + this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); // This is a fatal error so close the transport. Destroy(); @@ -1137,20 +1160,21 @@ namespace RTC static const Json::StaticString k_dtlsState("dtlsState"); static const Json::StaticString v_closed("closed"); - Json::Value event_data(Json::objectValue); + Json::Value eventData(Json::objectValue); MS_DEBUG_TAG(dtls, "DTLS remotely closed"); // Notify. - event_data[k_class] = "Transport"; - event_data[k_dtlsState] = v_closed; - this->notifier->Emit(this->transportId, "dtlsstatechange", event_data); + eventData[k_class] = "Transport"; + eventData[k_dtlsState] = v_closed; + this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); // This is a fatal error so close the transport. Destroy(); } - void Transport::onOutgoingDtlsData(const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) + void Transport::onOutgoingDtlsData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) { MS_TRACE(); @@ -1164,7 +1188,8 @@ namespace RTC this->selectedTuple->Send(data, len); } - void Transport::onDtlsApplicationData(const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) + void Transport::onDtlsApplicationData( + const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) { MS_TRACE(); @@ -1175,41 +1200,44 @@ namespace RTC { MS_TRACE(); - uint32_t effective_bitrate; + uint32_t effectiveBitrate; uint64_t now = DepLibUV::GetTime(); // Limit bitrate if requested via API. if (this->maxBitrate) - effective_bitrate = std::min(bitrate, this->maxBitrate); + effectiveBitrate = std::min(bitrate, this->maxBitrate); else - effective_bitrate = bitrate; + effectiveBitrate = bitrate; if (MS_HAS_DEBUG_TAG(rbe)) { - std::ostringstream ssrcs_stream; + std::ostringstream ssrcsStream; - std::copy(ssrcs.begin(), ssrcs.end() - 1, std::ostream_iterator(ssrcs_stream, ",")); - ssrcs_stream << ssrcs.back(); + std::copy(ssrcs.begin(), ssrcs.end() - 1, std::ostream_iterator(ssrcsStream, ",")); + ssrcsStream << ssrcs.back(); - MS_DEBUG_TAG(rbe, - "sending RTCP REMB packet [estimated:%" PRIu32 "bps, effective:%" PRIu32 "bps, ssrcs:%s]", - bitrate, effective_bitrate, ssrcs_stream.str().c_str()); + MS_DEBUG_TAG( + rbe, + "sending RTCP REMB packet [estimated:%" PRIu32 "bps, effective:%" PRIu32 "bps, ssrcs:%s]", + bitrate, + effectiveBitrate, + ssrcsStream.str().c_str()); } RTC::RTCP::FeedbackPsRembPacket packet(0, 0); - packet.SetBitrate(effective_bitrate); + + packet.SetBitrate(effectiveBitrate); packet.SetSsrcs(ssrcs); - packet.Serialize(Transport::rtcpBuffer); + packet.Serialize(RTC::RTCP::buffer); this->SendRtcpPacket(&packet); // Trigger a full frame for all the suitable strams if the effective max bitrate // has decreased abruptly. if (now - this->lastEffectiveMaxBitrateAt > EffectiveMaxBitrateCheckInterval) { - if ( - bitrate && - this->effectiveMaxBitrate && - (double)effective_bitrate / (double)this->effectiveMaxBitrate < EffectiveMaxBitrateThresholdBeforeFullFrame) + if (bitrate && this->effectiveMaxBitrate && + (double)effectiveBitrate / (double)this->effectiveMaxBitrate < + EffectiveMaxBitrateThresholdBeforeFullFrame) { MS_WARN_TAG(rbe, "uplink effective max bitrate abruptly decrease, requesting full frames"); @@ -1217,7 +1245,7 @@ namespace RTC } this->lastEffectiveMaxBitrateAt = now; - this->effectiveMaxBitrate = effective_bitrate; + this->effectiveMaxBitrate = effectiveBitrate; } } } diff --git a/worker/src/RTC/TransportTuple.cpp b/worker/src/RTC/TransportTuple.cpp index 1d7c6a78a1..85357f1a26 100644 --- a/worker/src/RTC/TransportTuple.cpp +++ b/worker/src/RTC/TransportTuple.cpp @@ -23,20 +23,20 @@ namespace RTC static const Json::StaticString v_tcp("tcp"); Json::Value json(Json::objectValue); - int ip_family; + int ipFamily; std::string ip; uint16_t port; - Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ip_family, ip, &port); - json[k_localIP] = ip; + Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ipFamily, ip, &port); + json[k_localIP] = ip; json[k_localPort] = (Json::UInt)port; if (this->GetProtocol() == RTC::TransportTuple::Protocol::UDP) json[k_protocol] = v_udp; else json[k_protocol] = v_tcp; - Utils::IP::GetAddressInfo(this->GetRemoteAddress(), &ip_family, ip, &port); - json[k_remoteIP] = ip; + Utils::IP::GetAddressInfo(this->GetRemoteAddress(), &ipFamily, ip, &port); + json[k_remoteIP] = ip; json[k_remotePort] = (Json::UInt)port; return json; @@ -50,16 +50,19 @@ namespace RTC { case Protocol::UDP: { - int remote_family; - std::string remote_ip; - uint16_t remote_port; + int remoteFamily; + std::string remoteIp; + uint16_t remotePort; - Utils::IP::GetAddressInfo(GetRemoteAddress(), &remote_family, remote_ip, &remote_port); + Utils::IP::GetAddressInfo(GetRemoteAddress(), &remoteFamily, remoteIp, &remotePort); MS_DUMP(""); - MS_DUMP(" [UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", - this->udpSocket->GetLocalIP().c_str(), this->udpSocket->GetLocalPort(), - remote_ip.c_str(), remote_port); + MS_DUMP( + " [UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", + this->udpSocket->GetLocalIP().c_str(), + this->udpSocket->GetLocalPort(), + remoteIp.c_str(), + remotePort); MS_DUMP(""); break; } @@ -67,9 +70,12 @@ namespace RTC case Protocol::TCP: { MS_DUMP(""); - MS_DUMP(" [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", - this->tcpConnection->GetLocalIP().c_str(), this->tcpConnection->GetLocalPort(), - this->tcpConnection->GetPeerIP().c_str(), this->tcpConnection->GetPeerPort()); + MS_DUMP( + " [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", + this->tcpConnection->GetLocalIP().c_str(), + this->tcpConnection->GetLocalPort(), + this->tcpConnection->GetPeerIP().c_str(), + this->tcpConnection->GetPeerPort()); MS_DUMP(""); break; } diff --git a/worker/src/RTC/UdpSocket.cpp b/worker/src/RTC/UdpSocket.cpp index 0bd1790278..0f471f1076 100644 --- a/worker/src/RTC/UdpSocket.cpp +++ b/worker/src/RTC/UdpSocket.cpp @@ -2,17 +2,16 @@ // #define MS_LOG_DEV #include "RTC/UdpSocket.hpp" -#include "Settings.hpp" -#include "Utils.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Settings.hpp" +#include "Utils.hpp" #include /* Static methods for UV callbacks. */ -static inline -void on_error_close(uv_handle_t* handle) +static inline void on_error_close(uv_handle_t* handle) { delete handle; } @@ -42,8 +41,10 @@ namespace RTC if (Settings::configuration.hasIPv4) { - err = uv_ip4_addr(Settings::configuration.rtcIPv4.c_str(), 0, - (struct sockaddr_in*)&RTC::UdpSocket::sockaddrStorageIPv4); + err = uv_ip4_addr( + Settings::configuration.rtcIPv4.c_str(), + 0, + (struct sockaddr_in*)&RTC::UdpSocket::sockaddrStorageIPv4); if (err) MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err)); @@ -51,8 +52,10 @@ namespace RTC if (Settings::configuration.hasIPv6) { - err = uv_ip6_addr(Settings::configuration.rtcIPv6.c_str(), 0, - (struct sockaddr_in6*)&RTC::UdpSocket::sockaddrStorageIPv6); + err = uv_ip6_addr( + Settings::configuration.rtcIPv6.c_str(), + 0, + (struct sockaddr_in6*)&RTC::UdpSocket::sockaddrStorageIPv6); if (err) MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err)); @@ -67,8 +70,7 @@ namespace RTC { RTC::UdpSocket::availableIPv4Ports[i] = true; RTC::UdpSocket::availableIPv6Ports[i] = true; - } - while (i++ != RTC::UdpSocket::maxPort); + } while (i++ != RTC::UdpSocket::maxPort); } uv_udp_t* UdpSocket::GetRandomPort(int addressFamily) @@ -86,23 +88,23 @@ namespace RTC const char* listenIp; uint16_t initialPort; uint16_t iteratingPort; - uint16_t attempt = 0; + uint16_t attempt = 0; uint16_t bindAttempt = 0; - int flags = 0; + int flags = 0; std::unordered_map* availablePorts; switch (addressFamily) { case AF_INET: availablePorts = &RTC::UdpSocket::availableIPv4Ports; - bindAddr = RTC::UdpSocket::sockaddrStorageIPv4; - listenIp = Settings::configuration.rtcIPv4.c_str(); + bindAddr = RTC::UdpSocket::sockaddrStorageIPv4; + listenIp = Settings::configuration.rtcIPv4.c_str(); break; case AF_INET6: availablePorts = &RTC::UdpSocket::availableIPv6Ports; - bindAddr = RTC::UdpSocket::sockaddrStorageIPv6; - listenIp = Settings::configuration.rtcIPv6.c_str(); + bindAddr = RTC::UdpSocket::sockaddrStorageIPv6; + listenIp = Settings::configuration.rtcIPv6.c_str(); // Don't also bind into IPv4 when listening in IPv6. flags |= UV_UDP_IPV6ONLY; break; @@ -113,8 +115,8 @@ namespace RTC } // Choose a random port to start from. - initialPort = (uint16_t)Utils::Crypto::GetRandomUInt((uint32_t)RTC::UdpSocket::minPort, - (uint32_t)RTC::UdpSocket::maxPort); + initialPort = (uint16_t)Utils::Crypto::GetRandomUInt( + (uint32_t)RTC::UdpSocket::minPort, (uint32_t)RTC::UdpSocket::maxPort); iteratingPort = initialPort; @@ -133,8 +135,10 @@ namespace RTC // Check whether the chosen port is available. if (!(*availablePorts)[iteratingPort]) { - MS_DEBUG_DEV("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", - iteratingPort, attempt); + MS_DEBUG_DEV( + "port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", + iteratingPort, + attempt); // If we have tried all the ports in the range raise an error. if (iteratingPort == initialPort) @@ -172,8 +176,11 @@ namespace RTC err = uv_udp_bind(uvHandle, (const struct sockaddr*)&bindAddr, flags); if (err) { - MS_WARN_DEV("uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", - attempt, iteratingPort, uv_strerror(err)); + MS_WARN_DEV( + "uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", + attempt, + iteratingPort, + uv_strerror(err)); uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close); @@ -183,8 +190,8 @@ namespace RTC // If bind() fails for more that MaxBindAttempts then raise an error. if (bindAttempt > MaxBindAttempts) - MS_THROW_ERROR("uv_udp_bind() fails more than %" PRIu16 " times for IP '%s'", - MaxBindAttempts, listenIp); + MS_THROW_ERROR( + "uv_udp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp); // If we have tried all the ports in the range raise an error. if (iteratingPort == initialPort) @@ -196,8 +203,11 @@ namespace RTC // Set the port as unavailable. (*availablePorts)[iteratingPort] = false; - MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", - listenIp, iteratingPort, attempt); + MS_DEBUG_DEV( + "bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", + listenIp, + iteratingPort, + attempt); return uvHandle; }; @@ -205,12 +215,12 @@ namespace RTC /* Instance methods. */ - UdpSocket::UdpSocket(Listener* listener, int addressFamily) : - // Provide the parent class constructor with a UDP uv handle. - // NOTE: This may throw a MediaSoupError exception if the address family is not available - // or there are no available ports. - ::UdpSocket::UdpSocket(GetRandomPort(addressFamily)), - listener(listener) + UdpSocket::UdpSocket(Listener* listener, int addressFamily) + : // Provide the parent class constructor with a UDP uv handle. + // NOTE: This may throw a MediaSoupError exception if the address family is not available + // or there are no available ports. + ::UdpSocket::UdpSocket(GetRandomPort(addressFamily)) + , listener(listener) { MS_TRACE(); } diff --git a/worker/src/Settings.cpp b/worker/src/Settings.cpp index 668820eb89..2b77acf419 100644 --- a/worker/src/Settings.cpp +++ b/worker/src/Settings.cpp @@ -2,25 +2,25 @@ // #define MS_LOG_DEV #include "Settings.hpp" -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" +#include #include // isprint() #include #include // close() -#include -extern "C" -{ - #include +extern "C" { +#include } /* Helpers declaration. */ -static bool IsBindableIP(const std::string &ip, int family, int* _bind_err); +static bool IsBindableIP(const std::string& ip, int family, int* _bind_err); /* Class variables. */ struct Settings::Configuration Settings::configuration; +// clang-format off std::map Settings::string2LogLevel = { { "debug", LogLevel::LOG_DEBUG }, @@ -33,6 +33,7 @@ std::map Settings::logLevel2String = { LogLevel::LOG_WARN, "warn" }, { LogLevel::LOG_ERROR, "error" } }; +// clang-format on /* Class methods. */ @@ -47,13 +48,13 @@ void Settings::SetConfiguration(int argc, char* argv[]) /* Variables for getopt. */ - extern char *optarg; + extern char* optarg; extern int opterr, optopt; int c; int optionIdx = 0; std::string stringValue; std::vector logTags; - + // clang-format off struct option options[] = { { "logLevel", optional_argument, nullptr, 'l' }, @@ -68,6 +69,7 @@ void Settings::SetConfiguration(int argc, char* argv[]) { "dtlsPrivateKeyFile", optional_argument, nullptr, 'p' }, { 0, 0, 0, 0 } }; + // clang-format on /* Parse command line options. */ @@ -100,13 +102,13 @@ void Settings::SetConfiguration(int argc, char* argv[]) break; case '5': - stringValue = std::string(optarg); + stringValue = std::string(optarg); Settings::configuration.rtcAnnouncedIPv4 = stringValue; Settings::configuration.hasAnnouncedIPv4 = true; break; case '7': - stringValue = std::string(optarg); + stringValue = std::string(optarg); Settings::configuration.rtcAnnouncedIPv6 = stringValue; Settings::configuration.hasAnnouncedIPv6 = true; break; @@ -120,12 +122,12 @@ void Settings::SetConfiguration(int argc, char* argv[]) break; case 'c': - stringValue = std::string(optarg); + stringValue = std::string(optarg); Settings::configuration.dtlsCertificateFile = stringValue; break; case 'p': - stringValue = std::string(optarg); + stringValue = std::string(optarg); Settings::configuration.dtlsPrivateKeyFile = stringValue; break; @@ -200,16 +202,17 @@ void Settings::PrintConfiguration() MS_DEBUG_TAG(info, ""); - MS_DEBUG_TAG(info, " logLevel : \"%s\"", - Settings::logLevel2String[Settings::configuration.logLevel].c_str()); + MS_DEBUG_TAG( + info, + " logLevel : \"%s\"", + Settings::logLevel2String[Settings::configuration.logLevel].c_str()); for (auto& tag : logTags) { MS_DEBUG_TAG(info, " logTag : \"%s\"", tag.c_str()); } if (Settings::configuration.hasIPv4) { - MS_DEBUG_TAG(info, " rtcIPv4 : \"%s\"", - Settings::configuration.rtcIPv4.c_str()); + MS_DEBUG_TAG(info, " rtcIPv4 : \"%s\"", Settings::configuration.rtcIPv4.c_str()); } else { @@ -217,8 +220,7 @@ void Settings::PrintConfiguration() } if (Settings::configuration.hasIPv6) { - MS_DEBUG_TAG(info, " rtcIPv6 : \"%s\"", - Settings::configuration.rtcIPv6.c_str()); + MS_DEBUG_TAG(info, " rtcIPv6 : \"%s\"", Settings::configuration.rtcIPv6.c_str()); } else { @@ -226,8 +228,8 @@ void Settings::PrintConfiguration() } if (Settings::configuration.hasAnnouncedIPv4) { - MS_DEBUG_TAG(info, " rtcAnnouncedIPv4 : \"%s\"", - Settings::configuration.rtcAnnouncedIPv4.c_str()); + MS_DEBUG_TAG( + info, " rtcAnnouncedIPv4 : \"%s\"", Settings::configuration.rtcAnnouncedIPv4.c_str()); } else { @@ -235,7 +237,8 @@ void Settings::PrintConfiguration() } if (Settings::configuration.hasAnnouncedIPv6) { - MS_DEBUG_TAG(info, " rtcAnnouncedIPv6 : \"%s\"", Settings::configuration.rtcAnnouncedIPv6.c_str()); + MS_DEBUG_TAG( + info, " rtcAnnouncedIPv6 : \"%s\"", Settings::configuration.rtcAnnouncedIPv6.c_str()); } else { @@ -245,10 +248,10 @@ void Settings::PrintConfiguration() MS_DEBUG_TAG(info, " rtcMaxPort : %" PRIu16, Settings::configuration.rtcMaxPort); if (!Settings::configuration.dtlsCertificateFile.empty()) { - MS_DEBUG_TAG(info, " dtlsCertificateFile : \"%s\"", - Settings::configuration.dtlsCertificateFile.c_str()); - MS_DEBUG_TAG(info, " dtlsPrivateKeyFile : \"%s\"", - Settings::configuration.dtlsPrivateKeyFile.c_str()); + MS_DEBUG_TAG( + info, " dtlsCertificateFile : \"%s\"", Settings::configuration.dtlsCertificateFile.c_str()); + MS_DEBUG_TAG( + info, " dtlsPrivateKeyFile : \"%s\"", Settings::configuration.dtlsPrivateKeyFile.c_str()); } MS_DEBUG_TAG(info, ""); @@ -266,7 +269,7 @@ void Settings::HandleRequest(Channel::Request* request) static const Json::StaticString k_logTags("logTags"); Json::Value jsonLogLevel = request->data[k_logLevel]; - Json::Value jsonLogTags = request->data[k_logTags]; + Json::Value jsonLogTags = request->data[k_logTags]; try { @@ -284,7 +287,7 @@ void Settings::HandleRequest(Channel::Request* request) Settings::SetLogTags(jsonLogTags); } } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { request->Reject(error.what()); @@ -334,6 +337,7 @@ void Settings::SetDefaultRtcIP(int requestedFamily) int family; uint16_t port; std::string ip; + Utils::IP::GetAddressInfo((struct sockaddr*)(&address.address.address4), &family, ip, &port); if (family != requestedFamily) @@ -382,7 +386,7 @@ void Settings::SetDefaultRtcIP(int requestedFamily) uv_free_interface_addresses(addresses, numAddresses); } -void Settings::SetLogLevel(std::string &level) +void Settings::SetLogLevel(std::string& level) { MS_TRACE(); @@ -395,7 +399,7 @@ void Settings::SetLogLevel(std::string &level) Settings::configuration.logLevel = Settings::string2LogLevel[level]; } -void Settings::SetRtcIPv4(const std::string &ip) +void Settings::SetRtcIPv4(const std::string& ip) { MS_TRACE(); @@ -430,7 +434,7 @@ void Settings::SetRtcIPv4(const std::string &ip) MS_THROW_ERROR("cannot bind on '%s' for rtcIPv4: %s", ip.c_str(), std::strerror(bindErrno)); } -void Settings::SetRtcIPv6(const std::string &ip) +void Settings::SetRtcIPv6(const std::string& ip) { MS_TRACE(); @@ -496,22 +500,23 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles() { MS_TRACE(); - if (Settings::configuration.dtlsCertificateFile.empty() || Settings::configuration.dtlsPrivateKeyFile.empty()) + if (Settings::configuration.dtlsCertificateFile.empty() || + Settings::configuration.dtlsPrivateKeyFile.empty()) { Settings::configuration.dtlsCertificateFile = ""; - Settings::configuration.dtlsPrivateKeyFile = ""; + Settings::configuration.dtlsPrivateKeyFile = ""; return; } std::string dtlsCertificateFile = Settings::configuration.dtlsCertificateFile; - std::string dtlsPrivateKeyFile = Settings::configuration.dtlsPrivateKeyFile; + std::string dtlsPrivateKeyFile = Settings::configuration.dtlsPrivateKeyFile; try { Utils::File::CheckFile(dtlsCertificateFile.c_str()); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_THROW_ERROR("dtlsCertificateFile: %s", error.what()); } @@ -520,13 +525,13 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles() { Utils::File::CheckFile(dtlsPrivateKeyFile.c_str()); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_THROW_ERROR("dtlsPrivateKeyFile: %s", error.what()); } Settings::configuration.dtlsCertificateFile = dtlsCertificateFile; - Settings::configuration.dtlsPrivateKeyFile = dtlsPrivateKeyFile; + Settings::configuration.dtlsPrivateKeyFile = dtlsPrivateKeyFile; } void Settings::SetLogTags(std::vector& tags) @@ -578,7 +583,7 @@ void Settings::SetLogTags(Json::Value& json) /* Helpers. */ -bool IsBindableIP(const std::string &ip, int family, int* bindErrno) +bool IsBindableIP(const std::string& ip, int family, int* bindErrno) { MS_TRACE(); @@ -622,7 +627,7 @@ bool IsBindableIP(const std::string &ip, int family, int* bindErrno) } else { - success = false; + success = false; *bindErrno = errno; } diff --git a/worker/src/Utils/Crypto.cpp b/worker/src/Utils/Crypto.cpp index 2991c32365..67986bcd2c 100644 --- a/worker/src/Utils/Crypto.cpp +++ b/worker/src/Utils/Crypto.cpp @@ -1,8 +1,8 @@ #define MS_CLASS "Utils::Crypto" // #define MS_LOG_DEV -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include namespace Utils @@ -12,52 +12,44 @@ namespace Utils uint32_t Crypto::seed; HMAC_CTX Crypto::hmacSha1Ctx; uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long. - const uint32_t Crypto::crc32Table[] = - { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; + const uint32_t Crypto::crc32Table[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, + 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, + 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, + 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, + 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, + 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, + 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, + 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, + 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, + 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, + 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, + 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, + 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, + 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, + 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, + 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, + 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, + 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, + 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, + 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, + 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, + 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, + 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, + 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, + 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; /* Static methods. */ @@ -80,7 +72,7 @@ namespace Utils HMAC_CTX_cleanup(&Crypto::hmacSha1Ctx); } - const uint8_t* Crypto::GetHMAC_SHA1(const std::string &key, const uint8_t* data, size_t len) + const uint8_t* Crypto::GetHMAC_SHA1(const std::string& key, const uint8_t* data, size_t len) { MS_TRACE(); @@ -92,17 +84,22 @@ namespace Utils ret = HMAC_Update(&Crypto::hmacSha1Ctx, (const uint8_t*)data, (int)len); - MS_ASSERT(ret == 1, "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes", - key.c_str(), len); + MS_ASSERT( + ret == 1, + "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes", + key.c_str(), + len); uint32_t resultLen; - ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t *)Crypto::hmacSha1Buffer, &resultLen); + ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t*)Crypto::hmacSha1Buffer, &resultLen); - MS_ASSERT(ret == 1, "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes", - key.c_str(), len); - MS_ASSERT(resultLen == 20, "OpenSSL HMAC_Final() resultLen is %u instead of 20", - resultLen); + MS_ASSERT( + ret == 1, + "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes", + key.c_str(), + len); + MS_ASSERT(resultLen == 20, "OpenSSL HMAC_Final() resultLen is %u instead of 20", resultLen); return Crypto::hmacSha1Buffer; } diff --git a/worker/src/Utils/File.cpp b/worker/src/Utils/File.cpp index 75e863927f..44841e69be 100644 --- a/worker/src/Utils/File.cpp +++ b/worker/src/Utils/File.cpp @@ -1,12 +1,12 @@ #define MS_CLASS "Utils::File" // #define MS_LOG_DEV -#include "Utils.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" #include -#include // access(), R_OK #include // stat() +#include // access(), R_OK namespace Utils { diff --git a/worker/src/Utils/IP.cpp b/worker/src/Utils/IP.cpp index 02ce4a7d87..17c8b055e3 100644 --- a/worker/src/Utils/IP.cpp +++ b/worker/src/Utils/IP.cpp @@ -3,37 +3,31 @@ #define MS_CLASS "Utils::IP" // #define MS_LOG_DEV -#include "Utils.hpp" #include "Logger.hpp" +#include "Utils.hpp" #include namespace Utils { - int IP::GetFamily(const char *ip, size_t ip_len) + int IP::GetFamily(const char* ip, size_t ipLen) { MS_TRACE(); int ipFamily = 0; - /** - * Ragel: machine definition. - */ - +/** + * Ragel: machine definition. + */ + #line 38 "src/Utils/IP.rl" +/** + * Ragel: %%write data + * This generates Ragel's static variables. + */ - /** - * Ragel: %%write data - * This generates Ragel's static variables. - */ - #line 31 "src/Utils/IP.cpp" -static const int IPParser_start = 1; - - - - - + static const int IPParser_start = 1; #line 45 "src/Utils/IP.rl" @@ -42,3430 +36,4626 @@ static const int IPParser_start = 1; const unsigned char* p; const unsigned char* pe; - p = (const unsigned char*)ip; - pe = p + ip_len; + p = (const unsigned char*)ip; + pe = p + ipLen; + +/** + * Ragel: %%write init + */ - /** - * Ragel: %%write init - */ - #line 53 "src/Utils/IP.cpp" - { - cs = IPParser_start; - } + { + cs = IPParser_start; + } #line 58 "src/Utils/IP.rl" - /** - * Ragel: %%write exec - * This updates cs variable needed by Ragel. - */ - +/** + * Ragel: %%write exec + * This updates cs variable needed by Ragel. + */ + #line 65 "src/Utils/IP.cpp" - { - if ( p == pe ) - goto _test_eof; - switch ( cs ) - { -case 1: - switch( (*p) ) { - case 48u: goto st2; - case 49u: goto st76; - case 50u: goto st79; - case 58u: goto st83; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto st82; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st85; - } else - goto st85; - goto st0; -st0: -cs = 0; - goto _out; -st2: - if ( ++p == pe ) - goto _test_eof2; -case 2: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st16; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st16; - } else - goto st16; - goto st0; -st3: - if ( ++p == pe ) - goto _test_eof3; -case 3: - switch( (*p) ) { - case 48u: goto st4; - case 49u: goto st12; - case 50u: goto st14; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto st13; - goto st0; -st4: - if ( ++p == pe ) - goto _test_eof4; -case 4: - if ( (*p) == 46u ) - goto st5; - goto st0; -st5: - if ( ++p == pe ) - goto _test_eof5; -case 5: - switch( (*p) ) { - case 48u: goto st6; - case 49u: goto st8; - case 50u: goto st10; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto st9; - goto st0; -st6: - if ( ++p == pe ) - goto _test_eof6; -case 6: - if ( (*p) == 46u ) - goto st7; - goto st0; -st7: - if ( ++p == pe ) - goto _test_eof7; -case 7: - switch( (*p) ) { - case 48u: goto tr20; - case 49u: goto tr21; - case 50u: goto tr22; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr23; - goto st0; -tr20: + { + if (p == pe) + goto _test_eof; + switch (cs) + { + case 1: + switch ((*p)) + { + case 48u: + goto st2; + case 49u: + goto st76; + case 50u: + goto st79; + case 58u: + goto st83; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto st82; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st85; + } + else + goto st85; + goto st0; + st0: + cs = 0; + goto _out; + st2: + if (++p == pe) + goto _test_eof2; + case 2: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st16; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st16; + } + else + goto st16; + goto st0; + st3: + if (++p == pe) + goto _test_eof3; + case 3: + switch ((*p)) + { + case 48u: + goto st4; + case 49u: + goto st12; + case 50u: + goto st14; + } + if (51u <= (*p) && (*p) <= 57u) + goto st13; + goto st0; + st4: + if (++p == pe) + goto _test_eof4; + case 4: + if ((*p) == 46u) + goto st5; + goto st0; + st5: + if (++p == pe) + goto _test_eof5; + case 5: + switch ((*p)) + { + case 48u: + goto st6; + case 49u: + goto st8; + case 50u: + goto st10; + } + if (51u <= (*p) && (*p) <= 57u) + goto st9; + goto st0; + st6: + if (++p == pe) + goto _test_eof6; + case 6: + if ((*p) == 46u) + goto st7; + goto st0; + st7: + if (++p == pe) + goto _test_eof7; + case 7: + switch ((*p)) + { + case 48u: + goto tr20; + case 49u: + goto tr21; + case 50u: + goto tr22; + } + if (51u <= (*p) && (*p) <= 57u) + goto tr23; + goto st0; + tr20: #line 25 "src/Utils/IP.rl" - { - ipFamily = AF_INET; - } - goto st86; -tr77: + { + ipFamily = AF_INET; + } + goto st86; + tr77: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st86; -st86: - if ( ++p == pe ) - goto _test_eof86; -case 86: + { + ipFamily = AF_INET6; + } + goto st86; + st86: + if (++p == pe) + goto _test_eof86; + case 86: #line 173 "src/Utils/IP.cpp" - goto st0; -tr21: + goto st0; + tr21: #line 25 "src/Utils/IP.rl" - { - ipFamily = AF_INET; - } - goto st87; -st87: - if ( ++p == pe ) - goto _test_eof87; -case 87: + { + ipFamily = AF_INET; + } + goto st87; + st87: + if (++p == pe) + goto _test_eof87; + case 87: #line 185 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr23; - goto st0; -tr23: + if (48u <= (*p) && (*p) <= 57u) + goto tr23; + goto st0; + tr23: #line 25 "src/Utils/IP.rl" - { - ipFamily = AF_INET; - } - goto st88; -st88: - if ( ++p == pe ) - goto _test_eof88; -case 88: + { + ipFamily = AF_INET; + } + goto st88; + st88: + if (++p == pe) + goto _test_eof88; + case 88: #line 199 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr20; - goto st0; -tr22: + if (48u <= (*p) && (*p) <= 57u) + goto tr20; + goto st0; + tr22: #line 25 "src/Utils/IP.rl" - { - ipFamily = AF_INET; - } - goto st89; -st89: - if ( ++p == pe ) - goto _test_eof89; -case 89: + { + ipFamily = AF_INET; + } + goto st89; + st89: + if (++p == pe) + goto _test_eof89; + case 89: #line 213 "src/Utils/IP.cpp" - if ( (*p) == 53u ) - goto tr120; - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto tr20; - } else if ( (*p) >= 48u ) - goto tr23; - goto st0; -tr120: + if ((*p) == 53u) + goto tr120; + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto tr20; + } + else if ((*p) >= 48u) + goto tr23; + goto st0; + tr120: #line 25 "src/Utils/IP.rl" - { - ipFamily = AF_INET; - } - goto st90; -st90: - if ( ++p == pe ) - goto _test_eof90; -case 90: + { + ipFamily = AF_INET; + } + goto st90; + st90: + if (++p == pe) + goto _test_eof90; + case 90: #line 232 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr20; - goto st0; -st8: - if ( ++p == pe ) - goto _test_eof8; -case 8: - if ( (*p) == 46u ) - goto st7; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st9; - goto st0; -st9: - if ( ++p == pe ) - goto _test_eof9; -case 9: - if ( (*p) == 46u ) - goto st7; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st6; - goto st0; -st10: - if ( ++p == pe ) - goto _test_eof10; -case 10: - switch( (*p) ) { - case 46u: goto st7; - case 53u: goto st11; - } - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto st6; - } else if ( (*p) >= 48u ) - goto st9; - goto st0; -st11: - if ( ++p == pe ) - goto _test_eof11; -case 11: - if ( (*p) == 46u ) - goto st7; - if ( 48u <= (*p) && (*p) <= 53u ) - goto st6; - goto st0; -st12: - if ( ++p == pe ) - goto _test_eof12; -case 12: - if ( (*p) == 46u ) - goto st5; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st13; - goto st0; -st13: - if ( ++p == pe ) - goto _test_eof13; -case 13: - if ( (*p) == 46u ) - goto st5; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st4; - goto st0; -st14: - if ( ++p == pe ) - goto _test_eof14; -case 14: - switch( (*p) ) { - case 46u: goto st5; - case 53u: goto st15; - } - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto st4; - } else if ( (*p) >= 48u ) - goto st13; - goto st0; -st15: - if ( ++p == pe ) - goto _test_eof15; -case 15: - if ( (*p) == 46u ) - goto st5; - if ( 48u <= (*p) && (*p) <= 53u ) - goto st4; - goto st0; -st16: - if ( ++p == pe ) - goto _test_eof16; -case 16: - if ( (*p) == 58u ) - goto st19; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st17; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st17; - } else - goto st17; - goto st0; -st17: - if ( ++p == pe ) - goto _test_eof17; -case 17: - if ( (*p) == 58u ) - goto st19; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st18; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st18; - } else - goto st18; - goto st0; -st18: - if ( ++p == pe ) - goto _test_eof18; -case 18: - if ( (*p) == 58u ) - goto st19; - goto st0; -st19: - if ( ++p == pe ) - goto _test_eof19; -case 19: - if ( (*p) == 58u ) - goto tr29; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st20; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st20; - } else - goto st20; - goto st0; -st20: - if ( ++p == pe ) - goto _test_eof20; -case 20: - if ( (*p) == 58u ) - goto st24; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st21; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st21; - } else - goto st21; - goto st0; -st21: - if ( ++p == pe ) - goto _test_eof21; -case 21: - if ( (*p) == 58u ) - goto st24; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st22; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st22; - } else - goto st22; - goto st0; -st22: - if ( ++p == pe ) - goto _test_eof22; -case 22: - if ( (*p) == 58u ) - goto st24; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st23; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st23; - } else - goto st23; - goto st0; -st23: - if ( ++p == pe ) - goto _test_eof23; -case 23: - if ( (*p) == 58u ) - goto st24; - goto st0; -st24: - if ( ++p == pe ) - goto _test_eof24; -case 24: - if ( (*p) == 58u ) - goto tr35; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st25; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st25; - } else - goto st25; - goto st0; -st25: - if ( ++p == pe ) - goto _test_eof25; -case 25: - if ( (*p) == 58u ) - goto st29; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st26; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st26; - } else - goto st26; - goto st0; -st26: - if ( ++p == pe ) - goto _test_eof26; -case 26: - if ( (*p) == 58u ) - goto st29; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st27; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st27; - } else - goto st27; - goto st0; -st27: - if ( ++p == pe ) - goto _test_eof27; -case 27: - if ( (*p) == 58u ) - goto st29; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st28; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st28; - } else - goto st28; - goto st0; -st28: - if ( ++p == pe ) - goto _test_eof28; -case 28: - if ( (*p) == 58u ) - goto st29; - goto st0; -st29: - if ( ++p == pe ) - goto _test_eof29; -case 29: - if ( (*p) == 58u ) - goto tr41; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st30; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st30; - } else - goto st30; - goto st0; -st30: - if ( ++p == pe ) - goto _test_eof30; -case 30: - if ( (*p) == 58u ) - goto st34; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st31; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st31; - } else - goto st31; - goto st0; -st31: - if ( ++p == pe ) - goto _test_eof31; -case 31: - if ( (*p) == 58u ) - goto st34; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st32; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st32; - } else - goto st32; - goto st0; -st32: - if ( ++p == pe ) - goto _test_eof32; -case 32: - if ( (*p) == 58u ) - goto st34; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st33; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st33; - } else - goto st33; - goto st0; -st33: - if ( ++p == pe ) - goto _test_eof33; -case 33: - if ( (*p) == 58u ) - goto st34; - goto st0; -st34: - if ( ++p == pe ) - goto _test_eof34; -case 34: - if ( (*p) == 58u ) - goto tr47; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st35; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st35; - } else - goto st35; - goto st0; -st35: - if ( ++p == pe ) - goto _test_eof35; -case 35: - if ( (*p) == 58u ) - goto st39; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st36; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st36; - } else - goto st36; - goto st0; -st36: - if ( ++p == pe ) - goto _test_eof36; -case 36: - if ( (*p) == 58u ) - goto st39; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st37; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st37; - } else - goto st37; - goto st0; -st37: - if ( ++p == pe ) - goto _test_eof37; -case 37: - if ( (*p) == 58u ) - goto st39; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st38; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st38; - } else - goto st38; - goto st0; -st38: - if ( ++p == pe ) - goto _test_eof38; -case 38: - if ( (*p) == 58u ) - goto st39; - goto st0; -st39: - if ( ++p == pe ) - goto _test_eof39; -case 39: - if ( (*p) == 58u ) - goto tr53; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st40; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st40; - } else - goto st40; - goto st0; -st40: - if ( ++p == pe ) - goto _test_eof40; -case 40: - if ( (*p) == 58u ) - goto st44; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st41; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st41; - } else - goto st41; - goto st0; -st41: - if ( ++p == pe ) - goto _test_eof41; -case 41: - if ( (*p) == 58u ) - goto st44; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st42; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st42; - } else - goto st42; - goto st0; -st42: - if ( ++p == pe ) - goto _test_eof42; -case 42: - if ( (*p) == 58u ) - goto st44; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st43; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st43; - } else - goto st43; - goto st0; -st43: - if ( ++p == pe ) - goto _test_eof43; -case 43: - if ( (*p) == 58u ) - goto st44; - goto st0; -st44: - if ( ++p == pe ) - goto _test_eof44; -case 44: - switch( (*p) ) { - case 48u: goto st45; - case 49u: goto st63; - case 50u: goto st66; - case 58u: goto tr62; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto st69; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st70; - } else - goto st70; - goto st0; -st45: - if ( ++p == pe ) - goto _test_eof45; -case 45: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st59; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st59; - } else - goto st59; - goto st0; -st46: - if ( ++p == pe ) - goto _test_eof46; -case 46: - switch( (*p) ) { - case 48u: goto st47; - case 49u: goto st55; - case 50u: goto st57; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto st56; - goto st0; -st47: - if ( ++p == pe ) - goto _test_eof47; -case 47: - if ( (*p) == 46u ) - goto st48; - goto st0; -st48: - if ( ++p == pe ) - goto _test_eof48; -case 48: - switch( (*p) ) { - case 48u: goto st49; - case 49u: goto st51; - case 50u: goto st53; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto st52; - goto st0; -st49: - if ( ++p == pe ) - goto _test_eof49; -case 49: - if ( (*p) == 46u ) - goto st50; - goto st0; -st50: - if ( ++p == pe ) - goto _test_eof50; -case 50: - switch( (*p) ) { - case 48u: goto tr77; - case 49u: goto tr78; - case 50u: goto tr79; - } - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr80; - goto st0; -tr78: + if (48u <= (*p) && (*p) <= 53u) + goto tr20; + goto st0; + st8: + if (++p == pe) + goto _test_eof8; + case 8: + if ((*p) == 46u) + goto st7; + if (48u <= (*p) && (*p) <= 57u) + goto st9; + goto st0; + st9: + if (++p == pe) + goto _test_eof9; + case 9: + if ((*p) == 46u) + goto st7; + if (48u <= (*p) && (*p) <= 57u) + goto st6; + goto st0; + st10: + if (++p == pe) + goto _test_eof10; + case 10: + switch ((*p)) + { + case 46u: + goto st7; + case 53u: + goto st11; + } + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto st6; + } + else if ((*p) >= 48u) + goto st9; + goto st0; + st11: + if (++p == pe) + goto _test_eof11; + case 11: + if ((*p) == 46u) + goto st7; + if (48u <= (*p) && (*p) <= 53u) + goto st6; + goto st0; + st12: + if (++p == pe) + goto _test_eof12; + case 12: + if ((*p) == 46u) + goto st5; + if (48u <= (*p) && (*p) <= 57u) + goto st13; + goto st0; + st13: + if (++p == pe) + goto _test_eof13; + case 13: + if ((*p) == 46u) + goto st5; + if (48u <= (*p) && (*p) <= 57u) + goto st4; + goto st0; + st14: + if (++p == pe) + goto _test_eof14; + case 14: + switch ((*p)) + { + case 46u: + goto st5; + case 53u: + goto st15; + } + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto st4; + } + else if ((*p) >= 48u) + goto st13; + goto st0; + st15: + if (++p == pe) + goto _test_eof15; + case 15: + if ((*p) == 46u) + goto st5; + if (48u <= (*p) && (*p) <= 53u) + goto st4; + goto st0; + st16: + if (++p == pe) + goto _test_eof16; + case 16: + if ((*p) == 58u) + goto st19; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st17; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st17; + } + else + goto st17; + goto st0; + st17: + if (++p == pe) + goto _test_eof17; + case 17: + if ((*p) == 58u) + goto st19; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st18; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st18; + } + else + goto st18; + goto st0; + st18: + if (++p == pe) + goto _test_eof18; + case 18: + if ((*p) == 58u) + goto st19; + goto st0; + st19: + if (++p == pe) + goto _test_eof19; + case 19: + if ((*p) == 58u) + goto tr29; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st20; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st20; + } + else + goto st20; + goto st0; + st20: + if (++p == pe) + goto _test_eof20; + case 20: + if ((*p) == 58u) + goto st24; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st21; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st21; + } + else + goto st21; + goto st0; + st21: + if (++p == pe) + goto _test_eof21; + case 21: + if ((*p) == 58u) + goto st24; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st22; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st22; + } + else + goto st22; + goto st0; + st22: + if (++p == pe) + goto _test_eof22; + case 22: + if ((*p) == 58u) + goto st24; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st23; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st23; + } + else + goto st23; + goto st0; + st23: + if (++p == pe) + goto _test_eof23; + case 23: + if ((*p) == 58u) + goto st24; + goto st0; + st24: + if (++p == pe) + goto _test_eof24; + case 24: + if ((*p) == 58u) + goto tr35; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st25; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st25; + } + else + goto st25; + goto st0; + st25: + if (++p == pe) + goto _test_eof25; + case 25: + if ((*p) == 58u) + goto st29; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st26; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st26; + } + else + goto st26; + goto st0; + st26: + if (++p == pe) + goto _test_eof26; + case 26: + if ((*p) == 58u) + goto st29; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st27; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st27; + } + else + goto st27; + goto st0; + st27: + if (++p == pe) + goto _test_eof27; + case 27: + if ((*p) == 58u) + goto st29; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st28; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st28; + } + else + goto st28; + goto st0; + st28: + if (++p == pe) + goto _test_eof28; + case 28: + if ((*p) == 58u) + goto st29; + goto st0; + st29: + if (++p == pe) + goto _test_eof29; + case 29: + if ((*p) == 58u) + goto tr41; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st30; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st30; + } + else + goto st30; + goto st0; + st30: + if (++p == pe) + goto _test_eof30; + case 30: + if ((*p) == 58u) + goto st34; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st31; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st31; + } + else + goto st31; + goto st0; + st31: + if (++p == pe) + goto _test_eof31; + case 31: + if ((*p) == 58u) + goto st34; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st32; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st32; + } + else + goto st32; + goto st0; + st32: + if (++p == pe) + goto _test_eof32; + case 32: + if ((*p) == 58u) + goto st34; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st33; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st33; + } + else + goto st33; + goto st0; + st33: + if (++p == pe) + goto _test_eof33; + case 33: + if ((*p) == 58u) + goto st34; + goto st0; + st34: + if (++p == pe) + goto _test_eof34; + case 34: + if ((*p) == 58u) + goto tr47; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st35; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st35; + } + else + goto st35; + goto st0; + st35: + if (++p == pe) + goto _test_eof35; + case 35: + if ((*p) == 58u) + goto st39; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st36; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st36; + } + else + goto st36; + goto st0; + st36: + if (++p == pe) + goto _test_eof36; + case 36: + if ((*p) == 58u) + goto st39; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st37; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st37; + } + else + goto st37; + goto st0; + st37: + if (++p == pe) + goto _test_eof37; + case 37: + if ((*p) == 58u) + goto st39; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st38; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st38; + } + else + goto st38; + goto st0; + st38: + if (++p == pe) + goto _test_eof38; + case 38: + if ((*p) == 58u) + goto st39; + goto st0; + st39: + if (++p == pe) + goto _test_eof39; + case 39: + if ((*p) == 58u) + goto tr53; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st40; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st40; + } + else + goto st40; + goto st0; + st40: + if (++p == pe) + goto _test_eof40; + case 40: + if ((*p) == 58u) + goto st44; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st41; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st41; + } + else + goto st41; + goto st0; + st41: + if (++p == pe) + goto _test_eof41; + case 41: + if ((*p) == 58u) + goto st44; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st42; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st42; + } + else + goto st42; + goto st0; + st42: + if (++p == pe) + goto _test_eof42; + case 42: + if ((*p) == 58u) + goto st44; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st43; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st43; + } + else + goto st43; + goto st0; + st43: + if (++p == pe) + goto _test_eof43; + case 43: + if ((*p) == 58u) + goto st44; + goto st0; + st44: + if (++p == pe) + goto _test_eof44; + case 44: + switch ((*p)) + { + case 48u: + goto st45; + case 49u: + goto st63; + case 50u: + goto st66; + case 58u: + goto tr62; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto st69; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st70; + } + else + goto st70; + goto st0; + st45: + if (++p == pe) + goto _test_eof45; + case 45: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st59; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st59; + } + else + goto st59; + goto st0; + st46: + if (++p == pe) + goto _test_eof46; + case 46: + switch ((*p)) + { + case 48u: + goto st47; + case 49u: + goto st55; + case 50u: + goto st57; + } + if (51u <= (*p) && (*p) <= 57u) + goto st56; + goto st0; + st47: + if (++p == pe) + goto _test_eof47; + case 47: + if ((*p) == 46u) + goto st48; + goto st0; + st48: + if (++p == pe) + goto _test_eof48; + case 48: + switch ((*p)) + { + case 48u: + goto st49; + case 49u: + goto st51; + case 50u: + goto st53; + } + if (51u <= (*p) && (*p) <= 57u) + goto st52; + goto st0; + st49: + if (++p == pe) + goto _test_eof49; + case 49: + if ((*p) == 46u) + goto st50; + goto st0; + st50: + if (++p == pe) + goto _test_eof50; + case 50: + switch ((*p)) + { + case 48u: + goto tr77; + case 49u: + goto tr78; + case 50u: + goto tr79; + } + if (51u <= (*p) && (*p) <= 57u) + goto tr80; + goto st0; + tr78: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st91; -st91: - if ( ++p == pe ) - goto _test_eof91; -case 91: + { + ipFamily = AF_INET6; + } + goto st91; + st91: + if (++p == pe) + goto _test_eof91; + case 91: #line 786 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr80; - goto st0; -tr80: + if (48u <= (*p) && (*p) <= 57u) + goto tr80; + goto st0; + tr80: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st92; -st92: - if ( ++p == pe ) - goto _test_eof92; -case 92: + { + ipFamily = AF_INET6; + } + goto st92; + st92: + if (++p == pe) + goto _test_eof92; + case 92: #line 800 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr77; - goto st0; -tr79: + if (48u <= (*p) && (*p) <= 57u) + goto tr77; + goto st0; + tr79: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st93; -st93: - if ( ++p == pe ) - goto _test_eof93; -case 93: + { + ipFamily = AF_INET6; + } + goto st93; + st93: + if (++p == pe) + goto _test_eof93; + case 93: #line 814 "src/Utils/IP.cpp" - if ( (*p) == 53u ) - goto tr121; - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto tr77; - } else if ( (*p) >= 48u ) - goto tr80; - goto st0; -tr121: + if ((*p) == 53u) + goto tr121; + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto tr77; + } + else if ((*p) >= 48u) + goto tr80; + goto st0; + tr121: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st94; -st94: - if ( ++p == pe ) - goto _test_eof94; -case 94: + { + ipFamily = AF_INET6; + } + goto st94; + st94: + if (++p == pe) + goto _test_eof94; + case 94: #line 833 "src/Utils/IP.cpp" - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr77; - goto st0; -st51: - if ( ++p == pe ) - goto _test_eof51; -case 51: - if ( (*p) == 46u ) - goto st50; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st52; - goto st0; -st52: - if ( ++p == pe ) - goto _test_eof52; -case 52: - if ( (*p) == 46u ) - goto st50; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st49; - goto st0; -st53: - if ( ++p == pe ) - goto _test_eof53; -case 53: - switch( (*p) ) { - case 46u: goto st50; - case 53u: goto st54; - } - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto st49; - } else if ( (*p) >= 48u ) - goto st52; - goto st0; -st54: - if ( ++p == pe ) - goto _test_eof54; -case 54: - if ( (*p) == 46u ) - goto st50; - if ( 48u <= (*p) && (*p) <= 53u ) - goto st49; - goto st0; -st55: - if ( ++p == pe ) - goto _test_eof55; -case 55: - if ( (*p) == 46u ) - goto st48; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st56; - goto st0; -st56: - if ( ++p == pe ) - goto _test_eof56; -case 56: - if ( (*p) == 46u ) - goto st48; - if ( 48u <= (*p) && (*p) <= 57u ) - goto st47; - goto st0; -st57: - if ( ++p == pe ) - goto _test_eof57; -case 57: - switch( (*p) ) { - case 46u: goto st48; - case 53u: goto st58; - } - if ( (*p) > 52u ) { - if ( 54u <= (*p) && (*p) <= 57u ) - goto st47; - } else if ( (*p) >= 48u ) - goto st56; - goto st0; -st58: - if ( ++p == pe ) - goto _test_eof58; -case 58: - if ( (*p) == 46u ) - goto st48; - if ( 48u <= (*p) && (*p) <= 53u ) - goto st47; - goto st0; -st59: - if ( ++p == pe ) - goto _test_eof59; -case 59: - if ( (*p) == 58u ) - goto st62; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st60; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st60; - } else - goto st60; - goto st0; -st60: - if ( ++p == pe ) - goto _test_eof60; -case 60: - if ( (*p) == 58u ) - goto st62; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st61; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st61; - } else - goto st61; - goto st0; -st61: - if ( ++p == pe ) - goto _test_eof61; -case 61: - if ( (*p) == 58u ) - goto st62; - goto st0; -st62: - if ( ++p == pe ) - goto _test_eof62; -case 62: - if ( (*p) == 58u ) - goto tr77; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr85; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr85; - } else - goto tr85; - goto st0; -tr85: + if (48u <= (*p) && (*p) <= 53u) + goto tr77; + goto st0; + st51: + if (++p == pe) + goto _test_eof51; + case 51: + if ((*p) == 46u) + goto st50; + if (48u <= (*p) && (*p) <= 57u) + goto st52; + goto st0; + st52: + if (++p == pe) + goto _test_eof52; + case 52: + if ((*p) == 46u) + goto st50; + if (48u <= (*p) && (*p) <= 57u) + goto st49; + goto st0; + st53: + if (++p == pe) + goto _test_eof53; + case 53: + switch ((*p)) + { + case 46u: + goto st50; + case 53u: + goto st54; + } + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto st49; + } + else if ((*p) >= 48u) + goto st52; + goto st0; + st54: + if (++p == pe) + goto _test_eof54; + case 54: + if ((*p) == 46u) + goto st50; + if (48u <= (*p) && (*p) <= 53u) + goto st49; + goto st0; + st55: + if (++p == pe) + goto _test_eof55; + case 55: + if ((*p) == 46u) + goto st48; + if (48u <= (*p) && (*p) <= 57u) + goto st56; + goto st0; + st56: + if (++p == pe) + goto _test_eof56; + case 56: + if ((*p) == 46u) + goto st48; + if (48u <= (*p) && (*p) <= 57u) + goto st47; + goto st0; + st57: + if (++p == pe) + goto _test_eof57; + case 57: + switch ((*p)) + { + case 46u: + goto st48; + case 53u: + goto st58; + } + if ((*p) > 52u) + { + if (54u <= (*p) && (*p) <= 57u) + goto st47; + } + else if ((*p) >= 48u) + goto st56; + goto st0; + st58: + if (++p == pe) + goto _test_eof58; + case 58: + if ((*p) == 46u) + goto st48; + if (48u <= (*p) && (*p) <= 53u) + goto st47; + goto st0; + st59: + if (++p == pe) + goto _test_eof59; + case 59: + if ((*p) == 58u) + goto st62; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st60; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st60; + } + else + goto st60; + goto st0; + st60: + if (++p == pe) + goto _test_eof60; + case 60: + if ((*p) == 58u) + goto st62; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st61; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st61; + } + else + goto st61; + goto st0; + st61: + if (++p == pe) + goto _test_eof61; + case 61: + if ((*p) == 58u) + goto st62; + goto st0; + st62: + if (++p == pe) + goto _test_eof62; + case 62: + if ((*p) == 58u) + goto tr77; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr85; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr85; + } + else + goto tr85; + goto st0; + tr85: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st95; -st95: - if ( ++p == pe ) - goto _test_eof95; -case 95: + { + ipFamily = AF_INET6; + } + goto st95; + st95: + if (++p == pe) + goto _test_eof95; + case 95: #line 981 "src/Utils/IP.cpp" - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr122; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr122; - } else - goto tr122; - goto st0; -tr122: + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr122; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr122; + } + else + goto tr122; + goto st0; + tr122: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st96; -st96: - if ( ++p == pe ) - goto _test_eof96; -case 96: + { + ipFamily = AF_INET6; + } + goto st96; + st96: + if (++p == pe) + goto _test_eof96; + case 96: #line 1001 "src/Utils/IP.cpp" - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr123; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr123; - } else - goto tr123; - goto st0; -tr123: + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr123; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr123; + } + else + goto tr123; + goto st0; + tr123: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st97; -st97: - if ( ++p == pe ) - goto _test_eof97; -case 97: + { + ipFamily = AF_INET6; + } + goto st97; + st97: + if (++p == pe) + goto _test_eof97; + case 97: #line 1021 "src/Utils/IP.cpp" - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr77; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr77; - } else - goto tr77; - goto st0; -st63: - if ( ++p == pe ) - goto _test_eof63; -case 63: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st64; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st59; - } else - goto st59; - goto st0; -st64: - if ( ++p == pe ) - goto _test_eof64; -case 64: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st65; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st60; - } else - goto st60; - goto st0; -st65: - if ( ++p == pe ) - goto _test_eof65; -case 65: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st61; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st61; - } else - goto st61; - goto st0; -st66: - if ( ++p == pe ) - goto _test_eof66; -case 66: - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto st67; - case 58u: goto st62; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto st64; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st59; - } else if ( (*p) >= 65u ) - goto st59; - } else - goto st68; - goto st0; -st67: - if ( ++p == pe ) - goto _test_eof67; -case 67: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto st65; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st60; - } else if ( (*p) >= 65u ) - goto st60; - } else - goto st60; - goto st0; -st68: - if ( ++p == pe ) - goto _test_eof68; -case 68: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st60; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st60; - } else - goto st60; - goto st0; -st69: - if ( ++p == pe ) - goto _test_eof69; -case 69: - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st62; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st68; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st59; - } else - goto st59; - goto st0; -tr62: + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr77; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr77; + } + else + goto tr77; + goto st0; + st63: + if (++p == pe) + goto _test_eof63; + case 63: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st64; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st59; + } + else + goto st59; + goto st0; + st64: + if (++p == pe) + goto _test_eof64; + case 64: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st65; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st60; + } + else + goto st60; + goto st0; + st65: + if (++p == pe) + goto _test_eof65; + case 65: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st61; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st61; + } + else + goto st61; + goto st0; + st66: + if (++p == pe) + goto _test_eof66; + case 66: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto st67; + case 58u: + goto st62; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto st64; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st59; + } + else if ((*p) >= 65u) + goto st59; + } + else + goto st68; + goto st0; + st67: + if (++p == pe) + goto _test_eof67; + case 67: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto st65; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st60; + } + else if ((*p) >= 65u) + goto st60; + } + else + goto st60; + goto st0; + st68: + if (++p == pe) + goto _test_eof68; + case 68: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st60; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st60; + } + else + goto st60; + goto st0; + st69: + if (++p == pe) + goto _test_eof69; + case 69: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st62; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st68; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st59; + } + else + goto st59; + goto st0; + tr62: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st98; -st98: - if ( ++p == pe ) - goto _test_eof98; -case 98: + { + ipFamily = AF_INET6; + } + goto st98; + st98: + if (++p == pe) + goto _test_eof98; + case 98: #line 1167 "src/Utils/IP.cpp" - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr85; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr85; - } else - goto tr85; - goto st0; -st70: - if ( ++p == pe ) - goto _test_eof70; -case 70: - if ( (*p) == 58u ) - goto st62; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st59; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st59; - } else - goto st59; - goto st0; -tr53: + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr85; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr85; + } + else + goto tr85; + goto st0; + st70: + if (++p == pe) + goto _test_eof70; + case 70: + if ((*p) == 58u) + goto st62; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st59; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st59; + } + else + goto st59; + goto st0; + tr53: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st99; -st99: - if ( ++p == pe ) - goto _test_eof99; -case 99: + { + ipFamily = AF_INET6; + } + goto st99; + st99: + if (++p == pe) + goto _test_eof99; + case 99: #line 1202 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr90; - case 49u: goto tr91; - case 50u: goto tr92; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr93; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr94; - } else - goto tr94; - goto st0; -tr90: + switch ((*p)) + { + case 48u: + goto tr90; + case 49u: + goto tr91; + case 50u: + goto tr92; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr93; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr94; + } + else + goto tr94; + goto st0; + tr90: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st100; -st100: - if ( ++p == pe ) - goto _test_eof100; -case 100: + { + ipFamily = AF_INET6; + } + goto st100; + st100: + if (++p == pe) + goto _test_eof100; + case 100: #line 1227 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr124; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr124; - } else - goto tr124; - goto st0; -tr124: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr124; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr124; + } + else + goto tr124; + goto st0; + tr124: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st101; -st101: - if ( ++p == pe ) - goto _test_eof101; -case 101: + { + ipFamily = AF_INET6; + } + goto st101; + st101: + if (++p == pe) + goto _test_eof101; + case 101: #line 1251 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st71; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr126; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr126; - } else - goto tr126; - goto st0; -tr126: + if ((*p) == 58u) + goto st71; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr126; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr126; + } + else + goto tr126; + goto st0; + tr126: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st102; -st102: - if ( ++p == pe ) - goto _test_eof102; -case 102: + { + ipFamily = AF_INET6; + } + goto st102; + st102: + if (++p == pe) + goto _test_eof102; + case 102: #line 1273 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st71; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr127; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr127; - } else - goto tr127; - goto st0; -tr127: + if ((*p) == 58u) + goto st71; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr127; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr127; + } + else + goto tr127; + goto st0; + tr127: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st103; -st103: - if ( ++p == pe ) - goto _test_eof103; -case 103: + { + ipFamily = AF_INET6; + } + goto st103; + st103: + if (++p == pe) + goto _test_eof103; + case 103: #line 1295 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st71; - goto st0; -st71: - if ( ++p == pe ) - goto _test_eof71; -case 71: - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr85; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr85; - } else - goto tr85; - goto st0; -tr91: + if ((*p) == 58u) + goto st71; + goto st0; + st71: + if (++p == pe) + goto _test_eof71; + case 71: + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr85; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr85; + } + else + goto tr85; + goto st0; + tr91: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st104; -st104: - if ( ++p == pe ) - goto _test_eof104; -case 104: + { + ipFamily = AF_INET6; + } + goto st104; + st104: + if (++p == pe) + goto _test_eof104; + case 104: #line 1322 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr128; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr124; - } else - goto tr124; - goto st0; -tr128: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr128; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr124; + } + else + goto tr124; + goto st0; + tr128: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st105; -st105: - if ( ++p == pe ) - goto _test_eof105; -case 105: + { + ipFamily = AF_INET6; + } + goto st105; + st105: + if (++p == pe) + goto _test_eof105; + case 105: #line 1346 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr129; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr126; - } else - goto tr126; - goto st0; -tr129: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr129; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr126; + } + else + goto tr126; + goto st0; + tr129: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st106; -st106: - if ( ++p == pe ) - goto _test_eof106; -case 106: + { + ipFamily = AF_INET6; + } + goto st106; + st106: + if (++p == pe) + goto _test_eof106; + case 106: #line 1370 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr127; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr127; - } else - goto tr127; - goto st0; -tr92: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr127; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr127; + } + else + goto tr127; + goto st0; + tr92: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st107; -st107: - if ( ++p == pe ) - goto _test_eof107; -case 107: + { + ipFamily = AF_INET6; + } + goto st107; + st107: + if (++p == pe) + goto _test_eof107; + case 107: #line 1394 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr130; - case 58u: goto st71; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr128; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr124; - } else if ( (*p) >= 65u ) - goto tr124; - } else - goto tr131; - goto st0; -tr130: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr130; + case 58u: + goto st71; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr128; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr124; + } + else if ((*p) >= 65u) + goto tr124; + } + else + goto tr131; + goto st0; + tr130: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st108; -st108: - if ( ++p == pe ) - goto _test_eof108; -case 108: + { + ipFamily = AF_INET6; + } + goto st108; + st108: + if (++p == pe) + goto _test_eof108; + case 108: #line 1422 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr129; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr126; - } else if ( (*p) >= 65u ) - goto tr126; - } else - goto tr126; - goto st0; -tr131: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr129; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr126; + } + else if ((*p) >= 65u) + goto tr126; + } + else + goto tr126; + goto st0; + tr131: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st109; -st109: - if ( ++p == pe ) - goto _test_eof109; -case 109: + { + ipFamily = AF_INET6; + } + goto st109; + st109: + if (++p == pe) + goto _test_eof109; + case 109: #line 1449 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr126; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr126; - } else - goto tr126; - goto st0; -tr93: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr126; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr126; + } + else + goto tr126; + goto st0; + tr93: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st110; -st110: - if ( ++p == pe ) - goto _test_eof110; -case 110: + { + ipFamily = AF_INET6; + } + goto st110; + st110: + if (++p == pe) + goto _test_eof110; + case 110: #line 1473 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st71; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr131; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr124; - } else - goto tr124; - goto st0; -tr94: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st71; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr131; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr124; + } + else + goto tr124; + goto st0; + tr94: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st111; -st111: - if ( ++p == pe ) - goto _test_eof111; -case 111: + { + ipFamily = AF_INET6; + } + goto st111; + st111: + if (++p == pe) + goto _test_eof111; + case 111: #line 1497 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st71; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr124; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr124; - } else - goto tr124; - goto st0; -tr47: + if ((*p) == 58u) + goto st71; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr124; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr124; + } + else + goto tr124; + goto st0; + tr47: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st112; -st112: - if ( ++p == pe ) - goto _test_eof112; -case 112: + { + ipFamily = AF_INET6; + } + goto st112; + st112: + if (++p == pe) + goto _test_eof112; + case 112: #line 1519 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr95; - case 49u: goto tr96; - case 50u: goto tr97; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr98; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr99; - } else - goto tr99; - goto st0; -tr95: + switch ((*p)) + { + case 48u: + goto tr95; + case 49u: + goto tr96; + case 50u: + goto tr97; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr98; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr99; + } + else + goto tr99; + goto st0; + tr95: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st113; -st113: - if ( ++p == pe ) - goto _test_eof113; -case 113: + { + ipFamily = AF_INET6; + } + goto st113; + st113: + if (++p == pe) + goto _test_eof113; + case 113: #line 1544 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr132; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr132; - } else - goto tr132; - goto st0; -tr132: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr132; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr132; + } + else + goto tr132; + goto st0; + tr132: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st114; -st114: - if ( ++p == pe ) - goto _test_eof114; -case 114: + { + ipFamily = AF_INET6; + } + goto st114; + st114: + if (++p == pe) + goto _test_eof114; + case 114: #line 1568 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st72; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr134; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr134; - } else - goto tr134; - goto st0; -tr134: + if ((*p) == 58u) + goto st72; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr134; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr134; + } + else + goto tr134; + goto st0; + tr134: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st115; -st115: - if ( ++p == pe ) - goto _test_eof115; -case 115: + { + ipFamily = AF_INET6; + } + goto st115; + st115: + if (++p == pe) + goto _test_eof115; + case 115: #line 1590 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st72; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr135; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr135; - } else - goto tr135; - goto st0; -tr135: + if ((*p) == 58u) + goto st72; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr135; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr135; + } + else + goto tr135; + goto st0; + tr135: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st116; -st116: - if ( ++p == pe ) - goto _test_eof116; -case 116: + { + ipFamily = AF_INET6; + } + goto st116; + st116: + if (++p == pe) + goto _test_eof116; + case 116: #line 1612 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st72; - goto st0; -st72: - if ( ++p == pe ) - goto _test_eof72; -case 72: - switch( (*p) ) { - case 48u: goto tr90; - case 49u: goto tr91; - case 50u: goto tr92; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr93; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr94; - } else - goto tr94; - goto st0; -tr96: + if ((*p) == 58u) + goto st72; + goto st0; + st72: + if (++p == pe) + goto _test_eof72; + case 72: + switch ((*p)) + { + case 48u: + goto tr90; + case 49u: + goto tr91; + case 50u: + goto tr92; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr93; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr94; + } + else + goto tr94; + goto st0; + tr96: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st117; -st117: - if ( ++p == pe ) - goto _test_eof117; -case 117: + { + ipFamily = AF_INET6; + } + goto st117; + st117: + if (++p == pe) + goto _test_eof117; + case 117: #line 1644 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr136; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr132; - } else - goto tr132; - goto st0; -tr136: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr136; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr132; + } + else + goto tr132; + goto st0; + tr136: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st118; -st118: - if ( ++p == pe ) - goto _test_eof118; -case 118: + { + ipFamily = AF_INET6; + } + goto st118; + st118: + if (++p == pe) + goto _test_eof118; + case 118: #line 1668 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr137; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr134; - } else - goto tr134; - goto st0; -tr137: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr137; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr134; + } + else + goto tr134; + goto st0; + tr137: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st119; -st119: - if ( ++p == pe ) - goto _test_eof119; -case 119: + { + ipFamily = AF_INET6; + } + goto st119; + st119: + if (++p == pe) + goto _test_eof119; + case 119: #line 1692 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr135; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr135; - } else - goto tr135; - goto st0; -tr97: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr135; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr135; + } + else + goto tr135; + goto st0; + tr97: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st120; -st120: - if ( ++p == pe ) - goto _test_eof120; -case 120: + { + ipFamily = AF_INET6; + } + goto st120; + st120: + if (++p == pe) + goto _test_eof120; + case 120: #line 1716 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr138; - case 58u: goto st72; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr136; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr132; - } else if ( (*p) >= 65u ) - goto tr132; - } else - goto tr139; - goto st0; -tr138: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr138; + case 58u: + goto st72; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr136; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr132; + } + else if ((*p) >= 65u) + goto tr132; + } + else + goto tr139; + goto st0; + tr138: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st121; -st121: - if ( ++p == pe ) - goto _test_eof121; -case 121: + { + ipFamily = AF_INET6; + } + goto st121; + st121: + if (++p == pe) + goto _test_eof121; + case 121: #line 1744 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr137; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr134; - } else if ( (*p) >= 65u ) - goto tr134; - } else - goto tr134; - goto st0; -tr139: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr137; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr134; + } + else if ((*p) >= 65u) + goto tr134; + } + else + goto tr134; + goto st0; + tr139: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st122; -st122: - if ( ++p == pe ) - goto _test_eof122; -case 122: + { + ipFamily = AF_INET6; + } + goto st122; + st122: + if (++p == pe) + goto _test_eof122; + case 122: #line 1771 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr134; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr134; - } else - goto tr134; - goto st0; -tr98: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr134; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr134; + } + else + goto tr134; + goto st0; + tr98: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st123; -st123: - if ( ++p == pe ) - goto _test_eof123; -case 123: + { + ipFamily = AF_INET6; + } + goto st123; + st123: + if (++p == pe) + goto _test_eof123; + case 123: #line 1795 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st72; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr139; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr132; - } else - goto tr132; - goto st0; -tr99: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st72; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr139; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr132; + } + else + goto tr132; + goto st0; + tr99: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st124; -st124: - if ( ++p == pe ) - goto _test_eof124; -case 124: + { + ipFamily = AF_INET6; + } + goto st124; + st124: + if (++p == pe) + goto _test_eof124; + case 124: #line 1819 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st72; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr132; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr132; - } else - goto tr132; - goto st0; -tr41: + if ((*p) == 58u) + goto st72; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr132; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr132; + } + else + goto tr132; + goto st0; + tr41: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st125; -st125: - if ( ++p == pe ) - goto _test_eof125; -case 125: + { + ipFamily = AF_INET6; + } + goto st125; + st125: + if (++p == pe) + goto _test_eof125; + case 125: #line 1841 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr100; - case 49u: goto tr101; - case 50u: goto tr102; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr103; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr104; - } else - goto tr104; - goto st0; -tr100: + switch ((*p)) + { + case 48u: + goto tr100; + case 49u: + goto tr101; + case 50u: + goto tr102; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr103; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr104; + } + else + goto tr104; + goto st0; + tr100: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st126; -st126: - if ( ++p == pe ) - goto _test_eof126; -case 126: + { + ipFamily = AF_INET6; + } + goto st126; + st126: + if (++p == pe) + goto _test_eof126; + case 126: #line 1866 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr140; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr140; - } else - goto tr140; - goto st0; -tr140: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr140; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr140; + } + else + goto tr140; + goto st0; + tr140: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st127; -st127: - if ( ++p == pe ) - goto _test_eof127; -case 127: + { + ipFamily = AF_INET6; + } + goto st127; + st127: + if (++p == pe) + goto _test_eof127; + case 127: #line 1890 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st73; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr142; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr142; - } else - goto tr142; - goto st0; -tr142: + if ((*p) == 58u) + goto st73; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr142; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr142; + } + else + goto tr142; + goto st0; + tr142: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st128; -st128: - if ( ++p == pe ) - goto _test_eof128; -case 128: + { + ipFamily = AF_INET6; + } + goto st128; + st128: + if (++p == pe) + goto _test_eof128; + case 128: #line 1912 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st73; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr143; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr143; - } else - goto tr143; - goto st0; -tr143: + if ((*p) == 58u) + goto st73; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr143; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr143; + } + else + goto tr143; + goto st0; + tr143: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st129; -st129: - if ( ++p == pe ) - goto _test_eof129; -case 129: + { + ipFamily = AF_INET6; + } + goto st129; + st129: + if (++p == pe) + goto _test_eof129; + case 129: #line 1934 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st73; - goto st0; -st73: - if ( ++p == pe ) - goto _test_eof73; -case 73: - switch( (*p) ) { - case 48u: goto tr95; - case 49u: goto tr96; - case 50u: goto tr97; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr98; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr99; - } else - goto tr99; - goto st0; -tr101: + if ((*p) == 58u) + goto st73; + goto st0; + st73: + if (++p == pe) + goto _test_eof73; + case 73: + switch ((*p)) + { + case 48u: + goto tr95; + case 49u: + goto tr96; + case 50u: + goto tr97; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr98; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr99; + } + else + goto tr99; + goto st0; + tr101: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st130; -st130: - if ( ++p == pe ) - goto _test_eof130; -case 130: + { + ipFamily = AF_INET6; + } + goto st130; + st130: + if (++p == pe) + goto _test_eof130; + case 130: #line 1966 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr144; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr140; - } else - goto tr140; - goto st0; -tr144: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr144; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr140; + } + else + goto tr140; + goto st0; + tr144: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st131; -st131: - if ( ++p == pe ) - goto _test_eof131; -case 131: + { + ipFamily = AF_INET6; + } + goto st131; + st131: + if (++p == pe) + goto _test_eof131; + case 131: #line 1990 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr145; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr142; - } else - goto tr142; - goto st0; -tr145: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr145; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr142; + } + else + goto tr142; + goto st0; + tr145: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st132; -st132: - if ( ++p == pe ) - goto _test_eof132; -case 132: + { + ipFamily = AF_INET6; + } + goto st132; + st132: + if (++p == pe) + goto _test_eof132; + case 132: #line 2014 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr143; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr143; - } else - goto tr143; - goto st0; -tr102: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr143; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr143; + } + else + goto tr143; + goto st0; + tr102: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st133; -st133: - if ( ++p == pe ) - goto _test_eof133; -case 133: + { + ipFamily = AF_INET6; + } + goto st133; + st133: + if (++p == pe) + goto _test_eof133; + case 133: #line 2038 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr146; - case 58u: goto st73; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr144; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr140; - } else if ( (*p) >= 65u ) - goto tr140; - } else - goto tr147; - goto st0; -tr146: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr146; + case 58u: + goto st73; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr144; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr140; + } + else if ((*p) >= 65u) + goto tr140; + } + else + goto tr147; + goto st0; + tr146: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st134; -st134: - if ( ++p == pe ) - goto _test_eof134; -case 134: + { + ipFamily = AF_INET6; + } + goto st134; + st134: + if (++p == pe) + goto _test_eof134; + case 134: #line 2066 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr145; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr142; - } else if ( (*p) >= 65u ) - goto tr142; - } else - goto tr142; - goto st0; -tr147: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr145; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr142; + } + else if ((*p) >= 65u) + goto tr142; + } + else + goto tr142; + goto st0; + tr147: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st135; -st135: - if ( ++p == pe ) - goto _test_eof135; -case 135: + { + ipFamily = AF_INET6; + } + goto st135; + st135: + if (++p == pe) + goto _test_eof135; + case 135: #line 2093 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr142; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr142; - } else - goto tr142; - goto st0; -tr103: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr142; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr142; + } + else + goto tr142; + goto st0; + tr103: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st136; -st136: - if ( ++p == pe ) - goto _test_eof136; -case 136: + { + ipFamily = AF_INET6; + } + goto st136; + st136: + if (++p == pe) + goto _test_eof136; + case 136: #line 2117 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st73; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr147; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr140; - } else - goto tr140; - goto st0; -tr104: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st73; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr147; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr140; + } + else + goto tr140; + goto st0; + tr104: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st137; -st137: - if ( ++p == pe ) - goto _test_eof137; -case 137: + { + ipFamily = AF_INET6; + } + goto st137; + st137: + if (++p == pe) + goto _test_eof137; + case 137: #line 2141 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st73; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr140; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr140; - } else - goto tr140; - goto st0; -tr35: + if ((*p) == 58u) + goto st73; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr140; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr140; + } + else + goto tr140; + goto st0; + tr35: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st138; -st138: - if ( ++p == pe ) - goto _test_eof138; -case 138: + { + ipFamily = AF_INET6; + } + goto st138; + st138: + if (++p == pe) + goto _test_eof138; + case 138: #line 2163 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr105; - case 49u: goto tr106; - case 50u: goto tr107; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr108; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr109; - } else - goto tr109; - goto st0; -tr105: + switch ((*p)) + { + case 48u: + goto tr105; + case 49u: + goto tr106; + case 50u: + goto tr107; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr108; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr109; + } + else + goto tr109; + goto st0; + tr105: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st139; -st139: - if ( ++p == pe ) - goto _test_eof139; -case 139: + { + ipFamily = AF_INET6; + } + goto st139; + st139: + if (++p == pe) + goto _test_eof139; + case 139: #line 2188 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr148; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr148; - } else - goto tr148; - goto st0; -tr148: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr148; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr148; + } + else + goto tr148; + goto st0; + tr148: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st140; -st140: - if ( ++p == pe ) - goto _test_eof140; -case 140: + { + ipFamily = AF_INET6; + } + goto st140; + st140: + if (++p == pe) + goto _test_eof140; + case 140: #line 2212 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st74; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr150; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr150; - } else - goto tr150; - goto st0; -tr150: + if ((*p) == 58u) + goto st74; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr150; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr150; + } + else + goto tr150; + goto st0; + tr150: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st141; -st141: - if ( ++p == pe ) - goto _test_eof141; -case 141: + { + ipFamily = AF_INET6; + } + goto st141; + st141: + if (++p == pe) + goto _test_eof141; + case 141: #line 2234 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st74; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr151; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr151; - } else - goto tr151; - goto st0; -tr151: + if ((*p) == 58u) + goto st74; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr151; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr151; + } + else + goto tr151; + goto st0; + tr151: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st142; -st142: - if ( ++p == pe ) - goto _test_eof142; -case 142: + { + ipFamily = AF_INET6; + } + goto st142; + st142: + if (++p == pe) + goto _test_eof142; + case 142: #line 2256 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st74; - goto st0; -st74: - if ( ++p == pe ) - goto _test_eof74; -case 74: - switch( (*p) ) { - case 48u: goto tr100; - case 49u: goto tr101; - case 50u: goto tr102; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr103; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr104; - } else - goto tr104; - goto st0; -tr106: + if ((*p) == 58u) + goto st74; + goto st0; + st74: + if (++p == pe) + goto _test_eof74; + case 74: + switch ((*p)) + { + case 48u: + goto tr100; + case 49u: + goto tr101; + case 50u: + goto tr102; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr103; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr104; + } + else + goto tr104; + goto st0; + tr106: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st143; -st143: - if ( ++p == pe ) - goto _test_eof143; -case 143: + { + ipFamily = AF_INET6; + } + goto st143; + st143: + if (++p == pe) + goto _test_eof143; + case 143: #line 2288 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr152; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr148; - } else - goto tr148; - goto st0; -tr152: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr152; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr148; + } + else + goto tr148; + goto st0; + tr152: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st144; -st144: - if ( ++p == pe ) - goto _test_eof144; -case 144: + { + ipFamily = AF_INET6; + } + goto st144; + st144: + if (++p == pe) + goto _test_eof144; + case 144: #line 2312 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr153; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr150; - } else - goto tr150; - goto st0; -tr153: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr153; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr150; + } + else + goto tr150; + goto st0; + tr153: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st145; -st145: - if ( ++p == pe ) - goto _test_eof145; -case 145: + { + ipFamily = AF_INET6; + } + goto st145; + st145: + if (++p == pe) + goto _test_eof145; + case 145: #line 2336 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr151; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr151; - } else - goto tr151; - goto st0; -tr107: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr151; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr151; + } + else + goto tr151; + goto st0; + tr107: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st146; -st146: - if ( ++p == pe ) - goto _test_eof146; -case 146: + { + ipFamily = AF_INET6; + } + goto st146; + st146: + if (++p == pe) + goto _test_eof146; + case 146: #line 2360 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr154; - case 58u: goto st74; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr152; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr148; - } else if ( (*p) >= 65u ) - goto tr148; - } else - goto tr155; - goto st0; -tr154: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr154; + case 58u: + goto st74; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr152; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr148; + } + else if ((*p) >= 65u) + goto tr148; + } + else + goto tr155; + goto st0; + tr154: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st147; -st147: - if ( ++p == pe ) - goto _test_eof147; -case 147: + { + ipFamily = AF_INET6; + } + goto st147; + st147: + if (++p == pe) + goto _test_eof147; + case 147: #line 2388 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr153; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr150; - } else if ( (*p) >= 65u ) - goto tr150; - } else - goto tr150; - goto st0; -tr155: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr153; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr150; + } + else if ((*p) >= 65u) + goto tr150; + } + else + goto tr150; + goto st0; + tr155: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st148; -st148: - if ( ++p == pe ) - goto _test_eof148; -case 148: + { + ipFamily = AF_INET6; + } + goto st148; + st148: + if (++p == pe) + goto _test_eof148; + case 148: #line 2415 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr150; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr150; - } else - goto tr150; - goto st0; -tr108: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr150; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr150; + } + else + goto tr150; + goto st0; + tr108: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st149; -st149: - if ( ++p == pe ) - goto _test_eof149; -case 149: + { + ipFamily = AF_INET6; + } + goto st149; + st149: + if (++p == pe) + goto _test_eof149; + case 149: #line 2439 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st74; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr155; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr148; - } else - goto tr148; - goto st0; -tr109: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st74; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr155; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr148; + } + else + goto tr148; + goto st0; + tr109: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st150; -st150: - if ( ++p == pe ) - goto _test_eof150; -case 150: + { + ipFamily = AF_INET6; + } + goto st150; + st150: + if (++p == pe) + goto _test_eof150; + case 150: #line 2463 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st74; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr148; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr148; - } else - goto tr148; - goto st0; -tr29: + if ((*p) == 58u) + goto st74; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr148; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr148; + } + else + goto tr148; + goto st0; + tr29: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st151; -st151: - if ( ++p == pe ) - goto _test_eof151; -case 151: + { + ipFamily = AF_INET6; + } + goto st151; + st151: + if (++p == pe) + goto _test_eof151; + case 151: #line 2485 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr115; - case 49u: goto tr116; - case 50u: goto tr117; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr118; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr119; - } else - goto tr119; - goto st0; -tr115: + switch ((*p)) + { + case 48u: + goto tr115; + case 49u: + goto tr116; + case 50u: + goto tr117; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr118; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr119; + } + else + goto tr119; + goto st0; + tr115: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st152; -st152: - if ( ++p == pe ) - goto _test_eof152; -case 152: + { + ipFamily = AF_INET6; + } + goto st152; + st152: + if (++p == pe) + goto _test_eof152; + case 152: #line 2510 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr156; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr156; - } else - goto tr156; - goto st0; -tr156: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr156; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr156; + } + else + goto tr156; + goto st0; + tr156: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st153; -st153: - if ( ++p == pe ) - goto _test_eof153; -case 153: + { + ipFamily = AF_INET6; + } + goto st153; + st153: + if (++p == pe) + goto _test_eof153; + case 153: #line 2534 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st75; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr158; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr158; - } else - goto tr158; - goto st0; -tr158: + if ((*p) == 58u) + goto st75; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr158; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr158; + } + else + goto tr158; + goto st0; + tr158: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st154; -st154: - if ( ++p == pe ) - goto _test_eof154; -case 154: + { + ipFamily = AF_INET6; + } + goto st154; + st154: + if (++p == pe) + goto _test_eof154; + case 154: #line 2556 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st75; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr159; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr159; - } else - goto tr159; - goto st0; -tr159: + if ((*p) == 58u) + goto st75; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr159; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr159; + } + else + goto tr159; + goto st0; + tr159: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st155; -st155: - if ( ++p == pe ) - goto _test_eof155; -case 155: + { + ipFamily = AF_INET6; + } + goto st155; + st155: + if (++p == pe) + goto _test_eof155; + case 155: #line 2578 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st75; - goto st0; -st75: - if ( ++p == pe ) - goto _test_eof75; -case 75: - switch( (*p) ) { - case 48u: goto tr105; - case 49u: goto tr106; - case 50u: goto tr107; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr108; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr109; - } else - goto tr109; - goto st0; -tr116: + if ((*p) == 58u) + goto st75; + goto st0; + st75: + if (++p == pe) + goto _test_eof75; + case 75: + switch ((*p)) + { + case 48u: + goto tr105; + case 49u: + goto tr106; + case 50u: + goto tr107; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr108; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr109; + } + else + goto tr109; + goto st0; + tr116: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st156; -st156: - if ( ++p == pe ) - goto _test_eof156; -case 156: + { + ipFamily = AF_INET6; + } + goto st156; + st156: + if (++p == pe) + goto _test_eof156; + case 156: #line 2610 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr160; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr156; - } else - goto tr156; - goto st0; -tr160: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr160; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr156; + } + else + goto tr156; + goto st0; + tr160: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st157; -st157: - if ( ++p == pe ) - goto _test_eof157; -case 157: + { + ipFamily = AF_INET6; + } + goto st157; + st157: + if (++p == pe) + goto _test_eof157; + case 157: #line 2634 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr161; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr158; - } else - goto tr158; - goto st0; -tr161: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr161; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr158; + } + else + goto tr158; + goto st0; + tr161: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st158; -st158: - if ( ++p == pe ) - goto _test_eof158; -case 158: + { + ipFamily = AF_INET6; + } + goto st158; + st158: + if (++p == pe) + goto _test_eof158; + case 158: #line 2658 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr159; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr159; - } else - goto tr159; - goto st0; -tr117: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr159; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr159; + } + else + goto tr159; + goto st0; + tr117: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st159; -st159: - if ( ++p == pe ) - goto _test_eof159; -case 159: + { + ipFamily = AF_INET6; + } + goto st159; + st159: + if (++p == pe) + goto _test_eof159; + case 159: #line 2682 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr162; - case 58u: goto st75; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr160; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr156; - } else if ( (*p) >= 65u ) - goto tr156; - } else - goto tr163; - goto st0; -tr162: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr162; + case 58u: + goto st75; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr160; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr156; + } + else if ((*p) >= 65u) + goto tr156; + } + else + goto tr163; + goto st0; + tr162: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st160; -st160: - if ( ++p == pe ) - goto _test_eof160; -case 160: + { + ipFamily = AF_INET6; + } + goto st160; + st160: + if (++p == pe) + goto _test_eof160; + case 160: #line 2710 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr161; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr158; - } else if ( (*p) >= 65u ) - goto tr158; - } else - goto tr158; - goto st0; -tr163: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr161; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr158; + } + else if ((*p) >= 65u) + goto tr158; + } + else + goto tr158; + goto st0; + tr163: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st161; -st161: - if ( ++p == pe ) - goto _test_eof161; -case 161: + { + ipFamily = AF_INET6; + } + goto st161; + st161: + if (++p == pe) + goto _test_eof161; + case 161: #line 2737 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr158; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr158; - } else - goto tr158; - goto st0; -tr118: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr158; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr158; + } + else + goto tr158; + goto st0; + tr118: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st162; -st162: - if ( ++p == pe ) - goto _test_eof162; -case 162: + { + ipFamily = AF_INET6; + } + goto st162; + st162: + if (++p == pe) + goto _test_eof162; + case 162: #line 2761 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st75; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr163; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr156; - } else - goto tr156; - goto st0; -tr119: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st75; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr163; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr156; + } + else + goto tr156; + goto st0; + tr119: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st163; -st163: - if ( ++p == pe ) - goto _test_eof163; -case 163: + { + ipFamily = AF_INET6; + } + goto st163; + st163: + if (++p == pe) + goto _test_eof163; + case 163: #line 2785 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st75; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr156; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr156; - } else - goto tr156; - goto st0; -st76: - if ( ++p == pe ) - goto _test_eof76; -case 76: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st77; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st16; - } else - goto st16; - goto st0; -st77: - if ( ++p == pe ) - goto _test_eof77; -case 77: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st78; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st17; - } else - goto st17; - goto st0; -st78: - if ( ++p == pe ) - goto _test_eof78; -case 78: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st18; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st18; - } else - goto st18; - goto st0; -st79: - if ( ++p == pe ) - goto _test_eof79; -case 79: - switch( (*p) ) { - case 46u: goto st3; - case 53u: goto st80; - case 58u: goto st19; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto st77; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st16; - } else if ( (*p) >= 65u ) - goto st16; - } else - goto st81; - goto st0; -st80: - if ( ++p == pe ) - goto _test_eof80; -case 80: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto st78; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st17; - } else if ( (*p) >= 65u ) - goto st17; - } else - goto st17; - goto st0; -st81: - if ( ++p == pe ) - goto _test_eof81; -case 81: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st17; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st17; - } else - goto st17; - goto st0; -st82: - if ( ++p == pe ) - goto _test_eof82; -case 82: - switch( (*p) ) { - case 46u: goto st3; - case 58u: goto st19; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st81; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st16; - } else - goto st16; - goto st0; -st83: - if ( ++p == pe ) - goto _test_eof83; -case 83: - if ( (*p) == 58u ) - goto tr114; - goto st0; -tr114: + if ((*p) == 58u) + goto st75; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr156; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr156; + } + else + goto tr156; + goto st0; + st76: + if (++p == pe) + goto _test_eof76; + case 76: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st77; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st16; + } + else + goto st16; + goto st0; + st77: + if (++p == pe) + goto _test_eof77; + case 77: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st78; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st17; + } + else + goto st17; + goto st0; + st78: + if (++p == pe) + goto _test_eof78; + case 78: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st18; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st18; + } + else + goto st18; + goto st0; + st79: + if (++p == pe) + goto _test_eof79; + case 79: + switch ((*p)) + { + case 46u: + goto st3; + case 53u: + goto st80; + case 58u: + goto st19; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto st77; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st16; + } + else if ((*p) >= 65u) + goto st16; + } + else + goto st81; + goto st0; + st80: + if (++p == pe) + goto _test_eof80; + case 80: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto st78; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st17; + } + else if ((*p) >= 65u) + goto st17; + } + else + goto st17; + goto st0; + st81: + if (++p == pe) + goto _test_eof81; + case 81: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st17; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st17; + } + else + goto st17; + goto st0; + st82: + if (++p == pe) + goto _test_eof82; + case 82: + switch ((*p)) + { + case 46u: + goto st3; + case 58u: + goto st19; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st81; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st16; + } + else + goto st16; + goto st0; + st83: + if (++p == pe) + goto _test_eof83; + case 83: + if ((*p) == 58u) + goto tr114; + goto st0; + tr114: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st164; -st164: - if ( ++p == pe ) - goto _test_eof164; -case 164: + { + ipFamily = AF_INET6; + } + goto st164; + st164: + if (++p == pe) + goto _test_eof164; + case 164: #line 2940 "src/Utils/IP.cpp" - switch( (*p) ) { - case 48u: goto tr164; - case 49u: goto tr165; - case 50u: goto tr166; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr167; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr168; - } else - goto tr168; - goto st0; -tr164: + switch ((*p)) + { + case 48u: + goto tr164; + case 49u: + goto tr165; + case 50u: + goto tr166; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr167; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr168; + } + else + goto tr168; + goto st0; + tr164: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st165; -st165: - if ( ++p == pe ) - goto _test_eof165; -case 165: + { + ipFamily = AF_INET6; + } + goto st165; + st165: + if (++p == pe) + goto _test_eof165; + case 165: #line 2965 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr169; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr169; - } else - goto tr169; - goto st0; -tr169: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr169; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr169; + } + else + goto tr169; + goto st0; + tr169: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st166; -st166: - if ( ++p == pe ) - goto _test_eof166; -case 166: + { + ipFamily = AF_INET6; + } + goto st166; + st166: + if (++p == pe) + goto _test_eof166; + case 166: #line 2989 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st84; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr171; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr171; - } else - goto tr171; - goto st0; -tr171: + if ((*p) == 58u) + goto st84; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr171; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr171; + } + else + goto tr171; + goto st0; + tr171: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st167; -st167: - if ( ++p == pe ) - goto _test_eof167; -case 167: + { + ipFamily = AF_INET6; + } + goto st167; + st167: + if (++p == pe) + goto _test_eof167; + case 167: #line 3011 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st84; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr172; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr172; - } else - goto tr172; - goto st0; -tr172: + if ((*p) == 58u) + goto st84; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr172; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr172; + } + else + goto tr172; + goto st0; + tr172: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st168; -st168: - if ( ++p == pe ) - goto _test_eof168; -case 168: + { + ipFamily = AF_INET6; + } + goto st168; + st168: + if (++p == pe) + goto _test_eof168; + case 168: #line 3033 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st84; - goto st0; -st84: - if ( ++p == pe ) - goto _test_eof84; -case 84: - switch( (*p) ) { - case 48u: goto tr115; - case 49u: goto tr116; - case 50u: goto tr117; - } - if ( (*p) < 65u ) { - if ( 51u <= (*p) && (*p) <= 57u ) - goto tr118; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr119; - } else - goto tr119; - goto st0; -tr165: + if ((*p) == 58u) + goto st84; + goto st0; + st84: + if (++p == pe) + goto _test_eof84; + case 84: + switch ((*p)) + { + case 48u: + goto tr115; + case 49u: + goto tr116; + case 50u: + goto tr117; + } + if ((*p) < 65u) + { + if (51u <= (*p) && (*p) <= 57u) + goto tr118; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr119; + } + else + goto tr119; + goto st0; + tr165: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st169; -st169: - if ( ++p == pe ) - goto _test_eof169; -case 169: + { + ipFamily = AF_INET6; + } + goto st169; + st169: + if (++p == pe) + goto _test_eof169; + case 169: #line 3065 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr173; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr169; - } else - goto tr169; - goto st0; -tr173: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr173; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr169; + } + else + goto tr169; + goto st0; + tr173: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st170; -st170: - if ( ++p == pe ) - goto _test_eof170; -case 170: + { + ipFamily = AF_INET6; + } + goto st170; + st170: + if (++p == pe) + goto _test_eof170; + case 170: #line 3089 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr174; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr171; - } else - goto tr171; - goto st0; -tr174: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr174; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr171; + } + else + goto tr171; + goto st0; + tr174: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st171; -st171: - if ( ++p == pe ) - goto _test_eof171; -case 171: + { + ipFamily = AF_INET6; + } + goto st171; + st171: + if (++p == pe) + goto _test_eof171; + case 171: #line 3113 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr172; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr172; - } else - goto tr172; - goto st0; -tr166: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr172; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr172; + } + else + goto tr172; + goto st0; + tr166: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st172; -st172: - if ( ++p == pe ) - goto _test_eof172; -case 172: + { + ipFamily = AF_INET6; + } + goto st172; + st172: + if (++p == pe) + goto _test_eof172; + case 172: #line 3137 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 53u: goto tr175; - case 58u: goto st84; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 52u ) - goto tr173; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr169; - } else if ( (*p) >= 65u ) - goto tr169; - } else - goto tr176; - goto st0; -tr175: + switch ((*p)) + { + case 46u: + goto st46; + case 53u: + goto tr175; + case 58u: + goto st84; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 52u) + goto tr173; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr169; + } + else if ((*p) >= 65u) + goto tr169; + } + else + goto tr176; + goto st0; + tr175: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st173; -st173: - if ( ++p == pe ) - goto _test_eof173; -case 173: + { + ipFamily = AF_INET6; + } + goto st173; + st173: + if (++p == pe) + goto _test_eof173; + case 173: #line 3165 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 54u ) { - if ( 48u <= (*p) && (*p) <= 53u ) - goto tr174; - } else if ( (*p) > 57u ) { - if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr171; - } else if ( (*p) >= 65u ) - goto tr171; - } else - goto tr171; - goto st0; -tr176: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 54u) + { + if (48u <= (*p) && (*p) <= 53u) + goto tr174; + } + else if ((*p) > 57u) + { + if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr171; + } + else if ((*p) >= 65u) + goto tr171; + } + else + goto tr171; + goto st0; + tr176: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st174; -st174: - if ( ++p == pe ) - goto _test_eof174; -case 174: + { + ipFamily = AF_INET6; + } + goto st174; + st174: + if (++p == pe) + goto _test_eof174; + case 174: #line 3192 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr171; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr171; - } else - goto tr171; - goto st0; -tr167: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr171; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr171; + } + else + goto tr171; + goto st0; + tr167: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st175; -st175: - if ( ++p == pe ) - goto _test_eof175; -case 175: + { + ipFamily = AF_INET6; + } + goto st175; + st175: + if (++p == pe) + goto _test_eof175; + case 175: #line 3216 "src/Utils/IP.cpp" - switch( (*p) ) { - case 46u: goto st46; - case 58u: goto st84; - } - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr176; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr169; - } else - goto tr169; - goto st0; -tr168: + switch ((*p)) + { + case 46u: + goto st46; + case 58u: + goto st84; + } + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr176; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr169; + } + else + goto tr169; + goto st0; + tr168: #line 30 "src/Utils/IP.rl" - { - ipFamily = AF_INET6; - } - goto st176; -st176: - if ( ++p == pe ) - goto _test_eof176; -case 176: + { + ipFamily = AF_INET6; + } + goto st176; + st176: + if (++p == pe) + goto _test_eof176; + case 176: #line 3240 "src/Utils/IP.cpp" - if ( (*p) == 58u ) - goto st84; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto tr169; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto tr169; - } else - goto tr169; - goto st0; -st85: - if ( ++p == pe ) - goto _test_eof85; -case 85: - if ( (*p) == 58u ) - goto st19; - if ( (*p) < 65u ) { - if ( 48u <= (*p) && (*p) <= 57u ) - goto st16; - } else if ( (*p) > 70u ) { - if ( 97u <= (*p) && (*p) <= 102u ) - goto st16; - } else - goto st16; - goto st0; - } - _test_eof2: cs = 2; goto _test_eof; - _test_eof3: cs = 3; goto _test_eof; - _test_eof4: cs = 4; goto _test_eof; - _test_eof5: cs = 5; goto _test_eof; - _test_eof6: cs = 6; goto _test_eof; - _test_eof7: cs = 7; goto _test_eof; - _test_eof86: cs = 86; goto _test_eof; - _test_eof87: cs = 87; goto _test_eof; - _test_eof88: cs = 88; goto _test_eof; - _test_eof89: cs = 89; goto _test_eof; - _test_eof90: cs = 90; goto _test_eof; - _test_eof8: cs = 8; goto _test_eof; - _test_eof9: cs = 9; goto _test_eof; - _test_eof10: cs = 10; goto _test_eof; - _test_eof11: cs = 11; goto _test_eof; - _test_eof12: cs = 12; goto _test_eof; - _test_eof13: cs = 13; goto _test_eof; - _test_eof14: cs = 14; goto _test_eof; - _test_eof15: cs = 15; goto _test_eof; - _test_eof16: cs = 16; goto _test_eof; - _test_eof17: cs = 17; goto _test_eof; - _test_eof18: cs = 18; goto _test_eof; - _test_eof19: cs = 19; goto _test_eof; - _test_eof20: cs = 20; goto _test_eof; - _test_eof21: cs = 21; goto _test_eof; - _test_eof22: cs = 22; goto _test_eof; - _test_eof23: cs = 23; goto _test_eof; - _test_eof24: cs = 24; goto _test_eof; - _test_eof25: cs = 25; goto _test_eof; - _test_eof26: cs = 26; goto _test_eof; - _test_eof27: cs = 27; goto _test_eof; - _test_eof28: cs = 28; goto _test_eof; - _test_eof29: cs = 29; goto _test_eof; - _test_eof30: cs = 30; goto _test_eof; - _test_eof31: cs = 31; goto _test_eof; - _test_eof32: cs = 32; goto _test_eof; - _test_eof33: cs = 33; goto _test_eof; - _test_eof34: cs = 34; goto _test_eof; - _test_eof35: cs = 35; goto _test_eof; - _test_eof36: cs = 36; goto _test_eof; - _test_eof37: cs = 37; goto _test_eof; - _test_eof38: cs = 38; goto _test_eof; - _test_eof39: cs = 39; goto _test_eof; - _test_eof40: cs = 40; goto _test_eof; - _test_eof41: cs = 41; goto _test_eof; - _test_eof42: cs = 42; goto _test_eof; - _test_eof43: cs = 43; goto _test_eof; - _test_eof44: cs = 44; goto _test_eof; - _test_eof45: cs = 45; goto _test_eof; - _test_eof46: cs = 46; goto _test_eof; - _test_eof47: cs = 47; goto _test_eof; - _test_eof48: cs = 48; goto _test_eof; - _test_eof49: cs = 49; goto _test_eof; - _test_eof50: cs = 50; goto _test_eof; - _test_eof91: cs = 91; goto _test_eof; - _test_eof92: cs = 92; goto _test_eof; - _test_eof93: cs = 93; goto _test_eof; - _test_eof94: cs = 94; goto _test_eof; - _test_eof51: cs = 51; goto _test_eof; - _test_eof52: cs = 52; goto _test_eof; - _test_eof53: cs = 53; goto _test_eof; - _test_eof54: cs = 54; goto _test_eof; - _test_eof55: cs = 55; goto _test_eof; - _test_eof56: cs = 56; goto _test_eof; - _test_eof57: cs = 57; goto _test_eof; - _test_eof58: cs = 58; goto _test_eof; - _test_eof59: cs = 59; goto _test_eof; - _test_eof60: cs = 60; goto _test_eof; - _test_eof61: cs = 61; goto _test_eof; - _test_eof62: cs = 62; goto _test_eof; - _test_eof95: cs = 95; goto _test_eof; - _test_eof96: cs = 96; goto _test_eof; - _test_eof97: cs = 97; goto _test_eof; - _test_eof63: cs = 63; goto _test_eof; - _test_eof64: cs = 64; goto _test_eof; - _test_eof65: cs = 65; goto _test_eof; - _test_eof66: cs = 66; goto _test_eof; - _test_eof67: cs = 67; goto _test_eof; - _test_eof68: cs = 68; goto _test_eof; - _test_eof69: cs = 69; goto _test_eof; - _test_eof98: cs = 98; goto _test_eof; - _test_eof70: cs = 70; goto _test_eof; - _test_eof99: cs = 99; goto _test_eof; - _test_eof100: cs = 100; goto _test_eof; - _test_eof101: cs = 101; goto _test_eof; - _test_eof102: cs = 102; goto _test_eof; - _test_eof103: cs = 103; goto _test_eof; - _test_eof71: cs = 71; goto _test_eof; - _test_eof104: cs = 104; goto _test_eof; - _test_eof105: cs = 105; goto _test_eof; - _test_eof106: cs = 106; goto _test_eof; - _test_eof107: cs = 107; goto _test_eof; - _test_eof108: cs = 108; goto _test_eof; - _test_eof109: cs = 109; goto _test_eof; - _test_eof110: cs = 110; goto _test_eof; - _test_eof111: cs = 111; goto _test_eof; - _test_eof112: cs = 112; goto _test_eof; - _test_eof113: cs = 113; goto _test_eof; - _test_eof114: cs = 114; goto _test_eof; - _test_eof115: cs = 115; goto _test_eof; - _test_eof116: cs = 116; goto _test_eof; - _test_eof72: cs = 72; goto _test_eof; - _test_eof117: cs = 117; goto _test_eof; - _test_eof118: cs = 118; goto _test_eof; - _test_eof119: cs = 119; goto _test_eof; - _test_eof120: cs = 120; goto _test_eof; - _test_eof121: cs = 121; goto _test_eof; - _test_eof122: cs = 122; goto _test_eof; - _test_eof123: cs = 123; goto _test_eof; - _test_eof124: cs = 124; goto _test_eof; - _test_eof125: cs = 125; goto _test_eof; - _test_eof126: cs = 126; goto _test_eof; - _test_eof127: cs = 127; goto _test_eof; - _test_eof128: cs = 128; goto _test_eof; - _test_eof129: cs = 129; goto _test_eof; - _test_eof73: cs = 73; goto _test_eof; - _test_eof130: cs = 130; goto _test_eof; - _test_eof131: cs = 131; goto _test_eof; - _test_eof132: cs = 132; goto _test_eof; - _test_eof133: cs = 133; goto _test_eof; - _test_eof134: cs = 134; goto _test_eof; - _test_eof135: cs = 135; goto _test_eof; - _test_eof136: cs = 136; goto _test_eof; - _test_eof137: cs = 137; goto _test_eof; - _test_eof138: cs = 138; goto _test_eof; - _test_eof139: cs = 139; goto _test_eof; - _test_eof140: cs = 140; goto _test_eof; - _test_eof141: cs = 141; goto _test_eof; - _test_eof142: cs = 142; goto _test_eof; - _test_eof74: cs = 74; goto _test_eof; - _test_eof143: cs = 143; goto _test_eof; - _test_eof144: cs = 144; goto _test_eof; - _test_eof145: cs = 145; goto _test_eof; - _test_eof146: cs = 146; goto _test_eof; - _test_eof147: cs = 147; goto _test_eof; - _test_eof148: cs = 148; goto _test_eof; - _test_eof149: cs = 149; goto _test_eof; - _test_eof150: cs = 150; goto _test_eof; - _test_eof151: cs = 151; goto _test_eof; - _test_eof152: cs = 152; goto _test_eof; - _test_eof153: cs = 153; goto _test_eof; - _test_eof154: cs = 154; goto _test_eof; - _test_eof155: cs = 155; goto _test_eof; - _test_eof75: cs = 75; goto _test_eof; - _test_eof156: cs = 156; goto _test_eof; - _test_eof157: cs = 157; goto _test_eof; - _test_eof158: cs = 158; goto _test_eof; - _test_eof159: cs = 159; goto _test_eof; - _test_eof160: cs = 160; goto _test_eof; - _test_eof161: cs = 161; goto _test_eof; - _test_eof162: cs = 162; goto _test_eof; - _test_eof163: cs = 163; goto _test_eof; - _test_eof76: cs = 76; goto _test_eof; - _test_eof77: cs = 77; goto _test_eof; - _test_eof78: cs = 78; goto _test_eof; - _test_eof79: cs = 79; goto _test_eof; - _test_eof80: cs = 80; goto _test_eof; - _test_eof81: cs = 81; goto _test_eof; - _test_eof82: cs = 82; goto _test_eof; - _test_eof83: cs = 83; goto _test_eof; - _test_eof164: cs = 164; goto _test_eof; - _test_eof165: cs = 165; goto _test_eof; - _test_eof166: cs = 166; goto _test_eof; - _test_eof167: cs = 167; goto _test_eof; - _test_eof168: cs = 168; goto _test_eof; - _test_eof84: cs = 84; goto _test_eof; - _test_eof169: cs = 169; goto _test_eof; - _test_eof170: cs = 170; goto _test_eof; - _test_eof171: cs = 171; goto _test_eof; - _test_eof172: cs = 172; goto _test_eof; - _test_eof173: cs = 173; goto _test_eof; - _test_eof174: cs = 174; goto _test_eof; - _test_eof175: cs = 175; goto _test_eof; - _test_eof176: cs = 176; goto _test_eof; - _test_eof85: cs = 85; goto _test_eof; + if ((*p) == 58u) + goto st84; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto tr169; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto tr169; + } + else + goto tr169; + goto st0; + st85: + if (++p == pe) + goto _test_eof85; + case 85: + if ((*p) == 58u) + goto st19; + if ((*p) < 65u) + { + if (48u <= (*p) && (*p) <= 57u) + goto st16; + } + else if ((*p) > 70u) + { + if (97u <= (*p) && (*p) <= 102u) + goto st16; + } + else + goto st16; + goto st0; + } + _test_eof2: + cs = 2; + goto _test_eof; + _test_eof3: + cs = 3; + goto _test_eof; + _test_eof4: + cs = 4; + goto _test_eof; + _test_eof5: + cs = 5; + goto _test_eof; + _test_eof6: + cs = 6; + goto _test_eof; + _test_eof7: + cs = 7; + goto _test_eof; + _test_eof86: + cs = 86; + goto _test_eof; + _test_eof87: + cs = 87; + goto _test_eof; + _test_eof88: + cs = 88; + goto _test_eof; + _test_eof89: + cs = 89; + goto _test_eof; + _test_eof90: + cs = 90; + goto _test_eof; + _test_eof8: + cs = 8; + goto _test_eof; + _test_eof9: + cs = 9; + goto _test_eof; + _test_eof10: + cs = 10; + goto _test_eof; + _test_eof11: + cs = 11; + goto _test_eof; + _test_eof12: + cs = 12; + goto _test_eof; + _test_eof13: + cs = 13; + goto _test_eof; + _test_eof14: + cs = 14; + goto _test_eof; + _test_eof15: + cs = 15; + goto _test_eof; + _test_eof16: + cs = 16; + goto _test_eof; + _test_eof17: + cs = 17; + goto _test_eof; + _test_eof18: + cs = 18; + goto _test_eof; + _test_eof19: + cs = 19; + goto _test_eof; + _test_eof20: + cs = 20; + goto _test_eof; + _test_eof21: + cs = 21; + goto _test_eof; + _test_eof22: + cs = 22; + goto _test_eof; + _test_eof23: + cs = 23; + goto _test_eof; + _test_eof24: + cs = 24; + goto _test_eof; + _test_eof25: + cs = 25; + goto _test_eof; + _test_eof26: + cs = 26; + goto _test_eof; + _test_eof27: + cs = 27; + goto _test_eof; + _test_eof28: + cs = 28; + goto _test_eof; + _test_eof29: + cs = 29; + goto _test_eof; + _test_eof30: + cs = 30; + goto _test_eof; + _test_eof31: + cs = 31; + goto _test_eof; + _test_eof32: + cs = 32; + goto _test_eof; + _test_eof33: + cs = 33; + goto _test_eof; + _test_eof34: + cs = 34; + goto _test_eof; + _test_eof35: + cs = 35; + goto _test_eof; + _test_eof36: + cs = 36; + goto _test_eof; + _test_eof37: + cs = 37; + goto _test_eof; + _test_eof38: + cs = 38; + goto _test_eof; + _test_eof39: + cs = 39; + goto _test_eof; + _test_eof40: + cs = 40; + goto _test_eof; + _test_eof41: + cs = 41; + goto _test_eof; + _test_eof42: + cs = 42; + goto _test_eof; + _test_eof43: + cs = 43; + goto _test_eof; + _test_eof44: + cs = 44; + goto _test_eof; + _test_eof45: + cs = 45; + goto _test_eof; + _test_eof46: + cs = 46; + goto _test_eof; + _test_eof47: + cs = 47; + goto _test_eof; + _test_eof48: + cs = 48; + goto _test_eof; + _test_eof49: + cs = 49; + goto _test_eof; + _test_eof50: + cs = 50; + goto _test_eof; + _test_eof91: + cs = 91; + goto _test_eof; + _test_eof92: + cs = 92; + goto _test_eof; + _test_eof93: + cs = 93; + goto _test_eof; + _test_eof94: + cs = 94; + goto _test_eof; + _test_eof51: + cs = 51; + goto _test_eof; + _test_eof52: + cs = 52; + goto _test_eof; + _test_eof53: + cs = 53; + goto _test_eof; + _test_eof54: + cs = 54; + goto _test_eof; + _test_eof55: + cs = 55; + goto _test_eof; + _test_eof56: + cs = 56; + goto _test_eof; + _test_eof57: + cs = 57; + goto _test_eof; + _test_eof58: + cs = 58; + goto _test_eof; + _test_eof59: + cs = 59; + goto _test_eof; + _test_eof60: + cs = 60; + goto _test_eof; + _test_eof61: + cs = 61; + goto _test_eof; + _test_eof62: + cs = 62; + goto _test_eof; + _test_eof95: + cs = 95; + goto _test_eof; + _test_eof96: + cs = 96; + goto _test_eof; + _test_eof97: + cs = 97; + goto _test_eof; + _test_eof63: + cs = 63; + goto _test_eof; + _test_eof64: + cs = 64; + goto _test_eof; + _test_eof65: + cs = 65; + goto _test_eof; + _test_eof66: + cs = 66; + goto _test_eof; + _test_eof67: + cs = 67; + goto _test_eof; + _test_eof68: + cs = 68; + goto _test_eof; + _test_eof69: + cs = 69; + goto _test_eof; + _test_eof98: + cs = 98; + goto _test_eof; + _test_eof70: + cs = 70; + goto _test_eof; + _test_eof99: + cs = 99; + goto _test_eof; + _test_eof100: + cs = 100; + goto _test_eof; + _test_eof101: + cs = 101; + goto _test_eof; + _test_eof102: + cs = 102; + goto _test_eof; + _test_eof103: + cs = 103; + goto _test_eof; + _test_eof71: + cs = 71; + goto _test_eof; + _test_eof104: + cs = 104; + goto _test_eof; + _test_eof105: + cs = 105; + goto _test_eof; + _test_eof106: + cs = 106; + goto _test_eof; + _test_eof107: + cs = 107; + goto _test_eof; + _test_eof108: + cs = 108; + goto _test_eof; + _test_eof109: + cs = 109; + goto _test_eof; + _test_eof110: + cs = 110; + goto _test_eof; + _test_eof111: + cs = 111; + goto _test_eof; + _test_eof112: + cs = 112; + goto _test_eof; + _test_eof113: + cs = 113; + goto _test_eof; + _test_eof114: + cs = 114; + goto _test_eof; + _test_eof115: + cs = 115; + goto _test_eof; + _test_eof116: + cs = 116; + goto _test_eof; + _test_eof72: + cs = 72; + goto _test_eof; + _test_eof117: + cs = 117; + goto _test_eof; + _test_eof118: + cs = 118; + goto _test_eof; + _test_eof119: + cs = 119; + goto _test_eof; + _test_eof120: + cs = 120; + goto _test_eof; + _test_eof121: + cs = 121; + goto _test_eof; + _test_eof122: + cs = 122; + goto _test_eof; + _test_eof123: + cs = 123; + goto _test_eof; + _test_eof124: + cs = 124; + goto _test_eof; + _test_eof125: + cs = 125; + goto _test_eof; + _test_eof126: + cs = 126; + goto _test_eof; + _test_eof127: + cs = 127; + goto _test_eof; + _test_eof128: + cs = 128; + goto _test_eof; + _test_eof129: + cs = 129; + goto _test_eof; + _test_eof73: + cs = 73; + goto _test_eof; + _test_eof130: + cs = 130; + goto _test_eof; + _test_eof131: + cs = 131; + goto _test_eof; + _test_eof132: + cs = 132; + goto _test_eof; + _test_eof133: + cs = 133; + goto _test_eof; + _test_eof134: + cs = 134; + goto _test_eof; + _test_eof135: + cs = 135; + goto _test_eof; + _test_eof136: + cs = 136; + goto _test_eof; + _test_eof137: + cs = 137; + goto _test_eof; + _test_eof138: + cs = 138; + goto _test_eof; + _test_eof139: + cs = 139; + goto _test_eof; + _test_eof140: + cs = 140; + goto _test_eof; + _test_eof141: + cs = 141; + goto _test_eof; + _test_eof142: + cs = 142; + goto _test_eof; + _test_eof74: + cs = 74; + goto _test_eof; + _test_eof143: + cs = 143; + goto _test_eof; + _test_eof144: + cs = 144; + goto _test_eof; + _test_eof145: + cs = 145; + goto _test_eof; + _test_eof146: + cs = 146; + goto _test_eof; + _test_eof147: + cs = 147; + goto _test_eof; + _test_eof148: + cs = 148; + goto _test_eof; + _test_eof149: + cs = 149; + goto _test_eof; + _test_eof150: + cs = 150; + goto _test_eof; + _test_eof151: + cs = 151; + goto _test_eof; + _test_eof152: + cs = 152; + goto _test_eof; + _test_eof153: + cs = 153; + goto _test_eof; + _test_eof154: + cs = 154; + goto _test_eof; + _test_eof155: + cs = 155; + goto _test_eof; + _test_eof75: + cs = 75; + goto _test_eof; + _test_eof156: + cs = 156; + goto _test_eof; + _test_eof157: + cs = 157; + goto _test_eof; + _test_eof158: + cs = 158; + goto _test_eof; + _test_eof159: + cs = 159; + goto _test_eof; + _test_eof160: + cs = 160; + goto _test_eof; + _test_eof161: + cs = 161; + goto _test_eof; + _test_eof162: + cs = 162; + goto _test_eof; + _test_eof163: + cs = 163; + goto _test_eof; + _test_eof76: + cs = 76; + goto _test_eof; + _test_eof77: + cs = 77; + goto _test_eof; + _test_eof78: + cs = 78; + goto _test_eof; + _test_eof79: + cs = 79; + goto _test_eof; + _test_eof80: + cs = 80; + goto _test_eof; + _test_eof81: + cs = 81; + goto _test_eof; + _test_eof82: + cs = 82; + goto _test_eof; + _test_eof83: + cs = 83; + goto _test_eof; + _test_eof164: + cs = 164; + goto _test_eof; + _test_eof165: + cs = 165; + goto _test_eof; + _test_eof166: + cs = 166; + goto _test_eof; + _test_eof167: + cs = 167; + goto _test_eof; + _test_eof168: + cs = 168; + goto _test_eof; + _test_eof84: + cs = 84; + goto _test_eof; + _test_eof169: + cs = 169; + goto _test_eof; + _test_eof170: + cs = 170; + goto _test_eof; + _test_eof171: + cs = 171; + goto _test_eof; + _test_eof172: + cs = 172; + goto _test_eof; + _test_eof173: + cs = 173; + goto _test_eof; + _test_eof174: + cs = 174; + goto _test_eof; + _test_eof175: + cs = 175; + goto _test_eof; + _test_eof176: + cs = 176; + goto _test_eof; + _test_eof85: + cs = 85; + goto _test_eof; - _test_eof: {} - _out: {} - } + _test_eof: + { + } + _out: + { + } + } #line 64 "src/Utils/IP.rl" // Ensure that the parsing has consumed all the given length. - if (ip_len == (size_t)(p - (const unsigned char*)ip)) + if (ipLen == (size_t)(p - (const unsigned char*)ip)) return ipFamily; else return AF_UNSPEC; } - void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, uint16_t* port) + void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string& ip, uint16_t* port) { MS_TRACE(); - char _ip[INET6_ADDRSTRLEN+1]; + char ipBuffer[INET6_ADDRSTRLEN + 1]; int err; switch (addr->sa_family) { case AF_INET: { - err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, - INET_ADDRSTRLEN); + err = + uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, ipBuffer, INET_ADDRSTRLEN); if (err) MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); @@ -3477,8 +4667,8 @@ case 85: case AF_INET6: { - err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, - INET6_ADDRSTRLEN); + err = uv_inet_ntop( + AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, ipBuffer, INET6_ADDRSTRLEN); if (err) MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); @@ -3493,6 +4683,6 @@ case 85: } *family = addr->sa_family; - ip.assign(_ip); + ip.assign(ipBuffer); } } diff --git a/worker/src/Utils/IP.rl b/worker/src/Utils/IP.rl index fc8533db02..5de9bd5411 100644 --- a/worker/src/Utils/IP.rl +++ b/worker/src/Utils/IP.rl @@ -7,7 +7,7 @@ namespace Utils { - int IP::GetFamily(const char *ip, size_t ip_len) + int IP::GetFamily(const char *ip, size_t ipLen) { MS_TRACE(); @@ -49,7 +49,7 @@ namespace Utils const unsigned char* pe; p = (const unsigned char*)ip; - pe = p + ip_len; + pe = p + ipLen; /** * Ragel: %%write init @@ -63,7 +63,7 @@ namespace Utils %%write exec; // Ensure that the parsing has consumed all the given length. - if (ip_len == (size_t)(p - (const unsigned char*)ip)) + if (ipLen == (size_t)(p - (const unsigned char*)ip)) return ipFamily; else return AF_UNSPEC; @@ -73,15 +73,15 @@ namespace Utils { MS_TRACE(); - char _ip[INET6_ADDRSTRLEN+1]; + char ipBuffer[INET6_ADDRSTRLEN+1]; int err; switch (addr->sa_family) { case AF_INET: { - err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, - INET_ADDRSTRLEN); + err = uv_inet_ntop( + AF_INET, &((struct sockaddr_in*)addr)->sin_addr, ipBuffer, INET_ADDRSTRLEN); if (err) MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); @@ -93,8 +93,8 @@ namespace Utils case AF_INET6: { - err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, - INET6_ADDRSTRLEN); + err = uv_inet_ntop( + AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, ipBuffer, INET6_ADDRSTRLEN); if (err) MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); @@ -109,6 +109,6 @@ namespace Utils } *family = addr->sa_family; - ip.assign(_ip); + ip.assign(ipBuffer); } } diff --git a/worker/src/handles/SignalsHandler.cpp b/worker/src/handles/SignalsHandler.cpp index c6c91b895c..8bdfc77ed9 100644 --- a/worker/src/handles/SignalsHandler.cpp +++ b/worker/src/handles/SignalsHandler.cpp @@ -3,27 +3,25 @@ #include "handles/SignalsHandler.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" /* Static methods for UV callbacks. */ -static inline -void on_signal(uv_signal_t* handle, int signum) +inline static void onSignal(uv_signal_t* handle, int signum) { static_cast(handle->data)->onUvSignal(signum); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { delete handle; } /* Instance methods. */ -SignalsHandler::SignalsHandler(Listener* listener) : - listener(listener) +SignalsHandler::SignalsHandler(Listener* listener) + : listener(listener) { MS_TRACE(); } @@ -35,16 +33,17 @@ void SignalsHandler::AddSignal(int signum, std::string name) int err; uv_signal_t* uvHandle = new uv_signal_t; - uvHandle->data = (void*)this; + uvHandle->data = (void*)this; err = uv_signal_init(DepLibUV::GetLoop(), uvHandle); if (err) { delete uvHandle; + MS_THROW_ERROR("uv_signal_init() failed for signal %s: %s", name.c_str(), uv_strerror(err)); } - err = uv_signal_start(uvHandle, (uv_signal_cb)on_signal, signum); + err = uv_signal_start(uvHandle, (uv_signal_cb)onSignal, signum); if (err) MS_THROW_ERROR("uv_signal_start() failed for signal %s: %s", name.c_str(), uv_strerror(err)); @@ -58,15 +57,14 @@ void SignalsHandler::Destroy() for (auto uvHandle : uvHandles) { - uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)uvHandle, (uv_close_cb)onClose); } // And delete this. delete this; } -inline -void SignalsHandler::onUvSignal(int signum) +inline void SignalsHandler::onUvSignal(int signum) { MS_TRACE(); diff --git a/worker/src/handles/TcpConnection.cpp b/worker/src/handles/TcpConnection.cpp index 9a1a06ad47..123a2db976 100644 --- a/worker/src/handles/TcpConnection.cpp +++ b/worker/src/handles/TcpConnection.cpp @@ -2,61 +2,56 @@ // #define MS_LOG_DEV #include "handles/TcpConnection.hpp" -#include "Utils.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" -#include // std::memcpy() +#include "MediaSoupError.hpp" +#include "Utils.hpp" #include // std::malloc(), std::free() +#include // std::memcpy() /* Static methods for UV callbacks. */ -static inline -void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) +inline static void onAlloc(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf) { - static_cast(handle->data)->onUvReadAlloc(suggested_size, buf); + static_cast(handle->data)->onUvReadAlloc(suggestedSize, buf); } -static inline -void on_read(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) +inline static void onRead(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static_cast(handle->data)->onUvRead(nread, buf); } -static inline -void on_write(uv_write_t* req, int status) +inline static void onWrite(uv_write_t* req, int status) { - TcpConnection::UvWriteData* write_data = static_cast(req->data); - TcpConnection* connection = write_data->connection; + TcpConnection::UvWriteData* writeData = static_cast(req->data); + TcpConnection* connection = writeData->connection; // Delete the UvWriteData struct (which includes the uv_req_t and the store char[]). - std::free(write_data); + std::free(writeData); // Just notify the TcpConnection when error. if (status) connection->onUvWriteError(status); } -static inline -void on_shutdown(uv_shutdown_t* req, int status) +inline static void onShutdown(uv_shutdown_t* req, int status) { static_cast(req->data)->onUvShutdown(req, status); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { static_cast(handle->data)->onUvClosed(); } /* Instance methods. */ -TcpConnection::TcpConnection(size_t bufferSize) : - bufferSize(bufferSize) +TcpConnection::TcpConnection(size_t bufferSize) + : bufferSize(bufferSize) { MS_TRACE(); - this->uvHandle = new uv_tcp_t; + this->uvHandle = new uv_tcp_t; this->uvHandle->data = (void*)this; // NOTE: Don't allocate the buffer here. Instead wait for the first uv_alloc_cb(). @@ -72,7 +67,8 @@ TcpConnection::~TcpConnection() delete[] this->buffer; } -void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort) +void TcpConnection::Setup( + Listener* listener, struct sockaddr_storage* localAddr, const std::string& localIP, uint16_t localPort) { MS_TRACE(); @@ -93,7 +89,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr // Set the local address. this->localAddr = localAddr; - this->localIP = localIP; + this->localIP = localIP; this->localPort = localPort; } @@ -119,25 +115,28 @@ void TcpConnection::Destroy() // Use uv_shutdown() so pending data to be written will be sent to the peer // before closing. uv_shutdown_t* req = new uv_shutdown_t; - req->data = (void*)this; - err = uv_shutdown(req, (uv_stream_t*)this->uvHandle, (uv_shutdown_cb)on_shutdown); + req->data = (void*)this; + err = uv_shutdown(req, (uv_stream_t*)this->uvHandle, (uv_shutdown_cb)onShutdown); if (err) MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err)); } // Otherwise directly close the socket. else { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } } void TcpConnection::Dump() const { MS_DUMP(""); - MS_DUMP(" [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]", - this->localIP.c_str(), (uint16_t)this->localPort, - this->peerIP.c_str(), (uint16_t)this->peerPort, - (!this->isClosing) ? "open" : "closed"); + MS_DUMP( + " [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]", + this->localIP.c_str(), + (uint16_t)this->localPort, + this->peerIP.c_str(), + (uint16_t)this->peerPort, + (!this->isClosing) ? "open" : "closed"); MS_DUMP(""); } @@ -150,7 +149,7 @@ void TcpConnection::Start() int err; - err = uv_read_start((uv_stream_t*)this->uvHandle, (uv_alloc_cb)on_alloc, (uv_read_cb)on_read); + err = uv_read_start((uv_stream_t*)this->uvHandle, (uv_alloc_cb)onAlloc, (uv_read_cb)onRead); if (err) MS_THROW_ERROR("uv_read_start() failed: %s", uv_strerror(err)); @@ -176,7 +175,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len) // First try uv_try_write(). In case it can not directly write all the given // data then build a uv_req_t and use uv_write(). - buffer = uv_buf_init((char*)data, len); + buffer = uv_buf_init((char*)data, len); written = uv_try_write((uv_stream_t*)this->uvHandle, &buffer, 1); // All the data was written. Done. @@ -187,7 +186,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len) // Cannot write any data at first time. Use uv_write(). else if (written == UV_EAGAIN || written == UV_ENOSYS) { - // Set written to 0 so pending_len can be properly calculated. + // Set written to 0 so pendingLen can be properly calculated. written = 0; } // Error. Should not happen. @@ -196,23 +195,24 @@ void TcpConnection::Write(const uint8_t* data, size_t len) MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); Destroy(); + return; } - // MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, len); - - size_t pending_len = len - written; + // MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", + // (size_t)written, len); + size_t pendingLen = len - written; // Allocate a special UvWriteData struct pointer. - UvWriteData* write_data = static_cast(std::malloc(sizeof(UvWriteData) + pending_len)); + UvWriteData* writeData = static_cast(std::malloc(sizeof(UvWriteData) + pendingLen)); - write_data->connection = this; - std::memcpy(write_data->store, data + written, pending_len); - write_data->req.data = (void*)write_data; + writeData->connection = this; + std::memcpy(writeData->store, data + written, pendingLen); + writeData->req.data = (void*)writeData; - buffer = uv_buf_init((char*)write_data->store, pending_len); + buffer = uv_buf_init((char*)writeData->store, pendingLen); - err = uv_write(&write_data->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)on_write); + err = uv_write(&writeData->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)onWrite); if (err) MS_ABORT("uv_write() failed: %s", uv_strerror(err)); } @@ -227,7 +227,7 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data if (len1 == 0 && len2 == 0) return; - size_t total_len = len1 + len2; + size_t totalLen = len1 + len2; uv_buf_t buffers[2]; int written; int err; @@ -237,17 +237,17 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data buffers[0] = uv_buf_init((char*)data1, len1); buffers[1] = uv_buf_init((char*)data2, len2); - written = uv_try_write((uv_stream_t*)this->uvHandle, buffers, 2); + written = uv_try_write((uv_stream_t*)this->uvHandle, buffers, 2); // All the data was written. Done. - if (written == (int)total_len) + if (written == (int)totalLen) { return; } // Cannot write any data at first time. Use uv_write(). else if (written == UV_EAGAIN || written == UV_ENOSYS) { - // Set written to 0 so pending_len can be properly calculated. + // Set written to 0 so pendingLen can be properly calculated. written = 0; } // Error. Should not happen. @@ -259,30 +259,31 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data return; } - // MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, total_len); + // MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", + // (size_t)written, totalLen); - size_t pending_len = total_len - written; + size_t pendingLen = totalLen - written; // Allocate a special UvWriteData struct pointer. - UvWriteData* write_data = static_cast(std::malloc(sizeof(UvWriteData) + pending_len)); + UvWriteData* writeData = static_cast(std::malloc(sizeof(UvWriteData) + pendingLen)); - write_data->connection = this; + writeData->connection = this; // If the first buffer was not entirely written then splice it. if ((size_t)written < len1) { - std::memcpy(write_data->store, data1 + (size_t)written, len1 - (size_t)written); - std::memcpy(write_data->store + (len1 - (size_t)written), data2, len2); + std::memcpy(writeData->store, data1 + (size_t)written, len1 - (size_t)written); + std::memcpy(writeData->store + (len1 - (size_t)written), data2, len2); } // Otherwise just take the pending data in the second buffer. else { - std::memcpy(write_data->store, data2 + ((size_t)written - len1), len2 - ((size_t)written - len1)); + std::memcpy(writeData->store, data2 + ((size_t)written - len1), len2 - ((size_t)written - len1)); } - write_data->req.data = (void*)write_data; + writeData->req.data = (void*)writeData; - uv_buf_t buffer = uv_buf_init((char*)write_data->store, pending_len); + uv_buf_t buffer = uv_buf_init((char*)writeData->store, pendingLen); - err = uv_write(&write_data->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)on_write); + err = uv_write(&writeData->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)onWrite); if (err) MS_ABORT("uv_write() failed: %s", uv_strerror(err)); } @@ -303,13 +304,13 @@ bool TcpConnection::SetPeerAddress() } int family; - Utils::IP::GetAddressInfo((const struct sockaddr*)&this->peerAddr, &family, this->peerIP, &this->peerPort); + Utils::IP::GetAddressInfo( + (const struct sockaddr*)&this->peerAddr, &family, this->peerIP, &this->peerPort); return true; } -inline -void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) +inline void TcpConnection::onUvReadAlloc(size_t suggestedSize, uv_buf_t* buf) { MS_TRACE(); @@ -318,7 +319,7 @@ void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) this->buffer = new uint8_t[this->bufferSize]; // Tell UV to write after the last data byte in the buffer. - buf->base = (char *)(this->buffer + this->bufferDataLen); + buf->base = (char*)(this->buffer + this->bufferDataLen); // Give UV all the remaining space in the buffer. if (this->bufferSize > this->bufferDataLen) { @@ -332,8 +333,7 @@ void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) } } -inline -void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) +inline void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) { MS_TRACE(); @@ -374,8 +374,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) } } -inline -void TcpConnection::onUvWriteError(int error) +inline void TcpConnection::onUvWriteError(int error) { MS_TRACE(); @@ -390,8 +389,7 @@ void TcpConnection::onUvWriteError(int error) Destroy(); } -inline -void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status) +inline void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status) { MS_TRACE(); @@ -403,11 +401,10 @@ void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status) } // Now do close the handle. - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } -inline -void TcpConnection::onUvClosed() +inline void TcpConnection::onUvClosed() { MS_TRACE(); diff --git a/worker/src/handles/TcpServer.cpp b/worker/src/handles/TcpServer.cpp index d33d485781..1614d5e6d7 100644 --- a/worker/src/handles/TcpServer.cpp +++ b/worker/src/handles/TcpServer.cpp @@ -2,41 +2,38 @@ // #define MS_LOG_DEV #include "handles/TcpServer.hpp" -#include "Utils.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" /* Static methods for UV callbacks. */ -static inline -void on_connection(uv_stream_t* handle, int status) +inline static void onConnection(uv_stream_t* handle, int status) { static_cast(handle->data)->onUvConnection(status); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { static_cast(handle->data)->onUvClosed(); } -static inline -void on_error_close(uv_handle_t* handle) +inline static void onErrorClose(uv_handle_t* handle) { delete handle; } /* Instance methods. */ -TcpServer::TcpServer(const std::string &ip, uint16_t port, int backlog) +TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog) { MS_TRACE(); int err; int flags = 0; - this->uvHandle = new uv_tcp_t; + this->uvHandle = new uv_tcp_t; this->uvHandle->data = (void*)this; err = uv_tcp_init(DepLibUV::GetLoop(), this->uvHandle); @@ -44,21 +41,22 @@ TcpServer::TcpServer(const std::string &ip, uint16_t port, int backlog) { delete this->uvHandle; this->uvHandle = nullptr; + MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err)); } - struct sockaddr_storage bind_addr; + struct sockaddr_storage bindAddr; switch (Utils::IP::GetFamily(ip)) { case AF_INET: - err = uv_ip4_addr(ip.c_str(), (int)port, (struct sockaddr_in*)&bind_addr); + err = uv_ip4_addr(ip.c_str(), (int)port, (struct sockaddr_in*)&bindAddr); if (err) MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); break; case AF_INET6: - err = uv_ip6_addr(ip.c_str(), (int)port, (struct sockaddr_in6*)&bind_addr); + err = uv_ip6_addr(ip.c_str(), (int)port, (struct sockaddr_in6*)&bindAddr); if (err) MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); // Don't also bind into IPv4 when listening in IPv6. @@ -66,35 +64,35 @@ TcpServer::TcpServer(const std::string &ip, uint16_t port, int backlog) break; default: - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("invalid binding IP '%s'", ip.c_str()); break; } - err = uv_tcp_bind(this->uvHandle, (const struct sockaddr*)&bind_addr, flags); + err = uv_tcp_bind(this->uvHandle, (const struct sockaddr*)&bindAddr, flags); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_tcp_bind() failed: %s", uv_strerror(err)); } - err = uv_listen((uv_stream_t*)this->uvHandle, backlog, (uv_connection_cb)on_connection); + err = uv_listen((uv_stream_t*)this->uvHandle, backlog, (uv_connection_cb)onConnection); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_listen() failed: %s", uv_strerror(err)); } // Set local address. if (!SetLocalAddress()) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("error setting local IP and port"); } } -TcpServer::TcpServer(uv_tcp_t* uvHandle, int backlog) : - uvHandle(uvHandle) +TcpServer::TcpServer(uv_tcp_t* uvHandle, int backlog) + : uvHandle(uvHandle) { MS_TRACE(); @@ -102,17 +100,17 @@ TcpServer::TcpServer(uv_tcp_t* uvHandle, int backlog) : this->uvHandle->data = (void*)this; - err = uv_listen((uv_stream_t*)this->uvHandle, backlog, (uv_connection_cb)on_connection); + err = uv_listen((uv_stream_t*)this->uvHandle, backlog, (uv_connection_cb)onConnection); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_listen() failed: %s", uv_strerror(err)); } // Set local address. if (!SetLocalAddress()) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("error setting local IP and port"); } } @@ -137,7 +135,7 @@ void TcpServer::Destroy() // If there are no connections then close now. if (this->connections.empty()) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } // Otherwise close all the connections (but not the TCP server). else @@ -147,6 +145,7 @@ void TcpServer::Destroy() for (auto it = this->connections.begin(); it != this->connections.end(); ++it) { TcpConnection* connection = *it; + connection->Destroy(); } } @@ -155,10 +154,12 @@ void TcpServer::Destroy() void TcpServer::Dump() const { MS_DUMP(""); - MS_DUMP(" [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]", - this->localIP.c_str(), (uint16_t)this->localPort, - (!this->isClosing) ? "open" : "closed", - this->connections.size()); + MS_DUMP( + " [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]", + this->localIP.c_str(), + (uint16_t)this->localPort, + (!this->isClosing) ? "open" : "closed", + this->connections.size()); MS_DUMP(""); } @@ -178,13 +179,13 @@ bool TcpServer::SetLocalAddress() } int family; - Utils::IP::GetAddressInfo((const struct sockaddr*)&this->localAddr, &family, this->localIP, &this->localPort); + Utils::IP::GetAddressInfo( + (const struct sockaddr*)&this->localAddr, &family, this->localIP, &this->localPort); return true; } -inline -void TcpServer::onUvConnection(int status) +inline void TcpServer::onUvConnection(int status) { MS_TRACE(); @@ -203,15 +204,17 @@ void TcpServer::onUvConnection(int status) // Notify the subclass so it provides an allocated derived class of TCPConnection. TcpConnection* connection = nullptr; userOnTcpConnectionAlloc(&connection); + MS_ASSERT(connection != nullptr, "TcpConnection pointer was not allocated by the user"); try { connection->Setup(this, &(this->localAddr), this->localIP, this->localPort); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { delete connection; + return; } @@ -228,7 +231,7 @@ void TcpServer::onUvConnection(int status) { connection->Start(); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("cannot run the TCP connection, closing the connection: %s", error.what()); @@ -242,8 +245,7 @@ void TcpServer::onUvConnection(int status) userOnNewTcpConnection(connection); } -inline -void TcpServer::onUvClosed() +inline void TcpServer::onUvClosed() { MS_TRACE(); @@ -254,8 +256,7 @@ void TcpServer::onUvClosed() delete this; } -inline -void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_by_peer) +inline void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool isClosedByPeer) { MS_TRACE(); @@ -278,10 +279,10 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_ this->connections.erase(connection); // Notify the subclass. - userOnTcpConnectionClosed(connection, is_closed_by_peer); + userOnTcpConnectionClosed(connection, isClosedByPeer); // Check if the server was closing connections, and if this is the last // connection then close the server now. if (wasClosing && this->connections.empty()) - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } diff --git a/worker/src/handles/Timer.cpp b/worker/src/handles/Timer.cpp index b577ea6c62..d6f5839510 100644 --- a/worker/src/handles/Timer.cpp +++ b/worker/src/handles/Timer.cpp @@ -2,28 +2,26 @@ // #define MS_LOG_DEV #include "handles/Timer.hpp" -#include "MediaSoupError.hpp" #include "DepLibUV.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" /* Static methods for UV callbacks. */ -static inline -void on_timer(uv_timer_t* handle) +inline static void onTimer(uv_timer_t* handle) { static_cast(handle->data)->onUvTimer(); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { delete handle; } /* Instance methods. */ -Timer::Timer(Listener* listener) : - listener(listener) +Timer::Timer(Listener* listener) + : listener(listener) { MS_TRACE(); @@ -37,6 +35,7 @@ Timer::Timer(Listener* listener) : { delete this->uvHandle; this->uvHandle = nullptr; + MS_THROW_ERROR("uv_timer_init() failed: %s", uv_strerror(err)); } } @@ -45,7 +44,7 @@ void Timer::Destroy() { MS_TRACE(); - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); // Delete this. delete this; @@ -60,7 +59,7 @@ void Timer::Start(uint64_t timeout) if (uv_is_active((uv_handle_t*)this->uvHandle)) Stop(); - err = uv_timer_start(this->uvHandle, (uv_timer_cb)on_timer, timeout, 0); + err = uv_timer_start(this->uvHandle, (uv_timer_cb)onTimer, timeout, 0); if (err) MS_THROW_ERROR("uv_timer_start() failed: %s", uv_strerror(err)); } @@ -76,8 +75,7 @@ void Timer::Stop() MS_THROW_ERROR("uv_timer_stop() failed: %s", uv_strerror(err)); } -inline -void Timer::onUvTimer() +inline void Timer::onUvTimer() { MS_TRACE(); diff --git a/worker/src/handles/UdpSocket.cpp b/worker/src/handles/UdpSocket.cpp index 084fe6794f..2b236786cc 100644 --- a/worker/src/handles/UdpSocket.cpp +++ b/worker/src/handles/UdpSocket.cpp @@ -2,67 +2,62 @@ // #define MS_LOG_DEV #include "handles/UdpSocket.hpp" -#include "Utils.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" +#include "MediaSoupError.hpp" +#include "Utils.hpp" + +/* Static. */ -#define MS_READ_BUFFER_SIZE 65536 +static constexpr size_t ReadBufferSize = 65536; +static uint8_t ReadBuffer[ReadBufferSize]; /* Static methods for UV callbacks. */ -static inline -void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) +inline static void onAlloc(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf) { - static_cast(handle->data)->onUvRecvAlloc(suggested_size, buf); + static_cast(handle->data)->onUvRecvAlloc(suggestedSize, buf); } -static inline -void on_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) +inline static void onRecv( + uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) { static_cast(handle->data)->onUvRecv(nread, buf, addr, flags); } -static inline -void on_send(uv_udp_send_t* req, int status) +inline static void onSend(uv_udp_send_t* req, int status) { - UdpSocket::UvSendData* send_data = static_cast(req->data); - UdpSocket* socket = send_data->socket; + UdpSocket::UvSendData* sendData = static_cast(req->data); + UdpSocket* socket = sendData->socket; // Delete the UvSendData struct (which includes the uv_req_t and the store char[]). - std::free(send_data); + std::free(sendData); // Just notify the UdpSocket when error. if (status) socket->onUvSendError(status); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { static_cast(handle->data)->onUvClosed(); } -static inline -void on_error_close(uv_handle_t* handle) +inline static void onErrorClose(uv_handle_t* handle) { delete handle; } -/* Class variables. */ - -uint8_t UdpSocket::readBuffer[MS_READ_BUFFER_SIZE]; - /* Instance methods. */ -UdpSocket::UdpSocket(const std::string &ip, uint16_t port) +UdpSocket::UdpSocket(const std::string& ip, uint16_t port) { MS_TRACE(); int err; int flags = 0; - this->uvHandle = new uv_udp_t; + this->uvHandle = new uv_udp_t; this->uvHandle->data = (void*)this; err = uv_udp_init(DepLibUV::GetLoop(), this->uvHandle); @@ -70,6 +65,7 @@ UdpSocket::UdpSocket(const std::string &ip, uint16_t port) { delete this->uvHandle; this->uvHandle = nullptr; + MS_THROW_ERROR("uv_udp_init() failed: %s", uv_strerror(err)); } @@ -92,7 +88,7 @@ UdpSocket::UdpSocket(const std::string &ip, uint16_t port) break; default: - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("invalid binding IP '%s'", ip.c_str()); break; } @@ -100,27 +96,27 @@ UdpSocket::UdpSocket(const std::string &ip, uint16_t port) err = uv_udp_bind(this->uvHandle, (const struct sockaddr*)&bind_addr, flags); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_udp_bind() failed: %s", uv_strerror(err)); } - err = uv_udp_recv_start(this->uvHandle, (uv_alloc_cb)on_alloc, (uv_udp_recv_cb)on_recv); + err = uv_udp_recv_start(this->uvHandle, (uv_alloc_cb)onAlloc, (uv_udp_recv_cb)onRecv); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_udp_recv_start() failed: %s", uv_strerror(err)); } // Set local address. if (!SetLocalAddress()) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("error setting local IP and port"); } } -UdpSocket::UdpSocket(uv_udp_t* uvHandle) : - uvHandle(uvHandle) +UdpSocket::UdpSocket(uv_udp_t* uvHandle) + : uvHandle(uvHandle) { MS_TRACE(); @@ -128,17 +124,17 @@ UdpSocket::UdpSocket(uv_udp_t* uvHandle) : this->uvHandle->data = (void*)this; - err = uv_udp_recv_start(this->uvHandle, (uv_alloc_cb)on_alloc, (uv_udp_recv_cb)on_recv); + err = uv_udp_recv_start(this->uvHandle, (uv_alloc_cb)onAlloc, (uv_udp_recv_cb)onRecv); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("uv_udp_recv_start() failed: %s", uv_strerror(err)); } // Set local address. if (!SetLocalAddress()) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); MS_THROW_ERROR("error setting local IP and port"); } } @@ -167,15 +163,17 @@ void UdpSocket::Destroy() if (err) MS_ABORT("uv_udp_recv_stop() failed: %s", uv_strerror(err)); - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } void UdpSocket::Dump() const { MS_DUMP(""); - MS_DUMP(" [UDP, local:%s :%" PRIu16 ", status:%s]", - this->localIP.c_str(), (uint16_t)this->localPort, - (!this->isClosing) ? "open" : "closed"); + MS_DUMP( + " [UDP, local:%s :%" PRIu16 ", status:%s]", + this->localIP.c_str(), + (uint16_t)this->localPort, + (!this->isClosing) ? "open" : "closed"); MS_DUMP(""); } @@ -197,7 +195,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add // then build a uv_req_t and use uv_udp_send(). buffer = uv_buf_init((char*)data, len); - sent = uv_udp_try_send(this->uvHandle, &buffer, 1, addr); + sent = uv_udp_try_send(this->uvHandle, &buffer, 1, addr); // Entire datagram was sent. Done. if (sent == (int)len) @@ -222,15 +220,15 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add // MS_DEBUG_DEV("could not send the datagram at first time, using uv_udp_send() now"); // Allocate a special UvSendData struct pointer. - UvSendData* send_data = static_cast(std::malloc(sizeof(UvSendData) + len)); + UvSendData* sendData = static_cast(std::malloc(sizeof(UvSendData) + len)); - send_data->socket = this; - std::memcpy(send_data->store, data, len); - send_data->req.data = (void*)send_data; + sendData->socket = this; + std::memcpy(sendData->store, data, len); + sendData->req.data = (void*)sendData; - buffer = uv_buf_init((char*)send_data->store, len); + buffer = uv_buf_init((char*)sendData->store, len); - err = uv_udp_send(&send_data->req, this->uvHandle, &buffer, 1, addr, (uv_udp_send_cb)on_send); + err = uv_udp_send(&sendData->req, this->uvHandle, &buffer, 1, addr, (uv_udp_send_cb)onSend); if (err) { // NOTE: uv_udp_send() returns error if a wrong INET family is given @@ -238,11 +236,11 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add MS_WARN_DEV("uv_udp_send() failed: %s", uv_strerror(err)); // Delete the UvSendData struct (which includes the uv_req_t and the store char[]). - std::free(send_data); + std::free(sendData); } } -void UdpSocket::Send(const uint8_t* data, size_t len, const std::string &ip, uint16_t port) +void UdpSocket::Send(const uint8_t* data, size_t len, const std::string& ip, uint16_t port) { MS_TRACE(); @@ -295,24 +293,24 @@ bool UdpSocket::SetLocalAddress() } int family; - Utils::IP::GetAddressInfo((const struct sockaddr*)&this->localAddr, &family, this->localIP, &this->localPort); + Utils::IP::GetAddressInfo( + (const struct sockaddr*)&this->localAddr, &family, this->localIP, &this->localPort); return true; } -inline -void UdpSocket::onUvRecvAlloc(size_t suggested_size, uv_buf_t* buf) +inline void UdpSocket::onUvRecvAlloc(size_t suggestedSize, uv_buf_t* buf) { MS_TRACE(); // Tell UV to write into the static buffer. - buf->base = (char *)UdpSocket::readBuffer; + buf->base = (char*)ReadBuffer; // Give UV all the buffer space. - buf->len = MS_READ_BUFFER_SIZE; + buf->len = ReadBufferSize; } -inline -void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) +inline void UdpSocket::onUvRecv( + ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) { MS_TRACE(); @@ -338,7 +336,6 @@ void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad // Notify the subclass. userOnUdpDatagramRecv((uint8_t*)buf->base, nread, addr); } - // Some error. else { @@ -346,8 +343,7 @@ void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad } } -inline -void UdpSocket::onUvSendError(int error) +inline void UdpSocket::onUvSendError(int error) { MS_TRACE(); @@ -357,8 +353,7 @@ void UdpSocket::onUvSendError(int error) MS_DEBUG_DEV("send error: %s", uv_strerror(error)); } -inline -void UdpSocket::onUvClosed() +inline void UdpSocket::onUvClosed() { MS_TRACE(); diff --git a/worker/src/handles/UnixStreamSocket.cpp b/worker/src/handles/UnixStreamSocket.cpp index a2c839d8f1..5655d891f9 100644 --- a/worker/src/handles/UnixStreamSocket.cpp +++ b/worker/src/handles/UnixStreamSocket.cpp @@ -8,67 +8,61 @@ #include "handles/UnixStreamSocket.hpp" #include "DepLibUV.hpp" -#include "MediaSoupError.hpp" #include "Logger.hpp" -#include // std::memcpy() +#include "MediaSoupError.hpp" #include // std::malloc(), std::free() +#include // std::memcpy() /* Static methods for UV callbacks. */ -static inline -void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) +inline static void onAlloc(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf) { - static_cast(handle->data)->onUvReadAlloc(suggested_size, buf); + static_cast(handle->data)->onUvReadAlloc(suggestedSize, buf); } -static inline -void on_read(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) +inline static void onRead(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static_cast(handle->data)->onUvRead(nread, buf); } -static inline -void on_write(uv_write_t* req, int status) +inline static void onWrite(uv_write_t* req, int status) { - UnixStreamSocket::UvWriteData* write_data = static_cast(req->data); - UnixStreamSocket* socket = write_data->socket; + UnixStreamSocket::UvWriteData* writeData = static_cast(req->data); + UnixStreamSocket* socket = writeData->socket; // Delete the UvWriteData struct (which includes the uv_req_t and the store char[]). - std::free(write_data); + std::free(writeData); // Just notify the UnixStreamSocket when error. if (status) socket->onUvWriteError(status); } -static inline -void on_shutdown(uv_shutdown_t* req, int status) +inline static void onShutdown(uv_shutdown_t* req, int status) { static_cast(req->data)->onUvShutdown(req, status); } -static inline -void on_close(uv_handle_t* handle) +inline static void onClose(uv_handle_t* handle) { static_cast(handle->data)->onUvClosed(); } -static inline -void on_error_close(uv_handle_t* handle) +inline static void onErrorClose(uv_handle_t* handle) { delete handle; } /* Instance methods. */ -UnixStreamSocket::UnixStreamSocket(int fd, size_t bufferSize) : - bufferSize(bufferSize) +UnixStreamSocket::UnixStreamSocket(int fd, size_t bufferSize) + : bufferSize(bufferSize) { MS_TRACE_STD(); int err; - this->uvHandle = new uv_pipe_t; + this->uvHandle = new uv_pipe_t; this->uvHandle->data = (void*)this; err = uv_pipe_init(DepLibUV::GetLoop(), this->uvHandle, 0); @@ -76,21 +70,24 @@ UnixStreamSocket::UnixStreamSocket(int fd, size_t bufferSize) : { delete this->uvHandle; this->uvHandle = nullptr; + MS_THROW_ERROR_STD("uv_pipe_init() failed: %s", uv_strerror(err)); } err = uv_pipe_open(this->uvHandle, fd); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); + MS_THROW_ERROR_STD("uv_pipe_open() failed: %s", uv_strerror(err)); } // Start reading. - err = uv_read_start((uv_stream_t*)this->uvHandle, (uv_alloc_cb)on_alloc, (uv_read_cb)on_read); + err = uv_read_start((uv_stream_t*)this->uvHandle, (uv_alloc_cb)onAlloc, (uv_read_cb)onRead); if (err) { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_error_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onErrorClose); + MS_THROW_ERROR_STD("uv_read_start() failed: %s", uv_strerror(err)); } @@ -128,15 +125,15 @@ void UnixStreamSocket::Destroy() { // Use uv_shutdown() so pending data to be written will be sent to the peer before closing. uv_shutdown_t* req = new uv_shutdown_t; - req->data = (void*)this; - err = uv_shutdown(req, (uv_stream_t*)this->uvHandle, (uv_shutdown_cb)on_shutdown); + req->data = (void*)this; + err = uv_shutdown(req, (uv_stream_t*)this->uvHandle, (uv_shutdown_cb)onShutdown); if (err) MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err)); } // Otherwise directly close the socket. else { - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } } @@ -155,7 +152,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) // First try uv_try_write(). In case it can not directly send all the given data // then build a uv_req_t and use uv_write(). - buffer = uv_buf_init((char*)data, len); + buffer = uv_buf_init((char*)data, len); written = uv_try_write((uv_stream_t*)this->uvHandle, &buffer, 1); // All the data was written. Done. @@ -166,7 +163,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) // Cannot write any data at first time. Use uv_write(). else if (written == UV_EAGAIN || written == UV_ENOSYS) { - // Set written to 0 so pending_len can be properly calculated. + // Set written to 0 so pendingLen can be properly calculated. written = 0; } // Error. Should not happen. @@ -175,27 +172,27 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) MS_ERROR_STD("uv_try_write() failed, closing the socket: %s", uv_strerror(written)); Destroy(); + return; } - size_t pending_len = len - written; + size_t pendingLen = len - written; // Allocate a special UvWriteData struct pointer. - UvWriteData* write_data = static_cast(std::malloc(sizeof(UvWriteData) + pending_len)); + UvWriteData* writeData = static_cast(std::malloc(sizeof(UvWriteData) + pendingLen)); - write_data->socket = this; - std::memcpy(write_data->store, data + written, pending_len); - write_data->req.data = (void*)write_data; + writeData->socket = this; + std::memcpy(writeData->store, data + written, pendingLen); + writeData->req.data = (void*)writeData; - buffer = uv_buf_init((char*)write_data->store, pending_len); + buffer = uv_buf_init((char*)writeData->store, pendingLen); - err = uv_write(&write_data->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)on_write); + err = uv_write(&writeData->req, (uv_stream_t*)this->uvHandle, &buffer, 1, (uv_write_cb)onWrite); if (err) MS_ABORT("uv_write() failed: %s", uv_strerror(err)); } -inline -void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) +inline void UnixStreamSocket::onUvReadAlloc(size_t suggestedSize, uv_buf_t* buf) { MS_TRACE_STD(); @@ -204,7 +201,7 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) this->buffer = new uint8_t[this->bufferSize]; // Tell UV to write after the last data byte in the buffer. - buf->base = (char *)(this->buffer + this->bufferDataLen); + buf->base = (char*)(this->buffer + this->bufferDataLen); // Give UV all the remaining space in the buffer. if (this->bufferSize > this->bufferDataLen) { @@ -218,8 +215,7 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) } } -inline -void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) +inline void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) { MS_TRACE_STD(); @@ -255,8 +251,7 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) } } -inline -void UnixStreamSocket::onUvWriteError(int error) +inline void UnixStreamSocket::onUvWriteError(int error) { MS_TRACE_STD(); @@ -271,8 +266,7 @@ void UnixStreamSocket::onUvWriteError(int error) Destroy(); } -inline -void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status) +inline void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status) { MS_TRACE_STD(); @@ -284,11 +278,10 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status) } // Now do close the handle. - uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); + uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)onClose); } -inline -void UnixStreamSocket::onUvClosed() +inline void UnixStreamSocket::onUvClosed() { MS_TRACE_STD(); diff --git a/worker/src/main.cpp b/worker/src/main.cpp index 66d2384a7e..41c7d8e06f 100644 --- a/worker/src/main.cpp +++ b/worker/src/main.cpp @@ -2,27 +2,27 @@ // #define MS_LOG_DEV #include "common.hpp" -#include "Settings.hpp" +#include "DepLibSRTP.hpp" #include "DepLibUV.hpp" #include "DepOpenSSL.hpp" -#include "DepLibSRTP.hpp" +#include "Logger.hpp" +#include "Loop.hpp" +#include "MediaSoupError.hpp" +#include "Settings.hpp" #include "Utils.hpp" #include "Channel/UnixStreamSocket.hpp" -#include "RTC/UdpSocket.hpp" -#include "RTC/TcpServer.hpp" #include "RTC/DtlsTransport.hpp" #include "RTC/SrtpSession.hpp" -#include "Loop.hpp" -#include "MediaSoupError.hpp" -#include "Logger.hpp" +#include "RTC/TcpServer.hpp" +#include "RTC/UdpSocket.hpp" +#include +#include +#include // sigaction() +#include // std::_Exit(), std::genenv() +#include // std::cout, std::cerr, std::endl #include #include -#include // std::cout, std::cerr, std::endl -#include // std::_Exit(), std::genenv() -#include // sigaction() -#include #include // getpid(), usleep() -#include static void init(); static void ignoreSignals(); @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) } std::string id = std::string(argv[1]); - int channelFd = std::stoi(std::getenv("MEDIASOUP_CHANNEL_FD")); + int channelFd = std::stoi(std::getenv("MEDIASOUP_CHANNEL_FD")); // Initialize libuv stuff (we need it for the Channel). DepLibUV::ClassInit(); @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) { Settings::SetConfiguration(argc, argv); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR("configuration error: %s", error.what()); @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) // Print the effective configuration. Settings::PrintConfiguration(); - MS_DEBUG_TAG(info, "starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid()); + MS_DEBUG_TAG(info, "starting mediasoup-worker [pid:%ld]", (long)getpid()); #if defined(MS_LITTLE_ENDIAN) MS_DEBUG_TAG(info, "Little-Endian CPU detected"); @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) destroy(); exitSuccess(); } - catch (const MediaSoupError &error) + catch (const MediaSoupError& error) { MS_ERROR_STD("failure exit: %s", error.what()); @@ -127,31 +127,24 @@ void ignoreSignals() int err; struct sigaction act; - std::map ignoredSignals = - { - { "PIPE", SIGPIPE }, - { "HUP", SIGHUP }, - { "ALRM", SIGALRM }, - { "USR1", SIGUSR2 }, - { "USR2", SIGUSR1 } - }; + std::map ignoredSignals = { + {"PIPE", SIGPIPE}, {"HUP", SIGHUP}, {"ALRM", SIGALRM}, {"USR1", SIGUSR2}, {"USR2", SIGUSR1}}; act.sa_handler = SIG_IGN; - act.sa_flags = 0; - err = sigfillset(&act.sa_mask); + act.sa_flags = 0; + err = sigfillset(&act.sa_mask); if (err) MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno)); for (auto it = ignoredSignals.begin(); it != ignoredSignals.end(); ++it) { auto& sigName = it->first; - int sigId = it->second; + int sigId = it->second; err = sigaction(sigId, &act, nullptr); if (err) { - MS_THROW_ERROR("sigaction() failed for signal %s: %s", - sigName.c_str(), std::strerror(errno)); + MS_THROW_ERROR("sigaction() failed for signal %s: %s", sigName.c_str(), std::strerror(errno)); } } } diff --git a/worker/test/include/helpers.hpp b/worker/test/include/helpers.hpp index 7964ca27e9..ee2fcbe240 100644 --- a/worker/test/include/helpers.hpp +++ b/worker/test/include/helpers.hpp @@ -10,9 +10,9 @@ class Helpers public: static bool ReadBinaryFile(const char* file, uint8_t* buffer, size_t* len) { - std::string file_path = "test/" + std::string(file); + std::string filePath = "test/" + std::string(file); - std::ifstream in(file_path, std::ios::ate | std::ios::binary); + std::ifstream in(filePath, std::ios::ate | std::ios::binary); if (!in) return false; diff --git a/worker/test/test-bitrate.cpp b/worker/test/test-bitrate.cpp index c1874ad86c..92bee16085 100644 --- a/worker/test/test-bitrate.cpp +++ b/worker/test/test-bitrate.cpp @@ -13,14 +13,14 @@ struct data uint32_t rate; }; -void validate(RateCalculator& rate, uint64_t time_base, std::vector& input) +void validate(RateCalculator& rate, uint64_t timeBase, std::vector& input) { for (auto it = input.begin(); it != input.end(); ++it) { auto& item = *it; - rate.Update(item.size, time_base + item.offset); - REQUIRE(rate.GetRate(time_base + item.offset) == item.rate); + rate.Update(item.size, timeBase + item.offset); + REQUIRE(rate.GetRate(timeBase + item.offset) == item.rate); } } diff --git a/worker/test/test-nack.cpp b/worker/test/test-nack.cpp index 947afd4572..9ff5d6895c 100644 --- a/worker/test/test-nack.cpp +++ b/worker/test/test-nack.cpp @@ -15,48 +15,57 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]") { SECTION("receive NACK and get retransmitted packets") { - uint8_t rtp_buffer1[] = + uint8_t rtpBuffer1[] = { 0b10000000, 0b01111011, 0b01010010, 0b00001110, 0b01011011, 0b01101011, 0b11001010, 0b10110101, 0, 0, 0, 2 }; - uint8_t rtp_buffer2[65536]; - uint8_t rtp_buffer3[65536]; - uint8_t rtp_buffer4[65536]; - uint8_t rtp_buffer5[65536]; + uint8_t rtpBuffer2[65536]; + uint8_t rtpBuffer3[65536]; + uint8_t rtpBuffer4[65536]; + uint8_t rtpBuffer5[65536]; // packet1 [pt:123, seq:21006, timestamp:1533790901] - RtpPacket* packet1 = RtpPacket::Parse(rtp_buffer1, sizeof(rtp_buffer1)); + RtpPacket* packet1 = RtpPacket::Parse(rtpBuffer1, sizeof(rtpBuffer1)); + REQUIRE(packet1); REQUIRE(packet1->GetSequenceNumber() == 21006); REQUIRE(packet1->GetTimestamp() == 1533790901); // packet2 [pt:123, seq:21007, timestamp:1533790901] - RtpPacket* packet2 = packet1->Clone(rtp_buffer2); + RtpPacket* packet2 = packet1->Clone(rtpBuffer2); + packet2->SetSequenceNumber(21007); packet2->SetTimestamp(1533790901); + REQUIRE(packet2->GetSequenceNumber() == 21007); REQUIRE(packet2->GetTimestamp() == 1533790901); // packet3 [pt:123, seq:21008, timestamp:1533793871] - RtpPacket* packet3 = packet1->Clone(rtp_buffer3); + RtpPacket* packet3 = packet1->Clone(rtpBuffer3); + packet3->SetSequenceNumber(21008); packet3->SetTimestamp(1533793871); + REQUIRE(packet3->GetSequenceNumber() == 21008); REQUIRE(packet3->GetTimestamp() == 1533793871); // packet4 [pt:123, seq:21009, timestamp:1533793871] - RtpPacket* packet4 = packet1->Clone(rtp_buffer4); + RtpPacket* packet4 = packet1->Clone(rtpBuffer4); + packet4->SetSequenceNumber(21009); packet4->SetTimestamp(1533793871); + REQUIRE(packet4->GetSequenceNumber() == 21009); REQUIRE(packet4->GetTimestamp() == 1533793871); // packet5 [pt:123, seq:21010, timestamp:1533796931] - RtpPacket* packet5 = packet1->Clone(rtp_buffer5); + RtpPacket* packet5 = packet1->Clone(rtpBuffer5); + packet5->SetSequenceNumber(21010); packet5->SetTimestamp(1533796931); + REQUIRE(packet5->GetSequenceNumber() == 21010); REQUIRE(packet5->GetTimestamp() == 1533796931); @@ -77,11 +86,13 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]") stream->ReceivePacket(packet5); // Create a NACK item that request for all the packets. - RTCP::FeedbackRtpNackItem nack_item(21006, 0b0000000000001111); - REQUIRE(nack_item.GetPacketId() == 21006); - REQUIRE(nack_item.GetLostPacketBitmask() == 0b0000000000001111); + RTCP::FeedbackRtpNackItem nackItem(21006, 0b0000000000001111); + + REQUIRE(nackItem.GetPacketId() == 21006); + REQUIRE(nackItem.GetLostPacketBitmask() == 0b0000000000001111); - stream->RequestRtpRetransmission(nack_item.GetPacketId(), nack_item.GetLostPacketBitmask(), rtpRetransmissionContainer); + stream->RequestRtpRetransmission( + nackItem.GetPacketId(), nackItem.GetLostPacketBitmask(), rtpRetransmissionContainer); auto rtxPacket1 = rtpRetransmissionContainer[0]; auto rtxPacket2 = rtpRetransmissionContainer[1]; diff --git a/worker/test/test-rtcp.cpp b/worker/test/test-rtcp.cpp index 764ee05b27..60f2ce325a 100644 --- a/worker/test/test-rtcp.cpp +++ b/worker/test/test-rtcp.cpp @@ -111,7 +111,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") SdesItem::Type type = SdesItem::Type::CNAME; std::string value = "outChannel"; size_t len = value.size(); - SdesChunk* chunk = SdesChunk::Parse(buffer, sizeof(buffer)); REQUIRE(chunk->GetSsrc() == ssrc); @@ -131,12 +130,12 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") SdesItem::Type type = SdesItem::Type::CNAME; std::string value = "outChannel"; size_t len = value.size(); - // Create sdes item. SdesItem* item = new SdesItem(type, len, value.c_str()); // Create sdes chunk. SdesChunk chunk(ssrc); + chunk.AddItem(item); // Check chunk content. @@ -168,7 +167,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t rtpTs = 1234; uint32_t packetCount = 1234; uint32_t octetCount = 1234; - SenderReport* report = SenderReport::Parse(buffer, sizeof(SenderReport::Header)); REQUIRE(report); @@ -191,7 +189,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t rtpTs = 1234; uint32_t packetCount = 1234; uint32_t octetCount = 1234; - // Create local report and check content. // SenderReport(); SenderReport report1; @@ -227,9 +224,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint8_t buffer[] = { 0x00, 0x00, 0x04, 0xD2, // ssrc - 0x01, // fraction_lost - 0x00, 0x00, 0x04, // total_lost - 0x00, 0x00, 0x04, 0xD2, // last_seq + 0x01, // fractionLost + 0x00, 0x00, 0x04, // totalLost + 0x00, 0x00, 0x04, 0xD2, // lastSeq 0x00, 0x00, 0x04, 0xD2, // jitter 0x00, 0x00, 0x04, 0xD2, // lsr 0x00, 0x00, 0x04, 0xD2 // dlsr @@ -242,11 +239,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t jitter = 1234; uint32_t lastSenderReport = 1234; uint32_t delaySinceLastSenderReport = 1234; - ReceiverReport* report = ReceiverReport::Parse(buffer, sizeof(ReceiverReport::Header)); REQUIRE(report); - REQUIRE(report->GetSsrc() == ssrc); REQUIRE(report->GetFractionLost() == fractionLost); REQUIRE(report->GetTotalLost() == totalLost); @@ -265,7 +260,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t jitter = 1234; uint32_t lastSenderReport = 1234; uint32_t delaySinceLastSenderReport = 1234; - // Create local report and check content. // ReceiverReport(); ReceiverReport report1; @@ -304,7 +298,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t ssrc1 = 1111; uint32_t ssrc2 = 2222; std::string reason("hasta la vista"); - // Create local Bye packet and check content. // ByePacket(); ByePacket bye1; @@ -322,6 +315,7 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") // Locally store the content of the packet. uint8_t buffer[bye1.GetSize()]; + bye1.Serialize(buffer); // Parse the buffer of the previous packet and check content. @@ -341,10 +335,8 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") { 0x09, 0xc4, 0b10101010, 0b01010101 }; - uint16_t packetId = 2500; uint16_t lostPacketBitmask = 0b1010101001010101; - FeedbackRtpNackItem* item = FeedbackRtpNackItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -358,7 +350,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") { uint16_t packetId = 1; uint16_t lostPacketBitmask = 0b1010101001010101; - // Create local NackItem and check content. // FeedbackRtpNackItem(); FeedbackRtpNackItem item1(packetId, lostPacketBitmask); @@ -391,8 +382,8 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint32_t ssrc = 1234; uint64_t bitrate = 3000000; // bits per second. uint32_t overhead = 1; - FeedbackRtpTmmbrItem item; + item.SetSsrc(ssrc); item.SetBitrate(bitrate); item.SetOverhead(overhead); @@ -402,7 +393,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") REQUIRE(item.GetOverhead() == overhead); uint8_t buffer[8]; + item.Serialize(buffer); + FeedbackRtpTmmbrItem* item2 = FeedbackRtpTmmbrItem::Parse(buffer, sizeof(buffer)); REQUIRE(item2); @@ -420,11 +413,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0xba, 0xac, 0x8c, 0xcd, 0x18, 0x2c, 0x9e, 0x00 }; - uint32_t ssrc = 3131870413; uint64_t bitrate = 365504; uint16_t overhead = 0; - FeedbackRtpTmmbrItem* item = FeedbackRtpTmmbrItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -446,18 +437,16 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0xba, 0xac, 0x8c, 0xcd, 0x18, 0x2c, 0x9e, 0x00 }; - uint32_t ssrc = 3131870413; uint64_t bitrate = 365504; uint16_t overhead = 0; - FeedbackRtpTmmbrPacket* packet = FeedbackRtpTmmbrPacket::Parse(buffer, sizeof(buffer)); REQUIRE(packet); - REQUIRE(packet->Begin() != packet->End()); FeedbackRtpTmmbrItem* item = (*packet->Begin()); + REQUIRE(item->GetSsrc() == ssrc); REQUIRE(item->GetBitrate() == bitrate); REQUIRE(item->GetOverhead() == overhead); @@ -471,10 +460,8 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") { 0x00, 0x01, 0b10101010, 0b01010101 }; - uint16_t packetId = 1; uint16_t lostPacketBitmask = 0b1010101001010101; - FeedbackRtpTlleiItem* item = FeedbackRtpTlleiItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -496,7 +483,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x00, 0x01, // Lost Packets Counter 0x00, 0x01 // Duplication Counter }; - uint32_t sequenceNumber = 1; uint32_t ect0Counter = 1; uint32_t ect1Counter = 1; @@ -504,7 +490,6 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") uint16_t notEctCounter = 1; uint16_t lostPackets = 1; uint16_t duplicatedPackets = 1; - FeedbackRtpEcnItem* item = FeedbackRtpEcnItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -525,11 +510,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") { 0x00, 0x08, 0x01, 0x01 }; - uint16_t first = 1; uint16_t number = 4; uint8_t pictureId = 1; - FeedbackPsSliItem* item = FeedbackPsSliItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -549,11 +532,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x00, 0x00, // Native RPSI bit string 0x00, 0x00, 0x01, 0x00 }; - uint8_t payloadType = 1; uint8_t payloadMask = 1; size_t length = 5; - FeedbackPsRpsiItem* item = FeedbackPsRpsiItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -571,10 +552,8 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x00, 0x00, 0x00, 0x00, // SSRC 0x08, 0x00, 0x00, 0x00 // Seq nr. }; - uint32_t ssrc = 0; uint8_t seq = 8; - FeedbackPsFirItem* item = FeedbackPsFirItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -592,11 +571,9 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x08, // Seq nr. 0x00, 0x00, 0x08 // Reserved | Index }; - uint32_t ssrc = 0; uint8_t seq = 8; uint8_t index = 1; - FeedbackPsTstnItem* item = FeedbackPsTstnItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -618,13 +595,11 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x01, // VBCM Octet String 0x00, 0x00, 0x00 // Padding }; - uint32_t ssrc = 0; uint8_t seq = 8; uint8_t payloadType = 1; uint16_t length = 1; uint8_t valueMask = 1; - FeedbackPsVbcmItem* item = FeedbackPsVbcmItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -643,9 +618,7 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") { 0x00, 0x00, 0x00, 0x01 // SSRC }; - uint32_t ssrc = 1; - FeedbackPsLeiItem* item = FeedbackPsLeiItem::Parse(buffer, sizeof(buffer)); REQUIRE(item); @@ -663,10 +636,8 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") 0x00, 0x00, 0x00, 0x00, // Media SSRC 0x00, 0x00, 0x00, 0x01 // Data }; - size_t dataSize = 4; uint8_t dataBitmask = 1; - FeedbackPsAfbPacket* packet = FeedbackPsAfbPacket::Parse(buffer, sizeof(buffer)); REQUIRE(packet); @@ -683,14 +654,15 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") // Precission lost. uint64_t bitrateParsed = 654320; std::vector ssrcs { 11111, 22222, 33333, 44444 }; - // Create a packet. FeedbackPsRembPacket packet(sender_ssrc, media_ssrc); + packet.SetBitrate(bitrate); packet.SetSsrcs(ssrcs); // Serialize. - uint8_t rtcpBuffer[MS_RTCP_BUFFER_SIZE]; + uint8_t rtcpBuffer[RTC::RTCP::bufferSize]; + packet.Serialize(rtcpBuffer); RTC::RTCP::Packet::CommonHeader* header = reinterpret_cast(rtcpBuffer); @@ -698,6 +670,7 @@ SCENARIO("parse RTCP packets", "[parser][rtcp]") // Recover the packet out of the serialized buffer. FeedbackPsRembPacket* parsed = FeedbackPsRembPacket::Parse(rtcpBuffer, len); + REQUIRE(parsed); REQUIRE(parsed->GetMediaSsrc() == media_ssrc); REQUIRE(parsed->GetSenderSsrc() == sender_ssrc); diff --git a/worker/test/test-rtp.cpp b/worker/test/test-rtp.cpp index 7c7574115f..c273540eb3 100644 --- a/worker/test/test-rtp.cpp +++ b/worker/test/test-rtp.cpp @@ -14,8 +14,8 @@ SCENARIO("parse RTP packets", "[parser][rtp]") SECTION("parse packet1.raw") { size_t len; - uint8_t exten_len; - uint8_t* exten_value; + uint8_t extenLen; + uint8_t* extenValue; if (!Helpers::ReadBinaryFile("data/packet1.raw", buffer, &len)) FAIL("cannot open file"); @@ -39,21 +39,21 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasOneByteExtensions()); REQUIRE(!packet->HasTwoBytesExtensions()); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::TO_OFFSET, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::TO_OFFSET, &extenLen); - REQUIRE(exten_len == 1); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0xff); + REQUIRE(extenLen == 1); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0xff); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::RTP_STREAM_ID, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::RTP_STREAM_ID, &extenLen); - REQUIRE(exten_len == 0); - REQUIRE(exten_value == nullptr); + REQUIRE(extenLen == 0); + REQUIRE(extenValue == nullptr); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION, &extenLen); - REQUIRE(exten_len == 0); - REQUIRE(exten_value == nullptr); + REQUIRE(extenLen == 0); + REQUIRE(extenValue == nullptr); packet->Serialize(buffer2); @@ -68,16 +68,16 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasOneByteExtensions()); REQUIRE(!packet->HasTwoBytesExtensions()); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::TO_OFFSET, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::TO_OFFSET, &extenLen); - REQUIRE(exten_len == 1); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0xff); + REQUIRE(extenLen == 1); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0xff); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::RTP_STREAM_ID, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::RTP_STREAM_ID, &extenLen); - REQUIRE(exten_len == 0); - REQUIRE(exten_value == nullptr); + REQUIRE(extenLen == 0); + REQUIRE(extenValue == nullptr); delete packet; } @@ -111,8 +111,8 @@ SCENARIO("parse RTP packets", "[parser][rtp]") SECTION("parse packet3.raw") { size_t len; - uint8_t exten_len; - uint8_t* exten_value; + uint8_t extenLen; + uint8_t* extenValue; bool voice; uint8_t volume; uint32_t absSendTime; @@ -139,19 +139,19 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasOneByteExtensions()); REQUIRE(!packet->HasTwoBytesExtensions()); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &extenLen); - REQUIRE(exten_len == 3); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0x65); - REQUIRE(exten_value[1] == 0x34); - REQUIRE(exten_value[2] == 0x1e); + REQUIRE(extenLen == 3); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0x65); + REQUIRE(extenValue[1] == 0x34); + REQUIRE(extenValue[2] == 0x1e); - exten_value = packet->GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &exten_len); + extenValue = packet->GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &extenLen); - REQUIRE(exten_len == 1); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0xd0); + REQUIRE(extenLen == 1); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0xd0); REQUIRE(packet->ReadAudioLevel(&volume, &voice) == true); REQUIRE(volume == 0b1010000); @@ -159,42 +159,42 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->ReadAbsSendTime(&absSendTime) == true); REQUIRE(absSendTime == 0x65341e); - auto cloned_packet = packet->Clone(buffer2); + auto clonedPacket = packet->Clone(buffer2); delete packet; - REQUIRE(cloned_packet->HasMarker() == false); - REQUIRE(cloned_packet->HasExtensionHeader() == true); - REQUIRE(cloned_packet->GetExtensionHeaderId() == 0xBEDE); - REQUIRE(cloned_packet->GetExtensionHeaderLength() == 8); - REQUIRE(cloned_packet->GetPayloadType() == 111); - REQUIRE(cloned_packet->GetSequenceNumber() == 19354); - REQUIRE(cloned_packet->GetTimestamp() == 863466045); - REQUIRE(cloned_packet->GetSsrc() == 235797202); - REQUIRE(cloned_packet->HasOneByteExtensions()); - REQUIRE(!cloned_packet->HasTwoBytesExtensions()); + REQUIRE(clonedPacket->HasMarker() == false); + REQUIRE(clonedPacket->HasExtensionHeader() == true); + REQUIRE(clonedPacket->GetExtensionHeaderId() == 0xBEDE); + REQUIRE(clonedPacket->GetExtensionHeaderLength() == 8); + REQUIRE(clonedPacket->GetPayloadType() == 111); + REQUIRE(clonedPacket->GetSequenceNumber() == 19354); + REQUIRE(clonedPacket->GetTimestamp() == 863466045); + REQUIRE(clonedPacket->GetSsrc() == 235797202); + REQUIRE(clonedPacket->HasOneByteExtensions()); + REQUIRE(!clonedPacket->HasTwoBytesExtensions()); - exten_value = cloned_packet->GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &exten_len); + extenValue = clonedPacket->GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &extenLen); - REQUIRE(exten_len == 3); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0x65); - REQUIRE(exten_value[1] == 0x34); - REQUIRE(exten_value[2] == 0x1e); + REQUIRE(extenLen == 3); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0x65); + REQUIRE(extenValue[1] == 0x34); + REQUIRE(extenValue[2] == 0x1e); - exten_value = cloned_packet->GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &exten_len); + extenValue = clonedPacket->GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &extenLen); - REQUIRE(exten_len == 1); - REQUIRE(exten_value); - REQUIRE(exten_value[0] == 0xd0); + REQUIRE(extenLen == 1); + REQUIRE(extenValue); + REQUIRE(extenValue[0] == 0xd0); - REQUIRE(cloned_packet->ReadAudioLevel(&volume, &voice) == true); + REQUIRE(clonedPacket->ReadAudioLevel(&volume, &voice) == true); REQUIRE(volume == 0b1010000); REQUIRE(voice == true); - REQUIRE(cloned_packet->ReadAbsSendTime(&absSendTime) == true); + REQUIRE(clonedPacket->ReadAbsSendTime(&absSendTime) == true); REQUIRE(absSendTime == 0x65341e); - delete cloned_packet; + delete clonedPacket; } SECTION("create RtpPacket without extension header") @@ -205,7 +205,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") 0, 0, 0, 4, 0, 0, 0, 5 }; - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); if (!packet) @@ -235,7 +234,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") 0xFF, 0, 0, 0b00110011, 0xFF, 0xFF, 0xFF, 0xFF }; - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); if (!packet) @@ -267,7 +265,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") 0xFF, 0, 3, 4, 0xFF, 0xFF, 0xFF, 0xFF }; - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); if (!packet) diff --git a/worker/test/test-rtpstreamrecv.cpp b/worker/test/test-rtpstreamrecv.cpp index 36124632c9..214cfee4c5 100644 --- a/worker/test/test-rtpstreamrecv.cpp +++ b/worker/test/test-rtpstreamrecv.cpp @@ -15,30 +15,30 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") public RtpStreamRecv::Listener { public: - virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector& seq_numbers) override + virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector& seqNumbers) override { INFO("NACK required"); - REQUIRE(this->should_trigger_nack == true); + REQUIRE(this->shouldTriggerNack == true); - this->should_trigger_nack = false; - this->seq_numbers = seq_numbers; + this->shouldTriggerNack = false; + this->seqNumbers = seqNumbers; } virtual void onPliRequired(RtpStreamRecv* rtpStream) override { INFO("PLI required"); - REQUIRE(this->should_trigger_pli == true); + REQUIRE(this->shouldTriggerPli == true); - this->should_trigger_pli = false; - this->seq_numbers.clear(); + this->shouldTriggerPli = false; + this->seqNumbers.clear(); } public: - bool should_trigger_nack = false; - bool should_trigger_pli = false; - std::vector seq_numbers; + bool shouldTriggerNack = false; + bool shouldTriggerPli = false; + std::vector seqNumbers; }; uint8_t buffer[] = @@ -68,22 +68,22 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") rtpStream.ReceivePacket(packet); packet->SetSequenceNumber(3); - listener.should_trigger_nack = true; + listener.shouldTriggerNack = true; rtpStream.ReceivePacket(packet); - REQUIRE(listener.seq_numbers.size() == 1); - REQUIRE(listener.seq_numbers[0] == 2); - listener.seq_numbers.clear(); + REQUIRE(listener.seqNumbers.size() == 1); + REQUIRE(listener.seqNumbers[0] == 2); + listener.seqNumbers.clear(); packet->SetSequenceNumber(2); rtpStream.ReceivePacket(packet); - REQUIRE(listener.seq_numbers.size() == 0); + REQUIRE(listener.seqNumbers.size() == 0); packet->SetSequenceNumber(4); rtpStream.ReceivePacket(packet); - REQUIRE(listener.seq_numbers.size() == 0); + REQUIRE(listener.seqNumbers.size() == 0); } SECTION("wrapping sequence numbers") @@ -95,13 +95,13 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") rtpStream.ReceivePacket(packet); packet->SetSequenceNumber(1); - listener.should_trigger_nack = true; + listener.shouldTriggerNack = true; rtpStream.ReceivePacket(packet); - REQUIRE(listener.seq_numbers.size() == 2); - REQUIRE(listener.seq_numbers[0] == 0xffff); - REQUIRE(listener.seq_numbers[1] == 0); - listener.seq_numbers.clear(); + REQUIRE(listener.seqNumbers.size() == 2); + REQUIRE(listener.seqNumbers[0] == 0xffff); + REQUIRE(listener.seqNumbers[1] == 0); + listener.seqNumbers.clear(); } SECTION("require PLI") @@ -113,7 +113,7 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") rtpStream.ReceivePacket(packet); packet->SetSequenceNumber(510); - listener.should_trigger_pli = true; + listener.shouldTriggerPli = true; rtpStream.ReceivePacket(packet); }