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