提交 22900858 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

clang-format: Use 2 spaces for indentation instead of 4

上级 7fc6a08a
...@@ -37,8 +37,8 @@ BreakStringLiterals: false ...@@ -37,8 +37,8 @@ BreakStringLiterals: false
ColumnLimit: 100 ColumnLimit: 100
CommentPragmas: 'NOLINT' CommentPragmas: 'NOLINT'
ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4 ContinuationIndentWidth: 2
Cpp11BracedListStyle: false Cpp11BracedListStyle: false
DerivePointerAlignment: false DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
......
...@@ -16,13 +16,13 @@ namespace Channel ...@@ -16,13 +16,13 @@ namespace Channel
void Emit(uint32_t targetId, const std::string& event); void Emit(uint32_t targetId, const std::string& event);
void Emit(uint32_t targetId, const std::string& event, Json::Value& data); void Emit(uint32_t targetId, const std::string& event, Json::Value& data);
void EmitWithBinary( void EmitWithBinary(
uint32_t targetId, const std::string& event, const uint8_t* binaryData, size_t binaryLen); uint32_t targetId, const std::string& event, const uint8_t* binaryData, size_t binaryLen);
void EmitWithBinary( void EmitWithBinary(
uint32_t targetId, uint32_t targetId,
const std::string& event, const std::string& event,
const uint8_t* binaryData, const uint8_t* binaryData,
size_t binaryLen, size_t binaryLen,
Json::Value& data); Json::Value& data);
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -23,10 +23,10 @@ namespace RTC ...@@ -23,10 +23,10 @@ namespace RTC
{ {
public: public:
Consumer( Consumer(
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t consumerId, uint32_t consumerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
uint32_t sourceProducerId); uint32_t sourceProducerId);
private: private:
virtual ~Consumer(); virtual ~Consumer();
......
...@@ -72,13 +72,13 @@ namespace RTC ...@@ -72,13 +72,13 @@ namespace RTC
// and remote fingerprint verification). Outgoing media can now flow through. // and remote fingerprint verification). Outgoing media can now flow through.
// NOTE: The caller MUST NOT call any method during this callback. // NOTE: The caller MUST NOT call any method during this callback.
virtual void OnDtlsConnected( virtual void OnDtlsConnected(
const RTC::DtlsTransport* dtlsTransport, const RTC::DtlsTransport* dtlsTransport,
RTC::SrtpSession::Profile srtpProfile, RTC::SrtpSession::Profile srtpProfile,
uint8_t* srtpLocalKey, uint8_t* srtpLocalKey,
size_t srtpLocalKeyLen, size_t srtpLocalKeyLen,
uint8_t* srtpRemoteKey, uint8_t* srtpRemoteKey,
size_t srtpRemoteKeyLen, size_t srtpRemoteKeyLen,
std::string& remoteCert) = 0; std::string& remoteCert) = 0;
// The DTLS connection has been closed as the result of an error (such as a // The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint). // DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
...@@ -89,11 +89,11 @@ namespace RTC ...@@ -89,11 +89,11 @@ namespace RTC
// Need to send DTLS data to the peer. // Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void OnOutgoingDtlsData( virtual void OnOutgoingDtlsData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
// DTLS application data received. // DTLS application data received.
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void OnDtlsApplicationData( virtual void OnDtlsApplicationData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
}; };
public: public:
...@@ -190,7 +190,7 @@ namespace RTC ...@@ -190,7 +190,7 @@ namespace RTC
} }
inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm( inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(
const std::string& fingerprint) const std::string& fingerprint)
{ {
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint); auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
...@@ -203,10 +203,10 @@ namespace RTC ...@@ -203,10 +203,10 @@ namespace RTC
inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len) inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len)
{ {
return ( return (
// Minimum DTLS record length is 13 bytes. // Minimum DTLS record length is 13 bytes.
(len >= 13) && (len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)); (data[0] > 19 && data[0] < 64));
} }
/* Inline instance methods. */ /* Inline instance methods. */
......
...@@ -32,7 +32,7 @@ namespace RTC ...@@ -32,7 +32,7 @@ namespace RTC
* returns, so the given pointers are still usable. * returns, so the given pointers are still usable.
*/ */
virtual void OnOutgoingStunMessage( virtual void OnOutgoingStunMessage(
const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0; const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0;
virtual void OnIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0; virtual void OnIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0;
virtual void OnIceConnected(const RTC::IceServer* iceServer) = 0; virtual void OnIceConnected(const RTC::IceServer* iceServer) = 0;
virtual void OnIceCompleted(const RTC::IceServer* iceServer) = 0; virtual void OnIceCompleted(const RTC::IceServer* iceServer) = 0;
......
...@@ -67,7 +67,7 @@ namespace RTC ...@@ -67,7 +67,7 @@ namespace RTC
// Inline instance methods. // Inline instance methods.
inline NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum) inline NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum)
: seq32(seq32), sendAtSeqNum(sendAtSeqNum) : seq32(seq32), sendAtSeqNum(sendAtSeqNum)
{ {
} }
} // namespace RTC } // namespace RTC
......
...@@ -44,7 +44,7 @@ namespace RTC ...@@ -44,7 +44,7 @@ namespace RTC
} }
explicit Value(std::vector<int32_t>& arrayOfIntegers) explicit Value(std::vector<int32_t>& arrayOfIntegers)
: type(Type::ARRAY_OF_INTEGERS), arrayOfIntegers(arrayOfIntegers) : type(Type::ARRAY_OF_INTEGERS), arrayOfIntegers(arrayOfIntegers)
{ {
} }
......
...@@ -35,17 +35,17 @@ namespace RTC ...@@ -35,17 +35,17 @@ namespace RTC
virtual void OnPeerProducerPaused(const RTC::Peer* peer, const RTC::Producer* producer) = 0; virtual void OnPeerProducerPaused(const RTC::Peer* peer, const RTC::Producer* producer) = 0;
virtual void OnPeerProducerResumed(const RTC::Peer* peer, const RTC::Producer* producer) = 0; virtual void OnPeerProducerResumed(const RTC::Peer* peer, const RTC::Producer* producer) = 0;
virtual void OnPeerProducerRtpPacket( virtual void OnPeerProducerRtpPacket(
const RTC::Peer* peer, RTC::Producer* producer, RTC::RtpPacket* packet) = 0; const RTC::Peer* peer, RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
virtual void OnPeerProducerRtcpSenderReport( virtual void OnPeerProducerRtcpSenderReport(
const RTC::Peer* peer, RTC::Producer* producer, RTC::RTCP::SenderReport* report) = 0; const RTC::Peer* peer, RTC::Producer* producer, RTC::RTCP::SenderReport* report) = 0;
virtual void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) = 0; virtual void OnPeerConsumerClosed(const RTC::Peer* peer, RTC::Consumer* consumer) = 0;
virtual void OnPeerConsumerRtcpReceiverReport( virtual void OnPeerConsumerRtcpReceiverReport(
const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::ReceiverReport* report) = 0; const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::ReceiverReport* report) = 0;
virtual void OnPeerConsumerRtcpFeedback( virtual void OnPeerConsumerRtcpFeedback(
const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::FeedbackPsPacket* packet) = 0; const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::FeedbackPsPacket* packet) = 0;
virtual void OnPeerConsumerRtcpFeedback( virtual void OnPeerConsumerRtcpFeedback(
const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::FeedbackRtpPacket* packet) = 0; const RTC::Peer* peer, RTC::Consumer* consumer, RTC::RTCP::FeedbackRtpPacket* packet) = 0;
virtual void OnPeerConsumerFullFrameRequired(RTC::Peer* peer, RTC::Consumer* consumer) = 0; virtual void OnPeerConsumerFullFrameRequired(RTC::Peer* peer, RTC::Consumer* consumer) = 0;
}; };
public: public:
...@@ -67,13 +67,13 @@ namespace RTC ...@@ -67,13 +67,13 @@ namespace RTC
* @param peerName - Name of the receiver Peer. * @param peerName - Name of the receiver Peer.
*/ */
void AddConsumer( void AddConsumer(
RTC::Consumer* consumer, RTC::RtpParameters* rtpParameters, uint32_t associatedProducerId); RTC::Consumer* consumer, RTC::RtpParameters* rtpParameters, uint32_t associatedProducerId);
RTC::Consumer* GetConsumer(uint32_t ssrc) const; RTC::Consumer* GetConsumer(uint32_t ssrc) const;
void SendRtcp(uint64_t now); void SendRtcp(uint64_t now);
private: private:
RTC::Transport* GetTransportFromRequest( RTC::Transport* GetTransportFromRequest(
Channel::Request* request, uint32_t* transportId = nullptr) const; Channel::Request* request, uint32_t* transportId = nullptr) const;
RTC::Producer* GetProducerFromRequest(Channel::Request* request, uint32_t* producerId = nullptr) const; RTC::Producer* GetProducerFromRequest(Channel::Request* request, uint32_t* producerId = nullptr) const;
RTC::Consumer* GetConsumerFromRequest(Channel::Request* request, uint32_t* consumerId = nullptr) const; RTC::Consumer* GetConsumerFromRequest(Channel::Request* request, uint32_t* consumerId = nullptr) const;
......
...@@ -38,13 +38,13 @@ namespace RTC ...@@ -38,13 +38,13 @@ namespace RTC
public: public:
Producer( Producer(
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t producerId, uint32_t producerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
RTC::Transport* transport, RTC::Transport* transport,
RTC::RtpParameters& rtpParameters, RTC::RtpParameters& rtpParameters,
struct RtpMapping& rtpMapping, struct RtpMapping& rtpMapping,
bool paused); bool paused);
public: public:
// Must be public because Router needs to call it. // Must be public because Router needs to call it.
......
...@@ -42,13 +42,13 @@ namespace RTC ...@@ -42,13 +42,13 @@ namespace RTC
template<typename Item> template<typename Item>
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader) inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader) : FeedbackPsPacket(commonHeader)
{ {
} }
template<typename Item> template<typename Item>
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc) inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc) : FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc)
{ {
} }
......
...@@ -23,9 +23,9 @@ namespace RTC ...@@ -23,9 +23,9 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsAfbPacket( explicit FeedbackPsAfbPacket(
CommonHeader* commonHeader, Application application = Application::UNKNOWN); CommonHeader* commonHeader, Application application = Application::UNKNOWN);
FeedbackPsAfbPacket( FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN); uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN);
~FeedbackPsAfbPacket() override = default; ~FeedbackPsAfbPacket() override = default;
Application GetApplication() const; Application GetApplication() const;
...@@ -45,7 +45,7 @@ namespace RTC ...@@ -45,7 +45,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application) inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application)
: FeedbackPsPacket(commonHeader) : FeedbackPsPacket(commonHeader)
{ {
this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) - this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) -
(sizeof(CommonHeader) + sizeof(FeedbackPacket::Header)); (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
...@@ -56,8 +56,8 @@ namespace RTC ...@@ -56,8 +56,8 @@ namespace RTC
} }
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket( inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application) uint32_t senderSsrc, uint32_t mediaSsrc, Application application)
: FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc) : FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
{ {
this->application = application; this->application = application;
} }
......
...@@ -26,12 +26,12 @@ namespace RTC ...@@ -26,12 +26,12 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader) inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader) : FeedbackPsPacket(commonHeader)
{ {
} }
inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc) inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc) : FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{ {
} }
} // namespace RTCP } // namespace RTCP
......
...@@ -66,7 +66,7 @@ namespace RTC ...@@ -66,7 +66,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc) inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB) : FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
{ {
} }
......
...@@ -46,7 +46,7 @@ namespace RTC ...@@ -46,7 +46,7 @@ namespace RTC
explicit FeedbackPsVbcmItem(Header* header); explicit FeedbackPsVbcmItem(Header* header);
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
FeedbackPsVbcmItem( FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value); uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
~FeedbackPsVbcmItem() override = default; ~FeedbackPsVbcmItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
......
...@@ -42,13 +42,13 @@ namespace RTC ...@@ -42,13 +42,13 @@ namespace RTC
template<typename Item> template<typename Item>
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader) inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader) : FeedbackRtpPacket(commonHeader)
{ {
} }
template<typename Item> template<typename Item>
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc) inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc) : FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc)
{ {
} }
......
...@@ -61,7 +61,7 @@ namespace RTC ...@@ -61,7 +61,7 @@ namespace RTC
} }
inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item) inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item)
: header(item->header) : header(item->header)
{ {
} }
......
...@@ -25,12 +25,12 @@ namespace RTC ...@@ -25,12 +25,12 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader) inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader) : FeedbackRtpPacket(commonHeader)
{ {
} }
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc) inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc) : FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{ {
} }
} // namespace RTCP } // namespace RTCP
......
...@@ -61,7 +61,7 @@ namespace RTC ...@@ -61,7 +61,7 @@ namespace RTC
} }
inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item) inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item)
: header(item->header) : header(item->header)
{ {
} }
......
...@@ -87,15 +87,15 @@ namespace RTC ...@@ -87,15 +87,15 @@ namespace RTC
auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
return ( return (
(len >= sizeof(CommonHeader)) && (len >= sizeof(CommonHeader)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) && (data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2. // RTP Version must be 2.
(header->version == 2) && (header->version == 2) &&
// RTCP packet types defined by IANA: // RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection. // RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(header->packetType >= 192 && header->packetType <= 223)); (header->packetType >= 192 && header->packetType <= 223));
} }
/* Inline instance methods. */ /* Inline instance methods. */
......
...@@ -136,7 +136,7 @@ namespace RTC ...@@ -136,7 +136,7 @@ namespace RTC
inline uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs) inline uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs)
{ {
this->currentBitrateBps = this->currentBitrateBps =
ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs); ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs);
return this->currentBitrateBps; return this->currentBitrateBps;
} }
......
...@@ -40,13 +40,13 @@ namespace RTC ...@@ -40,13 +40,13 @@ namespace RTC
// |arrivalTimeDeltaMs| (output) is the computed arrival-time delta. // |arrivalTimeDeltaMs| (output) is the computed arrival-time delta.
// |packetSizeDelta| (output) is the computed size delta. // |packetSizeDelta| (output) is the computed size delta.
bool ComputeDeltas( bool ComputeDeltas(
uint32_t timestamp, uint32_t timestamp,
int64_t arrivalTimeMs, int64_t arrivalTimeMs,
int64_t systemTimeMs, int64_t systemTimeMs,
size_t packetSize, size_t packetSize,
uint32_t* timestampDelta, uint32_t* timestampDelta,
int64_t* arrivalTimeDeltaMs, int64_t* arrivalTimeDeltaMs,
int* packetSizeDelta); int* packetSizeDelta);
private: private:
struct TimestampGroup struct TimestampGroup
...@@ -80,7 +80,7 @@ namespace RTC ...@@ -80,7 +80,7 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline InterArrival::TimestampGroup::TimestampGroup() inline InterArrival::TimestampGroup::TimestampGroup()
: size(0), firstTimestamp(0), timestamp(0), completeTimeMs(-1) : size(0), firstTimestamp(0), timestamp(0), completeTimeMs(-1)
{ {
} }
...@@ -90,10 +90,10 @@ namespace RTC ...@@ -90,10 +90,10 @@ namespace RTC
} }
inline InterArrival::InterArrival( inline InterArrival::InterArrival(
uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping) uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping)
: timestampGroupLengthTicks(timestampGroupLengthTicks), currentTimestampGroup(), : timestampGroupLengthTicks(timestampGroupLengthTicks), currentTimestampGroup(),
prevTimestampGroup(), timestampToMsCoeff(timestampToMsCoeff), prevTimestampGroup(), timestampToMsCoeff(timestampToMsCoeff),
burstGrouping(enableBurstGrouping), numConsecutiveReorderedPackets(0) burstGrouping(enableBurstGrouping), numConsecutiveReorderedPackets(0)
{ {
} }
} // namespace RTC } // namespace RTC
......
...@@ -46,7 +46,7 @@ namespace RTC ...@@ -46,7 +46,7 @@ namespace RTC
// |currentHypothesis| should be the hypothesis of the over-use detector at // |currentHypothesis| should be the hypothesis of the over-use detector at
// this time. // this time.
void Update( void Update(
int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs); int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs);
// Returns the estimated noise/jitter variance in ms^2. // Returns the estimated noise/jitter variance in ms^2.
double GetVarNoise() const; double GetVarNoise() const;
// Returns the estimated inter-arrival time delta offset in ms. // Returns the estimated inter-arrival time delta offset in ms.
...@@ -76,8 +76,8 @@ namespace RTC ...@@ -76,8 +76,8 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline OverUseDetectorOptions::OverUseDetectorOptions() inline OverUseDetectorOptions::OverUseDetectorOptions()
: initialSlope(8.0 / 512.0), initialOffset(0), initialE(), initialProcessNoise(), : initialSlope(8.0 / 512.0), initialOffset(0), initialE(), initialProcessNoise(),
initialAvgNoise(0.0), initialVarNoise(50) initialAvgNoise(0.0), initialVarNoise(50)
{ {
initialE[0][0] = 100; initialE[0][0] = 100;
initialE[1][1] = 1e-1; initialE[1][1] = 1e-1;
...@@ -87,10 +87,10 @@ namespace RTC ...@@ -87,10 +87,10 @@ namespace RTC
} }
inline OveruseEstimator::OveruseEstimator(OverUseDetectorOptions options) inline OveruseEstimator::OveruseEstimator(OverUseDetectorOptions options)
: options(std::move(options)), numOfDeltas(0), slope(this->options.initialSlope), : options(std::move(options)), numOfDeltas(0), slope(this->options.initialSlope),
offset(this->options.initialOffset), prevOffset(this->options.initialOffset), e(), offset(this->options.initialOffset), prevOffset(this->options.initialOffset), e(),
processNoise(), avgNoise(this->options.initialAvgNoise), processNoise(), avgNoise(this->options.initialAvgNoise),
varNoise(this->options.initialVarNoise), tsDeltaHist() varNoise(this->options.initialVarNoise), tsDeltaHist()
{ {
std::memcpy(this->e, this->options.initialE, sizeof(this->e)); std::memcpy(this->e, this->options.initialE, sizeof(this->e));
std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise)); std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise));
......
...@@ -20,8 +20,8 @@ namespace RTC ...@@ -20,8 +20,8 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline RateControlInput::RateControlInput( inline RateControlInput::RateControlInput(
BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar) BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar)
: bwState(bwState), incomingBitrate(incomingBitrate), noiseVar(noiseVar) : bwState(bwState), incomingBitrate(incomingBitrate), noiseVar(noiseVar)
{ {
} }
} // namespace RTC } // namespace RTC
......
...@@ -57,7 +57,7 @@ namespace RTC ...@@ -57,7 +57,7 @@ namespace RTC
// packet size excluding headers. // packet size excluding headers.
// Note that |arrivalTimeMs| can be of an arbitrary time base. // Note that |arrivalTimeMs| can be of an arbitrary time base.
virtual void IncomingPacket( virtual void IncomingPacket(
int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, uint32_t absSendTime) = 0; int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, uint32_t absSendTime) = 0;
// Removes all data for |ssrc|. // Removes all data for |ssrc|.
virtual void RemoveStream(uint32_t ssrc) = 0; virtual void RemoveStream(uint32_t ssrc) = 0;
......
...@@ -59,7 +59,7 @@ namespace RTC ...@@ -59,7 +59,7 @@ namespace RTC
~RemoteBitrateEstimatorAbsSendTime() override = default; ~RemoteBitrateEstimatorAbsSendTime() override = default;
void IncomingPacket( void IncomingPacket(
int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, uint32_t absSendTime) override; int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, uint32_t absSendTime) override;
// This class relies on Process() being called periodically (at least once // This class relies on Process() being called periodically (at least once
// every other second) for streams to be timed out properly. // every other second) for streams to be timed out properly.
void Process() override; void Process() override;
...@@ -80,7 +80,7 @@ namespace RTC ...@@ -80,7 +80,7 @@ namespace RTC
private: private:
void IncomingPacketInfo( void IncomingPacketInfo(
int64_t arrivalTimeMs, uint32_t sendTime24bits, size_t payloadSize, uint32_t ssrc); int64_t arrivalTimeMs, uint32_t sendTime24bits, size_t payloadSize, uint32_t ssrc);
void ComputeClusters(std::list<Cluster>* clusters) const; void ComputeClusters(std::list<Cluster>* clusters) const;
std::list<Cluster>::const_iterator FindBestProbe(const std::list<Cluster>& clusters) const; std::list<Cluster>::const_iterator FindBestProbe(const std::list<Cluster>& clusters) const;
...@@ -110,7 +110,7 @@ namespace RTC ...@@ -110,7 +110,7 @@ namespace RTC
/* Inline Methods. */ /* Inline Methods. */
inline Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize) inline Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize)
: sendTimeMs(sendTimeMs), recvTimeMs(recvTimeMs), payloadSize(payloadSize) : sendTimeMs(sendTimeMs), recvTimeMs(recvTimeMs), payloadSize(payloadSize)
{ {
} }
...@@ -129,7 +129,7 @@ namespace RTC ...@@ -129,7 +129,7 @@ namespace RTC
} }
inline RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer) inline RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer)
: observer(observer), interArrival(), estimator(), detector(), incomingBitrate() : observer(observer), interArrival(), estimator(), detector(), incomingBitrate()
{ {
} }
......
...@@ -34,10 +34,10 @@ namespace RTC ...@@ -34,10 +34,10 @@ namespace RTC
~RemoteBitrateEstimatorSingleStream() override; ~RemoteBitrateEstimatorSingleStream() override;
void IncomingPacket( void IncomingPacket(
int64_t arrivalTimeMs, int64_t arrivalTimeMs,
size_t payloadSize, size_t payloadSize,
const RtpPacket& packet, const RtpPacket& packet,
uint32_t transmissionTimeOffset) override; uint32_t transmissionTimeOffset) override;
void Process() override; void Process() override;
int64_t TimeUntilNextProcess() override; int64_t TimeUntilNextProcess() override;
void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override; void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override;
...@@ -53,7 +53,7 @@ namespace RTC ...@@ -53,7 +53,7 @@ namespace RTC
TIMESTAMP_GROUP_LENGTH_MS = 5 TIMESTAMP_GROUP_LENGTH_MS = 5
}; };
explicit Detector( explicit Detector(
int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping); int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping);
int64_t lastPacketTimeMs; int64_t lastPacketTimeMs;
InterArrival interArrival; InterArrival interArrival;
...@@ -87,16 +87,16 @@ namespace RTC ...@@ -87,16 +87,16 @@ namespace RTC
/* Inline Methods. */ /* Inline Methods. */
inline RemoteBitrateEstimatorSingleStream::Detector::Detector( inline RemoteBitrateEstimatorSingleStream::Detector::Detector(
int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping) int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping)
: lastPacketTimeMs(lastPacketTimeMs), : lastPacketTimeMs(lastPacketTimeMs),
interArrival(90 * TIMESTAMP_GROUP_LENGTH_MS, TimestampToMs, enableBurstGrouping), interArrival(90 * TIMESTAMP_GROUP_LENGTH_MS, TimestampToMs, enableBurstGrouping),
estimator(options), detector() estimator(options), detector()
{ {
} }
inline RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer) inline RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer)
: incomingBitrate(), remoteRate(new AimdRateControl()), observer(observer), : incomingBitrate(), remoteRate(new AimdRateControl()), observer(observer),
processIntervalMs(RemoteBitrateEstimator::processIntervalMs) processIntervalMs(RemoteBitrateEstimator::processIntervalMs)
{ {
// assert(this->observer); // assert(this->observer);
} }
......
...@@ -54,7 +54,7 @@ namespace RTC ...@@ -54,7 +54,7 @@ namespace RTC
private: private:
RTC::Transport* GetTransportFromRequest( RTC::Transport* GetTransportFromRequest(
Channel::Request* request, uint32_t* transportId = nullptr) const; Channel::Request* request, uint32_t* transportId = nullptr) const;
RTC::Producer* GetProducerFromRequest(Channel::Request* request, uint32_t* producerId = nullptr) const; RTC::Producer* GetProducerFromRequest(Channel::Request* request, uint32_t* producerId = nullptr) const;
RTC::Consumer* GetConsumerFromRequest(Channel::Request* request, uint32_t* consumerId = nullptr) const; RTC::Consumer* GetConsumerFromRequest(Channel::Request* request, uint32_t* consumerId = nullptr) const;
......
...@@ -65,7 +65,7 @@ namespace RTC ...@@ -65,7 +65,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline RateCalculator::RateCalculator(size_t windowSize, float scale) inline RateCalculator::RateCalculator(size_t windowSize, float scale)
: windowSize(windowSize), scale(scale) : windowSize(windowSize), scale(scale)
{ {
uint64_t now = DepLibUV::GetTime(); uint64_t now = DepLibUV::GetTime();
......
...@@ -27,10 +27,10 @@ namespace RTC ...@@ -27,10 +27,10 @@ namespace RTC
private: private:
void RollbackProducer( void RollbackProducer(
RTC::Producer* producer, RTC::Producer* producer,
std::vector<uint32_t>& previousSsrcs, std::vector<uint32_t>& previousSsrcs,
std::string& previousMuxId, std::string& previousMuxId,
std::vector<uint8_t>& previousPayloadTypes); std::vector<uint8_t>& previousPayloadTypes);
public: public:
// Table of SSRC / Producer pairs. // Table of SSRC / Producer pairs.
......
...@@ -80,12 +80,12 @@ namespace RTC ...@@ -80,12 +80,12 @@ namespace RTC
public: public:
RtpPacket( RtpPacket(
Header* header, Header* header,
ExtensionHeader* extensionHeader, ExtensionHeader* extensionHeader,
const uint8_t* payload, const uint8_t* payload,
size_t payloadLength, size_t payloadLength,
uint8_t payloadPadding, uint8_t payloadPadding,
size_t size); size_t size);
~RtpPacket(); ~RtpPacket();
void Dump() const; void Dump() const;
...@@ -148,11 +148,11 @@ namespace RTC ...@@ -148,11 +148,11 @@ namespace RTC
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data)); auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
return ( return (
(len >= sizeof(Header)) && (len >= sizeof(Header)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) && (data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2. // RTP Version must be 2.
(header->version == 2)); (header->version == 2));
} }
/* Inline instance methods. */ /* Inline instance methods. */
......
...@@ -15,8 +15,8 @@ namespace RTC ...@@ -15,8 +15,8 @@ namespace RTC
{ {
public: public:
virtual void OnNackRequired( virtual void OnNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0; RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0;
virtual void OnPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; virtual void OnPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
}; };
public: public:
......
...@@ -33,7 +33,7 @@ namespace RTC ...@@ -33,7 +33,7 @@ namespace RTC
bool ReceivePacket(RTC::RtpPacket* packet) override; bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void RequestRtpRetransmission( void RequestRtpRetransmission(
uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container); uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container);
RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now); RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now);
uint32_t GetRtt() const; uint32_t GetRtt() const;
void SetRtx(uint8_t payloadType, uint32_t ssrc); void SetRtx(uint8_t payloadType, uint32_t ssrc);
......
...@@ -61,7 +61,7 @@ namespace RTC ...@@ -61,7 +61,7 @@ namespace RTC
public: public:
StunMessage( StunMessage(
Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size); Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size);
~StunMessage(); ~StunMessage();
void Dump() const; void Dump() const;
...@@ -87,7 +87,7 @@ namespace RTC ...@@ -87,7 +87,7 @@ namespace RTC
bool HasMessageIntegrity() const; bool HasMessageIntegrity() const;
bool HasFingerprint() const; bool HasFingerprint() const;
Authentication CheckAuthentication( Authentication CheckAuthentication(
const std::string& localUsername, const std::string& localPassword); const std::string& localUsername, const std::string& localPassword);
StunMessage* CreateSuccessResponse(); StunMessage* CreateSuccessResponse();
StunMessage* CreateErrorResponse(uint16_t errorCode); StunMessage* CreateErrorResponse(uint16_t errorCode);
void Authenticate(const std::string& password); void Authenticate(const std::string& password);
...@@ -118,13 +118,13 @@ namespace RTC ...@@ -118,13 +118,13 @@ namespace RTC
inline bool StunMessage::IsStun(const uint8_t* data, size_t len) inline bool StunMessage::IsStun(const uint8_t* data, size_t len)
{ {
return ( return (
// STUN headers are 20 bytes. // STUN headers are 20 bytes.
(len >= 20) && (len >= 20) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] < 3) && (data[0] < 3) &&
// Magic cookie must match. // Magic cookie must match.
(data[4] == StunMessage::magicCookie[0]) && (data[5] == StunMessage::magicCookie[1]) && (data[4] == StunMessage::magicCookie[0]) && (data[5] == StunMessage::magicCookie[1]) &&
(data[6] == StunMessage::magicCookie[2]) && (data[7] == StunMessage::magicCookie[3])); (data[6] == StunMessage::magicCookie[2]) && (data[7] == StunMessage::magicCookie[3]));
} }
/* Inline instance methods. */ /* Inline instance methods. */
......
...@@ -20,7 +20,7 @@ namespace RTC ...@@ -20,7 +20,7 @@ namespace RTC
public: public:
virtual void OnRtcTcpConnectionClosed( virtual void OnRtcTcpConnectionClosed(
RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) = 0; RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) = 0;
}; };
public: public:
......
...@@ -84,15 +84,12 @@ namespace RTC ...@@ -84,15 +84,12 @@ namespace RTC
/* Pure virtual methods inherited from RTC::UdpSocket::Listener. */ /* Pure virtual methods inherited from RTC::UdpSocket::Listener. */
public: public:
void OnPacketRecv( void OnPacketRecv(
RTC::UdpSocket* socket, RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr) override;
const uint8_t* data,
size_t len,
const struct sockaddr* remoteAddr) override;
/* Pure virtual methods inherited from RTC::TcpServer::Listener. */ /* Pure virtual methods inherited from RTC::TcpServer::Listener. */
public: public:
void OnRtcTcpConnectionClosed( void OnRtcTcpConnectionClosed(
RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) override; RTC::TcpServer* tcpServer, RTC::TcpConnection* connection, bool isClosedByPeer) override;
/* Pure virtual methods inherited from RTC::TcpConnection::Listener. */ /* Pure virtual methods inherited from RTC::TcpConnection::Listener. */
public: public:
...@@ -101,9 +98,7 @@ namespace RTC ...@@ -101,9 +98,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::IceServer::Listener. */ /* Pure virtual methods inherited from RTC::IceServer::Listener. */
public: public:
void OnOutgoingStunMessage( void OnOutgoingStunMessage(
const RTC::IceServer* iceServer, const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) override;
const RTC::StunMessage* msg,
RTC::TransportTuple* tuple) override;
void OnIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) override; void OnIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) override;
void OnIceConnected(const RTC::IceServer* iceServer) override; void OnIceConnected(const RTC::IceServer* iceServer) override;
void OnIceCompleted(const RTC::IceServer* iceServer) override; void OnIceCompleted(const RTC::IceServer* iceServer) override;
...@@ -113,19 +108,19 @@ namespace RTC ...@@ -113,19 +108,19 @@ namespace RTC
public: public:
void OnDtlsConnecting(const RTC::DtlsTransport* dtlsTransport) override; void OnDtlsConnecting(const RTC::DtlsTransport* dtlsTransport) override;
void OnDtlsConnected( void OnDtlsConnected(
const RTC::DtlsTransport* dtlsTransport, const RTC::DtlsTransport* dtlsTransport,
RTC::SrtpSession::Profile srtpProfile, RTC::SrtpSession::Profile srtpProfile,
uint8_t* srtpLocalKey, uint8_t* srtpLocalKey,
size_t srtpLocalKeyLen, size_t srtpLocalKeyLen,
uint8_t* srtpRemoteKey, uint8_t* srtpRemoteKey,
size_t srtpRemoteKeyLen, size_t srtpRemoteKeyLen,
std::string& remoteCert) override; std::string& remoteCert) override;
void OnDtlsFailed(const RTC::DtlsTransport* dtlsTransport) override; void OnDtlsFailed(const RTC::DtlsTransport* dtlsTransport) override;
void OnDtlsClosed(const RTC::DtlsTransport* dtlsTransport) override; void OnDtlsClosed(const RTC::DtlsTransport* dtlsTransport) override;
void OnOutgoingDtlsData( void OnOutgoingDtlsData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override;
void OnDtlsApplicationData( void OnDtlsApplicationData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override; const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) override;
/* Pure virtual methods inherited from RTC::RemoteBitrateEstimator::Listener. */ /* Pure virtual methods inherited from RTC::RemoteBitrateEstimator::Listener. */
public: public:
...@@ -182,7 +177,9 @@ namespace RTC ...@@ -182,7 +177,9 @@ namespace RTC
inline bool Transport::IsConnected() const inline bool Transport::IsConnected() const
{ {
return this->dtlsTransport->GetState() == RTC::DtlsTransport::DtlsState::CONNECTED; return (
this->selectedTuple != nullptr &&
this->dtlsTransport->GetState() == RTC::DtlsTransport::DtlsState::CONNECTED);
} }
inline void Transport::EnableRemb() inline void Transport::EnableRemb()
......
...@@ -44,12 +44,12 @@ namespace RTC ...@@ -44,12 +44,12 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) inline TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr)
: udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP) : udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP)
{ {
} }
inline TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection) inline TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection)
: tcpConnection(tcpConnection), protocol(Protocol::TCP) : tcpConnection(tcpConnection), protocol(Protocol::TCP)
{ {
} }
...@@ -71,8 +71,8 @@ namespace RTC ...@@ -71,8 +71,8 @@ namespace RTC
if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP) if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP)
{ {
return ( return (
this->udpSocket == tuple->udpSocket && this->udpSocket == tuple->udpSocket &&
Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress())); Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress()));
} }
else if (this->protocol == Protocol::TCP && tuple->GetProtocol() == Protocol::TCP) else if (this->protocol == Protocol::TCP && tuple->GetProtocol() == Protocol::TCP)
{ {
......
...@@ -18,10 +18,7 @@ namespace RTC ...@@ -18,10 +18,7 @@ namespace RTC
public: public:
virtual void OnPacketRecv( virtual void OnPacketRecv(
RTC::UdpSocket* socket, RTC::UdpSocket* socket, const uint8_t* data, size_t len, const struct sockaddr* remoteAddr) = 0;
const uint8_t* data,
size_t len,
const struct sockaddr* remoteAddr) = 0;
}; };
public: public:
......
...@@ -29,8 +29,7 @@ namespace Utils ...@@ -29,8 +29,7 @@ namespace Utils
inline bool IP::CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2) inline bool IP::CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2)
{ {
// Compare family. // Compare family.
if (addr1->sa_family != addr2->sa_family || if (addr1->sa_family != addr2->sa_family || (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6))
(addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6))
{ {
return false; return false;
} }
...@@ -43,18 +42,13 @@ namespace Utils ...@@ -43,18 +42,13 @@ namespace Utils
switch (addr1->sa_family) switch (addr1->sa_family)
{ {
case AF_INET: case AF_INET:
if (std::memcmp( if (std::memcmp(&((struct sockaddr_in*)addr1)->sin_addr, &((struct sockaddr_in*)addr2)->sin_addr, 4) == 0)
&((struct sockaddr_in*)addr1)->sin_addr, &((struct sockaddr_in*)addr2)->sin_addr, 4) ==
0)
{ {
return true; return true;
} }
break; break;
case AF_INET6: case AF_INET6:
if (std::memcmp( if (std::memcmp(&((struct sockaddr_in6*)addr1)->sin6_addr, &((struct sockaddr_in6*)addr2)->sin6_addr, 16) == 0)
&((struct sockaddr_in6*)addr1)->sin6_addr,
&((struct sockaddr_in6*)addr2)->sin6_addr,
16) == 0)
{ {
return true; return true;
} }
...@@ -290,7 +284,7 @@ namespace Utils ...@@ -290,7 +284,7 @@ namespace Utils
ntp.seconds = tv.tv_sec + UnixNtpOffset; ntp.seconds = tv.tv_sec + UnixNtpOffset;
ntp.fractions = ntp.fractions =
static_cast<uint32_t>(static_cast<double>(tv.tv_usec) * NtpFractionalUnit * 1.0e-6); static_cast<uint32_t>(static_cast<double>(tv.tv_usec) * NtpFractionalUnit * 1.0e-6);
} }
inline bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp) inline bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp)
......
...@@ -45,10 +45,10 @@ public: ...@@ -45,10 +45,10 @@ public:
void Destroy(); void Destroy();
virtual void Dump() const; virtual void Dump() const;
void Setup( void Setup(
Listener* listener, Listener* listener,
struct sockaddr_storage* localAddr, struct sockaddr_storage* localAddr,
const std::string& localIP, const std::string& localIP,
uint16_t localPort); uint16_t localPort);
bool IsClosing() const; bool IsClosing() const;
uv_tcp_t* GetUvHandle() const; uv_tcp_t* GetUvHandle() const;
void Start(); void Start();
......
...@@ -46,7 +46,7 @@ namespace Channel ...@@ -46,7 +46,7 @@ namespace Channel
} }
void Notifier::EmitWithBinary( void Notifier::EmitWithBinary(
uint32_t targetId, const std::string& event, const uint8_t* binaryData, size_t binaryLen) uint32_t targetId, const std::string& event, const uint8_t* binaryData, size_t binaryLen)
{ {
MS_TRACE(); MS_TRACE();
...@@ -65,11 +65,11 @@ namespace Channel ...@@ -65,11 +65,11 @@ namespace Channel
} }
void Notifier::EmitWithBinary( void Notifier::EmitWithBinary(
uint32_t targetId, uint32_t targetId,
const std::string& event, const std::string& event,
const uint8_t* binaryData, const uint8_t* binaryData,
size_t binaryLen, size_t binaryLen,
Json::Value& data) Json::Value& data)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -201,7 +201,7 @@ namespace Channel ...@@ -201,7 +201,7 @@ namespace Channel
char* jsonStart = nullptr; char* jsonStart = nullptr;
size_t jsonLen; size_t jsonLen;
int nsRet = netstring_read( int nsRet = netstring_read(
reinterpret_cast<char*>(this->buffer + this->msgStart), readLen, &jsonStart, &jsonLen); reinterpret_cast<char*>(this->buffer + this->msgStart), readLen, &jsonStart, &jsonLen);
if (nsRet != 0) if (nsRet != 0)
{ {
...@@ -224,8 +224,8 @@ namespace Channel ...@@ -224,8 +224,8 @@ namespace Channel
else else
{ {
MS_ERROR_STD( MS_ERROR_STD(
"no more space in the buffer for the unfinished message being parsed, " "no more space in the buffer for the unfinished message being parsed, "
"discarding it"); "discarding it");
this->msgStart = 0; this->msgStart = 0;
this->bufferDataLen = 0; this->bufferDataLen = 0;
...@@ -266,14 +266,14 @@ namespace Channel ...@@ -266,14 +266,14 @@ namespace Channel
// If here it means that jsonStart points to the beginning of a JSON string // If here it means that jsonStart points to the beginning of a JSON string
// with jsonLen bytes length, so recalculate readLen. // with jsonLen bytes length, so recalculate readLen.
readLen = reinterpret_cast<const uint8_t*>(jsonStart) - (this->buffer + this->msgStart) + readLen =
jsonLen + 1; reinterpret_cast<const uint8_t*>(jsonStart) - (this->buffer + this->msgStart) + jsonLen + 1;
Json::Value json; Json::Value json;
std::string jsonParseError; std::string jsonParseError;
if (this->jsonReader->parse( if (this->jsonReader->parse(
(const char*)jsonStart, (const char*)jsonStart + jsonLen, &json, &jsonParseError)) (const char*)jsonStart, (const char*)jsonStart + jsonLen, &json, &jsonParseError))
{ {
Channel::Request* request = nullptr; Channel::Request* request = nullptr;
......
...@@ -18,8 +18,8 @@ namespace RTC ...@@ -18,8 +18,8 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Consumer::Consumer( Consumer::Consumer(
Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, uint32_t sourceProducerId) Channel::Notifier* notifier, uint32_t consumerId, RTC::Media::Kind kind, uint32_t sourceProducerId)
: consumerId(consumerId), kind(kind), sourceProducerId(sourceProducerId), notifier(notifier) : consumerId(consumerId), kind(kind), sourceProducerId(sourceProducerId), notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
...@@ -252,7 +252,7 @@ namespace RTC ...@@ -252,7 +252,7 @@ namespace RTC
// Build SDES chunk for this sender. // Build SDES chunk for this sender.
auto sdesChunk = new RTC::RTCP::SdesChunk(ssrc); auto sdesChunk = new RTC::RTCP::SdesChunk(ssrc);
auto sdesItem = auto sdesItem =
new RTC::RTCP::SdesItem(RTC::RTCP::SdesItem::Type::CNAME, cname.size(), cname.c_str()); new RTC::RTCP::SdesItem(RTC::RTCP::SdesItem::Type::CNAME, cname.size(), cname.c_str());
sdesChunk->AddItem(sdesItem); sdesChunk->AddItem(sdesItem);
packet->AddSdesChunk(sdesChunk); packet->AddSdesChunk(sdesChunk);
...@@ -271,7 +271,7 @@ namespace RTC ...@@ -271,7 +271,7 @@ namespace RTC
RTC::RTCP::FeedbackRtpNackItem* item = *it; RTC::RTCP::FeedbackRtpNackItem* item = *it;
this->rtpStream->RequestRtpRetransmission( this->rtpStream->RequestRtpRetransmission(
item->GetPacketId(), item->GetLostPacketBitmask(), RtpRetransmissionContainer); item->GetPacketId(), item->GetLostPacketBitmask(), RtpRetransmissionContainer);
auto it2 = RtpRetransmissionContainer.begin(); auto it2 = RtpRetransmissionContainer.begin();
for (; it2 != RtpRetransmissionContainer.end(); ++it2) for (; it2 != RtpRetransmissionContainer.end(); ++it2)
...@@ -386,22 +386,22 @@ namespace RTC ...@@ -386,22 +386,22 @@ namespace RTC
this->rtpStream->RtxEncode(rtxPacket); this->rtpStream->RtxEncode(rtxPacket);
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"sending rtx packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "sending rtx packet [ssrc: %" PRIu32 " seqnr: %" PRIu16
"] recovering original [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]", "] recovering original [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]",
rtxPacket->GetSsrc(), rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber(), rtxPacket->GetSequenceNumber(),
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
} }
else else
{ {
rtxPacket = packet; rtxPacket = packet;
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"retransmitting packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]", "retransmitting packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]",
rtxPacket->GetSsrc(), rtxPacket->GetSsrc(),
rtxPacket->GetSequenceNumber()); rtxPacket->GetSequenceNumber());
} }
// Update retransmitted RTP data counter. // Update retransmitted RTP data counter.
......
...@@ -95,8 +95,9 @@ namespace RTC ...@@ -95,8 +95,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
// Generate a X509 certificate and private key (unless PEM files are provided). // Generate a X509 certificate and private key (unless PEM files are provided).
if (Settings::configuration.dtlsCertificateFile.empty() || if (
Settings::configuration.dtlsPrivateKeyFile.empty()) Settings::configuration.dtlsCertificateFile.empty() ||
Settings::configuration.dtlsPrivateKeyFile.empty())
{ {
GenerateCertificateAndPrivateKey(); GenerateCertificateAndPrivateKey();
} }
...@@ -195,8 +196,8 @@ namespace RTC ...@@ -195,8 +196,8 @@ namespace RTC
// Set serial number (avoid default 0). // Set serial number (avoid default 0).
ASN1_INTEGER_set( ASN1_INTEGER_set(
X509_get_serialNumber(DtlsTransport::certificate), X509_get_serialNumber(DtlsTransport::certificate),
static_cast<uint64_t>(Utils::Crypto::GetRandomUInt(1000000, 9999999))); static_cast<uint64_t>(Utils::Crypto::GetRandomUInt(1000000, 9999999)));
// Set valid period. // Set valid period.
X509_gmtime_adj(X509_get_notBefore(DtlsTransport::certificate), -315360000); // -10 years. X509_gmtime_adj(X509_get_notBefore(DtlsTransport::certificate), -315360000); // -10 years.
...@@ -218,9 +219,9 @@ namespace RTC ...@@ -218,9 +219,9 @@ namespace RTC
goto error; goto error;
} }
X509_NAME_add_entry_by_txt( X509_NAME_add_entry_by_txt(
certName, "O", MBSTRING_ASC, reinterpret_cast<const uint8_t*>("mediasoup"), -1, -1, 0); certName, "O", MBSTRING_ASC, reinterpret_cast<const uint8_t*>("mediasoup"), -1, -1, 0);
X509_NAME_add_entry_by_txt( X509_NAME_add_entry_by_txt(
certName, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t*>("mediasoup"), -1, -1, 0); certName, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t*>("mediasoup"), -1, -1, 0);
// It is self-signed so set the issuer name to be the same as the subject. // It is self-signed so set the issuer name to be the same as the subject.
ret = X509_set_issuer_name(DtlsTransport::certificate, certName); ret = X509_set_issuer_name(DtlsTransport::certificate, certName);
...@@ -349,8 +350,8 @@ namespace RTC ...@@ -349,8 +350,8 @@ namespace RTC
// Set options. // Set options.
SSL_CTX_set_options( SSL_CTX_set_options(
DtlsTransport::sslCtx, DtlsTransport::sslCtx,
SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET | SSL_OP_SINGLE_ECDH_USE); SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET | SSL_OP_SINGLE_ECDH_USE);
// Don't use sessions cache. // Don't use sessions cache.
SSL_CTX_set_session_cache_mode(DtlsTransport::sslCtx, SSL_SESS_CACHE_OFF); SSL_CTX_set_session_cache_mode(DtlsTransport::sslCtx, SSL_SESS_CACHE_OFF);
...@@ -364,16 +365,14 @@ namespace RTC ...@@ -364,16 +365,14 @@ namespace RTC
// Require certificate from peer. // Require certificate from peer.
SSL_CTX_set_verify( SSL_CTX_set_verify(
DtlsTransport::sslCtx, DtlsTransport::sslCtx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, onSslCertificateVerify);
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
onSslCertificateVerify);
// Set SSL info callback. // Set SSL info callback.
SSL_CTX_set_info_callback(DtlsTransport::sslCtx, onSslInfo); SSL_CTX_set_info_callback(DtlsTransport::sslCtx, onSslInfo);
// Set ciphers. // Set ciphers.
ret = SSL_CTX_set_cipher_list( ret = SSL_CTX_set_cipher_list(
DtlsTransport::sslCtx, "ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH"); DtlsTransport::sslCtx, "ALL:!ADH:!LOW:!EXP:!MD5:!aNULL:!eNULL:@STRENGTH");
if (ret == 0) if (ret == 0)
{ {
LOG_OPENSSL_ERROR("SSL_CTX_set_cipher_list() failed"); LOG_OPENSSL_ERROR("SSL_CTX_set_cipher_list() failed");
...@@ -600,12 +599,12 @@ namespace RTC ...@@ -600,12 +599,12 @@ namespace RTC
MS_DUMP("<DtlsTransport>"); MS_DUMP("<DtlsTransport>");
MS_DUMP( MS_DUMP(
" [role:%s, running:%s, handshake done:%s, connected:%s]", " [role:%s, running:%s, handshake done:%s, connected:%s]",
(this->localRole == Role::SERVER ? "server" (this->localRole == Role::SERVER ? "server"
: (this->localRole == Role::CLIENT ? "client" : "none")), : (this->localRole == Role::CLIENT ? "client" : "none")),
IsRunning() ? "yes" : "no", IsRunning() ? "yes" : "no",
this->handshakeDone ? "yes" : "no", this->handshakeDone ? "yes" : "no",
this->state == DtlsState::CONNECTED ? "yes" : "no"); this->state == DtlsState::CONNECTED ? "yes" : "no");
MS_DUMP("</DtlsTransport>"); MS_DUMP("</DtlsTransport>");
} }
...@@ -614,8 +613,8 @@ namespace RTC ...@@ -614,8 +613,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
localRole == Role::CLIENT || localRole == Role::SERVER, localRole == Role::CLIENT || localRole == Role::SERVER,
"local DTLS role must be 'client' or 'server'"); "local DTLS role must be 'client' or 'server'");
Role previousLocalRole = this->localRole; Role previousLocalRole = this->localRole;
...@@ -669,7 +668,7 @@ namespace RTC ...@@ -669,7 +668,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
fingerprint.algorithm != FingerprintAlgorithm::NONE, "no fingerprint algorithm provided"); fingerprint.algorithm != FingerprintAlgorithm::NONE, "no fingerprint algorithm provided");
this->remoteFingerprint = fingerprint; this->remoteFingerprint = fingerprint;
...@@ -702,10 +701,10 @@ namespace RTC ...@@ -702,10 +701,10 @@ namespace RTC
if (written != static_cast<int>(len)) if (written != static_cast<int>(len))
{ {
MS_WARN_TAG( MS_WARN_TAG(
dtls, dtls,
"OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)", "OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)",
static_cast<size_t>(written), static_cast<size_t>(written),
len); len);
} }
// Must call SSL_read() to process received DTLS data. // Must call SSL_read() to process received DTLS data.
...@@ -735,7 +734,7 @@ namespace RTC ...@@ -735,7 +734,7 @@ namespace RTC
// Notify the listener. // Notify the listener.
this->listener->OnDtlsApplicationData( this->listener->OnDtlsApplicationData(
this, (uint8_t*)DtlsTransport::sslReadBuffer, static_cast<size_t>(read)); this, (uint8_t*)DtlsTransport::sslReadBuffer, static_cast<size_t>(read));
} }
} }
...@@ -770,7 +769,7 @@ namespace RTC ...@@ -770,7 +769,7 @@ namespace RTC
else if (written != static_cast<int>(len)) else if (written != static_cast<int>(len))
{ {
MS_WARN_TAG( MS_WARN_TAG(
dtls, "OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)", written, len); dtls, "OpenSSL SSL_write() wrote less (%d bytes) than given data (%zu bytes)", written, len);
} }
// Send data. // Send data.
...@@ -909,7 +908,7 @@ namespace RTC ...@@ -909,7 +908,7 @@ namespace RTC
// Notify the listener. // Notify the listener.
this->listener->OnOutgoingDtlsData( this->listener->OnOutgoingDtlsData(
this, reinterpret_cast<uint8_t*>(data), static_cast<size_t>(read)); this, reinterpret_cast<uint8_t*>(data), static_cast<size_t>(read));
// Clear the BIO buffer. // Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning. // NOTE: the (void) avoids the -Wunused-value warning.
...@@ -1013,8 +1012,7 @@ namespace RTC ...@@ -1013,8 +1012,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set");
"remote fingerprint not set");
X509* certificate; X509* certificate;
uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE];
...@@ -1073,10 +1071,10 @@ namespace RTC ...@@ -1073,10 +1071,10 @@ namespace RTC
if (this->remoteFingerprint.value != hexFingerprint) if (this->remoteFingerprint.value != hexFingerprint)
{ {
MS_WARN_TAG( MS_WARN_TAG(
dtls, dtls,
"fingerprint in the remote certificate (%s) does not match the announced one (%s)", "fingerprint in the remote certificate (%s) does not match the announced one (%s)",
hexFingerprint, hexFingerprint,
this->remoteFingerprint.value.c_str()); this->remoteFingerprint.value.c_str());
X509_free(certificate); X509_free(certificate);
...@@ -1140,7 +1138,7 @@ namespace RTC ...@@ -1140,7 +1138,7 @@ namespace RTC
int ret; int ret;
ret = SSL_export_keying_material( ret = SSL_export_keying_material(
this->ssl, srtpMaterial, SrtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0); this->ssl, srtpMaterial, SrtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0);
MS_ASSERT(ret != 0, "SSL_export_keying_material() failed"); MS_ASSERT(ret != 0, "SSL_export_keying_material() failed");
...@@ -1173,13 +1171,13 @@ namespace RTC ...@@ -1173,13 +1171,13 @@ namespace RTC
// Set state and notify the listener. // Set state and notify the listener.
this->state = DtlsState::CONNECTED; this->state = DtlsState::CONNECTED;
this->listener->OnDtlsConnected( this->listener->OnDtlsConnected(
this, this,
srtpProfile, srtpProfile,
srtpLocalMasterKey, srtpLocalMasterKey,
SrtpMasterLength, SrtpMasterLength,
srtpRemoteMasterKey, srtpRemoteMasterKey,
SrtpMasterLength, SrtpMasterLength,
this->remoteCert); this->remoteCert);
} }
inline RTC::SrtpSession::Profile DtlsTransport::GetNegotiatedSrtpProfile() inline RTC::SrtpSession::Profile DtlsTransport::GetNegotiatedSrtpProfile()
...@@ -1210,8 +1208,8 @@ namespace RTC ...@@ -1210,8 +1208,8 @@ namespace RTC
} }
MS_ASSERT( MS_ASSERT(
negotiatedSrtpProfile != RTC::SrtpSession::Profile::NONE, negotiatedSrtpProfile != RTC::SrtpSession::Profile::NONE,
"chosen SRTP profile is not an available one"); "chosen SRTP profile is not an available one");
return negotiatedSrtpProfile; return negotiatedSrtpProfile;
} }
......
...@@ -9,8 +9,8 @@ namespace RTC ...@@ -9,8 +9,8 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority) IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority)
: foundation("udpcandidate"), priority(priority), family(udpSocket->GetLocalFamily()), : foundation("udpcandidate"), priority(priority), family(udpSocket->GetLocalFamily()),
protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST) protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{ {
switch (this->family) switch (this->family)
{ {
...@@ -37,8 +37,8 @@ namespace RTC ...@@ -37,8 +37,8 @@ namespace RTC
} }
IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority) IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority)
: foundation("tcpcandidate"), priority(priority), family(tcpServer->GetLocalFamily()), : foundation("tcpcandidate"), priority(priority), family(tcpServer->GetLocalFamily()),
protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST) protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST)
{ {
switch (this->family) switch (this->family)
{ {
......
...@@ -16,16 +16,16 @@ namespace RTC ...@@ -16,16 +16,16 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
IceServer::IceServer(Listener* listener, std::string usernameFragment, std::string password) IceServer::IceServer(Listener* listener, std::string usernameFragment, std::string password)
: listener(listener), usernameFragment(std::move(usernameFragment)), : listener(listener), usernameFragment(std::move(usernameFragment)),
password(std::move(password)) password(std::move(password))
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_TAG( MS_DEBUG_TAG(
ice, ice,
"[usernameFragment:%s, password:%s]", "[usernameFragment:%s, password:%s]",
this->usernameFragment.c_str(), this->usernameFragment.c_str(),
this->password.c_str()); this->password.c_str());
} }
void IceServer::Destroy() void IceServer::Destroy()
...@@ -45,7 +45,7 @@ namespace RTC ...@@ -45,7 +45,7 @@ namespace RTC
if (msg->GetClass() == RTC::StunMessage::Class::REQUEST) if (msg->GetClass() == RTC::StunMessage::Class::REQUEST)
{ {
MS_WARN_TAG( MS_WARN_TAG(
ice, "unknown method %#.3x in STUN Request => 400", (unsigned int)msg->GetMethod()); ice, "unknown method %#.3x in STUN Request => 400", (unsigned int)msg->GetMethod());
// Reply 400. // Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400); RTC::StunMessage* response = msg->CreateErrorResponse(400);
...@@ -57,9 +57,9 @@ namespace RTC ...@@ -57,9 +57,9 @@ namespace RTC
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
ice, ice,
"ignoring STUN Indication or Response with unknown method %#.3x", "ignoring STUN Indication or Response with unknown method %#.3x",
(unsigned int)msg->GetMethod()); (unsigned int)msg->GetMethod());
} }
return; return;
...@@ -159,9 +159,9 @@ namespace RTC ...@@ -159,9 +159,9 @@ namespace RTC
// } // }
MS_DEBUG_DEV( MS_DEBUG_DEV(
"processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]",
static_cast<uint32_t>(msg->GetPriority()), static_cast<uint32_t>(msg->GetPriority()),
msg->HasUseCandidate() ? "true" : "false"); msg->HasUseCandidate() ? "true" : "false");
// Create a success response. // Create a success response.
RTC::StunMessage* response = msg->CreateSuccessResponse(); RTC::StunMessage* response = msg->CreateSuccessResponse();
...@@ -266,14 +266,14 @@ namespace RTC ...@@ -266,14 +266,14 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->selectedTuple != nullptr, this->selectedTuple != nullptr,
"cannot force the selected tuple if there was not a selected tuple"); "cannot force the selected tuple if there was not a selected tuple");
auto storedTuple = HasTuple(tuple); auto storedTuple = HasTuple(tuple);
MS_ASSERT( MS_ASSERT(
storedTuple, storedTuple,
"cannot force the selected tuple if the given tuple was not already a valid tuple"); "cannot force the selected tuple if the given tuple was not already a valid tuple");
// Mark it as selected tuple. // Mark it as selected tuple.
SetSelectedTuple(storedTuple); SetSelectedTuple(storedTuple);
...@@ -289,7 +289,7 @@ namespace RTC ...@@ -289,7 +289,7 @@ namespace RTC
{ {
// There should be no tuples. // There should be no tuples.
MS_ASSERT( MS_ASSERT(
this->tuples.empty(), "state is 'new' but there are %zu tuples", this->tuples.size()); this->tuples.empty(), "state is 'new' but there are %zu tuples", this->tuples.size());
// There shouldn't be a selected tuple. // There shouldn't be a selected tuple.
MS_ASSERT(this->selectedTuple == nullptr, "state is 'new' but there is selected tuple"); MS_ASSERT(this->selectedTuple == nullptr, "state is 'new' but there is selected tuple");
...@@ -330,13 +330,13 @@ namespace RTC ...@@ -330,13 +330,13 @@ namespace RTC
{ {
// There should be no tuples. // There should be no tuples.
MS_ASSERT( MS_ASSERT(
this->tuples.empty(), this->tuples.empty(),
"state is 'disconnected' but there are %zu tuples", "state is 'disconnected' but there are %zu tuples",
this->tuples.size()); this->tuples.size());
// There shouldn't be a selected tuple. // There shouldn't be a selected tuple.
MS_ASSERT( MS_ASSERT(
this->selectedTuple == nullptr, "state is 'disconnected' but there is selected tuple"); this->selectedTuple == nullptr, "state is 'disconnected' but there is selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate)
{ {
...@@ -377,7 +377,7 @@ namespace RTC ...@@ -377,7 +377,7 @@ namespace RTC
// There should be a selected tuple. // There should be a selected tuple.
MS_ASSERT( MS_ASSERT(
this->selectedTuple != nullptr, "state is 'connected' but there is not selected tuple"); this->selectedTuple != nullptr, "state is 'connected' but there is not selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate)
{ {
...@@ -413,7 +413,7 @@ namespace RTC ...@@ -413,7 +413,7 @@ namespace RTC
// There should be a selected tuple. // There should be a selected tuple.
MS_ASSERT( MS_ASSERT(
this->selectedTuple != nullptr, "state is 'completed' but there is not selected tuple"); this->selectedTuple != nullptr, "state is 'completed' but there is not selected tuple");
if (!hasUseCandidate) if (!hasUseCandidate)
{ {
......
...@@ -68,10 +68,10 @@ namespace RTC ...@@ -68,10 +68,10 @@ namespace RTC
if (it != this->nackList.end()) if (it != this->nackList.end())
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
this->nackList.erase(it); this->nackList.erase(it);
} }
...@@ -79,10 +79,10 @@ namespace RTC ...@@ -79,10 +79,10 @@ namespace RTC
else else
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"out of order packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "out of order packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
} }
return; return;
...@@ -133,7 +133,7 @@ namespace RTC ...@@ -133,7 +133,7 @@ namespace RTC
NackInfo nackInfo(seq32, sendAtSeqNum); NackInfo nackInfo(seq32, sendAtSeqNum);
MS_ASSERT( MS_ASSERT(
this->nackList.find(seq32) == this->nackList.end(), "packet already in the NACK list"); this->nackList.find(seq32) == this->nackList.end(), "packet already in the NACK list");
this->nackList[seq32] = nackInfo; this->nackList[seq32] = nackInfo;
} }
...@@ -150,8 +150,7 @@ namespace RTC ...@@ -150,8 +150,7 @@ namespace RTC
NackInfo& nackInfo = it->second; NackInfo& nackInfo = it->second;
uint16_t seq = nackInfo.seq32 % (1 << 16); uint16_t seq = nackInfo.seq32 % (1 << 16);
if (filter == NackFilter::SEQ && nackInfo.sentAtTime == 0 && if (filter == NackFilter::SEQ && nackInfo.sentAtTime == 0 && this->lastSeq32 >= nackInfo.sendAtSeqNum)
this->lastSeq32 >= nackInfo.sendAtSeqNum)
{ {
nackInfo.retries++; nackInfo.retries++;
nackInfo.sentAtTime = now; nackInfo.sentAtTime = now;
...@@ -159,9 +158,9 @@ namespace RTC ...@@ -159,9 +158,9 @@ namespace RTC
if (nackInfo.retries >= MaxNackRetries) if (nackInfo.retries >= MaxNackRetries)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]",
seq); seq);
it = this->nackList.erase(it); it = this->nackList.erase(it);
} }
...@@ -182,9 +181,9 @@ namespace RTC ...@@ -182,9 +181,9 @@ namespace RTC
if (nackInfo.retries >= MaxNackRetries) if (nackInfo.retries >= MaxNackRetries)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]",
seq); seq);
it = this->nackList.erase(it); it = this->nackList.erase(it);
} }
......
...@@ -16,7 +16,7 @@ namespace RTC ...@@ -16,7 +16,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Peer::Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName) Peer::Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName)
: peerId(peerId), peerName(peerName), listener(listener), notifier(notifier) : peerId(peerId), peerName(peerName), listener(listener), notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
...@@ -380,7 +380,7 @@ namespace RTC ...@@ -380,7 +380,7 @@ namespace RTC
} }
void Peer::AddConsumer( void Peer::AddConsumer(
RTC::Consumer* consumer, RTC::RtpParameters* rtpParameters, uint32_t associatedProducerId) RTC::Consumer* consumer, RTC::RtpParameters* rtpParameters, uint32_t associatedProducerId)
{ {
MS_TRACE(); MS_TRACE();
...@@ -391,8 +391,8 @@ namespace RTC ...@@ -391,8 +391,8 @@ namespace RTC
static const Json::StaticString JsonStringAssociatedProducerId{ "associatedProducerId" }; static const Json::StaticString JsonStringAssociatedProducerId{ "associatedProducerId" };
MS_ASSERT( MS_ASSERT(
this->consumers.find(consumer->consumerId) == this->consumers.end(), this->consumers.find(consumer->consumerId) == this->consumers.end(),
"given Consumer already exists in this Peer"); "given Consumer already exists in this Peer");
// Provide the Consumer with the received RTP parameters. // Provide the Consumer with the received RTP parameters.
consumer->Send(rtpParameters); consumer->Send(rtpParameters);
...@@ -658,9 +658,9 @@ namespace RTC ...@@ -658,9 +658,9 @@ namespace RTC
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"no Consumer found for received Receiver Report [ssrc:%" PRIu32 "]", "no Consumer found for received Receiver Report [ssrc:%" PRIu32 "]",
report->GetSsrc()); report->GetSsrc());
} }
} }
...@@ -705,12 +705,12 @@ namespace RTC ...@@ -705,12 +705,12 @@ namespace RTC
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"no Consumer found for received %s Feedback packet " "no Consumer found for received %s Feedback packet "
"[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]",
RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(),
feedback->GetMediaSsrc(), feedback->GetMediaSsrc(),
feedback->GetMediaSsrc()); feedback->GetMediaSsrc());
} }
break; break;
...@@ -725,12 +725,12 @@ namespace RTC ...@@ -725,12 +725,12 @@ namespace RTC
default: default:
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"ignoring unsupported %s Feedback packet " "ignoring unsupported %s Feedback packet "
"[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]",
RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(), RTCP::FeedbackPsPacket::MessageType2String(feedback->GetMessageType()).c_str(),
feedback->GetMediaSsrc(), feedback->GetMediaSsrc(),
feedback->GetMediaSsrc()); feedback->GetMediaSsrc());
break; break;
} }
...@@ -758,11 +758,11 @@ namespace RTC ...@@ -758,11 +758,11 @@ namespace RTC
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"no Consumer found for received NACK Feedback packet " "no Consumer found for received NACK Feedback packet "
"[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]",
feedback->GetMediaSsrc(), feedback->GetMediaSsrc(),
feedback->GetMediaSsrc()); feedback->GetMediaSsrc());
} }
break; break;
...@@ -779,12 +779,12 @@ namespace RTC ...@@ -779,12 +779,12 @@ namespace RTC
default: default:
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"ignoring unsupported %s Feedback packet " "ignoring unsupported %s Feedback packet "
"[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]", "[sender ssrc:%" PRIu32 ", media ssrc:%" PRIu32 "]",
RTCP::FeedbackRtpPacket::MessageType2String(feedback->GetMessageType()).c_str(), RTCP::FeedbackRtpPacket::MessageType2String(feedback->GetMessageType()).c_str(),
feedback->GetMediaSsrc(), feedback->GetMediaSsrc(),
feedback->GetMediaSsrc()); feedback->GetMediaSsrc());
break; break;
} }
...@@ -815,9 +815,9 @@ namespace RTC ...@@ -815,9 +815,9 @@ namespace RTC
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"no Producer found for received Sender Report [ssrc:%" PRIu32 "]", "no Producer found for received Sender Report [ssrc:%" PRIu32 "]",
report->GetSsrc()); report->GetSsrc());
} }
} }
...@@ -838,7 +838,7 @@ namespace RTC ...@@ -838,7 +838,7 @@ namespace RTC
if (producer == nullptr) if (producer == nullptr)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, "no Producer for received SDES chunk [ssrc:%" PRIu32 "]", chunk->GetSsrc()); rtcp, "no Producer for received SDES chunk [ssrc:%" PRIu32 "]", chunk->GetSsrc());
} }
} }
...@@ -855,9 +855,9 @@ namespace RTC ...@@ -855,9 +855,9 @@ namespace RTC
default: default:
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"unhandled RTCP type received [type:%" PRIu8 "]", "unhandled RTCP type received [type:%" PRIu8 "]",
static_cast<uint8_t>(packet->GetType())); static_cast<uint8_t>(packet->GetType()));
} }
} }
......
...@@ -18,15 +18,15 @@ namespace RTC ...@@ -18,15 +18,15 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Producer::Producer( Producer::Producer(
Channel::Notifier* notifier, Channel::Notifier* notifier,
uint32_t producerId, uint32_t producerId,
RTC::Media::Kind kind, RTC::Media::Kind kind,
RTC::Transport* transport, RTC::Transport* transport,
RTC::RtpParameters& rtpParameters, RTC::RtpParameters& rtpParameters,
struct RtpMapping& rtpMapping, struct RtpMapping& rtpMapping,
bool paused) bool paused)
: producerId(producerId), kind(kind), notifier(notifier), transport(transport), : producerId(producerId), kind(kind), notifier(notifier), transport(transport),
rtpParameters(rtpParameters), paused(paused) rtpParameters(rtpParameters), paused(paused)
{ {
MS_TRACE(); MS_TRACE();
...@@ -298,7 +298,7 @@ namespace RTC ...@@ -298,7 +298,7 @@ namespace RTC
eventData[JsonStringObject] = jsonObject; eventData[JsonStringObject] = jsonObject;
this->notifier->EmitWithBinary( this->notifier->EmitWithBinary(
this->producerId, "rtpobject", packet->GetPayload(), packet->GetPayloadLength(), eventData); this->producerId, "rtpobject", packet->GetPayload(), packet->GetPayloadLength(), eventData);
} }
// Apply the Producer RTP mapping before dispatching the packet to the Router. // Apply the Producer RTP mapping before dispatching the packet to the Router.
...@@ -407,8 +407,9 @@ namespace RTC ...@@ -407,8 +407,9 @@ namespace RTC
for (auto& exten : this->rtpParameters.headerExtensions) for (auto& exten : this->rtpParameters.headerExtensions)
{ {
if (this->kind == RTC::Media::Kind::AUDIO && (ssrcAudioLevelId == 0u) && if (
exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL) this->kind == RTC::Media::Kind::AUDIO && (ssrcAudioLevelId == 0u) &&
exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL)
{ {
if (idMapping.find(exten.id) != idMapping.end()) if (idMapping.find(exten.id) != idMapping.end())
ssrcAudioLevelId = idMapping[exten.id]; ssrcAudioLevelId = idMapping[exten.id];
...@@ -528,14 +529,13 @@ namespace RTC ...@@ -528,14 +529,13 @@ namespace RTC
if (this->knownHeaderExtensions.ssrcAudioLevelId) if (this->knownHeaderExtensions.ssrcAudioLevelId)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, this->knownHeaderExtensions.ssrcAudioLevelId);
this->knownHeaderExtensions.ssrcAudioLevelId);
} }
if (this->knownHeaderExtensions.absSendTimeId) if (this->knownHeaderExtensions.absSendTimeId)
{ {
packet->AddExtensionMapping( packet->AddExtensionMapping(
RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId); RtpHeaderExtensionUri::Type::ABS_SEND_TIME, this->knownHeaderExtensions.absSendTimeId);
} }
} }
......
...@@ -52,9 +52,9 @@ namespace RTC ...@@ -52,9 +52,9 @@ namespace RTC
{ {
// Fix header length field. // Fix header length field.
size_t length = size_t length =
((sizeof(SenderReport::Header) + ((sizeof(SenderReport::Header) +
(sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount())) / (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount())) /
4); 4);
header->length = uint16_t{ htons(length) }; header->length = uint16_t{ htons(length) };
......
...@@ -42,17 +42,17 @@ namespace RTC ...@@ -42,17 +42,17 @@ namespace RTC
template<typename T> template<typename T>
FeedbackPacket<T>::FeedbackPacket(CommonHeader* commonHeader) FeedbackPacket<T>::FeedbackPacket(CommonHeader* commonHeader)
: Packet(RTCP::Type(commonHeader->packetType)), : Packet(RTCP::Type(commonHeader->packetType)),
messageType(typename T::MessageType(commonHeader->count)) messageType(typename T::MessageType(commonHeader->count))
{ {
this->header = this->header =
reinterpret_cast<Header*>(reinterpret_cast<uint8_t*>(commonHeader) + sizeof(CommonHeader)); reinterpret_cast<Header*>(reinterpret_cast<uint8_t*>(commonHeader) + sizeof(CommonHeader));
} }
template<typename T> template<typename T>
FeedbackPacket<T>::FeedbackPacket( FeedbackPacket<T>::FeedbackPacket(
typename T::MessageType messageType, uint32_t senderSsrc, uint32_t mediaSsrc) typename T::MessageType messageType, uint32_t senderSsrc, uint32_t mediaSsrc)
: Packet(rtcpType), messageType(messageType) : Packet(rtcpType), messageType(messageType)
{ {
this->raw = new uint8_t[sizeof(Header)]; this->raw = new uint8_t[sizeof(Header)];
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
...@@ -177,9 +177,7 @@ namespace RTC ...@@ -177,9 +177,7 @@ namespace RTC
default: default:
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp, "unknown RTCP PS Feedback message type [packetType:%" PRIu8 "]", commonHeader->count);
"unknown RTCP PS Feedback message type [packetType:%" PRIu8 "]",
commonHeader->count);
} }
return packet; return packet;
...@@ -260,9 +258,9 @@ namespace RTC ...@@ -260,9 +258,9 @@ namespace RTC
default: default:
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"unknown RTCP RTP Feedback message type [packetType:%" PRIu8 "]", "unknown RTCP RTP Feedback message type [packetType:%" PRIu8 "]",
commonHeader->count); commonHeader->count);
} }
return packet; return packet;
......
...@@ -31,7 +31,7 @@ namespace RTC ...@@ -31,7 +31,7 @@ namespace RTC
auto* commonHeader = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); auto* commonHeader = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
std::unique_ptr<FeedbackPsItemsPacket<Item>> packet( std::unique_ptr<FeedbackPsItemsPacket<Item>> packet(
new FeedbackPsItemsPacket<Item>(commonHeader)); new FeedbackPsItemsPacket<Item>(commonHeader));
size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
......
...@@ -38,7 +38,7 @@ namespace RTC ...@@ -38,7 +38,7 @@ namespace RTC
} }
FeedbackPsRembPacket::FeedbackPsRembPacket(CommonHeader* commonHeader) FeedbackPsRembPacket::FeedbackPsRembPacket(CommonHeader* commonHeader)
: FeedbackPsAfbPacket(commonHeader, FeedbackPsAfbPacket::Application::REMB) : FeedbackPsAfbPacket(commonHeader, FeedbackPsAfbPacket::Application::REMB)
{ {
auto* data = reinterpret_cast<uint8_t*>(commonHeader + 1); auto* data = reinterpret_cast<uint8_t*>(commonHeader + 1);
...@@ -53,7 +53,7 @@ namespace RTC ...@@ -53,7 +53,7 @@ namespace RTC
size_t numSsrcs = data[12]; size_t numSsrcs = data[12];
uint8_t exponent = data[13] >> 2; uint8_t exponent = data[13] >> 2;
uint64_t mantissa = uint64_t mantissa =
(static_cast<uint32_t>(data[13] & 0x03) << 16) | Utils::Byte::Get2Bytes(data, 14); (static_cast<uint32_t>(data[13] & 0x03) << 16) | Utils::Byte::Get2Bytes(data, 14);
this->bitrate = (mantissa << exponent); this->bitrate = (mantissa << exponent);
if ((this->bitrate >> exponent) != mantissa) if ((this->bitrate >> exponent) != mantissa)
...@@ -67,11 +67,10 @@ namespace RTC ...@@ -67,11 +67,10 @@ namespace RTC
// Check length. // Check length.
size_t len = static_cast<size_t>(ntohs(commonHeader->length) + 1) * 4; size_t len = static_cast<size_t>(ntohs(commonHeader->length) + 1) * 4;
if (len != sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) + sizeof(Header) + if (len != sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) + sizeof(Header) + (numSsrcs * sizeof(uint32_t)))
(numSsrcs * sizeof(uint32_t)))
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, "invalid payload size (%zu bytes) for the given number of ssrcs (%zu)", len, numSsrcs); rtcp, "invalid payload size (%zu bytes) for the given number of ssrcs (%zu)", len, numSsrcs);
this->isCorrect = false; this->isCorrect = false;
return; return;
......
...@@ -67,8 +67,8 @@ namespace RTC ...@@ -67,8 +67,8 @@ namespace RTC
MS_ASSERT(payloadType <= 0x7f, "rpsi payload type exceeds the maximum value"); MS_ASSERT(payloadType <= 0x7f, "rpsi payload type exceeds the maximum value");
MS_ASSERT( MS_ASSERT(
length <= FeedbackPsRpsiItem::maxBitStringSize, length <= FeedbackPsRpsiItem::maxBitStringSize,
"rpsi bit string length exceeds the maximum value"); "rpsi bit string length exceeds the maximum value");
this->raw = new uint8_t[sizeof(Header)]; this->raw = new uint8_t[sizeof(Header)];
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
......
...@@ -71,13 +71,13 @@ namespace RTC ...@@ -71,13 +71,13 @@ namespace RTC
template<> template<>
const FeedbackPs::MessageType FeedbackPsTstItem<Tstr>::messageType = const FeedbackPs::MessageType FeedbackPsTstItem<Tstr>::messageType =
FeedbackPs::MessageType::TSTR; FeedbackPs::MessageType::TSTR;
/* Specialization for Tstn class. */ /* Specialization for Tstn class. */
template<> template<>
const FeedbackPs::MessageType FeedbackPsTstItem<Tstn>::messageType = const FeedbackPs::MessageType FeedbackPsTstItem<Tstn>::messageType =
FeedbackPs::MessageType::TSTN; FeedbackPs::MessageType::TSTN;
// Explicit instantiation to have all definitions in this file. // Explicit instantiation to have all definitions in this file.
template class FeedbackPsTstItem<Tstr>; template class FeedbackPsTstItem<Tstr>;
......
...@@ -30,7 +30,7 @@ namespace RTC ...@@ -30,7 +30,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
FeedbackPsVbcmItem::FeedbackPsVbcmItem( FeedbackPsVbcmItem::FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value) uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value)
{ {
this->raw = new uint8_t[8 + length]; this->raw = new uint8_t[8 + length];
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
......
...@@ -29,7 +29,7 @@ namespace RTC ...@@ -29,7 +29,7 @@ namespace RTC
auto* commonHeader = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); auto* commonHeader = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
std::unique_ptr<FeedbackRtpItemsPacket<Item>> packet( std::unique_ptr<FeedbackRtpItemsPacket<Item>> packet(
new FeedbackRtpItemsPacket<Item>(commonHeader)); new FeedbackRtpItemsPacket<Item>(commonHeader));
size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); size_t offset = sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
......
...@@ -95,13 +95,13 @@ namespace RTC ...@@ -95,13 +95,13 @@ namespace RTC
template<> template<>
const FeedbackRtp::MessageType FeedbackRtpTmmbItem<FeedbackRtpTmmbr>::messageType = const FeedbackRtp::MessageType FeedbackRtpTmmbItem<FeedbackRtpTmmbr>::messageType =
FeedbackRtp::MessageType::TMMBR; FeedbackRtp::MessageType::TMMBR;
/* Specialization for Tmmbn class. */ /* Specialization for Tmmbn class. */
template<> template<>
const FeedbackRtp::MessageType FeedbackRtpTmmbItem<FeedbackRtpTmmbn>::messageType = const FeedbackRtp::MessageType FeedbackRtpTmmbItem<FeedbackRtpTmmbn>::messageType =
FeedbackRtp::MessageType::TMMBN; FeedbackRtp::MessageType::TMMBN;
// Explicit instantiation to have all FeedbackRtpTmmbItem definitions in this file. // Explicit instantiation to have all FeedbackRtpTmmbItem definitions in this file.
template class FeedbackRtpTmmbItem<FeedbackRtpTmmbr>; template class FeedbackRtpTmmbItem<FeedbackRtpTmmbr>;
......
...@@ -60,11 +60,11 @@ namespace RTC ...@@ -60,11 +60,11 @@ namespace RTC
if (len < packetLlen) if (len < packetLlen)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtcp, rtcp,
"packet length exceeds remaining data [len:%zu, " "packet length exceeds remaining data [len:%zu, "
"packet len:%zu]", "packet len:%zu]",
len, len,
packetLlen); packetLlen);
return first; return first;
} }
...@@ -142,12 +142,12 @@ namespace RTC ...@@ -142,12 +142,12 @@ namespace RTC
if (Type(header->packetType) == Type::PSFB) if (Type(header->packetType) == Type::PSFB)
{ {
packetType += packetType +=
" " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count)); " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count));
} }
else if (Type(header->packetType) == Type::RTPFB) else if (Type(header->packetType) == Type::RTPFB)
{ {
packetType += packetType +=
" " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count)); " " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count));
} }
MS_WARN_TAG(rtcp, "error parsing %s Packet", packetType.c_str()); MS_WARN_TAG(rtcp, "error parsing %s Packet", packetType.c_str());
......
...@@ -74,7 +74,7 @@ namespace RTC ...@@ -74,7 +74,7 @@ namespace RTC
std::unique_ptr<ReceiverReportPacket> packet(new ReceiverReportPacket()); std::unique_ptr<ReceiverReportPacket> packet(new ReceiverReportPacket());
packet->SetSsrc( packet->SetSsrc(
Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), sizeof(CommonHeader))); Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), sizeof(CommonHeader)));
if (offset == 0) if (offset == 0)
offset = sizeof(Packet::CommonHeader) + sizeof(uint32_t) /* ssrc */; offset = sizeof(Packet::CommonHeader) + sizeof(uint32_t) /* ssrc */;
......
...@@ -31,7 +31,7 @@ namespace RTC ...@@ -31,7 +31,7 @@ namespace RTC
const int64_t minFeedbackIntervalMs{ 200 }; const int64_t minFeedbackIntervalMs{ 200 };
auto interval = auto interval =
int64_t{ std::lround((RtcpSize * 8.0 * 1000.0) / (0.05 * this->currentBitrateBps) + 0.5) }; int64_t{ std::lround((RtcpSize * 8.0 * 1000.0) / (0.05 * this->currentBitrateBps) + 0.5) };
return std::min(std::max(interval, minFeedbackIntervalMs), MaxFeedbackIntervalMs); return std::min(std::max(interval, minFeedbackIntervalMs), MaxFeedbackIntervalMs);
} }
...@@ -115,7 +115,7 @@ namespace RTC ...@@ -115,7 +115,7 @@ namespace RTC
} }
uint32_t AimdRateControl::ChangeBitrate( uint32_t AimdRateControl::ChangeBitrate(
uint32_t newBitrateBps, uint32_t incomingBitrateBps, int64_t nowMs) uint32_t newBitrateBps, uint32_t incomingBitrateBps, int64_t nowMs)
{ {
MS_TRACE(); MS_TRACE();
...@@ -143,8 +143,7 @@ namespace RTC ...@@ -143,8 +143,7 @@ namespace RTC
break; break;
case RC_INCREASE: case RC_INCREASE:
if (this->avgMaxBitrateKbps >= 0 && if (this->avgMaxBitrateKbps >= 0 && incomingBitrateKbps > this->avgMaxBitrateKbps + 3 * stdMaxBitRate)
incomingBitrateKbps > this->avgMaxBitrateKbps + 3 * stdMaxBitRate)
{ {
ChangeRegion(RC_MAX_UNKNOWN); ChangeRegion(RC_MAX_UNKNOWN);
this->avgMaxBitrateKbps = -1.0; this->avgMaxBitrateKbps = -1.0;
...@@ -158,7 +157,7 @@ namespace RTC ...@@ -158,7 +157,7 @@ namespace RTC
else else
{ {
uint32_t multiplicativeIncreaseBps = uint32_t multiplicativeIncreaseBps =
MultiplicativeRateIncrease(nowMs, this->timeLastBitrateChange, newBitrateBps); MultiplicativeRateIncrease(nowMs, this->timeLastBitrateChange, newBitrateBps);
newBitrateBps += multiplicativeIncreaseBps; newBitrateBps += multiplicativeIncreaseBps;
} }
...@@ -177,8 +176,8 @@ namespace RTC ...@@ -177,8 +176,8 @@ namespace RTC
// Avoid increasing the rate when over-using. // Avoid increasing the rate when over-using.
if (this->rateControlRegion != RC_MAX_UNKNOWN) if (this->rateControlRegion != RC_MAX_UNKNOWN)
{ {
newBitrateBps = static_cast<uint32_t>( newBitrateBps =
std::lround(this->beta * this->avgMaxBitrateKbps * 1000 + 0.5f)); static_cast<uint32_t>(std::lround(this->beta * this->avgMaxBitrateKbps * 1000 + 0.5f));
} }
newBitrateBps = std::min(newBitrateBps, this->currentBitrateBps); newBitrateBps = std::min(newBitrateBps, this->currentBitrateBps);
...@@ -223,7 +222,7 @@ namespace RTC ...@@ -223,7 +222,7 @@ namespace RTC
} }
uint32_t AimdRateControl::MultiplicativeRateIncrease( uint32_t AimdRateControl::MultiplicativeRateIncrease(
int64_t nowMs, int64_t lastMs, uint32_t currentBitrateBps) const int64_t nowMs, int64_t lastMs, uint32_t currentBitrateBps) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -262,7 +261,7 @@ namespace RTC ...@@ -262,7 +261,7 @@ namespace RTC
this->varMaxBitrateKbps = (1 - alpha) * this->varMaxBitrateKbps + this->varMaxBitrateKbps = (1 - alpha) * this->varMaxBitrateKbps +
alpha * (this->avgMaxBitrateKbps - incomingBitrateKbps) * alpha * (this->avgMaxBitrateKbps - incomingBitrateKbps) *
(this->avgMaxBitrateKbps - incomingBitrateKbps) / norm; (this->avgMaxBitrateKbps - incomingBitrateKbps) / norm;
// 0.4 ~= 14 kbit/s at 500 kbit/s // 0.4 ~= 14 kbit/s at 500 kbit/s
if (this->varMaxBitrateKbps < 0.4f) if (this->varMaxBitrateKbps < 0.4f)
......
...@@ -22,13 +22,13 @@ namespace RTC ...@@ -22,13 +22,13 @@ namespace RTC
static const int BurstDeltaThresholdMs{ 5 }; static const int BurstDeltaThresholdMs{ 5 };
bool InterArrival::ComputeDeltas( bool InterArrival::ComputeDeltas(
uint32_t timestamp, uint32_t timestamp,
int64_t arrivalTimeMs, int64_t arrivalTimeMs,
int64_t systemTimeMs, int64_t systemTimeMs,
size_t packetSize, size_t packetSize,
uint32_t* timestampDelta, uint32_t* timestampDelta,
int64_t* arrivalTimeDeltaMs, int64_t* arrivalTimeDeltaMs,
int* packetSizeDelta) int* packetSizeDelta)
{ {
MS_TRACE(); MS_TRACE();
...@@ -56,20 +56,20 @@ namespace RTC ...@@ -56,20 +56,20 @@ namespace RTC
{ {
*timestampDelta = this->currentTimestampGroup.timestamp - this->prevTimestampGroup.timestamp; *timestampDelta = this->currentTimestampGroup.timestamp - this->prevTimestampGroup.timestamp;
*arrivalTimeDeltaMs = *arrivalTimeDeltaMs =
this->currentTimestampGroup.completeTimeMs - this->prevTimestampGroup.completeTimeMs; this->currentTimestampGroup.completeTimeMs - this->prevTimestampGroup.completeTimeMs;
// Check system time differences to see if we have an unproportional jump // Check system time differences to see if we have an unproportional jump
// in arrival time. In that case reset the inter-arrival computations. // in arrival time. In that case reset the inter-arrival computations.
int64_t systemTimeDeltaMs = int64_t systemTimeDeltaMs =
this->currentTimestampGroup.lastSystemTimeMs - this->prevTimestampGroup.lastSystemTimeMs; this->currentTimestampGroup.lastSystemTimeMs - this->prevTimestampGroup.lastSystemTimeMs;
if (*arrivalTimeDeltaMs - systemTimeDeltaMs >= ArrivalTimeOffsetThresholdMs) if (*arrivalTimeDeltaMs - systemTimeDeltaMs >= ArrivalTimeOffsetThresholdMs)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rbe, rbe,
"the arrival time clock offset has changed, resetting" "the arrival time clock offset has changed, resetting"
"[diff:%" PRId64 "ms]", "[diff:%" PRId64 "ms]",
*arrivalTimeDeltaMs - systemTimeDeltaMs); *arrivalTimeDeltaMs - systemTimeDeltaMs);
Reset(); Reset();
...@@ -84,10 +84,10 @@ namespace RTC ...@@ -84,10 +84,10 @@ namespace RTC
if (this->numConsecutiveReorderedPackets >= ReorderedResetThreshold) if (this->numConsecutiveReorderedPackets >= ReorderedResetThreshold)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rbe, rbe,
"packets are being reordered on the path from the " "packets are being reordered on the path from the "
"socket to the bandwidth estimator, ignoring this " "socket to the bandwidth estimator, ignoring this "
"packet for bandwidth estimation, resetting"); "packet for bandwidth estimation, resetting");
Reset(); Reset();
} }
...@@ -112,7 +112,7 @@ namespace RTC ...@@ -112,7 +112,7 @@ namespace RTC
else else
{ {
this->currentTimestampGroup.timestamp = this->currentTimestampGroup.timestamp =
Utils::Time::LatestTimestamp(this->currentTimestampGroup.timestamp, timestamp); Utils::Time::LatestTimestamp(this->currentTimestampGroup.timestamp, timestamp);
} }
// Accumulate the frame size. // Accumulate the frame size.
...@@ -167,7 +167,7 @@ namespace RTC ...@@ -167,7 +167,7 @@ namespace RTC
int64_t arrivalTimeDeltaMs = arrivalTimeMs - this->currentTimestampGroup.completeTimeMs; int64_t arrivalTimeDeltaMs = arrivalTimeMs - this->currentTimestampGroup.completeTimeMs;
uint32_t timestampDiff = timestamp - this->currentTimestampGroup.timestamp; uint32_t timestampDiff = timestamp - this->currentTimestampGroup.timestamp;
auto tsDeltaMs = auto tsDeltaMs =
static_cast<int64_t>(std::lround(this->timestampToMsCoeff * timestampDiff + 0.5)); static_cast<int64_t>(std::lround(this->timestampToMsCoeff * timestampDiff + 0.5));
if (tsDeltaMs == 0) if (tsDeltaMs == 0)
return true; return true;
......
...@@ -24,7 +24,7 @@ namespace RTC ...@@ -24,7 +24,7 @@ namespace RTC
constexpr uint16_t DeltaCounterMax{ 1000 }; constexpr uint16_t DeltaCounterMax{ 1000 };
void OveruseEstimator::Update( void OveruseEstimator::Update(
int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs) int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs)
{ {
MS_TRACE(); MS_TRACE();
...@@ -42,8 +42,9 @@ namespace RTC ...@@ -42,8 +42,9 @@ namespace RTC
this->e[0][0] += this->processNoise[0]; this->e[0][0] += this->processNoise[0];
this->e[1][1] += this->processNoise[1]; this->e[1][1] += this->processNoise[1];
if ((currentHypothesis == BW_OVERUSING && this->offset < this->prevOffset) || if (
(currentHypothesis == BW_UNDERUSING && this->offset > this->prevOffset)) (currentHypothesis == BW_OVERUSING && this->offset < this->prevOffset) ||
(currentHypothesis == BW_UNDERUSING && this->offset > this->prevOffset))
{ {
this->e[1][1] += 10 * this->processNoise[1]; this->e[1][1] += 10 * this->processNoise[1];
} }
...@@ -135,8 +136,8 @@ namespace RTC ...@@ -135,8 +136,8 @@ namespace RTC
const double beta = pow(1 - alpha, tsDelta * 30.0 / 1000.0); const double beta = pow(1 - alpha, tsDelta * 30.0 / 1000.0);
this->avgNoise = beta * this->avgNoise + (1 - beta) * residual; this->avgNoise = beta * this->avgNoise + (1 - beta) * residual;
this->varNoise = beta * this->varNoise + this->varNoise =
(1 - beta) * (this->avgNoise - residual) * (this->avgNoise - residual); beta * this->varNoise + (1 - beta) * (this->avgNoise - residual) * (this->avgNoise - residual);
if (this->varNoise < 1) if (this->varNoise < 1)
this->varNoise = 1; this->varNoise = 1;
} }
......
...@@ -51,14 +51,14 @@ namespace RTC ...@@ -51,14 +51,14 @@ namespace RTC
uint32_t convertMsTo24Bits(int64_t timeMs) uint32_t convertMsTo24Bits(int64_t timeMs)
{ {
uint32_t time24Bits = uint32_t time24Bits =
static_cast<uint32_t>(((static_cast<uint64_t>(timeMs) << AbsSendTimeFraction) + 500) / 1000) & static_cast<uint32_t>(((static_cast<uint64_t>(timeMs) << AbsSendTimeFraction) + 500) / 1000) &
0x00FFFFFF; 0x00FFFFFF;
return time24Bits; return time24Bits;
} }
bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds( bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds(
int sendDeltaMs, const Cluster& clusterAggregate) int sendDeltaMs, const Cluster& clusterAggregate)
{ {
MS_TRACE(); MS_TRACE();
...@@ -123,7 +123,7 @@ namespace RTC ...@@ -123,7 +123,7 @@ namespace RTC
} }
std::list<Cluster>::const_iterator RemoteBitrateEstimatorAbsSendTime::FindBestProbe( std::list<Cluster>::const_iterator RemoteBitrateEstimatorAbsSendTime::FindBestProbe(
const std::list<Cluster>& clusters) const const std::list<Cluster>& clusters) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -136,8 +136,9 @@ namespace RTC ...@@ -136,8 +136,9 @@ namespace RTC
if (it->sendMeanMs == 0 || it->recvMeanMs == 0) if (it->sendMeanMs == 0 || it->recvMeanMs == 0)
continue; continue;
if (it->numAboveMinDelta > it->count / 2 && if (
(it->recvMeanMs - it->sendMeanMs <= 2.0f && it->sendMeanMs - it->recvMeanMs <= 5.0f)) it->numAboveMinDelta > it->count / 2 &&
(it->recvMeanMs - it->sendMeanMs <= 2.0f && it->sendMeanMs - it->recvMeanMs <= 5.0f))
{ {
int probeBitrateBps = std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); int probeBitrateBps = std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps());
...@@ -153,14 +154,14 @@ namespace RTC ...@@ -153,14 +154,14 @@ namespace RTC
int recvBitrateBps = it->meanSize * 8 * 1000 / it->recvMeanMs; int recvBitrateBps = it->meanSize * 8 * 1000 / it->recvMeanMs;
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, rbe,
"probe failed, sent at %d bps, received at %d bps [mean " "probe failed, sent at %d bps, received at %d bps [mean "
"send delta:%fms, mean recv delta:%fms, num probes:%d]", "send delta:%fms, mean recv delta:%fms, num probes:%d]",
sendBitrateBps, sendBitrateBps,
recvBitrateBps, recvBitrateBps,
it->sendMeanMs, it->sendMeanMs,
it->recvMeanMs, it->recvMeanMs,
it->count); it->count);
break; break;
} }
...@@ -170,7 +171,7 @@ namespace RTC ...@@ -170,7 +171,7 @@ namespace RTC
} }
RemoteBitrateEstimatorAbsSendTime::ProbeResult RemoteBitrateEstimatorAbsSendTime::ProcessClusters( RemoteBitrateEstimatorAbsSendTime::ProbeResult RemoteBitrateEstimatorAbsSendTime::ProcessClusters(
int64_t nowMs) int64_t nowMs)
{ {
MS_TRACE(); MS_TRACE();
...@@ -197,15 +198,15 @@ namespace RTC ...@@ -197,15 +198,15 @@ namespace RTC
if (IsBitrateImproving(probeBitrateBps)) if (IsBitrateImproving(probeBitrateBps))
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, rbe,
"probe successful, sent at %d bps, received at %d bps " "probe successful, sent at %d bps, received at %d bps "
"[mean send delta:%fms, mean recv delta: %f ms, " "[mean send delta:%fms, mean recv delta: %f ms, "
"num probes:%d", "num probes:%d",
bestIt->GetSendBitrateBps(), bestIt->GetSendBitrateBps(),
bestIt->GetRecvBitrateBps(), bestIt->GetRecvBitrateBps(),
bestIt->sendMeanMs, bestIt->sendMeanMs,
bestIt->recvMeanMs, bestIt->recvMeanMs,
bestIt->count); bestIt->count);
this->remoteRate.SetEstimate(probeBitrateBps, nowMs); this->remoteRate.SetEstimate(probeBitrateBps, nowMs);
...@@ -233,7 +234,7 @@ namespace RTC ...@@ -233,7 +234,7 @@ namespace RTC
} }
void RemoteBitrateEstimatorAbsSendTime::IncomingPacket( void RemoteBitrateEstimatorAbsSendTime::IncomingPacket(
int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime) int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime)
{ {
MS_TRACE(); MS_TRACE();
...@@ -241,7 +242,7 @@ namespace RTC ...@@ -241,7 +242,7 @@ namespace RTC
} }
void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo(
int64_t arrivalTimeMs, uint32_t sendTime24bits, size_t payloadSize, uint32_t ssrc) int64_t arrivalTimeMs, uint32_t sendTime24bits, size_t payloadSize, uint32_t ssrc)
{ {
MS_TRACE(); MS_TRACE();
...@@ -298,9 +299,10 @@ namespace RTC ...@@ -298,9 +299,10 @@ namespace RTC
// the sender. // the sender.
const size_t minProbePacketSize{ 200 }; const size_t minProbePacketSize{ 200 };
if (payloadSize > minProbePacketSize && if (
(!this->remoteRate.ValidEstimate() || payloadSize > minProbePacketSize &&
nowMs - this->firstPacketTimeMs < InitialProbingIntervalMs)) (!this->remoteRate.ValidEstimate() ||
nowMs - this->firstPacketTimeMs < InitialProbingIntervalMs))
{ {
// TODO(holmer): Use a map instead to get correct order? // TODO(holmer): Use a map instead to get correct order?
if (this->totalProbesReceived < MaxProbePackets) if (this->totalProbesReceived < MaxProbePackets)
...@@ -315,14 +317,14 @@ namespace RTC ...@@ -315,14 +317,14 @@ namespace RTC
} }
MS_DEBUG_TAG( MS_DEBUG_TAG(
rbe, rbe,
"probe packet received [send time:%" PRId64 "probe packet received [send time:%" PRId64
"ms, recv " "ms, recv "
"time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]", "time:%" PRId64 "ms, send delta:%dms, recv delta:%d ms]",
sendTimeMs, sendTimeMs,
arrivalTimeMs, arrivalTimeMs,
sendDeltaMs, sendDeltaMs,
recvDeltaMs); recvDeltaMs);
} }
this->probes.emplace_back(sendTimeMs, arrivalTimeMs, payloadSize); this->probes.emplace_back(sendTimeMs, arrivalTimeMs, payloadSize);
...@@ -335,21 +337,20 @@ namespace RTC ...@@ -335,21 +337,20 @@ namespace RTC
} }
if (this->interArrival->ComputeDeltas( if (this->interArrival->ComputeDeltas(
timestamp, arrivalTimeMs, nowMs, payloadSize, &tsDelta, &tDelta, &sizeDelta)) timestamp, arrivalTimeMs, nowMs, payloadSize, &tsDelta, &tDelta, &sizeDelta))
{ {
double tsDeltaMs = (1000.0 * tsDelta) / (1 << InterArrivalShift); double tsDeltaMs = (1000.0 * tsDelta) / (1 << InterArrivalShift);
this->estimator->Update(tDelta, tsDeltaMs, sizeDelta, this->detector.State(), arrivalTimeMs); this->estimator->Update(tDelta, tsDeltaMs, sizeDelta, this->detector.State(), arrivalTimeMs);
this->detector.Detect( this->detector.Detect(
this->estimator->GetOffset(), tsDeltaMs, this->estimator->GetNumOfDeltas(), arrivalTimeMs); this->estimator->GetOffset(), tsDeltaMs, this->estimator->GetNumOfDeltas(), arrivalTimeMs);
} }
if (!updateEstimate) if (!updateEstimate)
{ {
// Check if it's time for a periodic update or if we should update because // Check if it's time for a periodic update or if we should update because
// of an over-use. // of an over-use.
if (this->lastUpdateMs == -1 || if (this->lastUpdateMs == -1 || nowMs - this->lastUpdateMs > this->remoteRate.GetFeedbackInterval())
nowMs - this->lastUpdateMs > this->remoteRate.GetFeedbackInterval())
{ {
updateEstimate = true; updateEstimate = true;
} }
...@@ -368,9 +369,9 @@ namespace RTC ...@@ -368,9 +369,9 @@ namespace RTC
// We also have to update the estimate immediately if we are overusing // We also have to update the estimate immediately if we are overusing
// and the target bitrate is too high compared to what we are receiving. // and the target bitrate is too high compared to what we are receiving.
const RateControlInput input( const RateControlInput input(
this->detector.State(), this->detector.State(),
this->incomingBitrate.GetRate(arrivalTimeMs), this->incomingBitrate.GetRate(arrivalTimeMs),
this->estimator->GetVarNoise()); this->estimator->GetVarNoise());
this->remoteRate.Update(&input, nowMs); this->remoteRate.Update(&input, nowMs);
targetBitrateBps = this->remoteRate.UpdateBandwidthEstimate(nowMs); targetBitrateBps = this->remoteRate.UpdateBandwidthEstimate(nowMs);
...@@ -402,7 +403,7 @@ namespace RTC ...@@ -402,7 +403,7 @@ namespace RTC
{ {
// We can't update the estimate if we don't have any active streams. // We can't update the estimate if we don't have any active streams.
this->interArrival.reset(new InterArrival( this->interArrival.reset(new InterArrival(
(TimestampGroupLengthMs << InterArrivalShift) / 1000, TimestampToMs, true)); (TimestampGroupLengthMs << InterArrivalShift) / 1000, TimestampToMs, true));
this->estimator.reset(new OveruseEstimator(OverUseDetectorOptions())); this->estimator.reset(new OveruseEstimator(OverUseDetectorOptions()));
// We deliberately don't reset the this->firstPacketTimeMs here for now since // We deliberately don't reset the this->firstPacketTimeMs here for now since
// we only probe for bandwidth in the beginning of a call right now. // we only probe for bandwidth in the beginning of a call right now.
...@@ -410,7 +411,7 @@ namespace RTC ...@@ -410,7 +411,7 @@ namespace RTC
} }
bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate( bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate(
std::vector<uint32_t>* ssrcs, uint32_t* bitrateBps) const std::vector<uint32_t>* ssrcs, uint32_t* bitrateBps) const
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
namespace RTC namespace RTC
{ {
void RemoteBitrateEstimatorSingleStream::IncomingPacket( void RemoteBitrateEstimatorSingleStream::IncomingPacket(
int64_t arrivalTimeMs, int64_t arrivalTimeMs,
size_t payloadSize, size_t payloadSize,
const RtpPacket& packet, const RtpPacket& packet,
const uint32_t transmissionTimeOffset) const uint32_t transmissionTimeOffset)
{ {
MS_TRACE(); MS_TRACE();
...@@ -47,7 +47,7 @@ namespace RTC ...@@ -47,7 +47,7 @@ namespace RTC
// automatically cleaned up when we have one RemoteBitrateEstimator per REMB // automatically cleaned up when we have one RemoteBitrateEstimator per REMB
// group. // group.
std::pair<SsrcOveruseEstimatorMap::iterator, bool> insertResult = this->overuseDetectors.insert( std::pair<SsrcOveruseEstimatorMap::iterator, bool> insertResult = this->overuseDetectors.insert(
std::make_pair(ssrc, new Detector(nowMs, OverUseDetectorOptions(), true))); std::make_pair(ssrc, new Detector(nowMs, OverUseDetectorOptions(), true)));
it = insertResult.first; it = insertResult.first;
} }
...@@ -78,27 +78,28 @@ namespace RTC ...@@ -78,27 +78,28 @@ namespace RTC
int sizeDelta{ 0 }; int sizeDelta{ 0 };
if (estimator->interArrival.ComputeDeltas( if (estimator->interArrival.ComputeDeltas(
rtpTimestamp, arrivalTimeMs, nowMs, payloadSize, &timestampDelta, &timeDelta, &sizeDelta)) rtpTimestamp, arrivalTimeMs, nowMs, payloadSize, &timestampDelta, &timeDelta, &sizeDelta))
{ {
double timestampDeltaMs = timestampDelta * TimestampToMs; double timestampDeltaMs = timestampDelta * TimestampToMs;
estimator->estimator.Update( estimator->estimator.Update(
timeDelta, timestampDeltaMs, sizeDelta, estimator->detector.State(), nowMs); timeDelta, timestampDeltaMs, sizeDelta, estimator->detector.State(), nowMs);
estimator->detector.Detect( estimator->detector.Detect(
estimator->estimator.GetOffset(), estimator->estimator.GetOffset(),
timestampDeltaMs, timestampDeltaMs,
estimator->estimator.GetNumOfDeltas(), estimator->estimator.GetNumOfDeltas(),
nowMs); nowMs);
} }
if (estimator->detector.State() == BW_OVERUSING) if (estimator->detector.State() == BW_OVERUSING)
{ {
uint32_t incomingBitrateBps = this->incomingBitrate.GetRate(nowMs); uint32_t incomingBitrateBps = this->incomingBitrate.GetRate(nowMs);
if ((incomingBitrateBps != 0u) && if (
(priorState != BW_OVERUSING || (incomingBitrateBps != 0u) &&
GetRemoteRate()->TimeToReduceFurther(nowMs, incomingBitrateBps))) (priorState != BW_OVERUSING ||
GetRemoteRate()->TimeToReduceFurther(nowMs, incomingBitrateBps)))
{ {
// The first overuse should immediately trigger a new estimate. // The first overuse should immediately trigger a new estimate.
// We also have to update the estimate immediately if we are overusing // We also have to update the estimate immediately if we are overusing
...@@ -175,7 +176,7 @@ namespace RTC ...@@ -175,7 +176,7 @@ namespace RTC
} }
bool RemoteBitrateEstimatorSingleStream::LatestEstimate( bool RemoteBitrateEstimatorSingleStream::LatestEstimate(
std::vector<uint32_t>* ssrcs, uint32_t* bitrateBps) const std::vector<uint32_t>* ssrcs, uint32_t* bitrateBps) const
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -19,7 +19,7 @@ namespace RTC ...@@ -19,7 +19,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
Router::Router(Listener* listener, Channel::Notifier* notifier, uint32_t routerId) Router::Router(Listener* listener, Channel::Notifier* notifier, uint32_t routerId)
: routerId(routerId), listener(listener), notifier(notifier) : routerId(routerId), listener(listener), notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
...@@ -147,7 +147,7 @@ namespace RTC ...@@ -147,7 +147,7 @@ namespace RTC
auto* producer = kv.second; auto* producer = kv.second;
jsonMapConsumerProducer[std::to_string(consumer->consumerId)] = jsonMapConsumerProducer[std::to_string(consumer->consumerId)] =
std::to_string(producer->producerId); std::to_string(producer->producerId);
} }
json[JsonStringMapConsumerProducer] = jsonMapConsumerProducer; json[JsonStringMapConsumerProducer] = jsonMapConsumerProducer;
...@@ -353,7 +353,7 @@ namespace RTC ...@@ -353,7 +353,7 @@ namespace RTC
// Create a Producer instance. // Create a Producer instance.
producer = new RTC::Producer( producer = new RTC::Producer(
this->notifier, producerId, kind, transport, rtpParameters, rtpMapping, paused); this->notifier, producerId, kind, transport, rtpParameters, rtpMapping, paused);
// Add us as listener. // Add us as listener.
producer->AddListener(this); producer->AddListener(this);
...@@ -885,8 +885,8 @@ namespace RTC ...@@ -885,8 +885,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(), this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers"); "Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer]; auto& consumers = this->mapProducerConsumers[producer];
...@@ -901,8 +901,8 @@ namespace RTC ...@@ -901,8 +901,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(), this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers"); "Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer]; auto& consumers = this->mapProducerConsumers[producer];
...@@ -917,8 +917,8 @@ namespace RTC ...@@ -917,8 +917,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(), this->mapProducerConsumers.find(producer) != this->mapProducerConsumers.end(),
"Producer not present in mapProducerConsumers"); "Producer not present in mapProducerConsumers");
auto& consumers = this->mapProducerConsumers[producer]; auto& consumers = this->mapProducerConsumers[producer];
...@@ -969,8 +969,8 @@ namespace RTC ...@@ -969,8 +969,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapConsumerProducer.find(consumer) != this->mapConsumerProducer.end(), this->mapConsumerProducer.find(consumer) != this->mapConsumerProducer.end(),
"Consumer not present in mapConsumerProducer"); "Consumer not present in mapConsumerProducer");
auto* producer = this->mapConsumerProducer[consumer]; auto* producer = this->mapConsumerProducer[consumer];
......
...@@ -151,9 +151,9 @@ namespace RTC ...@@ -151,9 +151,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapKeyValues.find(key) != this->mapKeyValues.end(), this->mapKeyValues.find(key) != this->mapKeyValues.end(),
"key does not exist [key:%s]", "key does not exist [key:%s]",
key.c_str()); key.c_str());
return this->mapKeyValues[key].booleanValue; return this->mapKeyValues[key].booleanValue;
} }
...@@ -163,9 +163,9 @@ namespace RTC ...@@ -163,9 +163,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapKeyValues.find(key) != this->mapKeyValues.end(), this->mapKeyValues.find(key) != this->mapKeyValues.end(),
"key does not exist [key:%s]", "key does not exist [key:%s]",
key.c_str()); key.c_str());
return this->mapKeyValues[key].integerValue; return this->mapKeyValues[key].integerValue;
} }
...@@ -175,9 +175,9 @@ namespace RTC ...@@ -175,9 +175,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapKeyValues.find(key) != this->mapKeyValues.end(), this->mapKeyValues.find(key) != this->mapKeyValues.end(),
"key does not exist [key:%s]", "key does not exist [key:%s]",
key.c_str()); key.c_str());
return this->mapKeyValues[key].doubleValue; return this->mapKeyValues[key].doubleValue;
} }
...@@ -187,9 +187,9 @@ namespace RTC ...@@ -187,9 +187,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapKeyValues.find(key) != this->mapKeyValues.end(), this->mapKeyValues.find(key) != this->mapKeyValues.end(),
"key does not exist [key:%s]", "key does not exist [key:%s]",
key.c_str()); key.c_str());
return this->mapKeyValues[key].stringValue; return this->mapKeyValues[key].stringValue;
} }
...@@ -199,9 +199,9 @@ namespace RTC ...@@ -199,9 +199,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->mapKeyValues.find(key) != this->mapKeyValues.end(), this->mapKeyValues.find(key) != this->mapKeyValues.end(),
"key does not exist [key:%s]", "key does not exist [key:%s]",
key.c_str()); key.c_str());
return this->mapKeyValues[key].arrayOfIntegers; return this->mapKeyValues[key].arrayOfIntegers;
} }
......
...@@ -91,9 +91,9 @@ namespace RTC ...@@ -91,9 +91,9 @@ namespace RTC
} }
RtpParameters::RtpParameters(const RtpParameters* rtpParameters) RtpParameters::RtpParameters(const RtpParameters* rtpParameters)
: muxId(rtpParameters->muxId), codecs(rtpParameters->codecs), : muxId(rtpParameters->muxId), codecs(rtpParameters->codecs),
encodings(rtpParameters->encodings), headerExtensions(rtpParameters->headerExtensions), encodings(rtpParameters->encodings), headerExtensions(rtpParameters->headerExtensions),
rtcp(rtpParameters->rtcp), hasRtcp(rtpParameters->hasRtcp) rtcp(rtpParameters->rtcp), hasRtcp(rtpParameters->hasRtcp)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -184,8 +184,7 @@ namespace RTC ...@@ -184,8 +184,7 @@ namespace RTC
{ {
auto& codec = *it; auto& codec = *it;
if (codec.mime.IsFeatureCodec() && if (codec.mime.IsFeatureCodec() && codec.parameters.GetInteger(associatedPayloadType) == payloadType)
codec.parameters.GetInteger(associatedPayloadType) == payloadType)
{ {
return codec; return codec;
} }
......
...@@ -198,8 +198,9 @@ namespace RTC ...@@ -198,8 +198,9 @@ namespace RTC
{ {
auto& encoding = *it; auto& encoding = *it;
if ((encoding.ssrc == 0u) || (encoding.hasRtx && (encoding.rtx.ssrc == 0u)) || if (
(encoding.hasFec && (encoding.fec.ssrc == 0u))) (encoding.ssrc == 0u) || (encoding.hasRtx && (encoding.rtx.ssrc == 0u)) ||
(encoding.hasFec && (encoding.fec.ssrc == 0u)))
{ {
break; break;
} }
...@@ -221,7 +222,7 @@ namespace RTC ...@@ -221,7 +222,7 @@ namespace RTC
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes); RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes);
MS_THROW_ERROR( MS_THROW_ERROR(
"payloadType already exists in RTP listener [payloadType:%" PRIu8 "]", payloadType); "payloadType already exists in RTP listener [payloadType:%" PRIu8 "]", payloadType);
} }
} }
} }
...@@ -329,10 +330,10 @@ namespace RTC ...@@ -329,10 +330,10 @@ namespace RTC
} }
void RtpListener::RollbackProducer( void RtpListener::RollbackProducer(
RTC::Producer* producer, RTC::Producer* producer,
std::vector<uint32_t>& previousSsrcs, std::vector<uint32_t>& previousSsrcs,
std::string& previousMuxId, std::string& previousMuxId,
std::vector<uint8_t>& previousPayloadTypes) std::vector<uint8_t>& previousPayloadTypes)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -69,7 +69,7 @@ namespace RTC ...@@ -69,7 +69,7 @@ namespace RTC
if (len < (ptr - data) + 4 + extensionValueSize) if (len < (ptr - data) + 4 + extensionValueSize)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, "not enough space for the announced header extension value, packet discarded"); rtp, "not enough space for the announced header extension value, packet discarded");
return nullptr; return nullptr;
} }
...@@ -105,9 +105,9 @@ namespace RTC ...@@ -105,9 +105,9 @@ namespace RTC
if (payloadLength < static_cast<size_t>(payloadPadding)) if (payloadLength < static_cast<size_t>(payloadPadding))
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"number of padding octets is greater than available space for payload, packet " "number of padding octets is greater than available space for payload, packet "
"discarded"); "discarded");
return nullptr; return nullptr;
} }
...@@ -115,9 +115,9 @@ namespace RTC ...@@ -115,9 +115,9 @@ namespace RTC
} }
MS_ASSERT( MS_ASSERT(
len == sizeof(Header) + csrcListSize + (extensionHeader ? 4 + extensionValueSize : 0) + len == sizeof(Header) + csrcListSize + (extensionHeader ? 4 + extensionValueSize : 0) +
payloadLength + static_cast<size_t>(payloadPadding), payloadLength + static_cast<size_t>(payloadPadding),
"packet's computed size does not match received size"); "packet's computed size does not match received size");
auto packet = new RtpPacket(header, extensionHeader, payload, payloadLength, payloadPadding, len); auto packet = new RtpPacket(header, extensionHeader, payload, payloadLength, payloadPadding, len);
...@@ -130,14 +130,14 @@ namespace RTC ...@@ -130,14 +130,14 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RtpPacket::RtpPacket( RtpPacket::RtpPacket(
Header* header, Header* header,
ExtensionHeader* extensionHeader, ExtensionHeader* extensionHeader,
const uint8_t* payload, const uint8_t* payload,
size_t payloadLength, size_t payloadLength,
uint8_t payloadPadding, uint8_t payloadPadding,
size_t size) size_t size)
: header(header), extensionHeader(extensionHeader), payload(const_cast<uint8_t*>(payload)), : header(header), extensionHeader(extensionHeader), payload(const_cast<uint8_t*>(payload)),
payloadLength(payloadLength), payloadPadding(payloadPadding), size(size) payloadLength(payloadLength), payloadPadding(payloadPadding), size(size)
{ {
MS_TRACE(); MS_TRACE();
...@@ -187,7 +187,7 @@ namespace RTC ...@@ -187,7 +187,7 @@ namespace RTC
} }
std::copy( std::copy(
extIds.begin(), extIds.end() - 1, std::ostream_iterator<std::string>(extIdsStream, ",")); extIds.begin(), extIds.end() - 1, std::ostream_iterator<std::string>(extIdsStream, ","));
extIdsStream << extIds.back(); extIdsStream << extIds.back();
MS_DUMP(" RFC5285 ext ids : %s", extIdsStream.str().c_str()); MS_DUMP(" RFC5285 ext ids : %s", extIdsStream.str().c_str());
...@@ -362,7 +362,7 @@ namespace RTC ...@@ -362,7 +362,7 @@ namespace RTC
// Create the new RtpPacket instance and return it. // Create the new RtpPacket instance and return it.
auto packet = new RtpPacket( auto packet = new RtpPacket(
header, extensionHeader, payload, this->payloadLength, this->payloadPadding, this->size); header, extensionHeader, payload, this->payloadLength, this->payloadPadding, this->size);
// Parse RFC 5285 extension header. // Parse RFC 5285 extension header.
packet->ParseExtensions(); packet->ParseExtensions();
...@@ -457,7 +457,7 @@ namespace RTC ...@@ -457,7 +457,7 @@ namespace RTC
if (ptr + 1 + len > extensionEnd) if (ptr + 1 + len > extensionEnd)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, "not enough space for the announced One-Byte header extension element value"); rtp, "not enough space for the announced One-Byte header extension element value");
break; break;
} }
...@@ -490,7 +490,7 @@ namespace RTC ...@@ -490,7 +490,7 @@ namespace RTC
if (ptr + len > extensionEnd) if (ptr + len > extensionEnd)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, "not enough space for the announced Two-Bytes header extension element value"); rtp, "not enough space for the announced Two-Bytes header extension element value");
break; break;
} }
......
...@@ -48,10 +48,10 @@ namespace RTC ...@@ -48,10 +48,10 @@ namespace RTC
if (this->probation == 0u) if (this->probation == 0u)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
} }
return false; return false;
...@@ -59,7 +59,7 @@ namespace RTC ...@@ -59,7 +59,7 @@ namespace RTC
// Set the extended sequence number into the packet. // Set the extended sequence number into the packet.
packet->SetExtendedSequenceNumber( packet->SetExtendedSequenceNumber(
this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber())); this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber()));
// Update highest seen RTP timestamp. // Update highest seen RTP timestamp.
if (packet->GetTimestamp() > this->maxTimestamp) if (packet->GetTimestamp() > this->maxTimestamp)
...@@ -143,20 +143,20 @@ namespace RTC ...@@ -143,20 +143,20 @@ namespace RTC
* (i.e., pretend this was the first packet). * (i.e., pretend this was the first packet).
*/ */
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"too bad sequence number, re-syncing RTP [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "too bad sequence number, re-syncing RTP [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
InitSeq(seq); InitSeq(seq);
} }
else else
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
this->badSeq = (seq + 1) & (RtpSeqMod - 1); this->badSeq = (seq + 1) & (RtpSeqMod - 1);
......
...@@ -10,7 +10,7 @@ namespace RTC ...@@ -10,7 +10,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params) RtpStreamRecv::RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params)
: RtpStream::RtpStream(params), listener(listener) : RtpStream::RtpStream(params), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -69,12 +69,12 @@ namespace RTC ...@@ -69,12 +69,12 @@ namespace RTC
if (packet->GetPayloadType() != this->rtxPayloadType) if (packet->GetPayloadType() != this->rtxPayloadType)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring RTX packet with invalid payload type [ssrc: %" PRIu32 " seq: %" PRIu16 "ignoring RTX packet with invalid payload type [ssrc: %" PRIu32 " seq: %" PRIu16
" payload type: %" PRIu8 "]", " payload type: %" PRIu8 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetPayloadType()); packet->GetPayloadType());
return false; return false;
} }
...@@ -89,39 +89,38 @@ namespace RTC ...@@ -89,39 +89,38 @@ namespace RTC
if (packet->GetPayloadLength() < 2) if (packet->GetPayloadLength() < 2)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"ignoring empty RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 "ignoring empty RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 " payload type: %" PRIu8 "]",
" payload type: %" PRIu8 "]", packet->GetSsrc(),
packet->GetSsrc(), packet->GetSequenceNumber(),
packet->GetSequenceNumber(), packet->GetPayloadType());
packet->GetPayloadType());
return false; return false;
} }
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring malformed RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 "ignoring malformed RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 " payload type: %" PRIu8
" payload type: %" PRIu8 "]", "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetPayloadType()); packet->GetPayloadType());
return false; return false;
} }
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"received RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 "received RTX packet [ssrc: %" PRIu32 " seq: %" PRIu16 "] recovering original [ssrc: %" PRIu32
"] recovering original [ssrc: %" PRIu32 " seq: %" PRIu16 "]", " seq: %" PRIu16 "]",
this->rtxSsrc, this->rtxSsrc,
rtxSeq, rtxSeq,
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
// Set the extended sequence number into the packet. // Set the extended sequence number into the packet.
packet->SetExtendedSequenceNumber( packet->SetExtendedSequenceNumber(
this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber())); this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber()));
// Pass the packet to the NackGenerator. // Pass the packet to the NackGenerator.
if (this->params.useNack && this->nackGenerator) if (this->params.useNack && this->nackGenerator)
...@@ -216,7 +215,7 @@ namespace RTC ...@@ -216,7 +215,7 @@ namespace RTC
return; return;
auto transit = auto transit =
static_cast<int>(DepLibUV::GetTime() - (rtpTimestamp * 1000 / this->params.clockRate)); static_cast<int>(DepLibUV::GetTime() - (rtpTimestamp * 1000 / this->params.clockRate));
int d = transit - this->transit; int d = transit - this->transit;
this->transit = transit; this->transit = transit;
...@@ -249,11 +248,11 @@ namespace RTC ...@@ -249,11 +248,11 @@ namespace RTC
MS_ASSERT(this->params.useNack, "NACK required but not supported"); MS_ASSERT(this->params.useNack, "NACK required but not supported");
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"triggering NACK [ssrc:%" PRIu32 ", first seq:%" PRIu16 ", num packets:%zu]", "triggering NACK [ssrc:%" PRIu32 ", first seq:%" PRIu16 ", num packets:%zu]",
this->params.ssrc, this->params.ssrc,
seqNumbers[0], seqNumbers[0],
seqNumbers.size()); seqNumbers.size());
this->listener->OnNackRequired(this, seqNumbers); this->listener->OnNackRequired(this, seqNumbers);
} }
......
...@@ -18,7 +18,7 @@ namespace RTC ...@@ -18,7 +18,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize) RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize)
: RtpStream::RtpStream(params), storage(bufferSize) : RtpStream::RtpStream(params), storage(bufferSize)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -100,7 +100,7 @@ namespace RTC ...@@ -100,7 +100,7 @@ namespace RTC
// This method looks for the requested RTP packets and inserts them into the // This method looks for the requested RTP packets and inserts them into the
// given container (and set to null the next container position). // given container (and set to null the next container position).
void RtpStreamSend::RequestRtpRetransmission( void RtpStreamSend::RequestRtpRetransmission(
uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container) uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container)
{ {
MS_TRACE(); MS_TRACE();
...@@ -190,7 +190,7 @@ namespace RTC ...@@ -190,7 +190,7 @@ namespace RTC
{ {
auto currentPacket = (*bufferIt).packet; auto currentPacket = (*bufferIt).packet;
uint32_t diff = uint32_t diff =
(this->maxTimestamp - currentPacket->GetTimestamp()) * 1000 / this->params.clockRate; (this->maxTimestamp - currentPacket->GetTimestamp()) * 1000 / this->params.clockRate;
// Just provide the packet if no older than MaxRetransmissionAge ms. // Just provide the packet if no older than MaxRetransmissionAge ms.
if (diff > MaxRetransmissionAge) if (diff > MaxRetransmissionAge)
...@@ -198,12 +198,12 @@ namespace RTC ...@@ -198,12 +198,12 @@ namespace RTC
if (!tooOldPacketFound) if (!tooOldPacketFound)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring retransmission for too old packet " "ignoring retransmission for too old packet "
"[seq:%" PRIu16 ", max age:%" PRIu32 "ms, packet age:%" PRIu32 "ms]", "[seq:%" PRIu16 ", max age:%" PRIu32 "ms, packet age:%" PRIu32 "ms]",
currentPacket->GetSequenceNumber(), currentPacket->GetSequenceNumber(),
MaxRetransmissionAge, MaxRetransmissionAge,
diff); diff);
tooOldPacketFound = true; tooOldPacketFound = true;
} }
...@@ -217,11 +217,11 @@ namespace RTC ...@@ -217,11 +217,11 @@ namespace RTC
if ((resentAtTime != 0u) && now - resentAtTime < static_cast<uint64_t>(rtt)) if ((resentAtTime != 0u) && now - resentAtTime < static_cast<uint64_t>(rtt))
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring retransmission for a packet already resent in the last RTT ms " "ignoring retransmission for a packet already resent in the last RTT ms "
"[seq:%" PRIu16 ", rtt:%" PRIu32 "]", "[seq:%" PRIu16 ", rtt:%" PRIu32 "]",
currentPacket->GetSequenceNumber(), currentPacket->GetSequenceNumber(),
rtt); rtt);
break; break;
} }
...@@ -263,22 +263,22 @@ namespace RTC ...@@ -263,22 +263,22 @@ namespace RTC
if (!firstPacketSent || origBitmask != sentBitmask) if (!firstPacketSent || origBitmask != sentBitmask)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"could not resend all packets [seq:%" PRIu16 "could not resend all packets [seq:%" PRIu16
", first:%s, " ", first:%s, "
"bitmask:" MS_UINT16_TO_BINARY_PATTERN ", sent bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", "bitmask:" MS_UINT16_TO_BINARY_PATTERN ", sent bitmask:" MS_UINT16_TO_BINARY_PATTERN "]",
seq, seq,
firstPacketSent ? "yes" : "no", firstPacketSent ? "yes" : "no",
MS_UINT16_TO_BINARY(origBitmask), MS_UINT16_TO_BINARY(origBitmask),
MS_UINT16_TO_BINARY(sentBitmask)); MS_UINT16_TO_BINARY(sentBitmask));
} }
else else
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"all packets resent [seq:%" PRIu16 ", bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", "all packets resent [seq:%" PRIu16 ", bitmask:" MS_UINT16_TO_BINARY_PATTERN "]",
seq, seq,
MS_UINT16_TO_BINARY(origBitmask)); MS_UINT16_TO_BINARY(origBitmask));
} }
// Set the next container element to null. // Set the next container element to null.
...@@ -350,11 +350,11 @@ namespace RTC ...@@ -350,11 +350,11 @@ namespace RTC
if (packet->GetSize() > RTC::MtuSize) if (packet->GetSize() > RTC::MtuSize)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"packet too big [ssrc:%" PRIu32 ", seq:%" PRIu16 ", size:%zu]", "packet too big [ssrc:%" PRIu32 ", seq:%" PRIu16 ", size:%zu]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
packet->GetSize()); packet->GetSize());
return; return;
} }
...@@ -404,10 +404,10 @@ namespace RTC ...@@ -404,10 +404,10 @@ namespace RTC
if (bufferItReverse == this->buffer.rend()) if (bufferItReverse == this->buffer.rend())
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtp, rtp,
"ignoring packet older than anything in the buffer [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "ignoring packet older than anything in the buffer [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber()); packet->GetSequenceNumber());
return; return;
} }
......
...@@ -75,8 +75,8 @@ namespace RTC ...@@ -75,8 +75,8 @@ namespace RTC
} }
MS_ASSERT( MS_ASSERT(
(int)keyLen == policy.rtp.cipher_key_len, (int)keyLen == policy.rtp.cipher_key_len,
"given keyLen does not match policy.rtp.cipher_keyLen"); "given keyLen does not match policy.rtp.cipher_keyLen");
switch (type) switch (type)
{ {
......
...@@ -51,9 +51,9 @@ namespace RTC ...@@ -51,9 +51,9 @@ namespace RTC
if ((static_cast<size_t>(msgLength) != len - 20) || ((msgLength & 0x03) != 0)) if ((static_cast<size_t>(msgLength) != len - 20) || ((msgLength & 0x03) != 0))
{ {
MS_WARN_TAG( MS_WARN_TAG(
ice, ice,
"length field + 20 does not match total size (or it is not multiple of 4 bytes), " "length field + 20 does not match total size (or it is not multiple of 4 bytes), "
"message discarded"); "message discarded");
return nullptr; return nullptr;
} }
...@@ -66,7 +66,7 @@ namespace RTC ...@@ -66,7 +66,7 @@ namespace RTC
// Create a new StunMessage (data + 8 points to the received TransactionID field). // Create a new StunMessage (data + 8 points to the received TransactionID field).
auto msg = new StunMessage( auto msg = new StunMessage(
static_cast<Class>(msgClass), static_cast<Method>(msgMethod), data + 8, data, len); static_cast<Class>(msgClass), static_cast<Method>(msgMethod), data + 8, data, len);
/* /*
STUN Attributes STUN Attributes
...@@ -125,9 +125,9 @@ namespace RTC ...@@ -125,9 +125,9 @@ namespace RTC
if (hasMessageIntegrity && attrType != Attribute::FINGERPRINT) if (hasMessageIntegrity && attrType != Attribute::FINGERPRINT)
{ {
MS_WARN_TAG( MS_WARN_TAG(
ice, ice,
"attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, " "attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, "
"message discarded"); "message discarded");
delete msg; delete msg;
return nullptr; return nullptr;
...@@ -140,7 +140,7 @@ namespace RTC ...@@ -140,7 +140,7 @@ namespace RTC
case Attribute::USERNAME: case Attribute::USERNAME:
{ {
msg->SetUsername( msg->SetUsername(
reinterpret_cast<const char*>(attrValuePos), static_cast<size_t>(attrLength)); reinterpret_cast<const char*>(attrValuePos), static_cast<size_t>(attrLength));
break; break;
} }
...@@ -199,7 +199,7 @@ namespace RTC ...@@ -199,7 +199,7 @@ namespace RTC
// Set next attribute position. // Set next attribute position.
pos = pos =
static_cast<size_t>(Utils::Byte::PadTo4Bytes(static_cast<uint16_t>(pos + 4 + attrLength))); static_cast<size_t>(Utils::Byte::PadTo4Bytes(static_cast<uint16_t>(pos + 4 + attrLength)));
} }
// Ensure current position matches the total length. // Ensure current position matches the total length.
...@@ -222,9 +222,9 @@ namespace RTC ...@@ -222,9 +222,9 @@ namespace RTC
if (fingerprint != computedFingerprint) if (fingerprint != computedFingerprint)
{ {
MS_WARN_TAG( MS_WARN_TAG(
ice, ice,
"computed FINGERPRINT value does not match the value in the message, " "computed FINGERPRINT value does not match the value in the message, "
"message discarded"); "message discarded");
delete msg; delete msg;
return nullptr; return nullptr;
...@@ -237,9 +237,9 @@ namespace RTC ...@@ -237,9 +237,9 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
StunMessage::StunMessage( StunMessage::StunMessage(
Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size) Class klass, Method method, const uint8_t* transactionId, const uint8_t* data, size_t size)
: klass(klass), method(method), transactionId(transactionId), : klass(klass), method(method), transactionId(transactionId), data(const_cast<uint8_t*>(data)),
data(const_cast<uint8_t*>(data)), size(size) size(size)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -330,7 +330,7 @@ namespace RTC ...@@ -330,7 +330,7 @@ namespace RTC
} }
StunMessage::Authentication StunMessage::CheckAuthentication( StunMessage::Authentication StunMessage::CheckAuthentication(
const std::string& localUsername, const std::string& localPassword) const std::string& localUsername, const std::string& localPassword)
{ {
MS_TRACE(); MS_TRACE();
...@@ -346,9 +346,9 @@ namespace RTC ...@@ -346,9 +346,9 @@ namespace RTC
// Check that USERNAME attribute begins with our local username plus ":". // Check that USERNAME attribute begins with our local username plus ":".
size_t localUsernameLen = localUsername.length(); size_t localUsernameLen = localUsername.length();
if (this->username.length() <= localUsernameLen || if (
this->username.at(localUsernameLen) != ':' || this->username.length() <= localUsernameLen || this->username.at(localUsernameLen) != ':' ||
(this->username.compare(0, localUsernameLen, localUsername) != 0)) (this->username.compare(0, localUsernameLen, localUsername) != 0))
return Authentication::UNAUTHORIZED; return Authentication::UNAUTHORIZED;
break; break;
...@@ -372,7 +372,7 @@ namespace RTC ...@@ -372,7 +372,7 @@ namespace RTC
// Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules. // Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules.
const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHmacShA1( const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHmacShA1(
localPassword, this->data, (this->messageIntegrity - 4) - this->data); localPassword, this->data, (this->messageIntegrity - 4) - this->data);
Authentication result; Authentication result;
...@@ -394,8 +394,8 @@ namespace RTC ...@@ -394,8 +394,8 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->klass == Class::REQUEST, this->klass == Class::REQUEST,
"attempt to create a success response for a non Request STUN message"); "attempt to create a success response for a non Request STUN message");
return new StunMessage(Class::SUCCESS_RESPONSE, this->method, this->transactionId, nullptr, 0); return new StunMessage(Class::SUCCESS_RESPONSE, this->method, this->transactionId, nullptr, 0);
} }
...@@ -405,11 +405,11 @@ namespace RTC ...@@ -405,11 +405,11 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_ASSERT( MS_ASSERT(
this->klass == Class::REQUEST, this->klass == Class::REQUEST,
"attempt to create an error response for a non Request STUN message"); "attempt to create an error response for a non Request STUN message");
auto response = auto response =
new StunMessage(Class::ERROR_RESPONSE, this->method, this->transactionId, nullptr, 0); new StunMessage(Class::ERROR_RESPONSE, this->method, this->transactionId, nullptr, 0);
response->SetErrorCode(errorCode); response->SetErrorCode(errorCode);
...@@ -437,8 +437,8 @@ namespace RTC ...@@ -437,8 +437,8 @@ namespace RTC
uint16_t usernamePaddedLen{ 0 }; uint16_t usernamePaddedLen{ 0 };
uint16_t xorMappedAddressPaddedLen{ 0 }; uint16_t xorMappedAddressPaddedLen{ 0 };
bool addXorMappedAddress = bool addXorMappedAddress =
((this->xorMappedAddress != nullptr) && this->method == StunMessage::Method::BINDING && ((this->xorMappedAddress != nullptr) && this->method == StunMessage::Method::BINDING &&
this->klass == Class::SUCCESS_RESPONSE); this->klass == Class::SUCCESS_RESPONSE);
bool addErrorCode = ((this->errorCode != 0u) && this->klass == Class::ERROR_RESPONSE); bool addErrorCode = ((this->errorCode != 0u) && this->klass == Class::ERROR_RESPONSE);
bool addMessageIntegrity = (this->klass != Class::ERROR_RESPONSE && !this->password.empty()); bool addMessageIntegrity = (this->klass != Class::ERROR_RESPONSE && !this->password.empty());
bool addFingerprint{ true }; // Do always. bool addFingerprint{ true }; // Do always.
...@@ -591,16 +591,16 @@ namespace RTC ...@@ -591,16 +591,16 @@ namespace RTC
attrValue[1] = 0x01; attrValue[1] = 0x01;
// Set port and XOR it. // Set port and XOR it.
std::memcpy( std::memcpy(
attrValue + 2, attrValue + 2,
&(reinterpret_cast<const sockaddr_in*>(this->xorMappedAddress))->sin_port, &(reinterpret_cast<const sockaddr_in*>(this->xorMappedAddress))->sin_port,
2); 2);
attrValue[2] ^= StunMessage::magicCookie[0]; attrValue[2] ^= StunMessage::magicCookie[0];
attrValue[3] ^= StunMessage::magicCookie[1]; attrValue[3] ^= StunMessage::magicCookie[1];
// Set address and XOR it. // Set address and XOR it.
std::memcpy( std::memcpy(
attrValue + 4, attrValue + 4,
&(reinterpret_cast<const sockaddr_in*>(this->xorMappedAddress))->sin_addr.s_addr, &(reinterpret_cast<const sockaddr_in*>(this->xorMappedAddress))->sin_addr.s_addr,
4); 4);
attrValue[4] ^= StunMessage::magicCookie[0]; attrValue[4] ^= StunMessage::magicCookie[0];
attrValue[5] ^= StunMessage::magicCookie[1]; attrValue[5] ^= StunMessage::magicCookie[1];
attrValue[6] ^= StunMessage::magicCookie[2]; attrValue[6] ^= StunMessage::magicCookie[2];
...@@ -618,16 +618,16 @@ namespace RTC ...@@ -618,16 +618,16 @@ namespace RTC
attrValue[1] = 0x02; attrValue[1] = 0x02;
// Set port and XOR it. // Set port and XOR it.
std::memcpy( std::memcpy(
attrValue + 2, attrValue + 2,
&(reinterpret_cast<const sockaddr_in6*>(this->xorMappedAddress))->sin6_port, &(reinterpret_cast<const sockaddr_in6*>(this->xorMappedAddress))->sin6_port,
2); 2);
attrValue[2] ^= StunMessage::magicCookie[0]; attrValue[2] ^= StunMessage::magicCookie[0];
attrValue[3] ^= StunMessage::magicCookie[1]; attrValue[3] ^= StunMessage::magicCookie[1];
// Set address and XOR it. // Set address and XOR it.
std::memcpy( std::memcpy(
attrValue + 4, attrValue + 4,
&(reinterpret_cast<const sockaddr_in6*>(this->xorMappedAddress))->sin6_addr.s6_addr, &(reinterpret_cast<const sockaddr_in6*>(this->xorMappedAddress))->sin6_addr.s6_addr,
16); 16);
attrValue[4] ^= StunMessage::magicCookie[0]; attrValue[4] ^= StunMessage::magicCookie[0];
attrValue[5] ^= StunMessage::magicCookie[1]; attrValue[5] ^= StunMessage::magicCookie[1];
attrValue[6] ^= StunMessage::magicCookie[2]; attrValue[6] ^= StunMessage::magicCookie[2];
...@@ -676,7 +676,7 @@ namespace RTC ...@@ -676,7 +676,7 @@ namespace RTC
// Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules. // Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules.
const uint8_t* computedMessageIntegrity = const uint8_t* computedMessageIntegrity =
Utils::Crypto::GetHmacShA1(this->password, buffer, pos); Utils::Crypto::GetHmacShA1(this->password, buffer, pos);
Utils::Byte::Set2Bytes(buffer, pos, static_cast<uint16_t>(Attribute::MESSAGE_INTEGRITY)); Utils::Byte::Set2Bytes(buffer, pos, static_cast<uint16_t>(Attribute::MESSAGE_INTEGRITY));
Utils::Byte::Set2Bytes(buffer, pos + 2, 20); Utils::Byte::Set2Bytes(buffer, pos + 2, 20);
......
...@@ -11,7 +11,7 @@ namespace RTC ...@@ -11,7 +11,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
TcpConnection::TcpConnection(Listener* listener, size_t bufferSize) TcpConnection::TcpConnection(Listener* listener, size_t bufferSize)
: ::TcpConnection::TcpConnection(bufferSize), listener(listener) : ::TcpConnection::TcpConnection(bufferSize), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -21,11 +21,11 @@ namespace RTC ...@@ -21,11 +21,11 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV( MS_DEBUG_DEV(
"data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", "data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
GetLocalIP().c_str(), GetLocalIP().c_str(),
GetLocalPort(), GetLocalPort(),
GetPeerIP().c_str(), GetPeerIP().c_str(),
GetPeerPort()); GetPeerPort());
/* /*
* Framing RFC 4571 * Framing RFC 4571
...@@ -105,11 +105,11 @@ namespace RTC ...@@ -105,11 +105,11 @@ namespace RTC
if (this->frameStart != 0) if (this->frameStart != 0)
{ {
MS_DEBUG_DEV( MS_DEBUG_DEV(
"no more space in the buffer, moving parsed bytes to the beginning of " "no more space in the buffer, moving parsed bytes to the beginning of "
"the buffer and wait for more data"); "the buffer and wait for more data");
std::memmove( std::memmove(
this->buffer, this->buffer + this->frameStart, this->bufferSize - this->frameStart); this->buffer, this->buffer + this->frameStart, this->bufferSize - this->frameStart);
this->bufferDataLen = this->bufferSize - this->frameStart; this->bufferDataLen = this->bufferSize - this->frameStart;
this->frameStart = 0; this->frameStart = 0;
} }
...@@ -118,8 +118,8 @@ namespace RTC ...@@ -118,8 +118,8 @@ namespace RTC
else else
{ {
MS_WARN_DEV( MS_WARN_DEV(
"no more space in the buffer for the unfinished frame being parsed, closing the " "no more space in the buffer for the unfinished frame being parsed, closing the "
"connection"); "connection");
// Close the socket. // Close the socket.
Destroy(); Destroy();
......
...@@ -43,9 +43,9 @@ namespace RTC ...@@ -43,9 +43,9 @@ namespace RTC
if (!Settings::configuration.rtcIPv4.empty()) if (!Settings::configuration.rtcIPv4.empty())
{ {
err = uv_ip4_addr( err = uv_ip4_addr(
Settings::configuration.rtcIPv4.c_str(), Settings::configuration.rtcIPv4.c_str(),
0, 0,
reinterpret_cast<struct sockaddr_in*>(&RTC::TcpServer::sockaddrStorageIPv4)); reinterpret_cast<struct sockaddr_in*>(&RTC::TcpServer::sockaddrStorageIPv4));
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err));
...@@ -54,9 +54,9 @@ namespace RTC ...@@ -54,9 +54,9 @@ namespace RTC
if (!Settings::configuration.rtcIPv6.empty()) if (!Settings::configuration.rtcIPv6.empty())
{ {
err = uv_ip6_addr( err = uv_ip6_addr(
Settings::configuration.rtcIPv6.c_str(), Settings::configuration.rtcIPv6.c_str(),
0, 0,
reinterpret_cast<struct sockaddr_in6*>(&RTC::TcpServer::sockaddrStorageIPv6)); reinterpret_cast<struct sockaddr_in6*>(&RTC::TcpServer::sockaddrStorageIPv6));
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err));
...@@ -119,8 +119,7 @@ namespace RTC ...@@ -119,8 +119,7 @@ namespace RTC
// Choose a random first port to start from. // Choose a random first port to start from.
initialPort = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt( initialPort = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt(
static_cast<uint32_t>(RTC::TcpServer::minPort), static_cast<uint32_t>(RTC::TcpServer::minPort), static_cast<uint32_t>(RTC::TcpServer::maxPort)));
static_cast<uint32_t>(RTC::TcpServer::maxPort)));
iteratingPort = initialPort; iteratingPort = initialPort;
...@@ -140,9 +139,7 @@ namespace RTC ...@@ -140,9 +139,7 @@ namespace RTC
if (!(*availablePorts)[iteratingPort]) if (!(*availablePorts)[iteratingPort])
{ {
MS_DEBUG_DEV( MS_DEBUG_DEV(
"port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", "port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iteratingPort, attempt);
iteratingPort,
attempt);
// If we have tried all the ports in the range raise an error. // If we have tried all the ports in the range raise an error.
if (iteratingPort == initialPort) if (iteratingPort == initialPort)
...@@ -181,10 +178,10 @@ namespace RTC ...@@ -181,10 +178,10 @@ namespace RTC
if (err != 0) if (err != 0)
{ {
MS_WARN_DEV( MS_WARN_DEV(
"uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", "uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s",
attempt, attempt,
iteratingPort, iteratingPort,
uv_strerror(err)); uv_strerror(err));
uv_close(reinterpret_cast<uv_handle_t*>(uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -195,7 +192,7 @@ namespace RTC ...@@ -195,7 +192,7 @@ namespace RTC
// If bind() fails for more that MaxBindAttempts then raise an error. // If bind() fails for more that MaxBindAttempts then raise an error.
if (bindAttempt > MaxBindAttempts) if (bindAttempt > MaxBindAttempts)
MS_THROW_ERROR( MS_THROW_ERROR(
"uv_tcp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp); "uv_tcp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp);
// If we have tried all the ports in the range raise an error. // If we have tried all the ports in the range raise an error.
if (iteratingPort == initialPort) if (iteratingPort == initialPort)
...@@ -208,10 +205,7 @@ namespace RTC ...@@ -208,10 +205,7 @@ namespace RTC
(*availablePorts)[iteratingPort] = false; (*availablePorts)[iteratingPort] = false;
MS_DEBUG_DEV( MS_DEBUG_DEV(
"bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", "bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", listenIp, iteratingPort, attempt);
listenIp,
iteratingPort,
attempt);
return uvHandle; return uvHandle;
}; };
...@@ -220,11 +214,11 @@ namespace RTC ...@@ -220,11 +214,11 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
TcpServer::TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int addressFamily) TcpServer::TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, int addressFamily)
: // Provide the parent class constructor with a UDP uv handle. : // Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available // NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports. // or there are no available ports.
::TcpServer::TcpServer(GetRandomPort(addressFamily), 256), listener(listener), ::TcpServer::TcpServer(GetRandomPort(addressFamily), 256), listener(listener),
connListener(connListener) connListener(connListener)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -256,7 +250,7 @@ namespace RTC ...@@ -256,7 +250,7 @@ namespace RTC
if (!IsClosing()) if (!IsClosing())
{ {
this->listener->OnRtcTcpConnectionClosed( this->listener->OnRtcTcpConnectionClosed(
this, dynamic_cast<RTC::TcpConnection*>(connection), isClosedByPeer); this, dynamic_cast<RTC::TcpConnection*>(connection), isClosedByPeer);
} }
} }
......
...@@ -58,11 +58,11 @@ namespace RTC ...@@ -58,11 +58,11 @@ namespace RTC
MS_DUMP("<TransportTuple>"); MS_DUMP("<TransportTuple>");
MS_DUMP( MS_DUMP(
" [UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", " [UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
this->udpSocket->GetLocalIP().c_str(), this->udpSocket->GetLocalIP().c_str(),
this->udpSocket->GetLocalPort(), this->udpSocket->GetLocalPort(),
remoteIp.c_str(), remoteIp.c_str(),
remotePort); remotePort);
MS_DUMP("</TransportTuple>"); MS_DUMP("</TransportTuple>");
break; break;
} }
...@@ -71,11 +71,11 @@ namespace RTC ...@@ -71,11 +71,11 @@ namespace RTC
{ {
MS_DUMP("<TransportTuple>"); MS_DUMP("<TransportTuple>");
MS_DUMP( MS_DUMP(
" [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", " [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
this->tcpConnection->GetLocalIP().c_str(), this->tcpConnection->GetLocalIP().c_str(),
this->tcpConnection->GetLocalPort(), this->tcpConnection->GetLocalPort(),
this->tcpConnection->GetPeerIP().c_str(), this->tcpConnection->GetPeerIP().c_str(),
this->tcpConnection->GetPeerPort()); this->tcpConnection->GetPeerPort());
MS_DUMP("</TransportTuple>"); MS_DUMP("</TransportTuple>");
break; break;
} }
......
...@@ -42,9 +42,9 @@ namespace RTC ...@@ -42,9 +42,9 @@ namespace RTC
if (Settings::configuration.hasIPv4) if (Settings::configuration.hasIPv4)
{ {
err = uv_ip4_addr( err = uv_ip4_addr(
Settings::configuration.rtcIPv4.c_str(), Settings::configuration.rtcIPv4.c_str(),
0, 0,
reinterpret_cast<struct sockaddr_in*>(&RTC::UdpSocket::sockaddrStorageIPv4)); reinterpret_cast<struct sockaddr_in*>(&RTC::UdpSocket::sockaddrStorageIPv4));
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_ipv4_addr() failed: %s", uv_strerror(err));
...@@ -53,9 +53,9 @@ namespace RTC ...@@ -53,9 +53,9 @@ namespace RTC
if (Settings::configuration.hasIPv6) if (Settings::configuration.hasIPv6)
{ {
err = uv_ip6_addr( err = uv_ip6_addr(
Settings::configuration.rtcIPv6.c_str(), Settings::configuration.rtcIPv6.c_str(),
0, 0,
reinterpret_cast<struct sockaddr_in6*>(&RTC::UdpSocket::sockaddrStorageIPv6)); reinterpret_cast<struct sockaddr_in6*>(&RTC::UdpSocket::sockaddrStorageIPv6));
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_ipv6_addr() failed: %s", uv_strerror(err));
...@@ -118,8 +118,7 @@ namespace RTC ...@@ -118,8 +118,7 @@ namespace RTC
// Choose a random port to start from. // Choose a random port to start from.
initialPort = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt( initialPort = static_cast<uint16_t>(Utils::Crypto::GetRandomUInt(
static_cast<uint32_t>(RTC::UdpSocket::minPort), static_cast<uint32_t>(RTC::UdpSocket::minPort), static_cast<uint32_t>(RTC::UdpSocket::maxPort)));
static_cast<uint32_t>(RTC::UdpSocket::maxPort)));
iteratingPort = initialPort; iteratingPort = initialPort;
...@@ -139,9 +138,7 @@ namespace RTC ...@@ -139,9 +138,7 @@ namespace RTC
if (!(*availablePorts)[iteratingPort]) if (!(*availablePorts)[iteratingPort])
{ {
MS_DEBUG_DEV( MS_DEBUG_DEV(
"port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", "port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iteratingPort, attempt);
iteratingPort,
attempt);
// If we have tried all the ports in the range raise an error. // If we have tried all the ports in the range raise an error.
if (iteratingPort == initialPort) if (iteratingPort == initialPort)
...@@ -180,10 +177,10 @@ namespace RTC ...@@ -180,10 +177,10 @@ namespace RTC
if (err != 0) if (err != 0)
{ {
MS_WARN_DEV( MS_WARN_DEV(
"uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", "uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s",
attempt, attempt,
iteratingPort, iteratingPort,
uv_strerror(err)); uv_strerror(err));
uv_close(reinterpret_cast<uv_handle_t*>(uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -194,7 +191,7 @@ namespace RTC ...@@ -194,7 +191,7 @@ namespace RTC
// If bind() fails for more that MaxBindAttempts then raise an error. // If bind() fails for more that MaxBindAttempts then raise an error.
if (bindAttempt > MaxBindAttempts) if (bindAttempt > MaxBindAttempts)
MS_THROW_ERROR( MS_THROW_ERROR(
"uv_udp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp); "uv_udp_bind() fails more than %" PRIu16 " times for IP '%s'", MaxBindAttempts, listenIp);
// If we have tried all the ports in the range raise an error. // If we have tried all the ports in the range raise an error.
if (iteratingPort == initialPort) if (iteratingPort == initialPort)
...@@ -207,10 +204,7 @@ namespace RTC ...@@ -207,10 +204,7 @@ namespace RTC
(*availablePorts)[iteratingPort] = false; (*availablePorts)[iteratingPort] = false;
MS_DEBUG_DEV( MS_DEBUG_DEV(
"bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", "bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", listenIp, iteratingPort, attempt);
listenIp,
iteratingPort,
attempt);
return uvHandle; return uvHandle;
}; };
...@@ -219,10 +213,10 @@ namespace RTC ...@@ -219,10 +213,10 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
UdpSocket::UdpSocket(Listener* listener, int addressFamily) UdpSocket::UdpSocket(Listener* listener, int addressFamily)
: // Provide the parent class constructor with a UDP uv handle. : // Provide the parent class constructor with a UDP uv handle.
// NOTE: This may throw a MediaSoupError exception if the address family is not available // NOTE: This may throw a MediaSoupError exception if the address family is not available
// or there are no available ports. // or there are no available ports.
::UdpSocket::UdpSocket(GetRandomPort(addressFamily)), listener(listener) ::UdpSocket::UdpSocket(GetRandomPort(addressFamily)), listener(listener)
{ {
MS_TRACE(); MS_TRACE();
} }
......
...@@ -204,16 +204,16 @@ void Settings::PrintConfiguration() ...@@ -204,16 +204,16 @@ void Settings::PrintConfiguration()
if (!logTags.empty()) if (!logTags.empty())
{ {
std::copy( std::copy(
logTags.begin(), logTags.end() - 1, std::ostream_iterator<std::string>(logTagsStream, ",")); logTags.begin(), logTags.end() - 1, std::ostream_iterator<std::string>(logTagsStream, ","));
logTagsStream << logTags.back(); logTagsStream << logTags.back();
} }
MS_DEBUG_TAG(info, "<configuration>"); MS_DEBUG_TAG(info, "<configuration>");
MS_DEBUG_TAG( MS_DEBUG_TAG(
info, info,
" logLevel : \"%s\"", " logLevel : \"%s\"",
Settings::logLevel2String[Settings::configuration.logLevel].c_str()); Settings::logLevel2String[Settings::configuration.logLevel].c_str());
MS_DEBUG_TAG(info, " logTags : \"%s\"", logTagsStream.str().c_str()); MS_DEBUG_TAG(info, " logTags : \"%s\"", logTagsStream.str().c_str());
if (Settings::configuration.hasIPv4) if (Settings::configuration.hasIPv4)
{ {
...@@ -234,7 +234,7 @@ void Settings::PrintConfiguration() ...@@ -234,7 +234,7 @@ void Settings::PrintConfiguration()
if (Settings::configuration.hasAnnouncedIPv4) if (Settings::configuration.hasAnnouncedIPv4)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
info, " rtcAnnouncedIPv4 : \"%s\"", Settings::configuration.rtcAnnouncedIPv4.c_str()); info, " rtcAnnouncedIPv4 : \"%s\"", Settings::configuration.rtcAnnouncedIPv4.c_str());
} }
else else
{ {
...@@ -243,7 +243,7 @@ void Settings::PrintConfiguration() ...@@ -243,7 +243,7 @@ void Settings::PrintConfiguration()
if (Settings::configuration.hasAnnouncedIPv6) if (Settings::configuration.hasAnnouncedIPv6)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
info, " rtcAnnouncedIPv6 : \"%s\"", Settings::configuration.rtcAnnouncedIPv6.c_str()); info, " rtcAnnouncedIPv6 : \"%s\"", Settings::configuration.rtcAnnouncedIPv6.c_str());
} }
else else
{ {
...@@ -254,9 +254,9 @@ void Settings::PrintConfiguration() ...@@ -254,9 +254,9 @@ void Settings::PrintConfiguration()
if (!Settings::configuration.dtlsCertificateFile.empty()) if (!Settings::configuration.dtlsCertificateFile.empty())
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
info, " dtlsCertificateFile : \"%s\"", Settings::configuration.dtlsCertificateFile.c_str()); info, " dtlsCertificateFile : \"%s\"", Settings::configuration.dtlsCertificateFile.c_str());
MS_DEBUG_TAG( MS_DEBUG_TAG(
info, " dtlsPrivateKeyFile : \"%s\"", Settings::configuration.dtlsPrivateKeyFile.c_str()); info, " dtlsPrivateKeyFile : \"%s\"", Settings::configuration.dtlsPrivateKeyFile.c_str());
} }
MS_DEBUG_TAG(info, "</configuration>"); MS_DEBUG_TAG(info, "</configuration>");
...@@ -344,7 +344,7 @@ void Settings::SetDefaultRtcIP(int requestedFamily) ...@@ -344,7 +344,7 @@ void Settings::SetDefaultRtcIP(int requestedFamily)
std::string ip; std::string ip;
Utils::IP::GetAddressInfo( Utils::IP::GetAddressInfo(
reinterpret_cast<struct sockaddr*>(&address.address.address4), &family, ip, &port); reinterpret_cast<struct sockaddr*>(&address.address.address4), &family, ip, &port);
if (family != requestedFamily) if (family != requestedFamily)
continue; continue;
...@@ -506,8 +506,9 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles() ...@@ -506,8 +506,9 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles()
{ {
MS_TRACE(); MS_TRACE();
if (Settings::configuration.dtlsCertificateFile.empty() || if (
Settings::configuration.dtlsPrivateKeyFile.empty()) Settings::configuration.dtlsCertificateFile.empty() ||
Settings::configuration.dtlsPrivateKeyFile.empty())
{ {
Settings::configuration.dtlsCertificateFile = ""; Settings::configuration.dtlsCertificateFile = "";
Settings::configuration.dtlsPrivateKeyFile = ""; Settings::configuration.dtlsPrivateKeyFile = "";
...@@ -610,7 +611,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno) ...@@ -610,7 +611,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno)
MS_ABORT("socket() failed: %s", std::strerror(errno)); MS_ABORT("socket() failed: %s", std::strerror(errno));
err = bind( err = bind(
bindSocket, reinterpret_cast<const struct sockaddr*>(&bindAddr), sizeof(struct sockaddr_in)); bindSocket, reinterpret_cast<const struct sockaddr*>(&bindAddr), sizeof(struct sockaddr_in));
break; break;
case AF_INET6: case AF_INET6:
...@@ -622,9 +623,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno) ...@@ -622,9 +623,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno)
MS_ABORT("socket() failed: %s", std::strerror(errno)); MS_ABORT("socket() failed: %s", std::strerror(errno));
err = bind( err = bind(
bindSocket, bindSocket, reinterpret_cast<const struct sockaddr*>(&bindAddr), sizeof(struct sockaddr_in6));
reinterpret_cast<const struct sockaddr*>(&bindAddr),
sizeof(struct sockaddr_in6));
break; break;
default: default:
......
...@@ -13,7 +13,7 @@ namespace Utils ...@@ -13,7 +13,7 @@ namespace Utils
HMAC_CTX Crypto::hmacSha1Ctx; HMAC_CTX Crypto::hmacSha1Ctx;
uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long. uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long.
const uint32_t Crypto::crc32Table[] = const uint32_t Crypto::crc32Table[] =
// clang-format off // clang-format off
{ {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
...@@ -84,20 +84,17 @@ namespace Utils ...@@ -84,20 +84,17 @@ namespace Utils
ret = HMAC_Update(&Crypto::hmacSha1Ctx, data, static_cast<int>(len)); ret = HMAC_Update(&Crypto::hmacSha1Ctx, data, static_cast<int>(len));
MS_ASSERT( MS_ASSERT(
ret == 1, ret == 1,
"OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes", "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes",
key.c_str(), key.c_str(),
len); len);
uint32_t resultLen; uint32_t resultLen;
ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t*)Crypto::hmacSha1Buffer, &resultLen); ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t*)Crypto::hmacSha1Buffer, &resultLen);
MS_ASSERT( MS_ASSERT(
ret == 1, ret == 1, "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes", key.c_str(), len);
"OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes",
key.c_str(),
len);
MS_ASSERT(resultLen == 20, "OpenSSL HMAC_Final() resultLen is %u instead of 20", resultLen); MS_ASSERT(resultLen == 20, "OpenSSL HMAC_Final() resultLen is %u instead of 20", resultLen);
return Crypto::hmacSha1Buffer; return Crypto::hmacSha1Buffer;
......
...@@ -65,7 +65,7 @@ TcpConnection::~TcpConnection() ...@@ -65,7 +65,7 @@ TcpConnection::~TcpConnection()
} }
void TcpConnection::Setup( void TcpConnection::Setup(
Listener* listener, struct sockaddr_storage* localAddr, const std::string& localIP, uint16_t localPort) Listener* listener, struct sockaddr_storage* localAddr, const std::string& localIP, uint16_t localPort)
{ {
MS_TRACE(); MS_TRACE();
...@@ -114,7 +114,7 @@ void TcpConnection::Destroy() ...@@ -114,7 +114,7 @@ void TcpConnection::Destroy()
auto req = new uv_shutdown_t; auto req = new uv_shutdown_t;
req->data = (void*)this; req->data = (void*)this;
err = uv_shutdown( err = uv_shutdown(
req, reinterpret_cast<uv_stream_t*>(this->uvHandle), static_cast<uv_shutdown_cb>(onShutdown)); req, reinterpret_cast<uv_stream_t*>(this->uvHandle), static_cast<uv_shutdown_cb>(onShutdown));
if (err != 0) if (err != 0)
MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err)); MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err));
} }
...@@ -129,12 +129,12 @@ void TcpConnection::Dump() const ...@@ -129,12 +129,12 @@ void TcpConnection::Dump() const
{ {
MS_DUMP("<TcpConnection>"); MS_DUMP("<TcpConnection>");
MS_DUMP( MS_DUMP(
" [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]", " [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]",
this->localIP.c_str(), this->localIP.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
this->peerIP.c_str(), this->peerIP.c_str(),
static_cast<uint16_t>(this->peerPort), static_cast<uint16_t>(this->peerPort),
(!this->isClosing) ? "open" : "closed"); (!this->isClosing) ? "open" : "closed");
MS_DUMP("</TcpConnection>"); MS_DUMP("</TcpConnection>");
} }
...@@ -148,9 +148,9 @@ void TcpConnection::Start() ...@@ -148,9 +148,9 @@ void TcpConnection::Start()
int err; int err;
err = uv_read_start( err = uv_read_start(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_alloc_cb>(onAlloc),
static_cast<uv_read_cb>(onRead)); static_cast<uv_read_cb>(onRead));
if (err != 0) if (err != 0)
MS_THROW_ERROR("uv_read_start() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_read_start() failed: %s", uv_strerror(err));
...@@ -215,11 +215,11 @@ void TcpConnection::Write(const uint8_t* data, size_t len) ...@@ -215,11 +215,11 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen); buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
err = uv_write( err = uv_write(
&writeData->req, &writeData->req,
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
&buffer, &buffer,
1, 1,
static_cast<uv_write_cb>(onWrite)); static_cast<uv_write_cb>(onWrite));
if (err != 0) if (err != 0)
MS_ABORT("uv_write() failed: %s", uv_strerror(err)); MS_ABORT("uv_write() failed: %s", uv_strerror(err));
} }
...@@ -280,27 +280,27 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data ...@@ -280,27 +280,27 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
if (static_cast<size_t>(written) < len1) if (static_cast<size_t>(written) < len1)
{ {
std::memcpy( std::memcpy(
writeData->store, data1 + static_cast<size_t>(written), len1 - static_cast<size_t>(written)); writeData->store, data1 + static_cast<size_t>(written), len1 - static_cast<size_t>(written));
std::memcpy(writeData->store + (len1 - static_cast<size_t>(written)), data2, len2); std::memcpy(writeData->store + (len1 - static_cast<size_t>(written)), data2, len2);
} }
// Otherwise just take the pending data in the second buffer. // Otherwise just take the pending data in the second buffer.
else else
{ {
std::memcpy( std::memcpy(
writeData->store, writeData->store,
data2 + (static_cast<size_t>(written) - len1), data2 + (static_cast<size_t>(written) - len1),
len2 - (static_cast<size_t>(written) - len1)); len2 - (static_cast<size_t>(written) - len1));
} }
writeData->req.data = (void*)writeData; writeData->req.data = (void*)writeData;
uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen); uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
err = uv_write( err = uv_write(
&writeData->req, &writeData->req,
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
&buffer, &buffer,
1, 1,
static_cast<uv_write_cb>(onWrite)); static_cast<uv_write_cb>(onWrite));
if (err != 0) if (err != 0)
MS_ABORT("uv_write() failed: %s", uv_strerror(err)); MS_ABORT("uv_write() failed: %s", uv_strerror(err));
} }
...@@ -322,7 +322,7 @@ bool TcpConnection::SetPeerAddress() ...@@ -322,7 +322,7 @@ bool TcpConnection::SetPeerAddress()
int family; int family;
Utils::IP::GetAddressInfo( Utils::IP::GetAddressInfo(
reinterpret_cast<const struct sockaddr*>(&this->peerAddr), &family, this->peerIP, &this->peerPort); reinterpret_cast<const struct sockaddr*>(&this->peerAddr), &family, this->peerIP, &this->peerPort);
return true; return true;
} }
......
...@@ -53,14 +53,14 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog) ...@@ -53,14 +53,14 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog)
{ {
case AF_INET: case AF_INET:
err = uv_ip4_addr( err = uv_ip4_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&bindAddr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&bindAddr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
break; break;
case AF_INET6: case AF_INET6:
err = uv_ip6_addr( err = uv_ip6_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&bindAddr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
// Don't also bind into IPv4 when listening in IPv6. // Don't also bind into IPv4 when listening in IPv6.
...@@ -81,9 +81,9 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog) ...@@ -81,9 +81,9 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog)
} }
err = uv_listen( err = uv_listen(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
backlog, backlog,
static_cast<uv_connection_cb>(onConnection)); static_cast<uv_connection_cb>(onConnection));
if (err != 0) if (err != 0)
{ {
uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -107,9 +107,9 @@ TcpServer::TcpServer(uv_tcp_t* uvHandle, int backlog) : uvHandle(uvHandle) ...@@ -107,9 +107,9 @@ TcpServer::TcpServer(uv_tcp_t* uvHandle, int backlog) : uvHandle(uvHandle)
this->uvHandle->data = (void*)this; this->uvHandle->data = (void*)this;
err = uv_listen( err = uv_listen(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
backlog, backlog,
static_cast<uv_connection_cb>(onConnection)); static_cast<uv_connection_cb>(onConnection));
if (err != 0) if (err != 0)
{ {
uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -161,11 +161,11 @@ void TcpServer::Dump() const ...@@ -161,11 +161,11 @@ void TcpServer::Dump() const
{ {
MS_DUMP("<TcpServer>"); MS_DUMP("<TcpServer>");
MS_DUMP( MS_DUMP(
" [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]", " [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]",
this->localIP.c_str(), this->localIP.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
(!this->isClosing) ? "open" : "closed", (!this->isClosing) ? "open" : "closed",
this->connections.size()); this->connections.size());
MS_DUMP("</TcpServer>"); MS_DUMP("</TcpServer>");
} }
...@@ -177,7 +177,7 @@ bool TcpServer::SetLocalAddress() ...@@ -177,7 +177,7 @@ bool TcpServer::SetLocalAddress()
int len = sizeof(this->localAddr); int len = sizeof(this->localAddr);
err = err =
uv_tcp_getsockname(this->uvHandle, reinterpret_cast<struct sockaddr*>(&this->localAddr), &len); uv_tcp_getsockname(this->uvHandle, reinterpret_cast<struct sockaddr*>(&this->localAddr), &len);
if (err != 0) if (err != 0)
{ {
MS_ERROR("uv_tcp_getsockname() failed: %s", uv_strerror(err)); MS_ERROR("uv_tcp_getsockname() failed: %s", uv_strerror(err));
...@@ -187,10 +187,10 @@ bool TcpServer::SetLocalAddress() ...@@ -187,10 +187,10 @@ bool TcpServer::SetLocalAddress()
int family; int family;
Utils::IP::GetAddressInfo( Utils::IP::GetAddressInfo(
reinterpret_cast<const struct sockaddr*>(&this->localAddr), reinterpret_cast<const struct sockaddr*>(&this->localAddr),
&family, &family,
this->localIP, this->localIP,
&this->localPort); &this->localPort);
return true; return true;
} }
...@@ -230,8 +230,8 @@ inline void TcpServer::OnUvConnection(int status) ...@@ -230,8 +230,8 @@ inline void TcpServer::OnUvConnection(int status)
// Accept the connection. // Accept the connection.
err = uv_accept( err = uv_accept(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
reinterpret_cast<uv_stream_t*>(connection->GetUvHandle())); reinterpret_cast<uv_stream_t*>(connection->GetUvHandle()));
if (err != 0) if (err != 0)
MS_ABORT("uv_accept() failed: %s", uv_strerror(err)); MS_ABORT("uv_accept() failed: %s", uv_strerror(err));
......
...@@ -20,7 +20,7 @@ inline static void onAlloc(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* ...@@ -20,7 +20,7 @@ inline static void onAlloc(uv_handle_t* handle, size_t suggestedSize, uv_buf_t*
} }
inline static void onRecv( inline static void onRecv(
uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags)
{ {
static_cast<UdpSocket*>(handle->data)->OnUvRecv(nread, buf, addr, flags); static_cast<UdpSocket*>(handle->data)->OnUvRecv(nread, buf, addr, flags);
} }
...@@ -77,14 +77,14 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port) ...@@ -77,14 +77,14 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port)
{ {
case AF_INET: case AF_INET:
err = uv_ip4_addr( err = uv_ip4_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&bindAddr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&bindAddr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
break; break;
case AF_INET6: case AF_INET6:
err = uv_ip6_addr( err = uv_ip6_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&bindAddr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
// Don't also bind into IPv4 when listening in IPv6. // Don't also bind into IPv4 when listening in IPv6.
...@@ -105,7 +105,7 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port) ...@@ -105,7 +105,7 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port)
} }
err = uv_udp_recv_start( err = uv_udp_recv_start(
this->uvHandle, static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_udp_recv_cb>(onRecv)); this->uvHandle, static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_udp_recv_cb>(onRecv));
if (err != 0) if (err != 0)
{ {
uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -129,7 +129,7 @@ UdpSocket::UdpSocket(uv_udp_t* uvHandle) : uvHandle(uvHandle) ...@@ -129,7 +129,7 @@ UdpSocket::UdpSocket(uv_udp_t* uvHandle) : uvHandle(uvHandle)
this->uvHandle->data = (void*)this; this->uvHandle->data = (void*)this;
err = uv_udp_recv_start( err = uv_udp_recv_start(
this->uvHandle, static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_udp_recv_cb>(onRecv)); this->uvHandle, static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_udp_recv_cb>(onRecv));
if (err != 0) if (err != 0)
{ {
uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -174,10 +174,10 @@ void UdpSocket::Dump() const ...@@ -174,10 +174,10 @@ void UdpSocket::Dump() const
{ {
MS_DUMP("<UdpSocket>"); MS_DUMP("<UdpSocket>");
MS_DUMP( MS_DUMP(
" [UDP, local:%s :%" PRIu16 ", status:%s]", " [UDP, local:%s :%" PRIu16 ", status:%s]",
this->localIP.c_str(), this->localIP.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
(!this->isClosing) ? "open" : "closed"); (!this->isClosing) ? "open" : "closed");
MS_DUMP("</UdpSocket>"); MS_DUMP("</UdpSocket>");
} }
...@@ -233,7 +233,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add ...@@ -233,7 +233,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
buffer = uv_buf_init(reinterpret_cast<char*>(sendData->store), len); buffer = uv_buf_init(reinterpret_cast<char*>(sendData->store), len);
err = uv_udp_send( err = uv_udp_send(
&sendData->req, this->uvHandle, &buffer, 1, addr, static_cast<uv_udp_send_cb>(onSend)); &sendData->req, this->uvHandle, &buffer, 1, addr, static_cast<uv_udp_send_cb>(onSend));
if (err != 0) if (err != 0)
{ {
// NOTE: uv_udp_send() returns error if a wrong INET family is given // NOTE: uv_udp_send() returns error if a wrong INET family is given
...@@ -265,14 +265,14 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const std::string& ip, uin ...@@ -265,14 +265,14 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const std::string& ip, uin
{ {
case AF_INET: case AF_INET:
err = uv_ip4_addr( err = uv_ip4_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&addr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in*>(&addr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv4_addr() failed: %s", uv_strerror(err));
break; break;
case AF_INET6: case AF_INET6:
err = uv_ip6_addr( err = uv_ip6_addr(
ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&addr)); ip.c_str(), static_cast<int>(port), reinterpret_cast<struct sockaddr_in6*>(&addr));
if (err != 0) if (err != 0)
MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err)); MS_ABORT("uv_ipv6_addr() failed: %s", uv_strerror(err));
break; break;
...@@ -294,7 +294,7 @@ bool UdpSocket::SetLocalAddress() ...@@ -294,7 +294,7 @@ bool UdpSocket::SetLocalAddress()
int len = sizeof(this->localAddr); int len = sizeof(this->localAddr);
err = err =
uv_udp_getsockname(this->uvHandle, reinterpret_cast<struct sockaddr*>(&this->localAddr), &len); uv_udp_getsockname(this->uvHandle, reinterpret_cast<struct sockaddr*>(&this->localAddr), &len);
if (err != 0) if (err != 0)
{ {
MS_ERROR("uv_udp_getsockname() failed: %s", uv_strerror(err)); MS_ERROR("uv_udp_getsockname() failed: %s", uv_strerror(err));
...@@ -304,10 +304,10 @@ bool UdpSocket::SetLocalAddress() ...@@ -304,10 +304,10 @@ bool UdpSocket::SetLocalAddress()
int family; int family;
Utils::IP::GetAddressInfo( Utils::IP::GetAddressInfo(
reinterpret_cast<const struct sockaddr*>(&this->localAddr), reinterpret_cast<const struct sockaddr*>(&this->localAddr),
&family, &family,
this->localIP, this->localIP,
&this->localPort); &this->localPort);
return true; return true;
} }
...@@ -323,7 +323,7 @@ inline void UdpSocket::OnUvRecvAlloc(size_t /*suggestedSize*/, uv_buf_t* buf) ...@@ -323,7 +323,7 @@ inline void UdpSocket::OnUvRecvAlloc(size_t /*suggestedSize*/, uv_buf_t* buf)
} }
inline void UdpSocket::OnUvRecv( inline void UdpSocket::OnUvRecv(
ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -83,9 +83,9 @@ UnixStreamSocket::UnixStreamSocket(int fd, size_t bufferSize) : bufferSize(buffe ...@@ -83,9 +83,9 @@ UnixStreamSocket::UnixStreamSocket(int fd, size_t bufferSize) : bufferSize(buffe
// Start reading. // Start reading.
err = uv_read_start( err = uv_read_start(
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
static_cast<uv_alloc_cb>(onAlloc), static_cast<uv_alloc_cb>(onAlloc),
static_cast<uv_read_cb>(onRead)); static_cast<uv_read_cb>(onRead));
if (err != 0) if (err != 0)
{ {
uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose)); uv_close(reinterpret_cast<uv_handle_t*>(this->uvHandle), static_cast<uv_close_cb>(onErrorClose));
...@@ -127,7 +127,7 @@ void UnixStreamSocket::Destroy() ...@@ -127,7 +127,7 @@ void UnixStreamSocket::Destroy()
auto req = new uv_shutdown_t; auto req = new uv_shutdown_t;
req->data = (void*)this; req->data = (void*)this;
err = uv_shutdown( err = uv_shutdown(
req, reinterpret_cast<uv_stream_t*>(this->uvHandle), static_cast<uv_shutdown_cb>(onShutdown)); req, reinterpret_cast<uv_stream_t*>(this->uvHandle), static_cast<uv_shutdown_cb>(onShutdown));
if (err != 0) if (err != 0)
MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err)); MS_ABORT("uv_shutdown() failed: %s", uv_strerror(err));
} }
...@@ -189,11 +189,11 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -189,11 +189,11 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen); buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
err = uv_write( err = uv_write(
&writeData->req, &writeData->req,
reinterpret_cast<uv_stream_t*>(this->uvHandle), reinterpret_cast<uv_stream_t*>(this->uvHandle),
&buffer, &buffer,
1, 1,
static_cast<uv_write_cb>(onWrite)); static_cast<uv_write_cb>(onWrite));
if (err != 0) if (err != 0)
MS_ABORT("uv_write() failed: %s", uv_strerror(err)); MS_ABORT("uv_write() failed: %s", uv_strerror(err));
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论