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

Some work done in C++ syntax.

上级 68826efa
...@@ -38,9 +38,6 @@ namespace RTC ...@@ -38,9 +38,6 @@ namespace RTC
virtual void onIceDisconnected(const IceServer* iceServer) = 0; virtual void onIceDisconnected(const IceServer* iceServer) = 0;
}; };
private:
static uint8_t stunSerializeBuffer[];
public: public:
IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password); IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password);
...@@ -56,7 +53,7 @@ namespace RTC ...@@ -56,7 +53,7 @@ namespace RTC
void ForceSelectedTuple(const RTC::TransportTuple* tuple); void ForceSelectedTuple(const RTC::TransportTuple* tuple);
private: private:
void HandleTuple(RTC::TransportTuple* tuple, bool has_use_candidate); void HandleTuple(RTC::TransportTuple* tuple, bool hasUseCandidate);
/** /**
* Store the given tuple and return its stored address. * Store the given tuple and return its stored address.
*/ */
...@@ -69,7 +66,7 @@ namespace RTC ...@@ -69,7 +66,7 @@ namespace RTC
* Set the given tuple as the selected tuple. * Set the given tuple as the selected tuple.
* NOTE: The given tuple MUST be already stored within the list. * NOTE: The given tuple MUST be already stored within the list.
*/ */
void SetSelectedTuple(RTC::TransportTuple* stored_tuple); void SetSelectedTuple(RTC::TransportTuple* storedTuple);
private: private:
// Passed by argument. // Passed by argument.
......
...@@ -16,7 +16,7 @@ namespace RTC ...@@ -16,7 +16,7 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void onNackRequired(const std::vector<uint16_t>& seq_numbers) = 0; virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onFullFrameRequired() = 0; virtual void onFullFrameRequired() = 0;
}; };
...@@ -24,11 +24,11 @@ namespace RTC ...@@ -24,11 +24,11 @@ namespace RTC
struct NackInfo struct NackInfo
{ {
NackInfo() {}; NackInfo() {};
explicit NackInfo(uint32_t seq32, uint32_t send_at_seq_num); explicit NackInfo(uint32_t seq32, uint32_t sendAtSeqNum);
uint32_t seq32 = 0; uint32_t seq32 = 0;
uint32_t send_at_seq_num = 0; uint32_t sendAtSeqNum = 0;
uint64_t sent_at_time = 0; uint64_t sentAtTime = 0;
uint8_t retries = 0; uint8_t retries = 0;
}; };
...@@ -45,7 +45,7 @@ namespace RTC ...@@ -45,7 +45,7 @@ namespace RTC
void ReceivePacket(RTC::RtpPacket* packet); void ReceivePacket(RTC::RtpPacket* packet);
private: private:
void AddPacketsToNackList(uint32_t seq32_start, uint32_t seq32_end); void AddPacketsToNackList(uint32_t seq32Start, uint32_t seq32End);
std::vector<uint16_t> GetNackBatch(NackFilter filter); std::vector<uint16_t> GetNackBatch(NackFilter filter);
void MayRunTimer() const; void MayRunTimer() const;
...@@ -59,18 +59,18 @@ namespace RTC ...@@ -59,18 +59,18 @@ namespace RTC
// Allocated by this. // Allocated by this.
Timer* timer = nullptr; Timer* timer = nullptr;
// Others. // Others.
std::map<uint32_t, NackInfo> nack_list; std::map<uint32_t, NackInfo> nackList;
bool started = false; bool started = false;
uint32_t last_seq32 = 0; // Extended seq number of last valid packet. uint32_t lastSeq32 = 0; // Extended seq number of last valid packet.
uint32_t rtt = 0; // Round trip time (ms). uint32_t rtt = 0; // Round trip time (ms).
}; };
// Inline instance methods. // Inline instance methods.
inline inline
NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t send_at_seq_num) : NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum) :
seq32(seq32), seq32(seq32),
send_at_seq_num(send_at_seq_num) sendAtSeqNum(sendAtSeqNum)
{} {}
} }
......
...@@ -14,22 +14,22 @@ namespace RTC ...@@ -14,22 +14,22 @@ namespace RTC
/* Struct for RTP header. */ /* Struct for RTP header. */
struct Header struct Header
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t csrc_count:4; uint8_t csrcCount:4;
uint8_t extension:1; uint8_t extension:1;
uint8_t padding:1; uint8_t padding:1;
uint8_t version:2; uint8_t version:2;
uint8_t payload_type:7; uint8_t payloadType:7;
uint8_t marker:1; uint8_t marker:1;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t version:2; uint8_t version:2;
uint8_t padding:1; uint8_t padding:1;
uint8_t extension:1; uint8_t extension:1;
uint8_t csrc_count:4; uint8_t csrcCount:4;
uint8_t marker:1; uint8_t marker:1;
uint8_t payload_type:7; uint8_t payloadType:7;
#endif #endif
uint16_t sequence_number; uint16_t sequenceNumber;
uint32_t timestamp; uint32_t timestamp;
uint32_t ssrc; uint32_t ssrc;
}; };
...@@ -47,13 +47,13 @@ namespace RTC ...@@ -47,13 +47,13 @@ namespace RTC
/* Struct for One-Byte extension. */ /* Struct for One-Byte extension. */
struct OneByteExtension struct OneByteExtension
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t len:4; uint8_t len:4;
uint8_t id:4; uint8_t id:4;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t id:4; uint8_t id:4;
uint8_t len:4; uint8_t len:4;
#endif #endif
uint8_t value[1]; uint8_t value[1];
}; };
...@@ -61,13 +61,13 @@ namespace RTC ...@@ -61,13 +61,13 @@ namespace RTC
/* Struct for Two-Bytes extension. */ /* Struct for Two-Bytes extension. */
struct TwoBytesExtension struct TwoBytesExtension
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t len:8; uint8_t len:8;
uint8_t id:8; uint8_t id:8;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t id:8; uint8_t id:8;
uint8_t len:8; uint8_t len:8;
#endif #endif
uint8_t value[1]; uint8_t value[1];
}; };
...@@ -83,7 +83,7 @@ namespace RTC ...@@ -83,7 +83,7 @@ namespace RTC
const uint8_t* GetData() const; const uint8_t* GetData() const;
size_t GetSize() const; size_t GetSize() const;
uint8_t GetPayloadType() const; uint8_t GetPayloadType() const;
void SetPayloadType(uint8_t payload_type); void SetPayloadType(uint8_t payloadType);
bool HasMarker() const; bool HasMarker() const;
void SetMarker(bool marker); void SetMarker(bool marker);
uint16_t GetSequenceNumber() const; uint16_t GetSequenceNumber() const;
...@@ -162,13 +162,13 @@ namespace RTC ...@@ -162,13 +162,13 @@ namespace RTC
inline inline
uint8_t RtpPacket::GetPayloadType() const uint8_t RtpPacket::GetPayloadType() const
{ {
return this->header->payload_type; return this->header->payloadType;
} }
inline inline
void RtpPacket::SetPayloadType(uint8_t payload_type) void RtpPacket::SetPayloadType(uint8_t payloadType)
{ {
this->header->payload_type = payload_type; this->header->payloadType = payloadType;
} }
inline inline
...@@ -186,13 +186,13 @@ namespace RTC ...@@ -186,13 +186,13 @@ namespace RTC
inline inline
uint16_t RtpPacket::GetSequenceNumber() const uint16_t RtpPacket::GetSequenceNumber() const
{ {
return (uint16_t)ntohs(this->header->sequence_number); return (uint16_t)ntohs(this->header->sequenceNumber);
} }
inline inline
void RtpPacket::SetSequenceNumber(uint16_t seq) void RtpPacket::SetSequenceNumber(uint16_t seq)
{ {
this->header->sequence_number = (uint16_t)htons(seq); this->header->sequenceNumber = (uint16_t)htons(seq);
} }
inline inline
...@@ -298,6 +298,7 @@ namespace RTC ...@@ -298,6 +298,7 @@ namespace RTC
return nullptr; return nullptr;
*len = this->oneByteExtensions.at(id)->len + 1; *len = this->oneByteExtensions.at(id)->len + 1;
return this->oneByteExtensions.at(id)->value; return this->oneByteExtensions.at(id)->value;
} }
else if (HasTwoBytesExtensions()) else if (HasTwoBytesExtensions())
...@@ -306,6 +307,7 @@ namespace RTC ...@@ -306,6 +307,7 @@ namespace RTC
return nullptr; return nullptr;
*len = this->oneByteExtensions.at(id)->len; *len = this->oneByteExtensions.at(id)->len;
return this->twoBytesExtensions.at(id)->value; return this->twoBytesExtensions.at(id)->value;
} }
else else
...@@ -317,15 +319,15 @@ namespace RTC ...@@ -317,15 +319,15 @@ namespace RTC
inline inline
bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const
{ {
uint8_t exten_len; uint8_t extenLen;
uint8_t* exten_value; uint8_t* extenValue;
exten_value = GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &exten_len); extenValue = GetExtension(RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL, &extenLen);
if (!exten_value || exten_len != 1) if (!extenValue || extenLen != 1)
return false; return false;
*volume = Utils::Byte::Get1Byte(exten_value, 0); *volume = Utils::Byte::Get1Byte(extenValue, 0);
*voice = (*volume & (1 << 7)) ? true : false; *voice = (*volume & (1 << 7)) ? true : false;
*volume &= ~(1 << 7); *volume &= ~(1 << 7);
...@@ -335,15 +337,15 @@ namespace RTC ...@@ -335,15 +337,15 @@ namespace RTC
inline inline
bool RtpPacket::ReadAbsSendTime(uint32_t* time) const bool RtpPacket::ReadAbsSendTime(uint32_t* time) const
{ {
uint8_t exten_len; uint8_t extenLen;
uint8_t* exten_value; uint8_t* extenValue;
exten_value = GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &exten_len); extenValue = GetExtension(RtpHeaderExtensionUri::Type::ABS_SEND_TIME, &extenLen);
if (!exten_value || exten_len != 3) if (!extenValue || extenLen != 3)
return false; return false;
*time = Utils::Byte::Get3Bytes(exten_value, 0); *time = Utils::Byte::Get3Bytes(extenValue, 0);
return true; return true;
} }
......
...@@ -66,7 +66,7 @@ namespace RTC ...@@ -66,7 +66,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seq_numbers) override; virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override; virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override;
public: public:
...@@ -121,6 +121,7 @@ namespace RTC ...@@ -121,6 +121,7 @@ namespace RTC
void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report) void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{ {
auto it = this->rtpStreams.find(report->GetSsrc()); auto it = this->rtpStreams.find(report->GetSsrc());
if (it != this->rtpStreams.end()) if (it != this->rtpStreams.end())
{ {
auto rtpStream = it->second; auto rtpStream = it->second;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include <unordered_set> #include <unordered_set>
#include <vector>
#include <json/json.h> #include <json/json.h>
namespace RTC namespace RTC
...@@ -31,10 +30,6 @@ namespace RTC ...@@ -31,10 +30,6 @@ namespace RTC
virtual void onRtpSenderClosed(RtpSender* rtpSender) = 0; virtual void onRtpSenderClosed(RtpSender* rtpSender) = 0;
}; };
private:
// Container of RTP packets to retransmit.
static std::vector<RTC::RtpPacket*> rtpRetransmissionContainer;
public: public:
RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind); RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind);
......
...@@ -46,16 +46,16 @@ namespace RTC ...@@ -46,16 +46,16 @@ namespace RTC
// Others. // Others.
bool started = false; // Whether at least a RTP packet has been received. bool started = false; // Whether at least a RTP packet has been received.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff. // https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t max_seq = 0; // Highest seq. number seen. uint16_t maxSeq = 0; // Highest seq. number seen.
uint32_t cycles = 0; // Shifted count of seq. number cycles. uint32_t cycles = 0; // Shifted count of seq. number cycles.
uint32_t base_seq = 0; // Base seq number. uint32_t baseSeq = 0; // Base seq number.
uint32_t bad_seq = 0; // Last 'bad' seq number + 1. uint32_t badSeq = 0; // Last 'bad' seq number + 1.
uint32_t probation = 0; // Seq. packets till source is valid. uint32_t probation = 0; // Seq. packets till source is valid.
uint32_t received = 0; // Packets received. uint32_t received = 0; // Packets received.
uint32_t expected_prior = 0; // Packet expected at last interval. uint32_t expectedPrior = 0; // Packet expected at last interval.
uint32_t received_prior = 0; // Packet received at last interval. uint32_t receivedPrior = 0; // Packet received at last interval.
// Others. // Others.
uint32_t max_timestamp = 0; // Highest timestamp seen. uint32_t maxTimestamp = 0; // Highest timestamp seen.
}; };
/* Inline instance methods. */ /* Inline instance methods. */
......
...@@ -16,7 +16,7 @@ namespace RTC ...@@ -16,7 +16,7 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seq_numbers) = 0; virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
}; };
...@@ -39,15 +39,15 @@ namespace RTC ...@@ -39,15 +39,15 @@ namespace RTC
/* Pure virtual methods inherited from RTC::NackGenerator. */ /* Pure virtual methods inherited from RTC::NackGenerator. */
protected: protected:
virtual void onNackRequired(const std::vector<uint16_t>& seq_numbers) override; virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) override;
virtual void onFullFrameRequired() override; virtual void onFullFrameRequired() override;
private: private:
// Passed by argument. // Passed by argument.
Listener* listener = nullptr; Listener* listener = nullptr;
// Others. // Others.
uint32_t last_sr_timestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in the most recent sender report. uint32_t lastSrTimestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in the most recent sender report.
uint64_t last_sr_received = 0; // Wallclock time representing the most recent sender report arrival. uint64_t lastSrReceived = 0; // Wallclock time representing the most recent sender report arrival.
uint32_t transit = 0; // Relative trans time for prev pkt. uint32_t transit = 0; // Relative trans time for prev pkt.
uint32_t jitter = 0; // Estimated jitter. uint32_t jitter = 0; // Estimated jitter.
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
......
...@@ -21,8 +21,8 @@ namespace RTC ...@@ -21,8 +21,8 @@ namespace RTC
private: private:
struct BufferItem struct BufferItem
{ {
uint32_t seq32 = 0; // RTP seq in 32 bytes plus 16 bits cycles. uint32_t seq32 = 0; // RTP seq in 32 bytes plus 16 bits cycles.
uint64_t resent_at_time = 0; uint64_t resentAtTime = 0;
RTC::RtpPacket* packet = nullptr; RTC::RtpPacket* packet = nullptr;
}; };
......
...@@ -29,11 +29,8 @@ namespace RTC ...@@ -29,11 +29,8 @@ namespace RTC
private: private:
static void onSrtpEvent(srtp_event_data_t* data); static void onSrtpEvent(srtp_event_data_t* data);
private:
static uint8_t encryptBuffer[];
public: public:
SrtpSession(Type type, Profile profile, uint8_t* key, size_t key_len); SrtpSession(Type type, Profile profile, uint8_t* key, size_t keyLen);
private: private:
~SrtpSession(); ~SrtpSession();
......
...@@ -85,7 +85,7 @@ namespace RTC ...@@ -85,7 +85,7 @@ namespace RTC
uint16_t GetErrorCode() const; uint16_t GetErrorCode() const;
bool HasMessageIntegrity() const; bool HasMessageIntegrity() const;
bool HasFingerprint() const; bool HasFingerprint() const;
Authentication CheckAuthentication(const std::string &local_username, const std::string &local_password); Authentication CheckAuthentication(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);
......
...@@ -106,7 +106,9 @@ void DepOpenSSL::LockingFunction(int mode, int n, const char *file, int line) ...@@ -106,7 +106,9 @@ void DepOpenSSL::LockingFunction(int mode, int n, const char *file, int line)
* - line: line in the source file calling this function. * - line: line in the source file calling this function.
*/ */
// MS_DEBUG_DEV("[mode: %s+%s, mutex id: %d, file: %s, line: %d]", mode & CRYPTO_LOCK ? "LOCK" : "UNLOCK", mode & CRYPTO_READ ? "READ" : "WRITE", n, file, line); // MS_DEBUG_DEV("[mode: %s+%s, mutex id: %d, file: %s, line: %d]",
// mode & CRYPTO_LOCK ? "LOCK" : "UNLOCK", mode & CRYPTO_READ ? "READ" : "WRITE",
// n, file, line);
if (mode & CRYPTO_LOCK) if (mode & CRYPTO_LOCK)
uv_mutex_lock(&DepOpenSSL::mutexes[n]); uv_mutex_lock(&DepOpenSSL::mutexes[n]);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <string> #include <string>
#include <utility> // std::pair() #include <utility> // std::pair()
#include <cerrno> #include <cerrno>
#include <iostream> // std::cout, std::cerr #include <iostream> // std::cout, std::cerr
#include <json/json.h> #include <json/json.h>
/* Instance methods. */ /* Instance methods. */
...@@ -52,6 +52,7 @@ void Loop::Close() ...@@ -52,6 +52,7 @@ void Loop::Close()
return; return;
} }
this->closed = true; this->closed = true;
// Close the SignalsHandler. // Close the SignalsHandler.
...@@ -84,16 +85,16 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId) ...@@ -84,16 +85,16 @@ RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId)
static const Json::StaticString k_roomId("roomId"); static const Json::StaticString k_roomId("roomId");
auto json_roomId = request->internal[k_roomId]; auto jsonRoomId = request->internal[k_roomId];
if (!json_roomId.isUInt()) if (!jsonRoomId.isUInt())
MS_THROW_ERROR("Request has not numeric internal.roomId"); MS_THROW_ERROR("Request has not numeric internal.roomId");
// If given, fill roomId. // If given, fill roomId.
if (roomId) if (roomId)
*roomId = json_roomId.asUInt(); *roomId = jsonRoomId.asUInt();
auto it = this->rooms.find(json_roomId.asUInt()); auto it = this->rooms.find(jsonRoomId.asUInt());
if (it != this->rooms.end()) if (it != this->rooms.end())
{ {
RTC::Room* room = it->second; RTC::Room* room = it->second;
...@@ -123,7 +124,8 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum) ...@@ -123,7 +124,8 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum)
break; break;
default: default:
MS_WARN_DEV("received a signal (with signum %d) for which there is no handling code", signum); MS_WARN_DEV("received a signal (with signum %d) for which there is no handling code",
signum);
} }
} }
...@@ -151,6 +153,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -151,6 +153,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
json_rooms.append(room->toJson()); json_rooms.append(room->toJson());
} }
json[k_rooms] = json_rooms; json[k_rooms] = json_rooms;
request->Accept(json); request->Accept(json);
...@@ -179,12 +182,14 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -179,12 +182,14 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
request->Reject(error.what()); request->Reject(error.what());
return; return;
} }
if (room) if (room)
{ {
request->Reject("Room already exists"); request->Reject("Room already exists");
return; return;
} }
...@@ -195,6 +200,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -195,6 +200,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
request->Reject(error.what()); request->Reject(error.what());
return; return;
} }
...@@ -242,12 +248,14 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -242,12 +248,14 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
request->Reject(error.what()); request->Reject(error.what());
return; return;
} }
if (!room) if (!room)
{ {
request->Reject("Room does not exist"); request->Reject("Room does not exist");
return; return;
} }
......
...@@ -7,17 +7,19 @@ ...@@ -7,17 +7,19 @@
namespace RTC namespace RTC
{ {
constexpr uint32_t MAX_PACKET_AGE = 10000; /* Static. */
constexpr size_t MAX_NACK_PACKETS = 500;
constexpr uint32_t DEFAULT_RTT = 100; constexpr uint32_t MaxPacketAge = 10000;
constexpr uint8_t MAX_NACK_RETRIES = 8; constexpr size_t MaxNackPackets = 500;
constexpr uint64_t TIMER_INTERVAL = 25; constexpr uint32_t DefaultRtt = 100;
constexpr uint8_t MaxNackRetries = 8;
constexpr uint64_t TimerInterval = 25;
/* Instance methods. */ /* Instance methods. */
NackGenerator::NackGenerator(Listener* listener) : NackGenerator::NackGenerator(Listener* listener) :
listener(listener), listener(listener),
rtt(DEFAULT_RTT) rtt(DefaultRtt)
{ {
MS_TRACE(); MS_TRACE();
...@@ -41,36 +43,37 @@ namespace RTC ...@@ -41,36 +43,37 @@ namespace RTC
if (!this->started) if (!this->started)
{ {
this->last_seq32 = seq32; this->lastSeq32 = seq32;
this->started = true; this->started = true;
return; return;
} }
// Obviously never nacked, so ignore. // Obviously never nacked, so ignore.
if (seq32 == this->last_seq32) if (seq32 == this->lastSeq32)
{ {
return; return;
} }
else if (seq32 == this->last_seq32 + 1) else if (seq32 == this->lastSeq32 + 1)
{ {
this->last_seq32++; this->lastSeq32++;
return; return;
} }
// May be an out of order packet or a retransmitted packet (without RTX). // May be an out of order packet or a retransmitted packet (without RTX).
if (seq32 < this->last_seq32) if (seq32 < this->lastSeq32)
{ {
auto it = this->nack_list.find(seq32); auto it = this->nackList.find(seq32);
// It was a nacked packet. // It was a nacked packet.
if (it != this->nack_list.end()) if (it != this->nackList.end())
{ {
MS_DEBUG_TAG(rtx, MS_DEBUG_TAG(rtx,
"nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "nacked packet received [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSequenceNumber()); packet->GetSsrc(), packet->GetSequenceNumber());
this->nack_list.erase(it); this->nackList.erase(it);
} }
// Out of order packet. // Out of order packet.
else else
...@@ -84,84 +87,86 @@ namespace RTC ...@@ -84,84 +87,86 @@ namespace RTC
} }
// Otherwise we may have lost some packets. // Otherwise we may have lost some packets.
AddPacketsToNackList(this->last_seq32 + 1, seq32); AddPacketsToNackList(this->lastSeq32 + 1, seq32);
this->last_seq32 = seq32; this->lastSeq32 = seq32;
// Check if there are any nacks that are waiting for this seq number. // Check if there are any nacks that are waiting for this seq number.
std::vector<uint16_t> nack_batch = GetNackBatch(NackFilter::SEQ); std::vector<uint16_t> nackBatch = GetNackBatch(NackFilter::SEQ);
if (!nack_batch.empty()) if (!nackBatch.empty())
this->listener->onNackRequired(nack_batch); this->listener->onNackRequired(nackBatch);
MayRunTimer(); MayRunTimer();
} }
void NackGenerator::AddPacketsToNackList(uint32_t seq32_start, uint32_t seq32_end) void NackGenerator::AddPacketsToNackList(uint32_t seq32Start, uint32_t seq32End)
{ {
MS_TRACE(); MS_TRACE();
// Remove old packets. // Remove old packets.
auto it = this->nack_list.lower_bound(seq32_end - MAX_PACKET_AGE); auto it = this->nackList.lower_bound(seq32End - MaxPacketAge);
this->nack_list.erase(this->nack_list.begin(), it); this->nackList.erase(this->nackList.begin(), it);
// If the nack list is too large, clear it and request a full frame. // If the nack list is too large, clear it and request a full frame.
uint32_t num_new_nacks = seq32_end - seq32_start; uint32_t numNewNacks = seq32End - seq32Start;
if (this->nack_list.size() + num_new_nacks > MAX_NACK_PACKETS) if (this->nackList.size() + numNewNacks > MaxNackPackets)
{ {
MS_DEBUG_TAG(rtx, "nack list too large, clearing it and requesting a full frame"); MS_DEBUG_TAG(rtx, "nack list too large, clearing it and requesting a full frame");
this->nack_list.clear(); this->nackList.clear();
this->listener->onFullFrameRequired(); this->listener->onFullFrameRequired();
return; return;
} }
for (uint32_t seq32 = seq32_start; seq32 != seq32_end; ++seq32) for (uint32_t seq32 = seq32Start; seq32 != seq32End; ++seq32)
{ {
// NOTE: Let the packet become out of order for a while without requesting // NOTE: Let the packet become out of order for a while without requesting
// it into a NACK. // it into a NACK.
// TODO: To be done. // TODO: To be done.
uint32_t send_at_seq_num = seq32 + 0; uint32_t sendAtSeqNum = seq32 + 0;
NackInfo nack_info(seq32, send_at_seq_num); NackInfo nackInfo(seq32, sendAtSeqNum);
MS_ASSERT(this->nack_list.find(seq32) == this->nack_list.end(), "packet already in the NACK list"); MS_ASSERT(this->nackList.find(seq32) == this->nackList.end(),
"packet already in the NACK list");
this->nack_list[seq32] = nack_info; this->nackList[seq32] = nackInfo;
} }
} }
std::vector<uint16_t> NackGenerator::GetNackBatch(NackFilter filter) std::vector<uint16_t> NackGenerator::GetNackBatch(NackFilter filter)
{ {
uint64_t now = DepLibUV::GetTime(); uint64_t now = DepLibUV::GetTime();
std::vector<uint16_t> nack_batch; std::vector<uint16_t> nackBatch;
auto it = this->nack_list.begin(); auto it = this->nackList.begin();
while (it != this->nack_list.end()) while (it != this->nackList.end())
{ {
NackInfo& nack_info = it->second; NackInfo& nackInfo = it->second;
uint16_t seq = nack_info.seq32 % (1<<16); uint16_t seq = nackInfo.seq32 % (1<<16);
if ( if (
filter == NackFilter::SEQ && filter == NackFilter::SEQ &&
nack_info.sent_at_time == 0 && nackInfo.sentAtTime == 0 &&
this->last_seq32 >= nack_info.send_at_seq_num) this->lastSeq32 >= nackInfo.sendAtSeqNum)
{ {
nack_info.retries++; nackInfo.retries++;
nack_info.sent_at_time = now; nackInfo.sentAtTime = now;
if (nack_info.retries >= MAX_NACK_RETRIES) if (nackInfo.retries >= MaxNackRetries)
{ {
MS_WARN_TAG(rtx, MS_WARN_TAG(rtx,
"sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", seq); "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]",
seq);
it = this->nack_list.erase(it); it = this->nackList.erase(it);
} }
else else
{ {
nack_batch.emplace_back(seq); nackBatch.emplace_back(seq);
++it; ++it;
} }
...@@ -170,21 +175,22 @@ namespace RTC ...@@ -170,21 +175,22 @@ namespace RTC
if ( if (
filter == NackFilter::TIME && filter == NackFilter::TIME &&
nack_info.sent_at_time + this->rtt < now) nackInfo.sentAtTime + this->rtt < now)
{ {
nack_info.retries++; nackInfo.retries++;
nack_info.sent_at_time = now; nackInfo.sentAtTime = now;
if (nack_info.retries >= MAX_NACK_RETRIES) if (nackInfo.retries >= MaxNackRetries)
{ {
MS_WARN_TAG(rtx, MS_WARN_TAG(rtx,
"sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]", seq); "sequence number removed from the NACK list due to max retries [seq:%" PRIu16 "]",
seq);
it = this->nack_list.erase(it); it = this->nackList.erase(it);
} }
else else
{ {
nack_batch.emplace_back(seq); nackBatch.emplace_back(seq);
++it; ++it;
} }
...@@ -194,14 +200,14 @@ namespace RTC ...@@ -194,14 +200,14 @@ namespace RTC
++it; ++it;
} }
return nack_batch; return nackBatch;
} }
inline inline
void NackGenerator::MayRunTimer() const void NackGenerator::MayRunTimer() const
{ {
if (this->nack_list.size() > 0) if (this->nackList.size() > 0)
this->timer->Start(TIMER_INTERVAL); this->timer->Start(TimerInterval);
} }
inline inline
...@@ -209,10 +215,10 @@ namespace RTC ...@@ -209,10 +215,10 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
std::vector<uint16_t> nack_batch = GetNackBatch(NackFilter::TIME); std::vector<uint16_t> nackBatch = GetNackBatch(NackFilter::TIME);
if (!nack_batch.empty()) if (!nackBatch.empty())
this->listener->onNackRequired(nack_batch); this->listener->onNackRequired(nackBatch);
MayRunTimer(); MayRunTimer();
} }
......
差异被折叠。
差异被折叠。
...@@ -57,6 +57,7 @@ namespace RTC ...@@ -57,6 +57,7 @@ namespace RTC
if (newOldestTime > this->oldestTime + this->windowSize) if (newOldestTime > this->oldestTime + this->windowSize)
{ {
this->Reset(newOldestTime); this->Reset(newOldestTime);
return; return;
} }
...@@ -69,6 +70,7 @@ namespace RTC ...@@ -69,6 +70,7 @@ namespace RTC
if (++this->oldestIndex >= this->windowSize) if (++this->oldestIndex >= this->windowSize)
this->oldestIndex = 0; this->oldestIndex = 0;
++this->oldestTime; ++this->oldestTime;
} }
......
...@@ -18,9 +18,9 @@ namespace RTC ...@@ -18,9 +18,9 @@ namespace RTC
static const Json::StaticString k_ptTable("ptTable"); static const Json::StaticString k_ptTable("ptTable");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
Json::Value json_ssrcTable(Json::objectValue); Json::Value jsonSsrcTable(Json::objectValue);
Json::Value json_muxIdTable(Json::objectValue); Json::Value jsonMuxIdTable(Json::objectValue);
Json::Value json_ptTable(Json::objectValue); Json::Value jsonPtTable(Json::objectValue);
// Add `ssrcTable`. // Add `ssrcTable`.
for (auto& kv : this->ssrcTable) for (auto& kv : this->ssrcTable)
...@@ -28,9 +28,9 @@ namespace RTC ...@@ -28,9 +28,9 @@ namespace RTC
auto ssrc = kv.first; auto ssrc = kv.first;
auto rtpReceiver = kv.second; auto rtpReceiver = kv.second;
json_ssrcTable[std::to_string(ssrc)] = std::to_string(rtpReceiver->rtpReceiverId); jsonSsrcTable[std::to_string(ssrc)] = std::to_string(rtpReceiver->rtpReceiverId);
} }
json[k_ssrcTable] = json_ssrcTable; json[k_ssrcTable] = jsonSsrcTable;
// Add `muxIdTable`. // Add `muxIdTable`.
for (auto& kv : this->muxIdTable) for (auto& kv : this->muxIdTable)
...@@ -38,9 +38,9 @@ namespace RTC ...@@ -38,9 +38,9 @@ namespace RTC
auto muxId = kv.first; auto muxId = kv.first;
auto rtpReceiver = kv.second; auto rtpReceiver = kv.second;
json_muxIdTable[muxId] = std::to_string(rtpReceiver->rtpReceiverId); jsonMuxIdTable[muxId] = std::to_string(rtpReceiver->rtpReceiverId);
} }
json[k_muxIdTable] = json_muxIdTable; json[k_muxIdTable] = jsonMuxIdTable;
// Add `ptTable`. // Add `ptTable`.
for (auto& kv : this->ptTable) for (auto& kv : this->ptTable)
...@@ -48,9 +48,9 @@ namespace RTC ...@@ -48,9 +48,9 @@ namespace RTC
auto payloadType = kv.first; auto payloadType = kv.first;
auto rtpReceiver = kv.second; auto rtpReceiver = kv.second;
json_ptTable[std::to_string(payloadType)] = std::to_string(rtpReceiver->rtpReceiverId); jsonPtTable[std::to_string(payloadType)] = std::to_string(rtpReceiver->rtpReceiverId);
} }
json[k_ptTable] = json_ptTable; json[k_ptTable] = jsonPtTable;
return json; return json;
} }
...@@ -266,18 +266,6 @@ namespace RTC ...@@ -266,18 +266,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO: REMOVE.
// uint8_t* rid_pointer = packet->GetExtensionElementValue(5);
// if (rid_pointer)
// {
// uint8_t rid_length = packet->GetExtensionElementLength(5);
// std::string rid_value = std::string((const char*)rid_pointer, (size_t)rid_length);
// MS_DEBUG_TAG(rtp, "RID [length:%zu, value:'%s', pointer[0]:'%c']", (size_t)rid_length, rid_value.c_str(), (char)rid_pointer[0]);
// if ((char)rid_pointer[0] == '\0')
// MS_WARN_TAG(rtp, "RID data[0] is 0");
// }
// First lookup into the SSRC table. // First lookup into the SSRC table.
{ {
auto it = this->ssrcTable.find(packet->GetSsrc()); auto it = this->ssrcTable.find(packet->GetSsrc());
...@@ -296,7 +284,8 @@ namespace RTC ...@@ -296,7 +284,8 @@ namespace RTC
} }
// RTP PT not present. // RTP PT not present.
MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType()); MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]",
packet->GetPayloadType());
// TODO: We may emit "unhandledrtp" event. // TODO: We may emit "unhandledrtp" event.
return nullptr; return nullptr;
...@@ -323,7 +312,7 @@ namespace RTC ...@@ -323,7 +312,7 @@ namespace RTC
} }
} }
// TODO: We may emit 'unhandledrtp' event. // TODO: We may emit "unhandledrtp" event.
return nullptr; return nullptr;
} }
......
...@@ -26,32 +26,34 @@ namespace RTC ...@@ -26,32 +26,34 @@ namespace RTC
ptr += sizeof(Header); ptr += sizeof(Header);
// Check CSRC list. // Check CSRC list.
size_t csrc_list_size = 0; size_t csrcListSize = 0;
if (header->csrc_count) if (header->csrcCount)
{ {
csrc_list_size = header->csrc_count * sizeof(header->ssrc); csrcListSize = header->csrcCount * sizeof(header->ssrc);
// Packet size must be >= header size + CSRC list. // Packet size must be >= header size + CSRC list.
if (len < (ptr - data) + csrc_list_size) if (len < (ptr - data) + csrcListSize)
{ {
MS_WARN_TAG(rtp, "not enough space for the announced CSRC list, packet discarded"); MS_WARN_TAG(rtp,
"not enough space for the announced CSRC list, packet discarded");
return nullptr; return nullptr;
} }
ptr += csrc_list_size; ptr += csrcListSize;
} }
// Check header extension. // Check header extension.
ExtensionHeader* extensionHeader = nullptr; ExtensionHeader* extensionHeader = nullptr;
size_t extension_value_size = 0; size_t extensionValueSize = 0;
if (header->extension) if (header->extension)
{ {
// The extension header is at least 4 bytes. // The extension header is at least 4 bytes.
if (len < size_t(ptr - data) + 4) if (len < size_t(ptr - data) + 4)
{ {
MS_WARN_TAG(rtp, "not enough space for the announced extension header, packet discarded"); MS_WARN_TAG(rtp,
"not enough space for the announced extension header, packet discarded");
return nullptr; return nullptr;
} }
...@@ -60,16 +62,17 @@ namespace RTC ...@@ -60,16 +62,17 @@ namespace RTC
// The header extension contains a 16-bit length field that counts the number of // The header extension contains a 16-bit length field that counts the number of
// 32-bit words in the extension, excluding the four-octet extension header. // 32-bit words in the extension, excluding the four-octet extension header.
extension_value_size = (size_t)(ntohs(extensionHeader->length) * 4); extensionValueSize = (size_t)(ntohs(extensionHeader->length) * 4);
// Packet size must be >= header size + CSRC list + header extension size. // Packet size must be >= header size + CSRC list + header extension size.
if (len < (ptr - data) + 4 + extension_value_size) if (len < (ptr - data) + 4 + extensionValueSize)
{ {
MS_WARN_TAG(rtp, "not enough space for the announced header extension value, packet discarded"); MS_WARN_TAG(rtp,
"not enough space for the announced header extension value, packet discarded");
return nullptr; return nullptr;
} }
ptr += 4 + extension_value_size; ptr += 4 + extensionValueSize;
} }
// Get payload. // Get payload.
...@@ -85,7 +88,8 @@ namespace RTC ...@@ -85,7 +88,8 @@ namespace RTC
// Must be at least a single payload byte. // Must be at least a single payload byte.
if (payloadLength == 0) if (payloadLength == 0)
{ {
MS_WARN_TAG(rtp, "padding bit is set but no space for a padding byte, packet discarded"); MS_WARN_TAG(rtp,
"padding bit is set but no space for a padding byte, packet discarded");
return nullptr; return nullptr;
} }
...@@ -100,7 +104,8 @@ namespace RTC ...@@ -100,7 +104,8 @@ namespace RTC
if (payloadLength < (size_t)payloadPadding) if (payloadLength < (size_t)payloadPadding)
{ {
MS_WARN_TAG(rtp, "number of padding octets is greater than available space for payload, packet discarded"); MS_WARN_TAG(rtp,
"number of padding octets is greater than available space for payload, packet discarded");
return nullptr; return nullptr;
} }
...@@ -110,9 +115,12 @@ namespace RTC ...@@ -110,9 +115,12 @@ namespace RTC
if (payloadLength == 0) if (payloadLength == 0)
payload = nullptr; payload = nullptr;
MS_ASSERT(len == sizeof(Header) + csrc_list_size + (extensionHeader ? 4 + extension_value_size : 0) + payloadLength + (size_t)payloadPadding, "packet's computed size does not match received size"); MS_ASSERT(len == sizeof(Header) + csrcListSize + (extensionHeader ? 4 +
extensionValueSize : 0) + payloadLength + (size_t)payloadPadding,
"packet's computed size does not match received size");
RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, payloadLength, payloadPadding, len); RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, payloadLength,
payloadPadding, len);
// Parse RFC 5285 extension header. // Parse RFC 5285 extension header.
packet->ParseExtensions(); packet->ParseExtensions();
...@@ -132,7 +140,7 @@ namespace RTC ...@@ -132,7 +140,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->header->csrc_count) if (this->header->csrcCount)
this->csrcList = (uint8_t*)header + sizeof(Header); this->csrcList = (uint8_t*)header + sizeof(Header);
} }
...@@ -153,7 +161,7 @@ namespace RTC ...@@ -153,7 +161,7 @@ namespace RTC
MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId()); MS_DUMP(" id : %" PRIu16, GetExtensionHeaderId());
MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength()); MS_DUMP(" length : %zu bytes", GetExtensionHeaderLength());
} }
MS_DUMP(" csrc count : %" PRIu8, this->header->csrc_count); MS_DUMP(" csrc count : %" PRIu8, this->header->csrcCount);
MS_DUMP(" marker : %s", HasMarker() ? "true" : "false"); MS_DUMP(" marker : %s", HasMarker() ? "true" : "false");
MS_DUMP(" payload type : %" PRIu8, GetPayloadType()); MS_DUMP(" payload type : %" PRIu8, GetPayloadType());
MS_DUMP(" sequence number : %" PRIu16, GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu16, GetSequenceNumber());
...@@ -171,12 +179,12 @@ namespace RTC ...@@ -171,12 +179,12 @@ namespace RTC
this->size = sizeof(Header); // Minimum header. this->size = sizeof(Header); // Minimum header.
if (this->csrcList) if (this->csrcList)
this->size += this->header->csrc_count * sizeof(header->ssrc); this->size += this->header->csrcCount * sizeof(header->ssrc);
size_t extension_value_size = GetExtensionHeaderLength(); size_t extensionValueSize = GetExtensionHeaderLength();
if (this->extensionHeader) if (this->extensionHeader)
this->size += 4 + extension_value_size; this->size += 4 + extensionValueSize;
this->size += this->payloadLength; this->size += this->payloadLength;
this->size += (size_t)this->payloadPadding; this->size += (size_t)this->payloadPadding;
...@@ -193,21 +201,21 @@ namespace RTC ...@@ -193,21 +201,21 @@ namespace RTC
// Add CSRC list. // Add CSRC list.
if (this->csrcList) if (this->csrcList)
{ {
std::memcpy(ptr, this->csrcList, this->header->csrc_count * sizeof(this->header->ssrc)); std::memcpy(ptr, this->csrcList, this->header->csrcCount * sizeof(this->header->ssrc));
// Update the pointer. // Update the pointer.
this->csrcList = ptr; this->csrcList = ptr;
ptr += this->header->csrc_count * sizeof(this->header->ssrc); ptr += this->header->csrcCount * sizeof(this->header->ssrc);
} }
// Add extension header. // Add extension header.
if (this->extensionHeader) if (this->extensionHeader)
{ {
std::memcpy(ptr, this->extensionHeader, 4 + extension_value_size); std::memcpy(ptr, this->extensionHeader, 4 + extensionValueSize);
// Update the header extension pointer. // Update the header extension pointer.
this->extensionHeader = reinterpret_cast<ExtensionHeader*>(ptr); this->extensionHeader = reinterpret_cast<ExtensionHeader*>(ptr);
ptr += 4 + extension_value_size; ptr += 4 + extensionValueSize;
} }
// Parse and regenerate RFC 5285 extension header. // Parse and regenerate RFC 5285 extension header.
...@@ -248,7 +256,7 @@ namespace RTC ...@@ -248,7 +256,7 @@ namespace RTC
// Check CSRC list. // Check CSRC list.
if (this->csrcList) if (this->csrcList)
ptr += header->csrc_count * sizeof(header->ssrc); ptr += header->csrcCount * sizeof(header->ssrc);
// Check extension header. // Check extension header.
ExtensionHeader* extensionHeader = nullptr; ExtensionHeader* extensionHeader = nullptr;
...@@ -280,7 +288,8 @@ namespace RTC ...@@ -280,7 +288,8 @@ namespace RTC
MS_ASSERT(size_t(ptr - buffer) == this->size, "size_t(ptr - buffer) == this->size"); MS_ASSERT(size_t(ptr - buffer) == this->size, "size_t(ptr - buffer) == this->size");
// Create the new RtpPacket instance and return it. // Create the new RtpPacket instance and return it.
RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, this->payloadLength, this->payloadPadding, this->size); RtpPacket* packet = new RtpPacket(header, extensionHeader, payload, this->payloadLength,
this->payloadPadding, this->size);
// Parse RFC 5285 extension header. // Parse RFC 5285 extension header.
packet->ParseExtensions(); packet->ParseExtensions();
...@@ -301,18 +310,19 @@ namespace RTC ...@@ -301,18 +310,19 @@ namespace RTC
// Clear the One-Byte extension elements map. // Clear the One-Byte extension elements map.
this->oneByteExtensions.clear(); this->oneByteExtensions.clear();
uint8_t* extension_start = (uint8_t*)this->extensionHeader + 4; uint8_t* extensionStart = (uint8_t*)this->extensionHeader + 4;
uint8_t* extension_end = extension_start + GetExtensionHeaderLength(); uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength();
uint8_t* ptr = extension_start; uint8_t* ptr = extensionStart;
while (ptr < extension_end) while (ptr < extensionEnd)
{ {
uint8_t id = (*ptr & 0xF0) >> 4; uint8_t id = (*ptr & 0xF0) >> 4;
size_t len = (*ptr & 0x0F) + 1; size_t len = (*ptr & 0x0F) + 1;
if (ptr + 1 + len > extension_end) if (ptr + 1 + len > extensionEnd)
{ {
MS_WARN_TAG(rtp, "not enough space for the announced One-Byte header extension element value"); MS_WARN_TAG(rtp,
"not enough space for the announced One-Byte header extension element value");
break; break;
} }
...@@ -323,7 +333,7 @@ namespace RTC ...@@ -323,7 +333,7 @@ namespace RTC
ptr += 1 + len; ptr += 1 + len;
// Counting padding bytes. // Counting padding bytes.
while ((ptr < extension_end) && (*ptr == 0)) while ((ptr < extensionEnd) && (*ptr == 0))
++ptr; ++ptr;
} }
} }
...@@ -333,18 +343,19 @@ namespace RTC ...@@ -333,18 +343,19 @@ namespace RTC
// Clear the Two-Bytes extension elements map. // Clear the Two-Bytes extension elements map.
this->twoBytesExtensions.clear(); this->twoBytesExtensions.clear();
uint8_t* extension_start = (uint8_t*)this->extensionHeader + 4; uint8_t* extensionStart = (uint8_t*)this->extensionHeader + 4;
uint8_t* extension_end = extension_start + GetExtensionHeaderLength(); uint8_t* extensionEnd = extensionStart + GetExtensionHeaderLength();
uint8_t* ptr = extension_start; uint8_t* ptr = extensionStart;
while (ptr < extension_end) while (ptr < extensionEnd)
{ {
uint8_t id = *ptr; uint8_t id = *ptr;
size_t len = *(++ptr); size_t len = *(++ptr);
if (ptr + len > extension_end) if (ptr + len > extensionEnd)
{ {
MS_WARN_TAG(rtp, "not enough space for the announced Two-Bytes header extension element value"); MS_WARN_TAG(rtp,
"not enough space for the announced Two-Bytes header extension element value");
break; break;
} }
...@@ -355,7 +366,7 @@ namespace RTC ...@@ -355,7 +366,7 @@ namespace RTC
ptr += len; ptr += len;
// Counting padding bytes. // Counting padding bytes.
while ((ptr < extension_end) && (*ptr == 0)) while ((ptr < extensionEnd) && (*ptr == 0))
++ptr; ++ptr;
} }
} }
......
...@@ -47,11 +47,11 @@ namespace RTC ...@@ -47,11 +47,11 @@ namespace RTC
static const Json::StaticString k_class("class"); static const Json::StaticString k_class("class");
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
// Notify. // Notify.
event_data[k_class] = "RtpReceiver"; eventData[k_class] = "RtpReceiver";
this->notifier->Emit(this->rtpReceiverId, "close", event_data); this->notifier->Emit(this->rtpReceiverId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->onRtpReceiverClosed(this); this->listener->onRtpReceiverClosed(this);
...@@ -63,7 +63,6 @@ namespace RTC ...@@ -63,7 +63,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpReceiverId("rtpReceiverId"); static const Json::StaticString k_rtpReceiverId("rtpReceiverId");
static const Json::StaticString k_kind("kind"); static const Json::StaticString k_kind("kind");
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
...@@ -74,7 +73,7 @@ namespace RTC ...@@ -74,7 +73,7 @@ namespace RTC
static const Json::StaticString k_rtpStream("rtpStream"); static const Json::StaticString k_rtpStream("rtpStream");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
Json::Value json_rtpStreams(Json::arrayValue); Json::Value jsonRtpStreams(Json::arrayValue);
json[k_rtpReceiverId] = (Json::UInt)this->rtpReceiverId; json[k_rtpReceiverId] = (Json::UInt)this->rtpReceiverId;
...@@ -83,7 +82,7 @@ namespace RTC ...@@ -83,7 +82,7 @@ namespace RTC
if (this->rtpParameters) if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson(); json[k_rtpParameters] = this->rtpParameters->toJson();
else else
json[k_rtpParameters] = null_data; json[k_rtpParameters] = Json::nullValue;
json[k_hasTransport] = this->transport ? true : false; json[k_hasTransport] = this->transport ? true : false;
...@@ -95,9 +94,9 @@ namespace RTC ...@@ -95,9 +94,9 @@ namespace RTC
{ {
auto rtpStream = kv.second; auto rtpStream = kv.second;
json_rtpStreams.append(rtpStream->toJson()); jsonRtpStreams.append(rtpStream->toJson());
} }
json[k_rtpStreams] = json_rtpStreams; json[k_rtpStreams] = jsonRtpStreams;
return json; return json;
} }
...@@ -110,9 +109,9 @@ namespace RTC ...@@ -110,9 +109,9 @@ namespace RTC
{ {
case Channel::Request::MethodId::rtpReceiver_close: case Channel::Request::MethodId::rtpReceiver_close:
{ {
#ifdef MS_LOG_DEV #ifdef MS_LOG_DEV
uint32_t rtpReceiverId = this->rtpReceiverId; uint32_t rtpReceiverId = this->rtpReceiverId;
#endif #endif
Destroy(); Destroy();
...@@ -269,30 +268,32 @@ namespace RTC ...@@ -269,30 +268,32 @@ namespace RTC
// Emit "rtpraw" if enabled. // Emit "rtpraw" if enabled.
if (this->rtpRawEventEnabled) if (this->rtpRawEventEnabled)
{ {
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
event_data[k_class] = "RtpReceiver"; eventData[k_class] = "RtpReceiver";
this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpraw", event_data, packet->GetData(), packet->GetSize()); this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpraw", eventData,
packet->GetData(), packet->GetSize());
} }
// Emit "rtpobject" is enabled. // Emit "rtpobject" is enabled.
if (this->rtpObjectEventEnabled) if (this->rtpObjectEventEnabled)
{ {
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
Json::Value json_object(Json::objectValue); Json::Value jsonObject(Json::objectValue);
event_data[k_class] = "RtpReceiver"; eventData[k_class] = "RtpReceiver";
json_object[k_payloadType] = (Json::UInt)packet->GetPayloadType(); jsonObject[k_payloadType] = (Json::UInt)packet->GetPayloadType();
json_object[k_marker] = packet->HasMarker(); jsonObject[k_marker] = packet->HasMarker();
json_object[k_sequenceNumber] = (Json::UInt)packet->GetSequenceNumber(); jsonObject[k_sequenceNumber] = (Json::UInt)packet->GetSequenceNumber();
json_object[k_timestamp] = (Json::UInt)packet->GetTimestamp(); jsonObject[k_timestamp] = (Json::UInt)packet->GetTimestamp();
json_object[k_ssrc] = (Json::UInt)packet->GetSsrc(); jsonObject[k_ssrc] = (Json::UInt)packet->GetSsrc();
event_data[k_object] = json_object; eventData[k_object] = jsonObject;
this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpobject", event_data, packet->GetPayload(), packet->GetPayloadLength()); this->notifier->EmitWithBinary(this->rtpReceiverId, "rtpobject", eventData,
packet->GetPayload(), packet->GetPayloadLength());
} }
} }
...@@ -394,16 +395,19 @@ namespace RTC ...@@ -394,16 +395,19 @@ namespace RTC
if (!useNack && fb.type == "nack") if (!useNack && fb.type == "nack")
{ {
MS_DEBUG_TAG(rtcp, "enabling NACK generation"); MS_DEBUG_TAG(rtcp, "enabling NACK generation");
useNack = true; useNack = true;
} }
if (!usePli && fb.type == "nack" && fb.parameter == "pli") if (!usePli && fb.type == "nack" && fb.parameter == "pli")
{ {
MS_DEBUG_TAG(rtcp, "enabling PLI generation"); MS_DEBUG_TAG(rtcp, "enabling PLI generation");
usePli = true; usePli = true;
} }
else if (!useRemb && fb.type == "goog-remb") else if (!useRemb && fb.type == "goog-remb")
{ {
MS_DEBUG_TAG(rbe, "enabling REMB"); MS_DEBUG_TAG(rbe, "enabling REMB");
useRemb = true; useRemb = true;
} }
} }
...@@ -449,14 +453,14 @@ namespace RTC ...@@ -449,14 +453,14 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
} }
void RtpReceiver::onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seq_numbers) void RtpReceiver::onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers)
{ {
if (!this->transport) if (!this->transport)
return; return;
RTC::RTCP::FeedbackRtpNackPacket packet(0, rtpStream->GetSsrc()); RTC::RTCP::FeedbackRtpNackPacket packet(0, rtpStream->GetSsrc());
auto it = seq_numbers.begin(); auto it = seqNumbers.begin();
const auto end = seq_numbers.end(); const auto end = seqNumbers.end();
while (it != end) while (it != end)
{ {
......
...@@ -7,14 +7,13 @@ ...@@ -7,14 +7,13 @@
#include "Utils.hpp" #include "Utils.hpp"
#include "MediaSoupError.hpp" #include "MediaSoupError.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include <unordered_set> #include <vector>
namespace RTC namespace RTC
{ {
/* Class variables. */ /* Static. */
// Can retransmit up to 17 RTP packets. static std::vector<RTC::RtpPacket*> RtpRetransmissionContainer(18);
std::vector<RTC::RtpPacket*> RtpSender::rtpRetransmissionContainer(18);
/* Instance methods. */ /* Instance methods. */
...@@ -49,10 +48,10 @@ namespace RTC ...@@ -49,10 +48,10 @@ namespace RTC
static const Json::StaticString k_class("class"); static const Json::StaticString k_class("class");
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
event_data[k_class] = "RtpSender"; eventData[k_class] = "RtpSender";
this->notifier->Emit(this->rtpSenderId, "close", event_data); this->notifier->Emit(this->rtpSenderId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->onRtpSenderClosed(this); this->listener->onRtpSenderClosed(this);
...@@ -64,7 +63,6 @@ namespace RTC ...@@ -64,7 +63,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpSenderId("rtpSenderId"); static const Json::StaticString k_rtpSenderId("rtpSenderId");
static const Json::StaticString k_kind("kind"); static const Json::StaticString k_kind("kind");
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
...@@ -82,7 +80,7 @@ namespace RTC ...@@ -82,7 +80,7 @@ namespace RTC
if (this->rtpParameters) if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson(); json[k_rtpParameters] = this->rtpParameters->toJson();
else else
json[k_rtpParameters] = null_data; json[k_rtpParameters] = Json::nullValue;
json[k_hasTransport] = this->transport ? true : false; json[k_hasTransport] = this->transport ? true : false;
...@@ -133,6 +131,7 @@ namespace RTC ...@@ -133,6 +131,7 @@ namespace RTC
if (this->disabled == disabled) if (this->disabled == disabled)
{ {
request->Accept(); request->Accept();
return; return;
} }
...@@ -271,13 +270,13 @@ namespace RTC ...@@ -271,13 +270,13 @@ namespace RTC
// Emit "parameterschange" if these are updated parameters. // Emit "parameterschange" if these are updated parameters.
if (hadParameters) if (hadParameters)
{ {
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
event_data[k_class] = "RtpSender"; eventData[k_class] = "RtpSender";
event_data[k_rtpParameters] = this->rtpParameters->toJson(); eventData[k_rtpParameters] = this->rtpParameters->toJson();
event_data[k_active] = this->GetActive(); eventData[k_active] = this->GetActive();
this->notifier->Emit(this->rtpSenderId, "parameterschange", event_data); this->notifier->Emit(this->rtpSenderId, "parameterschange", eventData);
} }
} }
...@@ -295,7 +294,8 @@ namespace RTC ...@@ -295,7 +294,8 @@ namespace RTC
// RTP parameters. // RTP parameters.
if (packet->GetSsrc() != this->rtpParameters->encodings[0].ssrc) if (packet->GetSsrc() != this->rtpParameters->encodings[0].ssrc)
{ {
MS_WARN_TAG(rtp, "ignoring packet with unknown SSRC [ssrc:%" PRIu32 "]", packet->GetSsrc()); MS_WARN_TAG(rtp, "ignoring packet with unknown SSRC [ssrc:%" PRIu32 "]",
packet->GetSsrc());
return; return;
} }
...@@ -348,7 +348,8 @@ namespace RTC ...@@ -348,7 +348,8 @@ namespace RTC
// Build SDES chunk for this sender. // Build SDES chunk for this sender.
RTC::RTCP::SdesChunk *sdesChunk = new RTC::RTCP::SdesChunk(ssrc); RTC::RTCP::SdesChunk *sdesChunk = new RTC::RTCP::SdesChunk(ssrc);
RTC::RTCP::SdesItem *sdesItem = new RTC::RTCP::SdesItem(RTC::RTCP::SdesItem::Type::CNAME, cname.size(), cname.c_str()); RTC::RTCP::SdesItem *sdesItem =
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);
...@@ -371,11 +372,12 @@ namespace RTC ...@@ -371,11 +372,12 @@ namespace RTC
{ {
RTC::RTCP::FeedbackRtpNackItem* item = *it; RTC::RTCP::FeedbackRtpNackItem* item = *it;
this->rtpStream->RequestRtpRetransmission(item->GetPacketId(), item->GetLostPacketBitmask(), RtpSender::rtpRetransmissionContainer); this->rtpStream->RequestRtpRetransmission(item->GetPacketId(), item->GetLostPacketBitmask(), RtpRetransmissionContainer);
for (auto it = RtpSender::rtpRetransmissionContainer.begin(); it != RtpSender::rtpRetransmissionContainer.end(); ++it) auto it2 = RtpRetransmissionContainer.begin();
for (; it2 != RtpRetransmissionContainer.end(); ++it2)
{ {
RTC::RtpPacket* packet = *it; RTC::RtpPacket* packet = *it2;
if (packet == nullptr) if (packet == nullptr)
break; break;
...@@ -415,11 +417,13 @@ namespace RTC ...@@ -415,11 +417,13 @@ namespace RTC
if (!useNack && fb.type == "nack") if (!useNack && fb.type == "nack")
{ {
MS_DEBUG_TAG(rtcp, "enabling NACK reception"); MS_DEBUG_TAG(rtcp, "enabling NACK reception");
useNack = true; useNack = true;
} }
if (!usePli && fb.type == "nack" && fb.parameter == "pli") if (!usePli && fb.type == "nack" && fb.parameter == "pli")
{ {
MS_DEBUG_TAG(rtcp, "enabling PLI reception"); MS_DEBUG_TAG(rtcp, "enabling PLI reception");
usePli = true; usePli = true;
} }
} }
...@@ -475,10 +479,11 @@ namespace RTC ...@@ -475,10 +479,11 @@ namespace RTC
static const Json::StaticString k_class("class"); static const Json::StaticString k_class("class");
static const Json::StaticString k_active("active"); static const Json::StaticString k_active("active");
Json::Value event_data(Json::objectValue); Json::Value eventData(Json::objectValue);
eventData[k_class] = "RtpSender";
eventData[k_active] = this->GetActive();
event_data[k_class] = "RtpSender"; this->notifier->Emit(this->rtpSenderId, "activechange", eventData);
event_data[k_active] = this->GetActive();
this->notifier->Emit(this->rtpSenderId, "activechange", event_data);
} }
} }
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#define MIN_SEQUENTIAL 0
#define MAX_DROPOUT 3000
#define MAX_MISORDER 100
#define RTP_SEQ_MOD (1<<16)
namespace RTC namespace RTC
{ {
/* Static. */
static constexpr uint32_t MinSequential = 0;
static constexpr uint16_t MaxDropout = 3000;
static constexpr uint16_t MaxMisorder = 100;
static constexpr uint32_t RtpSeqMod = 1<<16;
/* Instance methods. */ /* Instance methods. */
RtpStream::RtpStream(RTC::RtpStream::Params& params) : RtpStream::RtpStream(RTC::RtpStream::Params& params) :
...@@ -37,8 +39,8 @@ namespace RTC ...@@ -37,8 +39,8 @@ namespace RTC
{ {
InitSeq(seq); InitSeq(seq);
this->started = true; this->started = true;
this->max_seq = seq - 1; this->maxSeq = seq - 1;
this->probation = MIN_SEQUENTIAL; this->probation = MinSequential;
} }
// If not a valid packet ignore it. // If not a valid packet ignore it.
...@@ -59,8 +61,8 @@ namespace RTC ...@@ -59,8 +61,8 @@ namespace RTC
this->cycles + (uint32_t)packet->GetSequenceNumber()); this->cycles + (uint32_t)packet->GetSequenceNumber());
// Update highest seen RTP timestamp. // Update highest seen RTP timestamp.
if (packet->GetTimestamp() > this->max_timestamp) if (packet->GetTimestamp() > this->maxTimestamp)
this->max_timestamp = packet->GetTimestamp(); this->maxTimestamp = packet->GetTimestamp();
return true; return true;
} }
...@@ -70,15 +72,15 @@ namespace RTC ...@@ -70,15 +72,15 @@ namespace RTC
MS_TRACE(); MS_TRACE();
// Initialize/reset RTP counters. // Initialize/reset RTP counters.
this->base_seq = seq; this->baseSeq = seq;
this->max_seq = seq; this->maxSeq = seq;
this->bad_seq = RTP_SEQ_MOD + 1; // So seq == bad_seq is false. this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false.
this->cycles = 0; this->cycles = 0;
this->received = 0; this->received = 0;
this->received_prior = 0; this->receivedPrior = 0;
this->expected_prior = 0; this->expectedPrior = 0;
// Also reset the highest seen RTP timestamp. // Also reset the highest seen RTP timestamp.
this->max_timestamp = 0; this->maxTimestamp = 0;
// Call the onInitSeq method of the child. // Call the onInitSeq method of the child.
onInitSeq(); onInitSeq();
...@@ -89,19 +91,19 @@ namespace RTC ...@@ -89,19 +91,19 @@ namespace RTC
MS_TRACE(); MS_TRACE();
uint16_t seq = packet->GetSequenceNumber(); uint16_t seq = packet->GetSequenceNumber();
uint16_t udelta = seq - this->max_seq; uint16_t udelta = seq - this->maxSeq;
/* /*
* Source is not valid until MIN_SEQUENTIAL packets with * Source is not valid until MinSequential packets with
* sequential sequence numbers have been received. * sequential sequence numbers have been received.
*/ */
if (this->probation) if (this->probation)
{ {
// Packet is in sequence. // Packet is in sequence.
if (seq == this->max_seq + 1) if (seq == this->maxSeq + 1)
{ {
this->probation--; this->probation--;
this->max_seq = seq; this->maxSeq = seq;
if (this->probation == 0) if (this->probation == 0)
{ {
...@@ -113,27 +115,27 @@ namespace RTC ...@@ -113,27 +115,27 @@ namespace RTC
} }
else else
{ {
this->probation = MIN_SEQUENTIAL - 1; this->probation = MinSequential - 1;
this->max_seq = seq; this->maxSeq = seq;
} }
return false; return false;
} }
else if (udelta < MAX_DROPOUT) else if (udelta < MaxDropout)
{ {
// In order, with permissible gap. // In order, with permissible gap.
if (seq < this->max_seq) if (seq < this->maxSeq)
{ {
// Sequence number wrapped: count another 64K cycle. // Sequence number wrapped: count another 64K cycle.
this->cycles += RTP_SEQ_MOD; this->cycles += RtpSeqMod;
} }
this->max_seq = seq; this->maxSeq = seq;
} }
else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) else if (udelta <= RtpSeqMod - MaxMisorder)
{ {
// The sequence number made a very large jump. // The sequence number made a very large jump.
if (seq == this->bad_seq) if (seq == this->badSeq)
{ {
/* /*
* Two sequential packets -- assume that the other side * Two sequential packets -- assume that the other side
...@@ -152,7 +154,7 @@ namespace RTC ...@@ -152,7 +154,7 @@ namespace RTC
"bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", "bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSequenceNumber()); packet->GetSsrc(), packet->GetSequenceNumber());
this->bad_seq = (seq + 1) & (RTP_SEQ_MOD - 1); this->badSeq = (seq + 1) & (RtpSeqMod - 1);
return false; return false;
} }
......
...@@ -35,7 +35,7 @@ namespace RTC ...@@ -35,7 +35,7 @@ namespace RTC
json[k_params] = this->params.toJson(); json[k_params] = this->params.toJson();
json[k_received] = (Json::UInt)this->received; json[k_received] = (Json::UInt)this->received;
json[k_maxTimestamp] = (Json::UInt)this->max_timestamp; json[k_maxTimestamp] = (Json::UInt)this->maxTimestamp;
json[k_transit] = (Json::UInt)this->transit; json[k_transit] = (Json::UInt)this->transit;
json[k_jitter] = (Json::UInt)this->jitter; json[k_jitter] = (Json::UInt)this->jitter;
...@@ -74,45 +74,44 @@ namespace RTC ...@@ -74,45 +74,44 @@ namespace RTC
RTC::RTCP::ReceiverReport* report = new RTC::RTCP::ReceiverReport(); RTC::RTCP::ReceiverReport* report = new RTC::RTCP::ReceiverReport();
// Calculate Packets Expected and Lost. // Calculate Packets Expected and Lost.
uint32_t expected = (this->cycles + this->max_seq) - this->base_seq + 1; uint32_t expected = (this->cycles + this->maxSeq) - this->baseSeq + 1;
int32_t total_lost = expected - this->received; int32_t totalLost = expected - this->received;
report->SetTotalLost(total_lost); report->SetTotalLost(totalLost);
// Calculate Fraction Lost. // Calculate Fraction Lost.
uint32_t expected_interval = expected - this->expected_prior; uint32_t expectedInterval = expected - this->expectedPrior;
this->expected_prior = expected; this->expectedPrior = expected;
uint32_t received_interval = this->received - this->received_prior; uint32_t receivedInterval = this->received - this->receivedPrior;
this->received_prior = this->received; this->receivedPrior = this->received;
int32_t lost_interval = expected_interval - received_interval; int32_t lostInterval = expectedInterval - receivedInterval;
uint8_t fraction_lost; uint8_t fractionLost;
if (expected_interval == 0 || lost_interval <= 0) if (expectedInterval == 0 || lostInterval <= 0)
fraction_lost = 0; fractionLost = 0;
else else
fraction_lost = (lost_interval << 8) / expected_interval; fractionLost = (lostInterval << 8) / expectedInterval;
report->SetFractionLost(fraction_lost); report->SetFractionLost(fractionLost);
// Fill the rest of the report. // Fill the rest of the report.
report->SetLastSeq((uint32_t)this->max_seq + this->cycles); report->SetLastSeq((uint32_t)this->maxSeq + this->cycles);
report->SetJitter(this->jitter); report->SetJitter(this->jitter);
if (this->last_sr_received) if (this->lastSrReceived)
{ {
// Get delay in milliseconds. // Get delay in milliseconds.
uint32_t delayMs = (DepLibUV::GetTime() - this->last_sr_received); uint32_t delayMs = (DepLibUV::GetTime() - this->lastSrReceived);
// Express delay in units of 1/65536 seconds. // Express delay in units of 1/65536 seconds.
uint32_t dlsr = (delayMs / 1000) << 16; uint32_t dlsr = (delayMs / 1000) << 16;
dlsr |= (uint32_t)((delayMs % 1000) * 65536 / 1000);
dlsr |= (uint32_t)((delayMs % 1000) * 65536 / 1000);
report->SetDelaySinceLastSenderReport(dlsr); report->SetDelaySinceLastSenderReport(dlsr);
report->SetLastSenderReport(this->last_sr_timestamp); report->SetLastSenderReport(this->lastSrTimestamp);
} }
else else
{ {
...@@ -127,9 +126,9 @@ namespace RTC ...@@ -127,9 +126,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
this->last_sr_received = DepLibUV::GetTime(); this->lastSrReceived = DepLibUV::GetTime();
this->last_sr_timestamp = report->GetNtpSec() << 16; this->lastSrTimestamp = report->GetNtpSec() << 16;
this->last_sr_timestamp += report->GetNtpFrac() >> 16; this->lastSrTimestamp += report->GetNtpFrac() >> 16;
} }
void RtpStreamRecv::RequestFullFrame() void RtpStreamRecv::RequestFullFrame()
...@@ -172,14 +171,13 @@ namespace RTC ...@@ -172,14 +171,13 @@ namespace RTC
// If we got out of sync, request a full frame. // If we got out of sync, request a full frame.
if (this->started && this->params.usePli) if (this->started && this->params.usePli)
{ {
MS_DEBUG_TAG(rtx, "triggering PLI [ssrc:%" PRIu32 "]", MS_DEBUG_TAG(rtx, "triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc);
this->params.ssrc);
this->listener->onPliRequired(this); this->listener->onPliRequired(this);
} }
} }
void RtpStreamRecv::onNackRequired(const std::vector<uint16_t>& seq_numbers) void RtpStreamRecv::onNackRequired(const std::vector<uint16_t>& seqNumbers)
{ {
MS_TRACE(); MS_TRACE();
...@@ -187,9 +185,9 @@ namespace RTC ...@@ -187,9 +185,9 @@ namespace RTC
MS_WARN_TAG(rtx, MS_WARN_TAG(rtx,
"triggering NACK [ssrc:%" PRIu32 ", first_seq:%" PRIu16 ", num_packets:%zu]", "triggering NACK [ssrc:%" PRIu32 ", first_seq:%" PRIu16 ", num_packets:%zu]",
this->params.ssrc, seq_numbers[0], seq_numbers.size()); this->params.ssrc, seqNumbers[0], seqNumbers.size());
this->listener->onNackRequired(this, seq_numbers); this->listener->onNackRequired(this, seqNumbers);
} }
void RtpStreamRecv::onFullFrameRequired() void RtpStreamRecv::onFullFrameRequired()
...@@ -203,8 +201,7 @@ namespace RTC ...@@ -203,8 +201,7 @@ namespace RTC
return; return;
} }
MS_DEBUG_TAG(rtx, MS_DEBUG_TAG(rtx, "triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc);
"triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc);
this->listener->onPliRequired(this); this->listener->onPliRequired(this);
} }
......
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
namespace RTC namespace RTC
{ {
/* Class variables. */ /* Static. */
uint8_t SrtpSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE]; static constexpr size_t EncryptBufferSize = 65536;
static uint8_t EncryptBuffer[EncryptBufferSize];
/* Class methods. */ /* Class methods. */
...@@ -51,7 +52,7 @@ namespace RTC ...@@ -51,7 +52,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
SrtpSession::SrtpSession(Type type, Profile profile, uint8_t* key, size_t key_len) SrtpSession::SrtpSession(Type type, Profile profile, uint8_t* key, size_t keyLen)
{ {
MS_TRACE(); MS_TRACE();
...@@ -75,7 +76,8 @@ namespace RTC ...@@ -75,7 +76,8 @@ namespace RTC
MS_ABORT("unknown SRTP suite"); MS_ABORT("unknown SRTP suite");
} }
MS_ASSERT((int)key_len == policy.rtp.cipher_key_len, "given key_len does not match policy.rtp.cipher_key_len"); MS_ASSERT((int)keyLen == policy.rtp.cipher_key_len,
"given keyLen does not match policy.rtp.cipher_keyLen");
switch (type) switch (type)
{ {
...@@ -91,7 +93,7 @@ namespace RTC ...@@ -91,7 +93,7 @@ namespace RTC
policy.key = key; policy.key = key;
// Required for sending RTP retransmission without RTX. // Required for sending RTP retransmission without RTX.
policy.allow_repeat_tx = 1; policy.allow_repeat_tx = 1;
policy.window_size = 4096; policy.window_size = 2048;
policy.next = nullptr; policy.next = nullptr;
// Set the SRTP session. // Set the SRTP session.
...@@ -133,11 +135,11 @@ namespace RTC ...@@ -133,11 +135,11 @@ namespace RTC
return false; return false;
} }
std::memcpy(SrtpSession::encryptBuffer, *data, *len); std::memcpy(EncryptBuffer, *data, *len);
srtp_err_status_t err; srtp_err_status_t err;
err = srtp_protect(this->session, (void*)SrtpSession::encryptBuffer, (int*)len); err = srtp_protect(this->session, (void*)EncryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
MS_WARN_TAG(srtp, "srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err)); MS_WARN_TAG(srtp, "srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err));
...@@ -146,7 +148,7 @@ namespace RTC ...@@ -146,7 +148,7 @@ namespace RTC
} }
// Update the given data pointer. // Update the given data pointer.
*data = (const uint8_t*)SrtpSession::encryptBuffer; *data = (const uint8_t*)EncryptBuffer;
return true; return true;
} }
...@@ -180,11 +182,11 @@ namespace RTC ...@@ -180,11 +182,11 @@ namespace RTC
return false; return false;
} }
std::memcpy(SrtpSession::encryptBuffer, *data, *len); std::memcpy(EncryptBuffer, *data, *len);
srtp_err_status_t err; srtp_err_status_t err;
err = srtp_protect_rtcp(this->session, (void*)SrtpSession::encryptBuffer, (int*)len); err = srtp_protect_rtcp(this->session, (void*)EncryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
MS_WARN_TAG(srtp, "srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err)); MS_WARN_TAG(srtp, "srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
...@@ -193,7 +195,7 @@ namespace RTC ...@@ -193,7 +195,7 @@ namespace RTC
} }
// Update the given data pointer. // Update the given data pointer.
*data = (const uint8_t*)SrtpSession::encryptBuffer; *data = (const uint8_t*)EncryptBuffer;
return true; return true;
} }
......
...@@ -22,8 +22,7 @@ namespace RTC ...@@ -22,8 +22,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]", MS_DEBUG_DEV("data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
GetLocalIP().c_str(), GetLocalPort(), GetLocalIP().c_str(), GetLocalPort(), GetPeerIP().c_str(), GetPeerPort());
GetPeerIP().c_str(), GetPeerPort());
/* /*
* Framing RFC 4571 * Framing RFC 4571
......
差异被折叠。
...@@ -87,15 +87,22 @@ namespace Utils ...@@ -87,15 +87,22 @@ namespace Utils
int ret; int ret;
ret = HMAC_Init_ex(&Crypto::hmacSha1Ctx, key.c_str(), key.length(), EVP_sha1(), nullptr); ret = HMAC_Init_ex(&Crypto::hmacSha1Ctx, key.c_str(), key.length(), EVP_sha1(), nullptr);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Init_ex() failed with key '%s'", key.c_str()); MS_ASSERT(ret == 1, "OpenSSL HMAC_Init_ex() failed with key '%s'", key.c_str());
ret = HMAC_Update(&Crypto::hmacSha1Ctx, (const uint8_t*)data, (int)len); ret = HMAC_Update(&Crypto::hmacSha1Ctx, (const uint8_t*)data, (int)len);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes", key.c_str(), len);
uint32_t result_len; MS_ASSERT(ret == 1, "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes",
ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t *)Crypto::hmacSha1Buffer, &result_len); key.c_str(), len);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes", key.c_str(), len);
MS_ASSERT(result_len == 20, "OpenSSL HMAC_Final() result_len is %u instead of 20", result_len); uint32_t resultLen;
ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t *)Crypto::hmacSha1Buffer, &resultLen);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes",
key.c_str(), len);
MS_ASSERT(resultLen == 20, "OpenSSL HMAC_Final() resultLen is %u instead of 20",
resultLen);
return Crypto::hmacSha1Buffer; return Crypto::hmacSha1Buffer;
} }
......
...@@ -14,16 +14,16 @@ namespace Utils ...@@ -14,16 +14,16 @@ namespace Utils
{ {
MS_TRACE(); MS_TRACE();
struct stat file_stat; struct stat fileStat;
int err; int err;
// Ensure the given file exists. // Ensure the given file exists.
err = stat(file, &file_stat); err = stat(file, &fileStat);
if (err) if (err)
MS_THROW_ERROR("cannot read file '%s': %s", file, std::strerror(errno)); MS_THROW_ERROR("cannot read file '%s': %s", file, std::strerror(errno));
// Ensure it is a regular file. // Ensure it is a regular file.
if (!S_ISREG(file_stat.st_mode)) if (!S_ISREG(fileStat.st_mode))
MS_THROW_ERROR("'%s' is not a regular file", file); MS_THROW_ERROR("'%s' is not a regular file", file);
// Ensure it is readable. // Ensure it is readable.
......
差异被折叠。
...@@ -11,7 +11,7 @@ namespace Utils ...@@ -11,7 +11,7 @@ namespace Utils
{ {
MS_TRACE(); MS_TRACE();
int ip_family = 0; int ipFamily = 0;
/** /**
* Ragel: machine definition. * Ragel: machine definition.
...@@ -23,12 +23,12 @@ namespace Utils ...@@ -23,12 +23,12 @@ namespace Utils
action on_ipv4 action on_ipv4
{ {
ip_family = AF_INET; ipFamily = AF_INET;
} }
action on_ipv6 action on_ipv6
{ {
ip_family = AF_INET6; ipFamily = AF_INET6;
} }
include grammar "grammar.rl"; include grammar "grammar.rl";
...@@ -64,7 +64,7 @@ namespace Utils ...@@ -64,7 +64,7 @@ namespace Utils
// Ensure that the parsing has consumed all the given length. // Ensure that the parsing has consumed all the given length.
if (ip_len == (size_t)(p - (const unsigned char*)ip)) if (ip_len == (size_t)(p - (const unsigned char*)ip))
return ip_family; return ipFamily;
else else
return AF_UNSPEC; return AF_UNSPEC;
} }
...@@ -80,9 +80,12 @@ namespace Utils ...@@ -80,9 +80,12 @@ namespace Utils
{ {
case AF_INET: case AF_INET:
{ {
err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, INET_ADDRSTRLEN); err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip,
INET_ADDRSTRLEN);
if (err) if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (uint16_t)ntohs(((struct sockaddr_in*)addr)->sin_port); *port = (uint16_t)ntohs(((struct sockaddr_in*)addr)->sin_port);
break; break;
...@@ -90,9 +93,12 @@ namespace Utils ...@@ -90,9 +93,12 @@ namespace Utils
case AF_INET6: case AF_INET6:
{ {
err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, INET6_ADDRSTRLEN); err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip,
INET6_ADDRSTRLEN);
if (err) if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err)); MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (uint16_t)ntohs(((struct sockaddr_in6*)addr)->sin6_port); *port = (uint16_t)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
break; break;
......
...@@ -36,6 +36,7 @@ int main(int argc, char* argv[]) ...@@ -36,6 +36,7 @@ int main(int argc, char* argv[])
if (argc == 1 || !std::getenv("MEDIASOUP_CHANNEL_FD")) if (argc == 1 || !std::getenv("MEDIASOUP_CHANNEL_FD"))
{ {
std::cerr << "ERROR: you don't seem to be my real father" << std::endl; std::cerr << "ERROR: you don't seem to be my real father" << std::endl;
std::_Exit(EXIT_FAILURE); std::_Exit(EXIT_FAILURE);
} }
...@@ -68,19 +69,19 @@ int main(int argc, char* argv[]) ...@@ -68,19 +69,19 @@ int main(int argc, char* argv[])
MS_DEBUG_TAG(info, "starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid()); MS_DEBUG_TAG(info, "starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid());
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
MS_DEBUG_TAG(info, "Little-Endian CPU detected"); MS_DEBUG_TAG(info, "Little-Endian CPU detected");
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
MS_DEBUG_TAG(info, "Big-Endian CPU detected"); MS_DEBUG_TAG(info, "Big-Endian CPU detected");
#endif #endif
#if defined(INTPTR_MAX) && defined(INT32_MAX) && (INTPTR_MAX == INT32_MAX) #if defined(INTPTR_MAX) && defined(INT32_MAX) && (INTPTR_MAX == INT32_MAX)
MS_DEBUG_TAG(info, "32 bits architecture detected"); MS_DEBUG_TAG(info, "32 bits architecture detected");
#elif defined(INTPTR_MAX) && defined(INT64_MAX) && (INTPTR_MAX == INT64_MAX) #elif defined(INTPTR_MAX) && defined(INT64_MAX) && (INTPTR_MAX == INT64_MAX)
MS_DEBUG_TAG(info, "64 bits architecture detected"); MS_DEBUG_TAG(info, "64 bits architecture detected");
#else #else
MS_WARN_TAG(info, "can not determine whether the architecture is 32 or 64 bits"); MS_WARN_TAG(info, "can not determine whether the architecture is 32 or 64 bits");
#endif #endif
try try
{ {
...@@ -95,9 +96,9 @@ int main(int argc, char* argv[]) ...@@ -95,9 +96,9 @@ int main(int argc, char* argv[])
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
destroy();
MS_ERROR_STD("failure exit: %s", error.what()); MS_ERROR_STD("failure exit: %s", error.what());
destroy();
exitWithError(); exitWithError();
} }
} }
...@@ -107,7 +108,6 @@ void init() ...@@ -107,7 +108,6 @@ void init()
MS_TRACE(); MS_TRACE();
ignoreSignals(); ignoreSignals();
DepLibUV::PrintVersion(); DepLibUV::PrintVersion();
// Initialize static stuff. // Initialize static stuff.
...@@ -127,7 +127,7 @@ void ignoreSignals() ...@@ -127,7 +127,7 @@ void ignoreSignals()
int err; int err;
struct sigaction act; struct sigaction act;
std::map<std::string, int> ignored_signals = std::map<std::string, int> ignoredSignals =
{ {
{ "PIPE", SIGPIPE }, { "PIPE", SIGPIPE },
{ "HUP", SIGHUP }, { "HUP", SIGHUP },
...@@ -142,14 +142,17 @@ void ignoreSignals() ...@@ -142,14 +142,17 @@ void ignoreSignals()
if (err) if (err)
MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno)); MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno));
for (auto it = ignored_signals.begin(); it != ignored_signals.end(); ++it) for (auto it = ignoredSignals.begin(); it != ignoredSignals.end(); ++it)
{ {
auto& sig_name = it->first; auto& sigName = it->first;
int sig_id = it->second; int sigId = it->second;
err = sigaction(sig_id, &act, nullptr); err = sigaction(sigId, &act, nullptr);
if (err) if (err)
MS_THROW_ERROR("sigaction() failed for signal %s: %s", sig_name.c_str(), std::strerror(errno)); {
MS_THROW_ERROR("sigaction() failed for signal %s: %s",
sigName.c_str(), std::strerror(errno));
}
} }
} }
...@@ -169,7 +172,6 @@ void exitSuccess() ...@@ -169,7 +172,6 @@ void exitSuccess()
{ {
// Wait a bit so peding messages to stdout/Channel arrive to the main process. // Wait a bit so peding messages to stdout/Channel arrive to the main process.
usleep(100000); usleep(100000);
// And exit with success status. // And exit with success status.
std::_Exit(EXIT_SUCCESS); std::_Exit(EXIT_SUCCESS);
} }
...@@ -178,7 +180,6 @@ void exitWithError() ...@@ -178,7 +180,6 @@ void exitWithError()
{ {
// Wait a bit so peding messages to stderr arrive to the main process. // Wait a bit so peding messages to stderr arrive to the main process.
usleep(100000); usleep(100000);
// And exit with error status. // And exit with error status.
std::_Exit(EXIT_FAILURE); std::_Exit(EXIT_FAILURE);
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论