Explorar o código

Code formatting

Paul-Louis Ageneau %!s(int64=4) %!d(string=hai) anos
pai
achega
1ceb0fd292

+ 2 - 1
include/rtc/candidate.hpp

@@ -78,6 +78,7 @@ private:
 
 RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate);
 RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate::Type &type);
-RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate::TransportType &transportType);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out,
+                                        const rtc::Candidate::TransportType &transportType);
 
 #endif

+ 2 - 1
include/rtc/datachannel.hpp

@@ -36,7 +36,8 @@ namespace rtc {
 class SctpTransport;
 class PeerConnection;
 
-class RTC_CPP_EXPORT DataChannel : public std::enable_shared_from_this<DataChannel>, public Channel {
+class RTC_CPP_EXPORT DataChannel : public std::enable_shared_from_this<DataChannel>,
+                                   public Channel {
 public:
 	DataChannel(std::weak_ptr<PeerConnection> pc, uint16_t stream, string label, string protocol,
 	            Reliability reliability);

+ 4 - 2
include/rtc/description.hpp

@@ -205,7 +205,8 @@ public:
 		void addAudioCodec(int payloadType, string codec,
 		                   std::optional<string> profile = std::nullopt);
 
-		void addOpusCodec(int payloadType, std::optional<string> profile = DEFAULT_OPUS_AUDIO_PROFILE);
+		void addOpusCodec(int payloadType,
+		                  std::optional<string> profile = DEFAULT_OPUS_AUDIO_PROFILE);
 	};
 
 	class RTC_CPP_EXPORT Video : public Media {
@@ -215,7 +216,8 @@ public:
 		void addVideoCodec(int payloadType, string codec,
 		                   std::optional<string> profile = std::nullopt);
 
-		void addH264Codec(int payloadType, std::optional<string> profile = DEFAULT_H264_VIDEO_PROFILE);
+		void addH264Codec(int payloadType,
+		                  std::optional<string> profile = DEFAULT_H264_VIDEO_PROFILE);
 		void addVP8Codec(int payloadType);
 		void addVP9Codec(int payloadType);
 	};

+ 34 - 30
include/rtc/h264packetizationhandler.hpp

@@ -21,51 +21,55 @@
 
 #if RTC_ENABLE_MEDIA
 
-#include "rtcp.hpp"
 #include "h264rtppacketizer.hpp"
-#include "rtcpsenderreportable.hpp"
 #include "nalunit.hpp"
+#include "rtcp.hpp"
+#include "rtcpsenderreportable.hpp"
 
 namespace rtc {
 
 /// Handler for H264 packetization
-class RTC_CPP_EXPORT H264PacketizationHandler: public RtcpHandler, public RTCPSenderReportable {
-    /// RTP packetizer for H264
-    const std::shared_ptr<H264RTPPacketizer> packetizer;
+class RTC_CPP_EXPORT H264PacketizationHandler : public RtcpHandler, public RTCPSenderReportable {
+	/// RTP packetizer for H264
+	const std::shared_ptr<H264RTPPacketizer> packetizer;
+
+	const uint16_t maximumFragmentSize;
 
-    const uint16_t maximumFragmentSize;
+	std::shared_ptr<NalUnits> splitMessage(message_ptr message);
 
-    std::shared_ptr<NalUnits> splitMessage(message_ptr message);
 public:
-    /// Nalunit separator
-    enum class Separator {
-        LongStartSequence,  // 0x00, 0x00, 0x00, 0x01
-        ShortStartSequence, // 0x00, 0x00, 0x01
-        StartSequence,      // LongStartSequence or ShortStartSequence
-        Length              // first 4 bytes is nal unit length
-    };
+	/// Nalunit separator
+	enum class Separator {
+		LongStartSequence,  // 0x00, 0x00, 0x00, 0x01
+		ShortStartSequence, // 0x00, 0x00, 0x01
+		StartSequence,      // LongStartSequence or ShortStartSequence
+		Length              // first 4 bytes is nal unit length
+	};
+
+	/// Construct handler for H264 packetization.
+	/// @param separator Nal units separator
+	/// @param packetizer RTP packetizer for h264
+	H264PacketizationHandler(Separator separator, std::shared_ptr<H264RTPPacketizer> packetizer,
+	                         uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
 
-    /// Construct handler for H264 packetization.
-    /// @param separator Nal units separator
-    /// @param packetizer RTP packetizer for h264
-    H264PacketizationHandler(Separator separator, std::shared_ptr<H264RTPPacketizer> packetizer, uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
+	/// Returns message unchanged
+	/// @param ptr message
+	message_ptr incoming(message_ptr ptr) override;
 
-    /// Returns message unchanged
-    /// @param ptr message
-    message_ptr incoming(message_ptr ptr) override;
+	/// Returns packetized message if message type is binary
+	/// @note NAL units in `ptr` message must be separated by `separator` given in constructor
+	/// @note If message generates multiple rtp packets, all but last are send using
+	/// `outgoingCallback`. It is your responsibility to send last packet.
+	/// @param ptr message containing all NAL units for current timestamp (one sample)
+	/// @return last packet
+	message_ptr outgoing(message_ptr ptr) override;
 
-    /// Returns packetized message if message type is binary
-    /// @note NAL units in `ptr` message must be separated by `separator` given in constructor
-    /// @note If message generates multiple rtp packets, all but last are send using `outgoingCallback`. It is your responsibility to send last packet.
-    /// @param ptr message containing all NAL units for current timestamp (one sample)
-    /// @return last packet
-    message_ptr outgoing(message_ptr ptr) override;
 private:
-    /// Separator
-    const Separator separator;
+	/// Separator
+	const Separator separator;
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 10 - 9
include/rtc/h264rtppacketizer.hpp

@@ -26,19 +26,20 @@
 namespace rtc {
 
 /// RTP packetization of h264 payload
-class RTC_CPP_EXPORT H264RTPPacketizer: public rtc::RTPPacketizer {
+class RTC_CPP_EXPORT H264RTPPacketizer : public rtc::RTPPacketizer {
 
 public:
-    /// Default clock rate for H264 in RTP
-    static const auto defaultClockRate = 90 * 1000;
-
-    /// Constructs h264 payload packetizer with given RTP configuration.
-    /// @note RTP configuration is used in packetization process which may change some configuration properties such as sequence number.
-    /// @param rtpConfig  RTP configuration
-    H264RTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig);
+	/// Default clock rate for H264 in RTP
+	static const auto defaultClockRate = 90 * 1000;
+
+	/// Constructs h264 payload packetizer with given RTP configuration.
+	/// @note RTP configuration is used in packetization process which may change some configuration
+	/// properties such as sequence number.
+	/// @param rtpConfig  RTP configuration
+	H264RTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig);
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 3 - 3
include/rtc/include.hpp

@@ -33,7 +33,7 @@
 #define _WIN32_WINNT 0x0602 // Windows 8
 #endif
 #ifdef _MSC_VER
-#pragma warning(disable:4251) // disable "X needs to have dll-interface..."
+#pragma warning(disable : 4251) // disable "X needs to have dll-interface..."
 #endif
 #else
 #define RTC_CPP_EXPORT
@@ -81,8 +81,8 @@ template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
 template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
 
 // weak_ptr bind helper
-template <typename F, typename T, typename... Args> auto weak_bind(F &&f, T *t, Args &&... _args) {
-	return [bound = std::bind(f, t, _args...), weak_this = t->weak_from_this()](auto &&... args) {
+template <typename F, typename T, typename... Args> auto weak_bind(F &&f, T *t, Args &&..._args) {
+	return [bound = std::bind(f, t, _args...), weak_this = t->weak_from_this()](auto &&...args) {
 		using result_type = typename decltype(bound)::result_type;
 		if (auto shared_this = weak_this.lock())
 			return bound(args...);

+ 5 - 4
include/rtc/message.hpp

@@ -65,12 +65,13 @@ message_ptr make_message(Iterator begin, Iterator end, Message::Type type = Mess
 	return message;
 }
 
-RTC_CPP_EXPORT message_ptr make_message(size_t size, Message::Type type = Message::Binary, unsigned int stream = 0,
-                         std::shared_ptr<Reliability> reliability = nullptr);
+RTC_CPP_EXPORT message_ptr make_message(size_t size, Message::Type type = Message::Binary,
+                                        unsigned int stream = 0,
+                                        std::shared_ptr<Reliability> reliability = nullptr);
 
 RTC_CPP_EXPORT message_ptr make_message(binary &&data, Message::Type type = Message::Binary,
-                         unsigned int stream = 0,
-                         std::shared_ptr<Reliability> reliability = nullptr);
+                                        unsigned int stream = 0,
+                                        std::shared_ptr<Reliability> reliability = nullptr);
 
 RTC_CPP_EXPORT message_ptr make_message(message_variant data);
 

+ 87 - 88
include/rtc/nalunit.hpp

@@ -29,128 +29,127 @@ namespace rtc {
 
 /// Nalu header
 struct RTC_CPP_EXPORT NalUnitHeader {
-    bool forbiddenBit() { return _first >> 7; }
-    uint8_t nri() { return _first >> 5 & 0x03; }
-    uint8_t unitType() { return _first & 0x1F; }
+	bool forbiddenBit() { return _first >> 7; }
+	uint8_t nri() { return _first >> 5 & 0x03; }
+	uint8_t unitType() { return _first & 0x1F; }
+
+	void setForbiddenBit(bool isSet) { _first = (_first & 0x7F) | (isSet << 7); }
+	void setNRI(uint8_t nri) { _first = (_first & 0x9F) | ((nri & 0x03) << 5); }
+	void setUnitType(uint8_t type) { _first = (_first & 0xE0) | (type & 0x1F); }
 
-    void setForbiddenBit(bool isSet) { _first = (_first & 0x7F) | (isSet << 7); }
-    void setNRI(uint8_t nri) { _first = (_first & 0x9F) | ((nri & 0x03) << 5); }
-    void setUnitType(uint8_t type) { _first = (_first &0xE0) | (type & 0x1F); }
 private:
-    uint8_t _first = 0;
+	uint8_t _first = 0;
 };
 
 /// Nalu fragment header
 struct RTC_CPP_EXPORT NalUnitFragmentHeader {
-    bool isStart() { return _first >> 7; }
-    bool reservedBit6() { return (_first >> 6) & 0x01; }
-    bool isEnd() { return (_first >> 5) & 0x01; }
-    uint8_t unitType() { return _first & 0x1F; }
-
-    void setStart(bool isSet) { _first = (_first & 0x7F) | (isSet << 7); }
-    void setEnd(bool isSet) { _first = (_first & 0xDF) | (isSet << 6); }
-    void setReservedBit6(bool isSet) { _first = (_first & 0xBF) | (isSet << 5); }
-    void setUnitType(uint8_t type) { _first = (_first &0xE0) | (type & 0x1F); }
+	bool isStart() { return _first >> 7; }
+	bool reservedBit6() { return (_first >> 6) & 0x01; }
+	bool isEnd() { return (_first >> 5) & 0x01; }
+	uint8_t unitType() { return _first & 0x1F; }
+
+	void setStart(bool isSet) { _first = (_first & 0x7F) | (isSet << 7); }
+	void setEnd(bool isSet) { _first = (_first & 0xDF) | (isSet << 6); }
+	void setReservedBit6(bool isSet) { _first = (_first & 0xBF) | (isSet << 5); }
+	void setUnitType(uint8_t type) { _first = (_first & 0xE0) | (type & 0x1F); }
+
 private:
-    uint8_t _first = 0;
+	uint8_t _first = 0;
 };
 
 #pragma pack(pop)
 
 /// Nal unit
-struct RTC_CPP_EXPORT NalUnit: rtc::binary {
-    NalUnit(const NalUnit &unit) = default;
-    NalUnit(size_t size, bool includingHeader = true): rtc::binary(size + (includingHeader ? 0 : 1)) { }
-
-    template <typename Iterator>
-    NalUnit(Iterator begin_, Iterator end_): rtc::binary(begin_, end_) { }
-
-    NalUnit(rtc::binary &&data) : rtc::binary(std::move(data)) { }
-
-    NalUnit(): rtc::binary(1) { }
-
-    bool forbiddenBit() { return header()->forbiddenBit(); }
-    uint8_t nri() { return header()->nri(); }
-    uint8_t unitType() { return header()->unitType(); }
-    rtc::binary payload() {
-        assert(size() >= 1);
-        return {begin() + 1, end()};
-    }
-
-    void setForbiddenBit(bool isSet) { header()->setForbiddenBit(isSet); }
-    void setNRI(uint8_t nri) { header()->setNRI(nri); }
-    void setUnitType(uint8_t type) { header()->setUnitType(type); }
-    void setPayload(rtc::binary payload) {
-        assert(size() >= 1);
-        erase(begin() + 1, end());
-        insert(end(), payload.begin(), payload.end());
-    }
+struct RTC_CPP_EXPORT NalUnit : rtc::binary {
+	NalUnit(const NalUnit &unit) = default;
+	NalUnit(size_t size, bool includingHeader = true)
+	    : rtc::binary(size + (includingHeader ? 0 : 1)) {}
+
+	template <typename Iterator>
+	NalUnit(Iterator begin_, Iterator end_) : rtc::binary(begin_, end_) {}
+
+	NalUnit(rtc::binary &&data) : rtc::binary(std::move(data)) {}
+
+	NalUnit() : rtc::binary(1) {}
+
+	bool forbiddenBit() { return header()->forbiddenBit(); }
+	uint8_t nri() { return header()->nri(); }
+	uint8_t unitType() { return header()->unitType(); }
+	rtc::binary payload() {
+		assert(size() >= 1);
+		return {begin() + 1, end()};
+	}
+
+	void setForbiddenBit(bool isSet) { header()->setForbiddenBit(isSet); }
+	void setNRI(uint8_t nri) { header()->setNRI(nri); }
+	void setUnitType(uint8_t type) { header()->setUnitType(type); }
+	void setPayload(rtc::binary payload) {
+		assert(size() >= 1);
+		erase(begin() + 1, end());
+		insert(end(), payload.begin(), payload.end());
+	}
 
 protected:
-    NalUnitHeader * header() {
-        assert(size() >= 1);
-        return (NalUnitHeader *) data();
-    }
+	NalUnitHeader *header() {
+		assert(size() >= 1);
+		return (NalUnitHeader *)data();
+	}
 };
 
 /// Nal unit fragment A
-struct RTC_CPP_EXPORT NalUnitFragmentA: NalUnit {
-    enum class FragmentType {
-        Start,
-        Middle,
-        End
-    };
+struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
+	enum class FragmentType { Start, Middle, End };
 
-    NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType, rtc::binary data);
+	NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType,
+	                 rtc::binary data);
 
-    static std::vector<NalUnitFragmentA> fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize);
+	static std::vector<NalUnitFragmentA> fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize);
 
-    uint8_t unitType() { return fragmentHeader()->unitType(); }
+	uint8_t unitType() { return fragmentHeader()->unitType(); }
 
-    rtc::binary payload() {
-        assert(size() >= 2);
-        return {begin() + 2, end()};
-    }
+	rtc::binary payload() {
+		assert(size() >= 2);
+		return {begin() + 2, end()};
+	}
 
-    FragmentType type() {
-        if(fragmentHeader()->isStart()) {
-            return FragmentType::Start;
-        } else if(fragmentHeader()->isEnd()) {
-            return FragmentType::End;
-        } else {
-            return FragmentType::Middle;
-        }
-    }
+	FragmentType type() {
+		if (fragmentHeader()->isStart()) {
+			return FragmentType::Start;
+		} else if (fragmentHeader()->isEnd()) {
+			return FragmentType::End;
+		} else {
+			return FragmentType::Middle;
+		}
+	}
 
-    void setUnitType(uint8_t type) { fragmentHeader()->setUnitType(type); }
+	void setUnitType(uint8_t type) { fragmentHeader()->setUnitType(type); }
 
-    void setPayload(rtc::binary payload) {
-        assert(size() >= 2);
-        erase(begin() + 2, end());
-        insert(end(), payload.begin(), payload.end());
-    }
+	void setPayload(rtc::binary payload) {
+		assert(size() >= 2);
+		erase(begin() + 2, end());
+		insert(end(), payload.begin(), payload.end());
+	}
 
-    void setFragmentType(FragmentType type);
+	void setFragmentType(FragmentType type);
 
 protected:
-    NalUnitHeader * fragmentIndicator() {
-        return (NalUnitHeader *) data();
-    }
+	NalUnitHeader *fragmentIndicator() { return (NalUnitHeader *)data(); }
 
-    NalUnitFragmentHeader * fragmentHeader() {
-        return (NalUnitFragmentHeader *) fragmentIndicator() + 1;
-    }
+	NalUnitFragmentHeader *fragmentHeader() {
+		return (NalUnitFragmentHeader *)fragmentIndicator() + 1;
+	}
 
-    const uint8_t nal_type_fu_A = 28;
+	const uint8_t nal_type_fu_A = 28;
 };
 
-class RTC_CPP_EXPORT NalUnits: public std::vector<NalUnit> {
+class RTC_CPP_EXPORT NalUnits : public std::vector<NalUnit> {
 public:
-    static const uint16_t defaultMaximumFragmentSize = 1100;
-    std::vector<rtc::binary> generateFragments(uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
+	static const uint16_t defaultMaximumFragmentSize = 1100;
+	std::vector<rtc::binary>
+	generateFragments(uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 15 - 15
include/rtc/opuspacketizationhandler.hpp

@@ -21,31 +21,31 @@
 
 #if RTC_ENABLE_MEDIA
 
-#include "rtcpsenderreportable.hpp"
 #include "opusrtppacketizer.hpp"
 #include "rtcp.hpp"
+#include "rtcpsenderreportable.hpp"
 
 namespace rtc {
 
 /// Handler for opus packetization
-class RTC_CPP_EXPORT OpusPacketizationHandler: public RtcpHandler, public RTCPSenderReportable {
-    /// RTP packetizer for opus
-    const std::shared_ptr<OpusRTPPacketizer> packetizer;
+class RTC_CPP_EXPORT OpusPacketizationHandler : public RtcpHandler, public RTCPSenderReportable {
+	/// RTP packetizer for opus
+	const std::shared_ptr<OpusRTPPacketizer> packetizer;
 
 public:
-    /// Construct handler for opus packetization.
-    /// @param packetizer RTP packetizer for opus
-    OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer);
-
-    /// Returns message unchanged
-    /// @param ptr message
-    message_ptr incoming(message_ptr ptr) override;
-    /// Returns packetized message if message type is binary
-    /// @param ptr message
-    message_ptr outgoing(message_ptr ptr) override;
+	/// Construct handler for opus packetization.
+	/// @param packetizer RTP packetizer for opus
+	OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer);
+
+	/// Returns message unchanged
+	/// @param ptr message
+	message_ptr incoming(message_ptr ptr) override;
+	/// Returns packetized message if message type is binary
+	/// @param ptr message
+	message_ptr outgoing(message_ptr ptr) override;
 };
 
-}   // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 16 - 15
include/rtc/opusrtppacketizer.hpp

@@ -26,25 +26,26 @@
 namespace rtc {
 
 /// RTP packetizer for opus
-class RTC_CPP_EXPORT OpusRTPPacketizer: public rtc::RTPPacketizer {
+class RTC_CPP_EXPORT OpusRTPPacketizer : public rtc::RTPPacketizer {
 
 public:
-    /// default clock rate used in opus RTP communication
-    static const uint32_t defaultClockRate = 48 * 1000;
-
-    /// Constructs opus packetizer with given RTP configuration.
-    /// @note RTP configuration is used in packetization process which may change some configuration properties such as sequence number.
-    /// @param rtpConfig  RTP configuration
-    OpusRTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig);
-
-    /// Creates RTP packet for given payload based on `rtpConfig`.
-    /// @note This function increase sequence number after packetization.
-    /// @param payload RTP payload
-    /// @param setMark This needs to be `false` for all RTP packets with opus payload
-    rtc::message_ptr packetize(rtc::binary payload, bool setMark) override;
+	/// default clock rate used in opus RTP communication
+	static const uint32_t defaultClockRate = 48 * 1000;
+
+	/// Constructs opus packetizer with given RTP configuration.
+	/// @note RTP configuration is used in packetization process which may change some configuration
+	/// properties such as sequence number.
+	/// @param rtpConfig  RTP configuration
+	OpusRTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig);
+
+	/// Creates RTP packet for given payload based on `rtpConfig`.
+	/// @note This function increase sequence number after packetization.
+	/// @param payload RTP payload
+	/// @param setMark This needs to be `false` for all RTP packets with opus payload
+	rtc::message_ptr packetize(rtc::binary payload, bool setMark) override;
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 4 - 2
include/rtc/peerconnection.hpp

@@ -206,7 +206,9 @@ private:
 } // namespace rtc
 
 RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state);
-RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::GatheringState state);
-RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState state);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out,
+                                        rtc::PeerConnection::GatheringState state);
+RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out,
+                                        rtc::PeerConnection::SignalingState state);
 
 #endif

+ 1 - 1
include/rtc/rtc.hpp

@@ -28,8 +28,8 @@
 #if RTC_ENABLE_MEDIA
 
 // opus/h264 streaming
-#include "opuspacketizationhandler.hpp"
 #include "h264packetizationhandler.hpp"
+#include "opuspacketizationhandler.hpp"
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 45 - 39
include/rtc/rtcpsenderreportable.hpp

@@ -28,59 +28,65 @@ namespace rtc {
 
 /// Class for sending RTCP SR
 class RTC_CPP_EXPORT RTCPSenderReportable {
-    bool needsToReport = false;
+	bool needsToReport = false;
 
-    uint32_t packetCount = 0;
-    uint32_t payloadOctets = 0;
-    double timeOffset = 0;
+	uint32_t packetCount = 0;
+	uint32_t payloadOctets = 0;
+	double timeOffset = 0;
 
-    uint32_t _previousReportedTimestamp = 0;
+	uint32_t _previousReportedTimestamp = 0;
+
+	void addToReport(RTP *rtp, uint32_t rtpSize);
+	message_ptr getSenderReport(uint32_t timestamp);
 
-    void addToReport(RTP * rtp, uint32_t rtpSize);
-    message_ptr getSenderReport(uint32_t timestamp);
 protected:
-    /// Outgoing callback for sender reports
-    synchronized_callback<message_ptr> senderReportOutgoingCallback;
+	/// Outgoing callback for sender reports
+	synchronized_callback<message_ptr> senderReportOutgoingCallback;
+
 public:
-    static uint64_t secondsToNTP(double seconds);
+	static uint64_t secondsToNTP(double seconds);
+
+	/// Timestamp of previous sender report
+	const uint32_t &previousReportedTimestamp = _previousReportedTimestamp;
 
-    /// Timestamp of previous sender report
-    const uint32_t & previousReportedTimestamp = _previousReportedTimestamp;
+	/// RTP configuration
+	const std::shared_ptr<RTPPacketizationConfig> rtpConfig;
 
-    /// RTP configuration
-    const std::shared_ptr<RTPPacketizationConfig> rtpConfig;
+	RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig);
 
-    RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig);
+	/// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same
+	/// timestamp.
+	void setNeedsToReport();
 
-    /// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same timestamp.
-    void setNeedsToReport();
+	/// Set offset to compute NTS for RTCP SR packets. Offset represents relation between real start
+	/// time and timestamp of the stream in RTP packets
+	/// @note `time_offset = rtpConfig->startTime_s -
+	/// rtpConfig->timestampToSeconds(rtpConfig->timestamp)`
+	void startRecording();
 
-    /// Set offset to compute NTS for RTCP SR packets. Offset represents relation between real start time and timestamp of the stream in RTP packets
-    /// @note `time_offset = rtpConfig->startTime_s - rtpConfig->timestampToSeconds(rtpConfig->timestamp)`
-    void startRecording();
+	/// Send RTCP SR with given timestamp
+	/// @param timestamp timestamp of the RTCP SR
+	void sendReport(uint32_t timestamp);
 
-    /// Send RTCP SR with given timestamp
-    /// @param timestamp timestamp of the RTCP SR
-    void sendReport(uint32_t timestamp);
-    
 protected:
-    /// Calls given block with function for statistics. Sends RTCP SR packet with current timestamp before `block` call if `needs_to_report` flag is true.
-    /// @param block Block of code to run. This block has function for rtp stats recording.
-    template <typename T>
-    T withStatsRecording(std::function<T (std::function<void (message_ptr)>)> block) {
-        if (needsToReport) {
-            sendReport(rtpConfig->timestamp);
-            needsToReport = false;
-        }
-        auto result = block([this](message_ptr _rtp) {
-            auto rtp = reinterpret_cast<RTP *>(_rtp->data());
-            this->addToReport(rtp, _rtp->size());
-        });
-        return result;
-    }
+	/// Calls given block with function for statistics. Sends RTCP SR packet with current timestamp
+	/// before `block` call if `needs_to_report` flag is true.
+	/// @param block Block of code to run. This block has function for rtp stats recording.
+	template <typename T>
+	T withStatsRecording(std::function<T(std::function<void(message_ptr)>)> block) {
+		if (needsToReport) {
+			sendReport(rtpConfig->timestamp);
+			needsToReport = false;
+		}
+		auto result = block([this](message_ptr _rtp) {
+			auto rtp = reinterpret_cast<RTP *>(_rtp->data());
+			this->addToReport(rtp, _rtp->size());
+		});
+		return result;
+	}
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 172 - 171
include/rtc/rtp.hpp

@@ -79,16 +79,14 @@ public:
 		return reinterpret_cast<const char *>(&csrc) + sizeof(SSRC) * csrcCount();
 	}
 
-    inline void preparePacket() {
-        _first |= (1 << 7);
-    }
+	inline void preparePacket() { _first |= (1 << 7); }
 
 	inline void setSeqNumber(uint16_t newSeqNo) { _seqNumber = htons(newSeqNo); }
 	inline void setPayloadType(uint8_t newPayloadType) {
 		_payloadType = (_payloadType & 0b10000000u) | (0b01111111u & newPayloadType);
 	}
 	inline void setSsrc(uint32_t in_ssrc) { _ssrc = htonl(in_ssrc); }
-    inline void setMarker(bool marker) { _payloadType = (_payloadType & 0x7F) | (marker << 7); };
+	inline void setMarker(bool marker) { _payloadType = (_payloadType & 0x7F) | (marker << 7); };
 
 	void setTimestamp(uint32_t i) { _timestamp = htonl(i); }
 
@@ -261,9 +259,9 @@ public:
 		return &_reportBlocks + num;
 	}
 
-    [[nodiscard]] static unsigned int size(unsigned int reportCount) {
-        return sizeof(RTCP_HEADER) + 24 + reportCount * sizeof(RTCP_ReportBlock);
-    }
+	[[nodiscard]] static unsigned int size(unsigned int reportCount) {
+		return sizeof(RTCP_HEADER) + 24 + reportCount * sizeof(RTCP_ReportBlock);
+	}
 
 	[[nodiscard]] inline size_t getSize() const {
 		// "length" in packet is one less than the number of 32 bit words in the packet.
@@ -277,9 +275,9 @@ public:
 	inline uint32_t senderSSRC() const { return ntohl(_senderSSRC); }
 
 	inline void setNtpTimestamp(uint64_t ts) { _ntpTimestamp = htonll(ts); }
-    inline void setRtpTimestamp(uint32_t ts) { _rtpTimestamp = htonl(ts); }
-    inline void setOctetCount(uint32_t ts) { _octetCount = htonl(ts); }
-    inline void setPacketCount(uint32_t ts) { _packetCount = htonl(ts); }
+	inline void setRtpTimestamp(uint32_t ts) { _rtpTimestamp = htonl(ts); }
+	inline void setOctetCount(uint32_t ts) { _octetCount = htonl(ts); }
+	inline void setPacketCount(uint32_t ts) { _packetCount = htonl(ts); }
 
 	inline void log() const {
 		header.log();
@@ -296,181 +294,184 @@ public:
 
 struct RTCP_SDES_ITEM {
 public:
-    uint8_t type;
+	uint8_t type;
+
 private:
-    uint8_t _length;
-    char _text;
+	uint8_t _length;
+	char _text;
+
 public:
-    inline std::string text() const {
-        return std::string(&_text, _length);
-    }
-    inline void setText(std::string text) {
-        _length = text.length();
-        memcpy(&_text, text.data(), _length);
-    }
-
-    inline uint8_t length() {
-        return _length;
-    }
-
-    [[nodiscard]] static unsigned int size(uint8_t textLength) {
-        return textLength + 2;
-    }
+	inline std::string text() const { return std::string(&_text, _length); }
+	inline void setText(std::string text) {
+		_length = text.length();
+		memcpy(&_text, text.data(), _length);
+	}
+
+	inline uint8_t length() { return _length; }
+
+	[[nodiscard]] static unsigned int size(uint8_t textLength) { return textLength + 2; }
 };
 
 struct RTCP_SDES_CHUNK {
 private:
-    SSRC _ssrc;
-    RTCP_SDES_ITEM _items;
+	SSRC _ssrc;
+	RTCP_SDES_ITEM _items;
+
 public:
-    inline SSRC ssrc() const { return ntohl(_ssrc); }
-    inline void setSSRC(SSRC ssrc) { _ssrc = htonl(ssrc); }
-
-    /// Get item at given index
-    /// @note All items with index < `num` must be valid, otherwise this function has undefined behaviour (use `safelyCountChunkSize` to check if chunk is valid)
-    /// @param num Index of item to return
-    inline RTCP_SDES_ITEM *getItem(int num) {
-        auto base = &_items;
-        while (num-- > 0) {
-            auto itemSize = RTCP_SDES_ITEM::size(base->length());
-            base = reinterpret_cast<RTCP_SDES_ITEM *>(reinterpret_cast<uint8_t *>(base) + itemSize);
-        }
-        return reinterpret_cast<RTCP_SDES_ITEM *>(base);
-    }
-
-    long safelyCountChunkSize(unsigned int maxChunkSize) {
-        if (maxChunkSize < RTCP_SDES_CHUNK::size({})) {
-            // chunk is truncated
-            return -1;
-        } else {
-            unsigned int size = sizeof(SSRC);
-            unsigned int i = 0;
-            // We can always access first 4 bytes of first item (in case of no items there will be 4 null bytes)
-            auto item = getItem(i);
-            std::vector<uint8_t> textsLength{};
-            while (item->type != 0) {
-                if (size + RTCP_SDES_ITEM::size(0) > maxChunkSize) {
-                    // item is too short
-                    return -1;
-                }
-                auto itemLength = item->length();
-                if (size + RTCP_SDES_ITEM::size(itemLength) >= maxChunkSize) {
-                    // item is too large (it can't be equal to chunk size because after item there must be 1-4 null bytes as padding)
-                    return -1;
-                }
-                textsLength.push_back(itemLength);
-                // safely to access next item
-                item = getItem(++i);
-            }
-            auto realSize = RTCP_SDES_CHUNK::size(textsLength);
-            if (realSize > maxChunkSize) {
-                // Chunk is too large
-                return -1;
-            }
-            return realSize;
-        }
-    }
-
-    [[nodiscard]] static unsigned int size(const std::vector<uint8_t> textLengths) {
-        unsigned int itemsSize = 0;
-        for (auto length: textLengths) {
-            itemsSize += RTCP_SDES_ITEM::size(length);
-        }
-        auto nullTerminatedItemsSize = itemsSize + 1;
-        auto words = uint8_t(std::ceil(double(nullTerminatedItemsSize) / 4)) + 1;
-        return words * 4;
-    }
-
-    /// Get size of chunk
-    /// @note All  items must be valid, otherwise this function has undefined behaviour (use `safelyCountChunkSize` to check if chunk is valid)
-    [[nodiscard]] unsigned int getSize() {
-        std::vector<uint8_t> textLengths{};
-        unsigned int i = 0;
-        auto item = getItem(i);
-        while (item->type != 0) {
-            textLengths.push_back(item->length());
-            item = getItem(++i);
-        }
-        return size(textLengths);
-    }
+	inline SSRC ssrc() const { return ntohl(_ssrc); }
+	inline void setSSRC(SSRC ssrc) { _ssrc = htonl(ssrc); }
+
+	/// Get item at given index
+	/// @note All items with index < `num` must be valid, otherwise this function has undefined
+	/// behaviour (use `safelyCountChunkSize` to check if chunk is valid)
+	/// @param num Index of item to return
+	inline RTCP_SDES_ITEM *getItem(int num) {
+		auto base = &_items;
+		while (num-- > 0) {
+			auto itemSize = RTCP_SDES_ITEM::size(base->length());
+			base = reinterpret_cast<RTCP_SDES_ITEM *>(reinterpret_cast<uint8_t *>(base) + itemSize);
+		}
+		return reinterpret_cast<RTCP_SDES_ITEM *>(base);
+	}
+
+	long safelyCountChunkSize(unsigned int maxChunkSize) {
+		if (maxChunkSize < RTCP_SDES_CHUNK::size({})) {
+			// chunk is truncated
+			return -1;
+		} else {
+			unsigned int size = sizeof(SSRC);
+			unsigned int i = 0;
+			// We can always access first 4 bytes of first item (in case of no items there will be 4
+			// null bytes)
+			auto item = getItem(i);
+			std::vector<uint8_t> textsLength{};
+			while (item->type != 0) {
+				if (size + RTCP_SDES_ITEM::size(0) > maxChunkSize) {
+					// item is too short
+					return -1;
+				}
+				auto itemLength = item->length();
+				if (size + RTCP_SDES_ITEM::size(itemLength) >= maxChunkSize) {
+					// item is too large (it can't be equal to chunk size because after item there
+					// must be 1-4 null bytes as padding)
+					return -1;
+				}
+				textsLength.push_back(itemLength);
+				// safely to access next item
+				item = getItem(++i);
+			}
+			auto realSize = RTCP_SDES_CHUNK::size(textsLength);
+			if (realSize > maxChunkSize) {
+				// Chunk is too large
+				return -1;
+			}
+			return realSize;
+		}
+	}
+
+	[[nodiscard]] static unsigned int size(const std::vector<uint8_t> textLengths) {
+		unsigned int itemsSize = 0;
+		for (auto length : textLengths) {
+			itemsSize += RTCP_SDES_ITEM::size(length);
+		}
+		auto nullTerminatedItemsSize = itemsSize + 1;
+		auto words = uint8_t(std::ceil(double(nullTerminatedItemsSize) / 4)) + 1;
+		return words * 4;
+	}
+
+	/// Get size of chunk
+	/// @note All  items must be valid, otherwise this function has undefined behaviour (use
+	/// `safelyCountChunkSize` to check if chunk is valid)
+	[[nodiscard]] unsigned int getSize() {
+		std::vector<uint8_t> textLengths{};
+		unsigned int i = 0;
+		auto item = getItem(i);
+		while (item->type != 0) {
+			textLengths.push_back(item->length());
+			item = getItem(++i);
+		}
+		return size(textLengths);
+	}
 };
 
 struct RTCP_SDES {
-    RTCP_HEADER header;
+	RTCP_HEADER header;
 
 private:
-    RTCP_SDES_CHUNK _chunks;
+	RTCP_SDES_CHUNK _chunks;
 
 public:
-    inline void preparePacket(uint8_t chunkCount) {
-        unsigned int chunkSize = 0;
-        for(uint8_t i = 0; i < chunkCount; i++) {
-            auto chunk = getChunk(i);
-            chunkSize += chunk->getSize();
-        }
-        uint16_t length = (sizeof(header) + chunkSize) / 4 - 1;
-        header.prepareHeader(202, chunkCount, length);
-    }
-
-    bool isValid() {
-        auto chunksSize = header.lengthInBytes() - sizeof(header);
-        if (chunksSize == 0) {
-            return true;
-        } else {
-            // there is at least one chunk
-            unsigned int i = 0;
-            unsigned int size = 0;
-            while (size < chunksSize) {
-                if (chunksSize < size + RTCP_SDES_CHUNK::size({})) {
-                    // chunk is truncated
-                    return false;
-                }
-                auto chunk = getChunk(i++);
-                auto chunkSize = chunk->safelyCountChunkSize(chunksSize - size);
-                if (chunkSize < 0) {
-                    // chunk is invalid
-                    return false;
-                }
-                size += chunkSize;
-            }
-            return size == chunksSize;
-        }
-    }
-
-    /// Returns number of chunks in this packet
-    /// @note Returns 0 if packet is invalid
-    inline unsigned int chunksCount() {
-        if (!isValid()) {
-            return 0;
-        }
-        uint16_t chunksSize = 4 * (header.length() + 1) - sizeof(header);
-        unsigned int size = 0;
-        unsigned int i = 0;
-        while (size < chunksSize) {
-            size += getChunk(i++)->getSize();
-        }
-        return i;
-    }
-
-    /// Get chunk at given index
-    /// @note All chunks (and their items) with index < `num` must be valid, otherwise this function has undefined behaviour (use `isValid` to check if chunk is valid)
-    /// @param num Index of chunk to return
-    inline RTCP_SDES_CHUNK *getChunk(int num) {
-        auto base = &_chunks;
-        while (num-- > 0) {
-            auto chunkSize = base->getSize();
-            base = reinterpret_cast<RTCP_SDES_CHUNK *>(reinterpret_cast<uint8_t *>(base) + chunkSize);
-        }
-        return reinterpret_cast<RTCP_SDES_CHUNK *>(base);
-    }
-
-    [[nodiscard]] static unsigned int size(const std::vector<std::vector<uint8_t>> lengths) {
-        unsigned int chunks_size = 0;
-        for (auto length: lengths) {
-            chunks_size += RTCP_SDES_CHUNK::size(length);
-        }
-        return 4 + chunks_size;
-    }
+	inline void preparePacket(uint8_t chunkCount) {
+		unsigned int chunkSize = 0;
+		for (uint8_t i = 0; i < chunkCount; i++) {
+			auto chunk = getChunk(i);
+			chunkSize += chunk->getSize();
+		}
+		uint16_t length = (sizeof(header) + chunkSize) / 4 - 1;
+		header.prepareHeader(202, chunkCount, length);
+	}
+
+	bool isValid() {
+		auto chunksSize = header.lengthInBytes() - sizeof(header);
+		if (chunksSize == 0) {
+			return true;
+		} else {
+			// there is at least one chunk
+			unsigned int i = 0;
+			unsigned int size = 0;
+			while (size < chunksSize) {
+				if (chunksSize < size + RTCP_SDES_CHUNK::size({})) {
+					// chunk is truncated
+					return false;
+				}
+				auto chunk = getChunk(i++);
+				auto chunkSize = chunk->safelyCountChunkSize(chunksSize - size);
+				if (chunkSize < 0) {
+					// chunk is invalid
+					return false;
+				}
+				size += chunkSize;
+			}
+			return size == chunksSize;
+		}
+	}
+
+	/// Returns number of chunks in this packet
+	/// @note Returns 0 if packet is invalid
+	inline unsigned int chunksCount() {
+		if (!isValid()) {
+			return 0;
+		}
+		uint16_t chunksSize = 4 * (header.length() + 1) - sizeof(header);
+		unsigned int size = 0;
+		unsigned int i = 0;
+		while (size < chunksSize) {
+			size += getChunk(i++)->getSize();
+		}
+		return i;
+	}
+
+	/// Get chunk at given index
+	/// @note All chunks (and their items) with index < `num` must be valid, otherwise this function
+	/// has undefined behaviour (use `isValid` to check if chunk is valid)
+	/// @param num Index of chunk to return
+	inline RTCP_SDES_CHUNK *getChunk(int num) {
+		auto base = &_chunks;
+		while (num-- > 0) {
+			auto chunkSize = base->getSize();
+			base =
+			    reinterpret_cast<RTCP_SDES_CHUNK *>(reinterpret_cast<uint8_t *>(base) + chunkSize);
+		}
+		return reinterpret_cast<RTCP_SDES_CHUNK *>(base);
+	}
+
+	[[nodiscard]] static unsigned int size(const std::vector<std::vector<uint8_t>> lengths) {
+		unsigned int chunks_size = 0;
+		for (auto length : lengths) {
+			chunks_size += RTCP_SDES_CHUNK::size(length);
+		}
+		return 4 + chunks_size;
+	}
 };
 
 struct RTCP_RR {

+ 59 - 54
include/rtc/rtppacketizationconfig.hpp

@@ -27,63 +27,68 @@ namespace rtc {
 
 /// RTP configuration used in packetization process
 class RTC_CPP_EXPORT RTPPacketizationConfig {
-    uint32_t _startTimestamp = 0;
-    double _startTime_s = 0;
-    RTPPacketizationConfig(const RTPPacketizationConfig&) = delete;
+	uint32_t _startTimestamp = 0;
+	double _startTime_s = 0;
+	RTPPacketizationConfig(const RTPPacketizationConfig &) = delete;
+
 public:
-    const SSRC ssrc;
-    const std::string cname;
-    const uint8_t payloadType;
-    const uint32_t clockRate;
-    const double & startTime_s = _startTime_s;
-    const uint32_t & startTimestamp = _startTimestamp;
-
-    /// current sequence number
-    uint16_t sequenceNumber;
-    /// current timestamp
-    uint32_t timestamp;
-
-    enum class EpochStart: unsigned long long {
-        T1970 = 2208988800, // number of seconds between 1970 and 1900
-        T1900 = 0
-    };
-
-    /// Creates relation between time and timestamp mapping given start time and start timestamp
-    /// @param startTime_s Start time of the stream
-    /// @param epochStart Type of used epoch
-    /// @param startTimestamp Corresponding timestamp for given start time (current timestamp will be used if value is nullopt)
-    void setStartTime(double startTime_s, EpochStart epochStart, std::optional<uint32_t> startTimestamp = std::nullopt);
-
-
-    /// Construct RTP configuration used in packetization process
-    /// @param ssrc SSRC of source
-    /// @param cname CNAME of source
-    /// @param payloadType Payload type of source
-    /// @param clockRate Clock rate of source used in timestamps
-    /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if nullopt)
-    /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
-    RTPPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate, std::optional<uint16_t> sequenceNumber = std::nullopt, std::optional<uint32_t> timestamp = std::nullopt);
-
-    /// Convert timestamp to seconds
-    /// @param timestamp Timestamp
-    /// @param clockRate Clock rate for timestamp calculation
-    static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
-
-    /// Convert timestamp to seconds
-    /// @param timestamp Timestamp
-    double timestampToSeconds(uint32_t timestamp);
-
-    /// Convert seconds to timestamp
-    /// @param seconds Number of seconds
-    /// @param clockRate Clock rate for timestamp calculation
-    static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
-
-    /// Convert seconds to timestamp
-    /// @param seconds Number of seconds
-    uint32_t secondsToTimestamp(double seconds);
+	const SSRC ssrc;
+	const std::string cname;
+	const uint8_t payloadType;
+	const uint32_t clockRate;
+	const double &startTime_s = _startTime_s;
+	const uint32_t &startTimestamp = _startTimestamp;
+
+	/// current sequence number
+	uint16_t sequenceNumber;
+	/// current timestamp
+	uint32_t timestamp;
+
+	enum class EpochStart : unsigned long long {
+		T1970 = 2208988800, // number of seconds between 1970 and 1900
+		T1900 = 0
+	};
+
+	/// Creates relation between time and timestamp mapping given start time and start timestamp
+	/// @param startTime_s Start time of the stream
+	/// @param epochStart Type of used epoch
+	/// @param startTimestamp Corresponding timestamp for given start time (current timestamp will
+	/// be used if value is nullopt)
+	void setStartTime(double startTime_s, EpochStart epochStart,
+	                  std::optional<uint32_t> startTimestamp = std::nullopt);
+
+	/// Construct RTP configuration used in packetization process
+	/// @param ssrc SSRC of source
+	/// @param cname CNAME of source
+	/// @param payloadType Payload type of source
+	/// @param clockRate Clock rate of source used in timestamps
+	/// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
+	/// nullopt)
+	/// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
+	RTPPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
+	                       std::optional<uint16_t> sequenceNumber = std::nullopt,
+	                       std::optional<uint32_t> timestamp = std::nullopt);
+
+	/// Convert timestamp to seconds
+	/// @param timestamp Timestamp
+	/// @param clockRate Clock rate for timestamp calculation
+	static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
+
+	/// Convert timestamp to seconds
+	/// @param timestamp Timestamp
+	double timestampToSeconds(uint32_t timestamp);
+
+	/// Convert seconds to timestamp
+	/// @param seconds Number of seconds
+	/// @param clockRate Clock rate for timestamp calculation
+	static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
+
+	/// Convert seconds to timestamp
+	/// @param seconds Number of seconds
+	uint32_t secondsToTimestamp(double seconds);
 };
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 18 - 16
include/rtc/rtppacketizer.hpp

@@ -21,31 +21,33 @@
 
 #if RTC_ENABLE_MEDIA
 
-#include "rtppacketizationconfig.hpp"
 #include "message.hpp"
+#include "rtppacketizationconfig.hpp"
 
 namespace rtc {
 
 /// Class responsizble for rtp packetization
 class RTC_CPP_EXPORT RTPPacketizer {
-    static const auto rtpHeaderSize = 12;
+	static const auto rtpHeaderSize = 12;
+
 public:
-    // rtp configuration
-    const std::shared_ptr<RTPPacketizationConfig> rtpConfig;
-
-    /// Constructs packetizer with given RTP configuration.
-    /// @note RTP configuration is used in packetization process which may change some configuration properties such as sequence number.
-    /// @param rtpConfig  RTP configuration
-    RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig);
-
-    /// Creates RTP packet for given payload based on `rtpConfig`.
-    /// @note This function increase sequence number after packetization.
-    /// @param payload RTP payload
-    /// @param setMark Set marker flag in RTP packet if true
-    virtual message_ptr packetize(binary payload, bool setMark);
+	// rtp configuration
+	const std::shared_ptr<RTPPacketizationConfig> rtpConfig;
+
+	/// Constructs packetizer with given RTP configuration.
+	/// @note RTP configuration is used in packetization process which may change some configuration
+	/// properties such as sequence number.
+	/// @param rtpConfig  RTP configuration
+	RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig);
+
+	/// Creates RTP packet for given payload based on `rtpConfig`.
+	/// @note This function increase sequence number after packetization.
+	/// @param payload RTP payload
+	/// @param setMark Set marker flag in RTP packet if true
+	virtual message_ptr packetize(binary payload, bool setMark);
 };
 
-}   // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */
 

+ 2 - 1
include/rtc/websocket.hpp

@@ -38,7 +38,8 @@ class TcpTransport;
 class TlsTransport;
 class WsTransport;
 
-class RTC_CPP_EXPORT WebSocket final : public Channel, public std::enable_shared_from_this<WebSocket> {
+class RTC_CPP_EXPORT WebSocket final : public Channel,
+                                       public std::enable_shared_from_this<WebSocket> {
 public:
 	enum class State : int {
 		Connecting = 0,

+ 5 - 4
src/datachannel.cpp

@@ -18,9 +18,9 @@
 
 #include "datachannel.hpp"
 #include "include.hpp"
+#include "logcounter.hpp"
 #include "peerconnection.hpp"
 #include "sctptransport.hpp"
-#include "logcounter.hpp"
 
 #ifdef _WIN32
 #include <winsock2.h>
@@ -28,7 +28,8 @@
 #include <arpa/inet.h>
 #endif
 
-rtc::LogCounter COUNTER_USERNEG_OPEN_MESSAGE(plog::warning, "Number of open messages for a user-negotiated DataChannel received");
+rtc::LogCounter COUNTER_USERNEG_OPEN_MESSAGE(
+    plog::warning, "Number of open messages for a user-negotiated DataChannel received");
 namespace rtc {
 
 using std::shared_ptr;
@@ -172,8 +173,8 @@ void DataChannel::open(shared_ptr<SctpTransport> transport) {
 }
 
 void DataChannel::processOpenMessage(message_ptr) {
-    PLOG_DEBUG << "Received an open message for a user-negotiated DataChannel, ignoring";
-    COUNTER_USERNEG_OPEN_MESSAGE++;
+	PLOG_DEBUG << "Received an open message for a user-negotiated DataChannel, ignoring";
+	COUNTER_USERNEG_OPEN_MESSAGE++;
 }
 
 bool DataChannel::outgoing(message_ptr message) {

+ 12 - 4
src/description.cpp

@@ -744,11 +744,17 @@ void Description::Media::addRTXCodec(unsigned int payloadType, unsigned int orig
 	addRTPMap(map);
 }
 
-void Description::Video::addH264Codec(int pt, std::optional<string> profile) { addVideoCodec(pt, "H264", profile); }
+void Description::Video::addH264Codec(int pt, std::optional<string> profile) {
+	addVideoCodec(pt, "H264", profile);
+}
 
-void Description::Video::addVP8Codec(int payloadType) { addVideoCodec(payloadType, "VP8", nullopt); }
+void Description::Video::addVP8Codec(int payloadType) {
+	addVideoCodec(payloadType, "VP8", nullopt);
+}
 
-void Description::Video::addVP9Codec(int payloadType) { addVideoCodec(payloadType, "VP9", nullopt); }
+void Description::Video::addVP9Codec(int payloadType) {
+	addVideoCodec(payloadType, "VP9", nullopt);
+}
 
 void Description::Media::setBitrate(int bitrate) { mBas = bitrate; }
 
@@ -901,7 +907,9 @@ void Description::Media::RTPMap::setMLine(string_view mline) {
 Description::Audio::Audio(string mid, Direction dir)
     : Media("audio 9 UDP/TLS/RTP/SAVPF", std::move(mid), dir) {}
 
-void Description::Audio::addOpusCodec(int payloadType, std::optional<string> profile) { addAudioCodec(payloadType, "OPUS", profile); }
+void Description::Audio::addOpusCodec(int payloadType, std::optional<string> profile) {
+	addAudioCodec(payloadType, "OPUS", profile);
+}
 
 Description::Video::Video(string mid, Direction dir)
     : Media("video 9 UDP/TLS/RTP/SAVPF", std::move(mid), dir) {}

+ 42 - 32
src/dtlssrtptransport.cpp

@@ -17,8 +17,8 @@
  */
 
 #include "dtlssrtptransport.hpp"
-#include "tls.hpp"
 #include "logcounter.hpp"
+#include "tls.hpp"
 
 #if RTC_ENABLE_MEDIA
 
@@ -29,14 +29,26 @@ using std::shared_ptr;
 using std::to_integer;
 using std::to_string;
 
-static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning, "Number of truncated SRT(C)P packets received");
-static rtc::LogCounter COUNTER_UNKNOWN_PACKET_TYPE(plog::warning, "Number of RTP packets received with an unknown packet type");
-static rtc::LogCounter COUNTER_SRTCP_REPLAY(plog::warning, "Number of SRTCP replay packets received");
-static rtc::LogCounter COUNTER_SRTCP_AUTH_FAIL(plog::warning, "Number of SRTCP packets received that failed authentication checks");
-static rtc::LogCounter COUNTER_SRTCP_FAIL(plog::warning, "Number of SRTCP packets received that had an unknown libSRTP failure");
+static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning,
+                                               "Number of truncated SRT(C)P packets received");
+static rtc::LogCounter
+    COUNTER_UNKNOWN_PACKET_TYPE(plog::warning,
+                                "Number of RTP packets received with an unknown packet type");
+static rtc::LogCounter COUNTER_SRTCP_REPLAY(plog::warning,
+                                            "Number of SRTCP replay packets received");
+static rtc::LogCounter
+    COUNTER_SRTCP_AUTH_FAIL(plog::warning,
+                            "Number of SRTCP packets received that failed authentication checks");
+static rtc::LogCounter
+    COUNTER_SRTCP_FAIL(plog::warning,
+                       "Number of SRTCP packets received that had an unknown libSRTP failure");
 static rtc::LogCounter COUNTER_SRTP_REPLAY(plog::warning, "Number of SRTP replay packets received");
-static rtc::LogCounter COUNTER_SRTP_AUTH_FAIL(plog::warning, "Number of SRTP packets received that failed authentication checks");
-static rtc::LogCounter COUNTER_SRTP_FAIL(plog::warning, "Number of SRTP packets received that had an unknown libSRTP failure");
+static rtc::LogCounter
+    COUNTER_SRTP_AUTH_FAIL(plog::warning,
+                           "Number of SRTP packets received that failed authentication checks");
+static rtc::LogCounter
+    COUNTER_SRTP_FAIL(plog::warning,
+                      "Number of SRTP packets received that had an unknown libSRTP failure");
 
 namespace rtc {
 
@@ -83,14 +95,13 @@ DtlsSrtpTransport::~DtlsSrtpTransport() {
 	srtp_dealloc(mSrtpOut);
 }
 
-
 bool DtlsSrtpTransport::sendMedia(message_ptr message) {
 	std::lock_guard lock(sendMutex);
 	if (!message)
 		return false;
 
 	if (!mInitDone) {
-        PLOG_ERROR << "SRTP media sent before keys are derived";
+		PLOG_ERROR << "SRTP media sent before keys are derived";
 		return false;
 	}
 
@@ -148,7 +159,6 @@ bool DtlsSrtpTransport::sendMedia(message_ptr message) {
 	return Transport::outgoing(message); // bypass DTLS DSCP marking
 }
 
-
 void DtlsSrtpTransport::incoming(message_ptr message) {
 	if (!mInitDone) {
 		// Bypas
@@ -177,7 +187,7 @@ void DtlsSrtpTransport::incoming(message_ptr message) {
 		// The RTP header has a minimum size of 12 bytes
 		// An RTCP packet can have a minimum size of 8 bytes
 		if (size < 8) {
-            COUNTER_MEDIA_TRUNCATED++;
+			COUNTER_MEDIA_TRUNCATED++;
 			PLOG_VERBOSE << "Incoming SRTP/SRTCP packet too short, size=" << size;
 			return;
 		}
@@ -191,15 +201,15 @@ void DtlsSrtpTransport::incoming(message_ptr message) {
 			PLOG_VERBOSE << "Incoming SRTCP packet, size=" << size;
 			if (srtp_err_status_t err = srtp_unprotect_rtcp(mSrtpIn, message->data(), &size)) {
 				if (err == srtp_err_status_replay_fail) {
-                    PLOG_VERBOSE << "Incoming SRTCP packet is a replay";
-                    COUNTER_SRTCP_REPLAY++;
-                }else if (err == srtp_err_status_auth_fail) {
-                    PLOG_VERBOSE << "Incoming SRTCP packet failed authentication check";
-                    COUNTER_SRTCP_AUTH_FAIL++;
-                }else {
-                    PLOG_VERBOSE << "SRTCP unprotect error, status=" << err;
-                    COUNTER_SRTCP_FAIL++;
-                }
+					PLOG_VERBOSE << "Incoming SRTCP packet is a replay";
+					COUNTER_SRTCP_REPLAY++;
+				} else if (err == srtp_err_status_auth_fail) {
+					PLOG_VERBOSE << "Incoming SRTCP packet failed authentication check";
+					COUNTER_SRTCP_AUTH_FAIL++;
+				} else {
+					PLOG_VERBOSE << "SRTCP unprotect error, status=" << err;
+					COUNTER_SRTCP_FAIL++;
+				}
 
 				return;
 			}
@@ -210,16 +220,16 @@ void DtlsSrtpTransport::incoming(message_ptr message) {
 		} else {
 			PLOG_VERBOSE << "Incoming SRTP packet, size=" << size;
 			if (srtp_err_status_t err = srtp_unprotect(mSrtpIn, message->data(), &size)) {
-                if (err == srtp_err_status_replay_fail) {
-                    PLOG_VERBOSE << "Incoming SRTP packet is a replay";
-                    COUNTER_SRTP_REPLAY++;
-                } else if (err == srtp_err_status_auth_fail) {
-                    PLOG_VERBOSE << "Incoming SRTP packet failed authentication check";
-                    COUNTER_SRTP_AUTH_FAIL++;
-                } else {
-                    PLOG_VERBOSE << "SRTP unprotect error, status=" << err;
-                    COUNTER_SRTP_FAIL++;
-                }
+				if (err == srtp_err_status_replay_fail) {
+					PLOG_VERBOSE << "Incoming SRTP packet is a replay";
+					COUNTER_SRTP_REPLAY++;
+				} else if (err == srtp_err_status_auth_fail) {
+					PLOG_VERBOSE << "Incoming SRTP packet failed authentication check";
+					COUNTER_SRTP_AUTH_FAIL++;
+				} else {
+					PLOG_VERBOSE << "SRTP unprotect error, status=" << err;
+					COUNTER_SRTP_FAIL++;
+				}
 				return;
 			}
 			PLOG_VERBOSE << "Unprotected SRTP packet, size=" << size;
@@ -231,7 +241,7 @@ void DtlsSrtpTransport::incoming(message_ptr message) {
 		mSrtpRecvCallback(message);
 
 	} else {
-	    COUNTER_UNKNOWN_PACKET_TYPE++;
+		COUNTER_UNKNOWN_PACKET_TYPE++;
 		PLOG_VERBOSE << "Unknown packet type, value=" << unsigned(value1) << ", size=" << size;
 	}
 }

+ 124 - 125
src/h264packetizationhandler.cpp

@@ -22,148 +22,147 @@
 
 namespace rtc {
 
-using std::shared_ptr;
-using std::make_shared;
 using std::function;
+using std::make_shared;
+using std::shared_ptr;
 
 typedef enum {
-    NUSM_noMatch,
-    NUSM_firstZero,
-    NUSM_secondZero,
-    NUSM_thirdZero,
-    NUSM_shortMatch,
-    NUSM_longMatch
+	NUSM_noMatch,
+	NUSM_firstZero,
+	NUSM_secondZero,
+	NUSM_thirdZero,
+	NUSM_shortMatch,
+	NUSM_longMatch
 } NalUnitStartSequenceMatch;
 
-NalUnitStartSequenceMatch StartSequenceMatchSucc(NalUnitStartSequenceMatch match, byte _byte, H264PacketizationHandler::Separator separator) {
-    assert(separator != H264PacketizationHandler::Separator::Length);
-    auto byte = (uint8_t) _byte;
-    auto detectShort = separator == H264PacketizationHandler::Separator::ShortStartSequence || separator == H264PacketizationHandler::Separator::StartSequence;
-    auto detectLong = separator == H264PacketizationHandler::Separator::LongStartSequence || separator == H264PacketizationHandler::Separator::StartSequence;
-    switch (match) {
-        case NUSM_noMatch:
-            if (byte == 0x00) {
-                return NUSM_firstZero;
-            }
-            break;
-        case NUSM_firstZero:
-            if (byte == 0x00) {
-                return NUSM_secondZero;
-            }
-            break;
-        case NUSM_secondZero:
-            if (byte == 0x00 && detectLong) {
-                return NUSM_thirdZero;
-            } else if (byte == 0x01 && detectShort) {
-                return NUSM_shortMatch;
-            }
-            break;
-        case NUSM_thirdZero:
-            if (byte == 0x01 && detectLong) {
-                return NUSM_longMatch;
-            }
-            break;
-        case NUSM_shortMatch:
-            return NUSM_shortMatch;
-        case NUSM_longMatch:
-            return NUSM_longMatch;
-    }
-    return NUSM_noMatch;
+NalUnitStartSequenceMatch StartSequenceMatchSucc(NalUnitStartSequenceMatch match, byte _byte,
+                                                 H264PacketizationHandler::Separator separator) {
+	assert(separator != H264PacketizationHandler::Separator::Length);
+	auto byte = (uint8_t)_byte;
+	auto detectShort = separator == H264PacketizationHandler::Separator::ShortStartSequence ||
+	                   separator == H264PacketizationHandler::Separator::StartSequence;
+	auto detectLong = separator == H264PacketizationHandler::Separator::LongStartSequence ||
+	                  separator == H264PacketizationHandler::Separator::StartSequence;
+	switch (match) {
+	case NUSM_noMatch:
+		if (byte == 0x00) {
+			return NUSM_firstZero;
+		}
+		break;
+	case NUSM_firstZero:
+		if (byte == 0x00) {
+			return NUSM_secondZero;
+		}
+		break;
+	case NUSM_secondZero:
+		if (byte == 0x00 && detectLong) {
+			return NUSM_thirdZero;
+		} else if (byte == 0x01 && detectShort) {
+			return NUSM_shortMatch;
+		}
+		break;
+	case NUSM_thirdZero:
+		if (byte == 0x01 && detectLong) {
+			return NUSM_longMatch;
+		}
+		break;
+	case NUSM_shortMatch:
+		return NUSM_shortMatch;
+	case NUSM_longMatch:
+		return NUSM_longMatch;
+	}
+	return NUSM_noMatch;
 }
 
-message_ptr H264PacketizationHandler::incoming(message_ptr ptr) {
-    return ptr;
-}
+message_ptr H264PacketizationHandler::incoming(message_ptr ptr) { return ptr; }
 
 shared_ptr<NalUnits> H264PacketizationHandler::splitMessage(rtc::message_ptr message) {
-    auto nalus = make_shared<NalUnits>();
-    if (separator == Separator::Length) {
-        unsigned long long index = 0;
-        while (index < message->size()) {
-            assert(index + 4 < message->size());
-            if (index + 4 >= message->size()) {
-                LOG_WARNING << "Invalid NAL Unit data (incomplete length), ignoring!";
-                break;
-            }
-            auto lengthPtr = (uint32_t *) (message->data() + index);
-            uint32_t length = ntohl(*lengthPtr);
-            auto naluStartIndex = index + 4;
-            auto naluEndIndex = naluStartIndex + length;
-
-            assert(naluEndIndex <= message->size());
-            if (naluEndIndex > message->size()) {
-                LOG_WARNING << "Invalid NAL Unit data (incomplete unit), ignoring!";
-                break;
-            }
-            nalus->push_back(NalUnit(message->begin() + naluStartIndex, message->begin() + naluEndIndex));
-            index = naluEndIndex;
-        }
-    } else {
-        NalUnitStartSequenceMatch match = NUSM_noMatch;
-        unsigned long long index = 0;
-        while (index < message->size()) {
-            match = StartSequenceMatchSucc(match, (*message)[index++], separator);
-            if (match == NUSM_longMatch || match == NUSM_shortMatch) {
-                match = NUSM_noMatch;
-                break;
-            }
-        }
-        index++;
-        unsigned long long naluStartIndex = index;
-
-        while (index < message->size()) {
-            match = StartSequenceMatchSucc(match, (*message)[index], separator);
-            if (match == NUSM_longMatch || match == NUSM_shortMatch) {
-                auto sequenceLength = match == NUSM_longMatch ? 4 : 3;
-                unsigned long long naluEndIndex = index - sequenceLength;
-                match = NUSM_noMatch;
-                nalus->push_back(NalUnit(message->begin() + naluStartIndex, message->begin() + naluEndIndex + 1));
-                naluStartIndex = index + 1;
-            }
-            index++;
-        }
-        nalus->push_back(NalUnit(message->begin() + naluStartIndex, message->end()));
-    }
-    return nalus;
+	auto nalus = make_shared<NalUnits>();
+	if (separator == Separator::Length) {
+		unsigned long long index = 0;
+		while (index < message->size()) {
+			assert(index + 4 < message->size());
+			if (index + 4 >= message->size()) {
+				LOG_WARNING << "Invalid NAL Unit data (incomplete length), ignoring!";
+				break;
+			}
+			auto lengthPtr = (uint32_t *)(message->data() + index);
+			uint32_t length = ntohl(*lengthPtr);
+			auto naluStartIndex = index + 4;
+			auto naluEndIndex = naluStartIndex + length;
+
+			assert(naluEndIndex <= message->size());
+			if (naluEndIndex > message->size()) {
+				LOG_WARNING << "Invalid NAL Unit data (incomplete unit), ignoring!";
+				break;
+			}
+			nalus->push_back(
+			    NalUnit(message->begin() + naluStartIndex, message->begin() + naluEndIndex));
+			index = naluEndIndex;
+		}
+	} else {
+		NalUnitStartSequenceMatch match = NUSM_noMatch;
+		unsigned long long index = 0;
+		while (index < message->size()) {
+			match = StartSequenceMatchSucc(match, (*message)[index++], separator);
+			if (match == NUSM_longMatch || match == NUSM_shortMatch) {
+				match = NUSM_noMatch;
+				break;
+			}
+		}
+		index++;
+		unsigned long long naluStartIndex = index;
+
+		while (index < message->size()) {
+			match = StartSequenceMatchSucc(match, (*message)[index], separator);
+			if (match == NUSM_longMatch || match == NUSM_shortMatch) {
+				auto sequenceLength = match == NUSM_longMatch ? 4 : 3;
+				unsigned long long naluEndIndex = index - sequenceLength;
+				match = NUSM_noMatch;
+				nalus->push_back(NalUnit(message->begin() + naluStartIndex,
+				                         message->begin() + naluEndIndex + 1));
+				naluStartIndex = index + 1;
+			}
+			index++;
+		}
+		nalus->push_back(NalUnit(message->begin() + naluStartIndex, message->end()));
+	}
+	return nalus;
 }
 
 message_ptr H264PacketizationHandler::outgoing(message_ptr ptr) {
-    if (ptr->type == Message::Binary) {
-        auto nalus = splitMessage(ptr);
-        auto fragments = nalus->generateFragments(maximumFragmentSize);
-
-         auto lastPacket = withStatsRecording<message_ptr>([fragments, this](function<void (message_ptr)> addToReport) {
-             for(unsigned long long index = 0; index < fragments.size() - 1; index++) {
-                 auto packet = packetizer->packetize(fragments[index], false);
-
-                 addToReport(packet);
-
-                 outgoingCallback(std::move(packet));
-             }
-             // packet is last, marker must be set
-             auto lastPacket = packetizer->packetize(fragments[fragments.size() - 1], true);
-             addToReport(lastPacket);
-             return lastPacket;
-         });
-        return lastPacket;
-    }
-    return ptr;
+	if (ptr->type == Message::Binary) {
+		auto nalus = splitMessage(ptr);
+		auto fragments = nalus->generateFragments(maximumFragmentSize);
+
+		auto lastPacket = withStatsRecording<message_ptr>(
+		    [fragments, this](function<void(message_ptr)> addToReport) {
+			    for (unsigned long long index = 0; index < fragments.size() - 1; index++) {
+				    auto packet = packetizer->packetize(fragments[index], false);
+
+				    addToReport(packet);
+
+				    outgoingCallback(std::move(packet));
+			    }
+			    // packet is last, marker must be set
+			    auto lastPacket = packetizer->packetize(fragments[fragments.size() - 1], true);
+			    addToReport(lastPacket);
+			    return lastPacket;
+		    });
+		return lastPacket;
+	}
+	return ptr;
 }
 
 H264PacketizationHandler::H264PacketizationHandler(Separator separator,
                                                    std::shared_ptr<H264RTPPacketizer> packetizer,
-                                                   uint16_t maximumFragmentSize):
-        RtcpHandler(),
-        rtc::RTCPSenderReportable(packetizer->rtpConfig),
-        packetizer(packetizer),
-        maximumFragmentSize(maximumFragmentSize),
-        separator(separator) {
-
-    senderReportOutgoingCallback = [this](message_ptr msg) {
-        outgoingCallback(msg);
-    };
+                                                   uint16_t maximumFragmentSize)
+    : RtcpHandler(), rtc::RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer),
+      maximumFragmentSize(maximumFragmentSize), separator(separator) {
+
+	senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); };
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 3 - 2
src/h264rtppacketizer.cpp

@@ -22,8 +22,9 @@
 
 namespace rtc {
 
-H264RTPPacketizer::H264RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig): RTPPacketizer(rtpConfig) { }
+H264RTPPacketizer::H264RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig)
+    : RTPPacketizer(rtpConfig) {}
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 1 - 1
src/icetransport.hpp

@@ -34,8 +34,8 @@
 
 #include <atomic>
 #include <chrono>
-#include <thread>
 #include <mutex>
+#include <thread>
 
 namespace rtc {
 

+ 23 - 17
src/logcounter.cpp

@@ -18,23 +18,29 @@
 
 #include "logcounter.hpp"
 
-rtc::LogCounter::LogCounter(plog::Severity severity, const std::string &text, std::chrono::seconds duration) {
-    mData = std::make_shared<LogData>();
-    mData->mDuration  =duration;
-    mData->mSeverity = severity;
-    mData->mText = text;
+rtc::LogCounter::LogCounter(plog::Severity severity, const std::string &text,
+                            std::chrono::seconds duration) {
+	mData = std::make_shared<LogData>();
+	mData->mDuration = duration;
+	mData->mSeverity = severity;
+	mData->mText = text;
 }
 
-rtc::LogCounter& rtc::LogCounter::operator++(int) {
-    if (mData->mCount++ == 0) {
-        ThreadPool::Instance().schedule(mData->mDuration, [](std::weak_ptr<LogData> data) {
-            if (auto ptr = data.lock()) {
-                int countCopy;
-                countCopy = ptr->mCount.exchange(0);
-                PLOG(ptr->mSeverity) << ptr->mText << ": " << countCopy << " (over "
-                               << std::chrono::duration_cast<std::chrono::seconds>(ptr->mDuration).count() << " seconds)";
-            }
-        }, mData);
-    }
-    return *this;
+rtc::LogCounter &rtc::LogCounter::operator++(int) {
+	if (mData->mCount++ == 0) {
+		ThreadPool::Instance().schedule(
+		    mData->mDuration,
+		    [](std::weak_ptr<LogData> data) {
+			    if (auto ptr = data.lock()) {
+				    int countCopy;
+				    countCopy = ptr->mCount.exchange(0);
+				    PLOG(ptr->mSeverity)
+				        << ptr->mText << ": " << countCopy << " (over "
+				        << std::chrono::duration_cast<std::chrono::seconds>(ptr->mDuration).count()
+				        << " seconds)";
+			    }
+		    },
+		    mData);
+	}
+	return *this;
 }

+ 13 - 13
src/logcounter.hpp

@@ -19,28 +19,28 @@
 #ifndef WEBRTC_SERVER_LOGCOUNTER_HPP
 #define WEBRTC_SERVER_LOGCOUNTER_HPP
 
-#include "threadpool.hpp"
 #include "include.hpp"
+#include "threadpool.hpp"
 
 namespace rtc {
 class LogCounter {
 private:
-    struct LogData {
-        plog::Severity mSeverity;
-        std::string mText;
-        std::chrono::steady_clock::duration mDuration;
+	struct LogData {
+		plog::Severity mSeverity;
+		std::string mText;
+		std::chrono::steady_clock::duration mDuration;
 
-        std::atomic<int> mCount = 0;
-    };
+		std::atomic<int> mCount = 0;
+	};
 
-    std::shared_ptr<LogData> mData;
+	std::shared_ptr<LogData> mData;
 
 public:
+	LogCounter(plog::Severity severity, const std::string &text,
+	           std::chrono::seconds duration = std::chrono::seconds(1));
 
-    LogCounter(plog::Severity severity, const std::string& text, std::chrono::seconds duration=std::chrono::seconds(1));
-
-    LogCounter& operator++(int);
+	LogCounter &operator++(int);
 };
-}
+} // namespace rtc
 
-#endif //WEBRTC_SERVER_LOGCOUNTER_HPP
+#endif // WEBRTC_SERVER_LOGCOUNTER_HPP

+ 71 - 67
src/nalunit.cpp

@@ -23,83 +23,87 @@
 
 namespace rtc {
 
-NalUnitFragmentA::NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType, binary data): NalUnit(data.size() + 2) {
-    setForbiddenBit(forbiddenBit);
-    setNRI(nri);
-    fragmentIndicator()->setUnitType(NalUnitFragmentA::nal_type_fu_A);
-    setFragmentType(type);
-    setUnitType(unitType);
-    copy(data.begin(), data.end(), begin() + 2);
+NalUnitFragmentA::NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri,
+                                   uint8_t unitType, binary data)
+    : NalUnit(data.size() + 2) {
+	setForbiddenBit(forbiddenBit);
+	setNRI(nri);
+	fragmentIndicator()->setUnitType(NalUnitFragmentA::nal_type_fu_A);
+	setFragmentType(type);
+	setUnitType(unitType);
+	copy(data.begin(), data.end(), begin() + 2);
 }
 
-std::vector<NalUnitFragmentA> NalUnitFragmentA::fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize) {
-    assert(nalu.size() > maximumFragmentSize);
-    if (nalu.size() <= maximumFragmentSize) {
-        // we need to change `maximum_fragment_size` to have at least two fragments
-        maximumFragmentSize = nalu.size() / 2;
-    }
-    auto fragments_count = ceil(double(nalu.size()) / maximumFragmentSize);
-    maximumFragmentSize = ceil(nalu.size() / fragments_count);
+std::vector<NalUnitFragmentA> NalUnitFragmentA::fragmentsFrom(NalUnit nalu,
+                                                              uint16_t maximumFragmentSize) {
+	assert(nalu.size() > maximumFragmentSize);
+	if (nalu.size() <= maximumFragmentSize) {
+		// we need to change `maximum_fragment_size` to have at least two fragments
+		maximumFragmentSize = nalu.size() / 2;
+	}
+	auto fragments_count = ceil(double(nalu.size()) / maximumFragmentSize);
+	maximumFragmentSize = ceil(nalu.size() / fragments_count);
 
-    // 2 bytes for FU indicator and FU header
-    maximumFragmentSize -= 2;
-    auto f = nalu.forbiddenBit();
-    uint8_t nri = nalu.nri() & 0x03;
-    uint8_t naluType = nalu.unitType() & 0x1F;
-    auto payload = nalu.payload();
-    vector<NalUnitFragmentA> result{};
-    uint64_t offset = 0;
-    while (offset < payload.size()) {
-        vector<byte> fragmentData;
-        FragmentType fragmentType;
-        if (offset == 0) {
-            fragmentType = FragmentType::Start;
-        } else if (offset + maximumFragmentSize < payload.size()) {
-            fragmentType = FragmentType::Middle;
-        } else {
-            if (offset + maximumFragmentSize > payload.size()) {
-                maximumFragmentSize = payload.size() - offset;
-            }
-            fragmentType = FragmentType::End;
-        }
-        fragmentData = {payload.begin() + offset, payload.begin() + offset + maximumFragmentSize};
-        NalUnitFragmentA fragment{fragmentType, f, nri, naluType, fragmentData};
-        result.push_back(fragment);
-        offset += maximumFragmentSize;
-    }
-    return result;
+	// 2 bytes for FU indicator and FU header
+	maximumFragmentSize -= 2;
+	auto f = nalu.forbiddenBit();
+	uint8_t nri = nalu.nri() & 0x03;
+	uint8_t naluType = nalu.unitType() & 0x1F;
+	auto payload = nalu.payload();
+	vector<NalUnitFragmentA> result{};
+	uint64_t offset = 0;
+	while (offset < payload.size()) {
+		vector<byte> fragmentData;
+		FragmentType fragmentType;
+		if (offset == 0) {
+			fragmentType = FragmentType::Start;
+		} else if (offset + maximumFragmentSize < payload.size()) {
+			fragmentType = FragmentType::Middle;
+		} else {
+			if (offset + maximumFragmentSize > payload.size()) {
+				maximumFragmentSize = payload.size() - offset;
+			}
+			fragmentType = FragmentType::End;
+		}
+		fragmentData = {payload.begin() + offset, payload.begin() + offset + maximumFragmentSize};
+		NalUnitFragmentA fragment{fragmentType, f, nri, naluType, fragmentData};
+		result.push_back(fragment);
+		offset += maximumFragmentSize;
+	}
+	return result;
 }
 
 void NalUnitFragmentA::setFragmentType(FragmentType type) {
-    fragmentHeader()->setReservedBit6(false);
-    switch (type) {
-        case FragmentType::Start:
-            fragmentHeader()->setStart(true);
-            fragmentHeader()->setEnd(false);
-            break;
-        case FragmentType::End:
-            fragmentHeader()->setStart(false);
-            fragmentHeader()->setEnd(true);
-            break;
-        default:
-            fragmentHeader()->setStart(false);
-            fragmentHeader()->setEnd(false);
-    }
+	fragmentHeader()->setReservedBit6(false);
+	switch (type) {
+	case FragmentType::Start:
+		fragmentHeader()->setStart(true);
+		fragmentHeader()->setEnd(false);
+		break;
+	case FragmentType::End:
+		fragmentHeader()->setStart(false);
+		fragmentHeader()->setEnd(true);
+		break;
+	default:
+		fragmentHeader()->setStart(false);
+		fragmentHeader()->setEnd(false);
+	}
 }
 
 std::vector<binary> NalUnits::generateFragments(uint16_t maximumFragmentSize) {
-    vector<binary> result{};
-    for (auto nalu: *this) {
-        if (nalu.size() > maximumFragmentSize) {
-            std::vector<NalUnitFragmentA> fragments = NalUnitFragmentA::fragmentsFrom(nalu, maximumFragmentSize);
-            result.insert(result.end(), fragments.begin(), fragments.end());
-        } else {
-            result.push_back(nalu);
-        }
-    }
-    return result;
+	vector<binary> result{};
+	for (auto nalu : *this) {
+		if (nalu.size() > maximumFragmentSize) {
+			std::vector<NalUnitFragmentA> fragments =
+			    NalUnitFragmentA::fragmentsFrom(nalu, maximumFragmentSize);
+			result.insert(result.end(), fragments.begin(), fragments.end());
+		} else {
+			result.push_back(nalu);
+		}
+	}
+	return result;
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 14 - 16
src/opuspacketizationhandler.cpp

@@ -22,27 +22,25 @@
 
 namespace rtc {
 
-OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer): RtcpHandler(), RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer) {
-    senderReportOutgoingCallback = [this](message_ptr msg) {
-        outgoingCallback(msg);
-    };
+OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer)
+    : RtcpHandler(), RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer) {
+	senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); };
 }
 
-message_ptr OpusPacketizationHandler::incoming(message_ptr ptr) {
-    return ptr;
-}
+message_ptr OpusPacketizationHandler::incoming(message_ptr ptr) { return ptr; }
 
 message_ptr OpusPacketizationHandler::outgoing(message_ptr ptr) {
-    if (ptr->type == Message::Binary) {
-        return withStatsRecording<message_ptr>([this, ptr](std::function<void (message_ptr)> addToReport) {
-            auto rtp = packetizer->packetize(*ptr, false);
-            addToReport(rtp);
-            return rtp;
-        });
-    }
-    return ptr;
+	if (ptr->type == Message::Binary) {
+		return withStatsRecording<message_ptr>(
+		    [this, ptr](std::function<void(message_ptr)> addToReport) {
+			    auto rtp = packetizer->packetize(*ptr, false);
+			    addToReport(rtp);
+			    return rtp;
+		    });
+	}
+	return ptr;
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 5 - 4
src/opusrtppacketizer.cpp

@@ -22,13 +22,14 @@
 
 namespace rtc {
 
-OpusRTPPacketizer::OpusRTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig): RTPPacketizer(rtpConfig) { }
+OpusRTPPacketizer::OpusRTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig)
+    : RTPPacketizer(rtpConfig) {}
 
 message_ptr OpusRTPPacketizer::packetize(binary payload, bool setMark) {
-    assert(!setMark);
-    return RTPPacketizer::packetize(payload, false);
+	assert(!setMark);
+	return RTPPacketizer::packetize(payload, false);
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 21 - 16
src/peerconnection.cpp

@@ -20,9 +20,9 @@
 #include "peerconnection.hpp"
 #include "certificate.hpp"
 #include "include.hpp"
+#include "logcounter.hpp"
 #include "processor.hpp"
 #include "threadpool.hpp"
-#include "logcounter.hpp"
 
 #include "dtlstransport.hpp"
 #include "icetransport.hpp"
@@ -47,10 +47,15 @@ inline std::shared_ptr<To> reinterpret_pointer_cast(std::shared_ptr<From> const
 using std::reinterpret_pointer_cast;
 #endif
 
-static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning, "Number of RTP packets truncated over past second");
-static rtc::LogCounter COUNTER_SRTP_DECRYPT_ERROR(plog::warning, "Number of SRTP decryption errors over past second");
-static rtc::LogCounter COUNTER_SRTP_ENCRYPT_ERROR(plog::warning, "Number of SRTP encryption errors over past second");
-static rtc::LogCounter COUNTER_UNKNOWN_PACKET_TYPE(plog::warning, "Number of unknown RTCP packet types over past second");
+static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning,
+                                               "Number of RTP packets truncated over past second");
+static rtc::LogCounter
+    COUNTER_SRTP_DECRYPT_ERROR(plog::warning, "Number of SRTP decryption errors over past second");
+static rtc::LogCounter
+    COUNTER_SRTP_ENCRYPT_ERROR(plog::warning, "Number of SRTP encryption errors over past second");
+static rtc::LogCounter
+    COUNTER_UNKNOWN_PACKET_TYPE(plog::warning,
+                                "Number of unknown RTCP packet types over past second");
 
 namespace rtc {
 
@@ -698,20 +703,20 @@ void PeerConnection::forwardMedia(message_ptr message) {
 				ssrcs.insert(rtcpsr->senderSSRC());
 				for (int i = 0; i < rtcpsr->header.reportCount(); ++i)
 					ssrcs.insert(rtcpsr->getReportBlock(i)->getSSRC());
-            } else if (header->payloadType() == 202) {
-                auto sdes = reinterpret_cast<RTCP_SDES *>(header);
-                if (!sdes->isValid()) {
-                    PLOG_WARNING << "RTCP SDES packet is invalid";
-                    continue;
-                }
-                for (unsigned int i = 0; i < sdes->chunksCount(); i++) {
-                    auto chunk = sdes->getChunk(i);
-                    ssrcs.insert(chunk->ssrc());
-                }
+			} else if (header->payloadType() == 202) {
+				auto sdes = reinterpret_cast<RTCP_SDES *>(header);
+				if (!sdes->isValid()) {
+					PLOG_WARNING << "RTCP SDES packet is invalid";
+					continue;
+				}
+				for (unsigned int i = 0; i < sdes->chunksCount(); i++) {
+					auto chunk = sdes->getChunk(i);
+					ssrcs.insert(chunk->ssrc());
+				}
 			} else {
 				// PT=207 == Extended Report
 				if (header->payloadType() != 207) {
-                    COUNTER_UNKNOWN_PACKET_TYPE++;
+					COUNTER_UNKNOWN_PACKET_TYPE++;
 				}
 			}
 		}

+ 3 - 3
src/processor.hpp

@@ -21,8 +21,8 @@
 
 #include "include.hpp"
 #include "init.hpp"
-#include "threadpool.hpp"
 #include "queue.hpp"
+#include "threadpool.hpp"
 
 #include <condition_variable>
 #include <future>
@@ -45,7 +45,7 @@ public:
 
 	void join();
 
-	template <class F, class... Args> void enqueue(F &&f, Args &&... args);
+	template <class F, class... Args> void enqueue(F &&f, Args &&...args);
 
 protected:
 	void schedule();
@@ -60,7 +60,7 @@ protected:
 	std::condition_variable mCondition;
 };
 
-template <class F, class... Args> void Processor::enqueue(F &&f, Args &&... args) {
+template <class F, class... Args> void Processor::enqueue(F &&f, Args &&...args) {
 	std::unique_lock lock(mMutex);
 	auto bound = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
 	auto task = [this, bound = std::move(bound)]() mutable {

+ 7 - 6
src/rtcp.cpp

@@ -19,10 +19,10 @@
 
 #include "rtcp.hpp"
 
+#include "logcounter.hpp"
 #include "track.hpp"
 #include <cmath>
 #include <utility>
-#include "logcounter.hpp"
 
 #ifdef _WIN32
 #include <winsock2.h>
@@ -33,7 +33,8 @@
 static rtc::LogCounter COUNTER_BAD_RTP_HEADER(plog::warning, "Number of malformed RTP headers");
 static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning, "Number of Unknown PPID messages");
 static rtc::LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning, "Number of Bad-Lengthed notifications");
-static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, "Number of unknown SCTP_STATUS errors");
+static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning,
+                                               "Number of unknown SCTP_STATUS errors");
 
 namespace rtc {
 
@@ -45,19 +46,19 @@ rtc::message_ptr RtcpReceivingSession::incoming(rtc::message_ptr ptr) {
 
 		// https://tools.ietf.org/html/rfc3550#appendix-A.1
 		if (rtp->version() != 2) {
-		    COUNTER_BAD_RTP_HEADER++;
+			COUNTER_BAD_RTP_HEADER++;
 			PLOG_VERBOSE << "RTP packet is not version 2";
 
 			return nullptr;
 		}
 		if (rtp->payloadType() == 201 || rtp->payloadType() == 200) {
-            COUNTER_BAD_RTP_HEADER++;
-            PLOG_VERBOSE << "RTP packet has a payload type indicating RR/SR";
+			COUNTER_BAD_RTP_HEADER++;
+			PLOG_VERBOSE << "RTP packet has a payload type indicating RR/SR";
 
 			return nullptr;
 		}
 
-        // Padding-processing is a user-level thing
+		// Padding-processing is a user-level thing
 
 		mSsrc = rtp->ssrc();
 

+ 33 - 33
src/rtcpsenderreportable.cpp

@@ -23,54 +23,54 @@
 namespace rtc {
 
 void RTCPSenderReportable::startRecording() {
-    _previousReportedTimestamp = rtpConfig->timestamp;
-    timeOffset = rtpConfig->startTime_s - rtpConfig->timestampToSeconds(rtpConfig->timestamp);
+	_previousReportedTimestamp = rtpConfig->timestamp;
+	timeOffset = rtpConfig->startTime_s - rtpConfig->timestampToSeconds(rtpConfig->timestamp);
 }
 
 void RTCPSenderReportable::sendReport(uint32_t timestamp) {
-    auto sr = getSenderReport(timestamp);
-    _previousReportedTimestamp = timestamp;
-    senderReportOutgoingCallback(move(sr));
+	auto sr = getSenderReport(timestamp);
+	_previousReportedTimestamp = timestamp;
+	senderReportOutgoingCallback(move(sr));
 }
 
-void RTCPSenderReportable::addToReport(RTP * rtp, uint32_t rtpSize) {
-    packetCount += 1;
-    assert(!rtp->padding());
-    payloadOctets += rtpSize - rtp->getSize();
+void RTCPSenderReportable::addToReport(RTP *rtp, uint32_t rtpSize) {
+	packetCount += 1;
+	assert(!rtp->padding());
+	payloadOctets += rtpSize - rtp->getSize();
 }
 
-RTCPSenderReportable::RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig): rtpConfig(rtpConfig) { }
+RTCPSenderReportable::RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig)
+    : rtpConfig(rtpConfig) {}
 
 uint64_t RTCPSenderReportable::secondsToNTP(double seconds) {
-    return std::round(seconds * double(uint64_t(1) << 32));
+	return std::round(seconds * double(uint64_t(1) << 32));
 }
 
-void RTCPSenderReportable::setNeedsToReport() {
-    needsToReport = true;
-}
+void RTCPSenderReportable::setNeedsToReport() { needsToReport = true; }
 
 message_ptr RTCPSenderReportable::getSenderReport(uint32_t timestamp) {
-    auto srSize = RTCP_SR::size(0);
-    auto msg = make_message(srSize + RTCP_SDES::size({{uint8_t(rtpConfig->cname.size())}}), Message::Type::Control);
-    auto sr = reinterpret_cast<RTCP_SR *>(msg->data());
-    auto timestamp_s = rtpConfig->timestampToSeconds(timestamp);
-    auto currentTime = timeOffset + timestamp_s;
-    sr->setNtpTimestamp(secondsToNTP(currentTime));
-    sr->setRtpTimestamp(timestamp);
-    sr->setPacketCount(packetCount);
-    sr->setOctetCount(payloadOctets);
-    sr->preparePacket(rtpConfig->ssrc, 0);
+	auto srSize = RTCP_SR::size(0);
+	auto msg = make_message(srSize + RTCP_SDES::size({{uint8_t(rtpConfig->cname.size())}}),
+	                        Message::Type::Control);
+	auto sr = reinterpret_cast<RTCP_SR *>(msg->data());
+	auto timestamp_s = rtpConfig->timestampToSeconds(timestamp);
+	auto currentTime = timeOffset + timestamp_s;
+	sr->setNtpTimestamp(secondsToNTP(currentTime));
+	sr->setRtpTimestamp(timestamp);
+	sr->setPacketCount(packetCount);
+	sr->setOctetCount(payloadOctets);
+	sr->preparePacket(rtpConfig->ssrc, 0);
 
-    auto sdes = reinterpret_cast<RTCP_SDES *>(msg->data() + srSize);
-    auto chunk = sdes->getChunk(0);
-    chunk->setSSRC(rtpConfig->ssrc);
-    auto item = chunk->getItem(0);
-    item->type = 1;
-    item->setText(rtpConfig->cname);
-    sdes->preparePacket(1);
-    return msg;
+	auto sdes = reinterpret_cast<RTCP_SDES *>(msg->data() + srSize);
+	auto chunk = sdes->getChunk(0);
+	chunk->setSSRC(rtpConfig->ssrc);
+	auto item = chunk->getItem(0);
+	item->type = 1;
+	item->setText(rtpConfig->cname);
+	sdes->preparePacket(1);
+	return msg;
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 30 - 30
src/rtppacketizationconfig.cpp

@@ -22,53 +22,53 @@
 
 namespace rtc {
 
-RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc,
-                                               string cname,
-                                               uint8_t payloadType,
+RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType,
                                                uint32_t clockRate,
                                                std::optional<uint16_t> sequenceNumber,
-                                               std::optional<uint32_t> timestamp): ssrc(ssrc), cname(cname), payloadType(payloadType), clockRate(clockRate) {
-    assert(clockRate > 0);
-    srand((unsigned)time(NULL));
-    if (sequenceNumber.has_value()) {
-        this->sequenceNumber = sequenceNumber.value();
-    } else {
-        this->sequenceNumber = rand();
-    }
-    if (timestamp.has_value()) {
-        this->timestamp = timestamp.value();
-    } else {
-        this->timestamp = rand();
-    }
-    this->_startTimestamp = this->timestamp;
+                                               std::optional<uint32_t> timestamp)
+    : ssrc(ssrc), cname(cname), payloadType(payloadType), clockRate(clockRate) {
+	assert(clockRate > 0);
+	srand((unsigned)time(NULL));
+	if (sequenceNumber.has_value()) {
+		this->sequenceNumber = sequenceNumber.value();
+	} else {
+		this->sequenceNumber = rand();
+	}
+	if (timestamp.has_value()) {
+		this->timestamp = timestamp.value();
+	} else {
+		this->timestamp = rand();
+	}
+	this->_startTimestamp = this->timestamp;
 }
 
-void RTPPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart, std::optional<uint32_t> startTimestamp) {
-    this->_startTime_s = startTime_s + static_cast<unsigned long long>(epochStart);
-    if (startTimestamp.has_value()) {
-        this->_startTimestamp = startTimestamp.value();
-        timestamp = this->startTimestamp;
-    } else {
-        this->_startTimestamp = timestamp;
-    }
+void RTPPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart,
+                                          std::optional<uint32_t> startTimestamp) {
+	this->_startTime_s = startTime_s + static_cast<unsigned long long>(epochStart);
+	if (startTimestamp.has_value()) {
+		this->_startTimestamp = startTimestamp.value();
+		timestamp = this->startTimestamp;
+	} else {
+		this->_startTimestamp = timestamp;
+	}
 }
 
 double RTPPacketizationConfig::getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate) {
-    return double(timestamp) / double(clockRate);
+	return double(timestamp) / double(clockRate);
 }
 
 double RTPPacketizationConfig::timestampToSeconds(uint32_t timestamp) {
-    return RTPPacketizationConfig::getSecondsFromTimestamp(timestamp, clockRate);
+	return RTPPacketizationConfig::getSecondsFromTimestamp(timestamp, clockRate);
 }
 
 uint32_t RTPPacketizationConfig::getTimestampFromSeconds(double seconds, uint32_t clockRate) {
-    return uint32_t(seconds * clockRate);
+	return uint32_t(seconds * clockRate);
 }
 
 uint32_t RTPPacketizationConfig::secondsToTimestamp(double seconds) {
-    return RTPPacketizationConfig::getTimestampFromSeconds(seconds, clockRate);
+	return RTPPacketizationConfig::getTimestampFromSeconds(seconds, clockRate);
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 16 - 15
src/rtppacketizer.cpp

@@ -22,24 +22,25 @@
 
 namespace rtc {
 
-RTPPacketizer::RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig): rtpConfig(rtpConfig) { }
+RTPPacketizer::RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig)
+    : rtpConfig(rtpConfig) {}
 
 message_ptr RTPPacketizer::packetize(binary payload, bool setMark) {
-    auto msg = make_message(rtpHeaderSize + payload.size());
-    auto * rtp = (RTP *)msg->data();
-    rtp->setPayloadType(rtpConfig->payloadType);
-    // increase sequence number
-    rtp->setSeqNumber(rtpConfig->sequenceNumber++);
-    rtp->setTimestamp(rtpConfig->timestamp);
-    rtp->setSsrc(rtpConfig->ssrc);
-    if (setMark) {
-        rtp->setMarker(true);
-    }
-    rtp->preparePacket();
-    copy(payload.begin(), payload.end(), msg->begin() + rtpHeaderSize);
-    return msg;
+	auto msg = make_message(rtpHeaderSize + payload.size());
+	auto *rtp = (RTP *)msg->data();
+	rtp->setPayloadType(rtpConfig->payloadType);
+	// increase sequence number
+	rtp->setSeqNumber(rtpConfig->sequenceNumber++);
+	rtp->setTimestamp(rtpConfig->timestamp);
+	rtp->setSsrc(rtpConfig->ssrc);
+	if (setMark) {
+		rtp->setMarker(true);
+	}
+	rtp->preparePacket();
+	copy(payload.begin(), payload.end(), msg->begin() + rtpHeaderSize);
+	return msg;
 }
 
-} // namespace
+} // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 8 - 4
src/sctptransport.cpp

@@ -49,9 +49,13 @@ using namespace std::chrono;
 
 using std::shared_ptr;
 
-static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning, "Number of SCTP packets received with an unknown PPID");
-static rtc::LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning, "Number of SCTP packets received with an bad notification length");
-static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, "Number of SCTP packets received with a bad status");
+static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning,
+                                            "Number of SCTP packets received with an unknown PPID");
+static rtc::LogCounter
+    COUNTER_BAD_NOTIF_LEN(plog::warning,
+                          "Number of SCTP packets received with an bad notification length");
+static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning,
+                                               "Number of SCTP packets received with a bad status");
 
 namespace rtc {
 
@@ -644,7 +648,7 @@ void SctpTransport::processData(binary &&data, uint16_t sid, PayloadId ppid) {
 
 void SctpTransport::processNotification(const union sctp_notification *notify, size_t len) {
 	if (len != size_t(notify->sn_header.sn_length)) {
-        COUNTER_BAD_NOTIF_LEN++;
+		COUNTER_BAD_NOTIF_LEN++;
 		return;
 	}
 

+ 0 - 1
src/sctptransport.hpp

@@ -24,7 +24,6 @@
 #include "processor.hpp"
 #include "queue.hpp"
 #include "transport.hpp"
-#include "processor.hpp"
 
 #include <condition_variable>
 #include <functional>

+ 8 - 5
src/track.cpp

@@ -21,8 +21,11 @@
 #include "include.hpp"
 #include "logcounter.hpp"
 
-static rtc::LogCounter COUNTER_MEDIA_BAD_DIRECTION(plog::warning, "Number of media packets sent in invalid directions");
-static rtc::LogCounter COUNTER_QUEUE_FULL(plog::warning, "Number of media packets dropped due to a full queue");
+static rtc::LogCounter
+    COUNTER_MEDIA_BAD_DIRECTION(plog::warning,
+                                "Number of media packets sent in invalid directions");
+static rtc::LogCounter COUNTER_QUEUE_FULL(plog::warning,
+                                          "Number of media packets dropped due to a full queue");
 
 namespace rtc {
 
@@ -56,7 +59,7 @@ bool Track::send(message_variant data) {
 	auto direction = mMediaDescription.direction();
 	if ((direction == Description::Direction::RecvOnly ||
 	     direction == Description::Direction::Inactive)) {
-	    COUNTER_MEDIA_BAD_DIRECTION++;
+		COUNTER_MEDIA_BAD_DIRECTION++;
 		return false;
 	}
 
@@ -118,7 +121,7 @@ void Track::incoming(message_ptr message) {
 	if ((direction == Description::Direction::SendOnly ||
 	     direction == Description::Direction::Inactive) &&
 	    message->type != Message::Control) {
-        COUNTER_MEDIA_BAD_DIRECTION++;
+		COUNTER_MEDIA_BAD_DIRECTION++;
 		return;
 	}
 
@@ -130,7 +133,7 @@ void Track::incoming(message_ptr message) {
 
 	// Tail drop if queue is full
 	if (mRecvQueue.full()) {
-        COUNTER_QUEUE_FULL++;
+		COUNTER_QUEUE_FULL++;
 		return;
 	}
 

+ 1 - 1
src/websocket.cpp

@@ -298,7 +298,7 @@ shared_ptr<WsTransport> WebSocket::initWsTransport() {
 		wsConfig.protocols = mConfig.protocols;
 
 		auto transport = std::make_shared<WsTransport>(
-			lower, wsConfig, weak_bind(&WebSocket::incoming, this, _1),
+		    lower, wsConfig, weak_bind(&WebSocket::incoming, this, _1),
 		    [this, weak_this = weak_from_this()](State state) {
 			    auto shared_this = weak_this.lock();
 			    if (!shared_this)

+ 0 - 1
src/wstransport.hpp

@@ -79,7 +79,6 @@ private:
 	binary mBuffer;
 	binary mPartial;
 	Opcode mPartialOpcode;
-
 };
 
 } // namespace rtc

+ 2 - 2
test/turn_connectivity.cpp

@@ -66,7 +66,7 @@ void test_turn_connectivity() {
 			return;
 		// For this test, filter out non-relay candidates to force TURN
 		string str(candidate);
-		if(str.find("relay") != string::npos) {
+		if (str.find("relay") != string::npos) {
 			cout << "Candidate 1: " << str << endl;
 			pc2->addRemoteCandidate(str);
 		}
@@ -96,7 +96,7 @@ void test_turn_connectivity() {
 			return;
 		// For this test, filter out non-relay candidates to force TURN
 		string str(candidate);
-		if(str.find("relay") != string::npos) {
+		if (str.find("relay") != string::npos) {
 			cout << "Candidate 1: " << str << endl;
 			pc1->addRemoteCandidate(str);
 		}