Skip to content

Commit

Permalink
Little optimizations and modernization (#916)
Browse files Browse the repository at this point in the history
Little optimizations and modernization
  • Loading branch information
jmillan authored Sep 30, 2022
1 parent bd1b434 commit f4b3558
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 49 deletions.
2 changes: 1 addition & 1 deletion worker/fuzzer/src/RTC/FuzzerRtpStreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Fuzzer::RTC::RtpStreamSend::Fuzz(const uint8_t* data, size_t len)
packet->SetSsrc(params.ssrc);

std::string mid;
::RTC::RtpStreamSend* stream = new ::RTC::RtpStreamSend(&testRtpStreamListener, params, mid);
auto* stream = new ::RTC::RtpStreamSend(&testRtpStreamListener, params, mid);

while (len >= 4u)
{
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/DtlsTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace RTC
{
return DtlsTransport::localFingerprints;
}
bool SetRemoteFingerprint(Fingerprint fingerprint);
bool SetRemoteFingerprint(const Fingerprint& fingerprint);
void ProcessDtlsData(const uint8_t* data, size_t len);
DtlsState GetState() const
{
Expand Down
12 changes: 6 additions & 6 deletions worker/src/RTC/ActiveSpeakerObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ namespace RTC
dominantSpeaker->EvalActivityScores();
double newDominantC2 = C2;

for (auto it = this->mapProducerSpeaker.begin(); it != this->mapProducerSpeaker.end(); ++it)
for (const auto& it : this->mapProducerSpeaker)
{
Speaker* speaker = it->second.speaker;
const std::string& id = it->second.producer->id;
Speaker* speaker = it.second.speaker;
const std::string& id = it.second.producer->id;

if (id == this->dominantId || speaker->paused)
{
Expand Down Expand Up @@ -351,10 +351,10 @@ namespace RTC
{
MS_TRACE();

for (auto it = this->mapProducerSpeaker.begin(); it != this->mapProducerSpeaker.end(); ++it)
for (const auto& it : this->mapProducerSpeaker)
{
Speaker* speaker = it->second.speaker;
const std::string& id = it->second.producer->id;
Speaker* speaker = it.second.speaker;
const std::string& id = it.second.producer->id;
uint64_t idle = now - speaker->lastLevelChangeTime;

if (SpeakerIdleTimeout < idle && (this->dominantId.empty() || id != this->dominantId))
Expand Down
4 changes: 2 additions & 2 deletions worker/src/RTC/DataConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace RTC
// Trigger 'bufferedamountlow' now.
if (this->bufferedAmount <= this->bufferedAmountLowThreshold)
{
std::string data("{\"bufferedAmount\":\"");
std::string data(R"({"bufferedAmount":")");

data.append(std::to_string(this->bufferedAmount));
data.append("\"}");
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace RTC
this->forceTriggerBufferedAmountLow = false;

// Notify the Node DataConsumer.
std::string data("{\"bufferedAmount\":\"");
std::string data(R"({"bufferedAmount":")");

data.append(std::to_string(this->bufferedAmount));
data.append("\"}");
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/DtlsTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ namespace RTC
}
}

bool DtlsTransport::SetRemoteFingerprint(Fingerprint fingerprint)
bool DtlsTransport::SetRemoteFingerprint(const Fingerprint& fingerprint)
{
MS_TRACE();

Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/RTCP/FeedbackRtpTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace RTC
}

size_t deltaIdx{ 0u };
int64_t currentReceivedAtMs = static_cast<int64_t>(this->referenceTime * 64);
auto currentReceivedAtMs = static_cast<int64_t>(this->referenceTime * 64);

for (size_t idx{ 0u }; idx < packetResults.size(); ++idx)
{
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/RtpPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ namespace RTC
MS_ASSERT(shift <= (this->payloadLength - payloadOffset), "shift too big");

uint8_t* payloadOffsetPtr = this->payload + payloadOffset;
size_t shiftedLen;
size_t shiftedLen{ 0 };

if (expand)
{
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ namespace RTC
auto nowMs = DepLibUV::GetTimeMs();
uint32_t desiredBitrate{ 0u };

for (int sIdx{ static_cast<int>(this->producerRtpStreams.size()) - 1 }; sIdx >= 0; --sIdx)
for (size_t sIdx{ this->producerRtpStreams.size() - 1 }; sIdx >= 0; --sIdx)
{
auto* producerRtpStream = this->producerRtpStreams.at(sIdx);

Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace RTC
TcpServer::TcpServer(Listener* listener, RTC::TcpConnection::Listener* connListener, std::string& ip)
: // This may throw.
::TcpServerHandler::TcpServerHandler(RTC::PortManager::BindTcp(ip)), listener(listener),
connListener(connListener), fixedPort(false)
connListener(connListener)
{
MS_TRACE();
}
Expand Down
3 changes: 1 addition & 2 deletions worker/src/RTC/UdpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace RTC

UdpSocket::UdpSocket(Listener* listener, std::string& ip)
: // This may throw.
::UdpSocketHandler::UdpSocketHandler(PortManager::BindUdp(ip)), listener(listener),
fixedPort(false)
::UdpSocketHandler::UdpSocketHandler(PortManager::BindUdp(ip)), listener(listener)
{
MS_TRACE();
}
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/WebRtcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ namespace RTC
// before the ":" symbol.

auto& username = packet->GetUsername();
size_t colonPos = username.find(":");
size_t colonPos = username.find(':');

// If no colon is found just return the whole USERNAME attribute anyway.
if (colonPos == std::string::npos)
Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestBye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace TestBye
{
REQUIRE(packet->GetReason() == reason);

ByePacket::Iterator it = packet->Begin();
auto it = packet->Begin();

REQUIRE(*it == ssrc1);

Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SCENARIO("RTCP Feedback PS FIR parsing", "[parser][rtcp][feedback-ps][fir]")
{
FeedbackPsFirPacket packet(senderSsrc, mediaSsrc);

FeedbackPsFirItem* item = new FeedbackPsFirItem(ssrc, seq);
auto* item = new FeedbackPsFirItem(ssrc, seq);

packet.AddItem(item);

Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SCENARIO("RTCP Feedback PS LEI parsing", "[parser][rtcp][feedback-ps][lei]")
{
FeedbackPsLeiPacket packet(senderSsrc, mediaSsrc);

FeedbackPsLeiItem* item = new FeedbackPsLeiItem(ssrc);
auto* item = new FeedbackPsLeiItem(ssrc);

packet.AddItem(item);

Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SCENARIO("RTCP Feedback PS TSTN parsing", "[parser][rtcp][feedback-ps][tstn]")
{
FeedbackPsTstnPacket packet(senderSsrc, mediaSsrc);

FeedbackPsTstnItem* item = new FeedbackPsTstnItem(ssrc, seq, TestFeedbackPsTstn::index);
auto* item = new FeedbackPsTstnItem(ssrc, seq, TestFeedbackPsTstn::index);

packet.AddItem(item);

Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SCENARIO("RTCP Feeback RTP NACK parsing", "[parser][rtcp][feedback-rtp][nack]")
SECTION("create FeedbackRtpNackPacket")
{
FeedbackRtpNackPacket packet(senderSsrc, mediaSsrc);
FeedbackRtpNackItem* item = new FeedbackRtpNackItem(pid, lostPacketBitmask);
auto* item = new FeedbackRtpNackItem(pid, lostPacketBitmask);

packet.AddItem(item);

Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SCENARIO("RTCP Feeback RTP TMMBR parsing", "[parser][rtcp][feedback-rtp][tmmb]")
SECTION("create FeedbackRtpTmmbrPacket")
{
FeedbackRtpTmmbrPacket packet(senderSsrc, mediaSsrc);
FeedbackRtpTmmbrItem* item = new FeedbackRtpTmmbrItem();
auto* item = new FeedbackRtpTmmbrItem();

item->SetSsrc(ssrc);
item->SetBitrate(bitrate);
Expand Down
7 changes: 2 additions & 5 deletions worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
FeedbackRtpTransportPacket::TimeWrapPeriod +
static_cast<int64_t>(12408746) * FeedbackRtpTransportPacket::BaseTimeTick);

// Let's also test the reference time reported by Wireshark.
int32_t wiresharkValue{ 12408746 };

REQUIRE(packet->GetFeedbackPacketCount() == 0);

SECTION("serialize packet")
Expand All @@ -577,15 +574,15 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"

SECTION("parse FeedbackRtpTransportPacket generated by Chrome with libwebrtc as a reference")
{
typedef struct
using FeedbackPacketsMeta = struct
{
uint32_t baseTimeRaw;
uint64_t baseTimeMs;
uint16_t baseSequence;
size_t packetStatusCount;
std::vector<int16_t> deltas;
std::vector<uint8_t> buffer;
} FeedbackPacketsMeta;
};

// Metadata collected by parsing buffers with libwebrtc, buffers itself.
// were generated by chrome in direction of mediasoup.
Expand Down
2 changes: 1 addition & 1 deletion worker/test/src/RTC/RTCP/TestSdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]")

SECTION("create SdesChunk")
{
SdesItem* item = new SdesItem(type, length, value.c_str());
auto* item = new SdesItem(type, length, value.c_str());

// Create sdes chunk.
SdesChunk chunk(ssrc);
Expand Down
16 changes: 8 additions & 8 deletions worker/test/src/RTC/TestNackGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ class TestPayloadDescriptorHandler : public Codecs::PayloadDescriptorHandler
{
public:
explicit TestPayloadDescriptorHandler(bool isKeyFrame) : isKeyFrame(isKeyFrame){};
~TestPayloadDescriptorHandler() = default;
void Dump() const
~TestPayloadDescriptorHandler() override = default;
void Dump() const override
{
return;
};
bool Process(Codecs::EncodingContext* /*context*/, uint8_t* /*data*/, bool& /*marker*/)
bool Process(Codecs::EncodingContext* /*context*/, uint8_t* /*data*/, bool& /*marker*/) override
{
return true;
};
void Restore(uint8_t* /*data*/)
void Restore(uint8_t* /*data*/) override
{
return;
};
uint8_t GetSpatialLayer() const
uint8_t GetSpatialLayer() const override
{
return 0;
};
uint8_t GetTemporalLayer() const
uint8_t GetTemporalLayer() const override
{
return 0;
};
bool IsKeyFrame() const
bool IsKeyFrame() const override
{
return this->isKeyFrame;
};
Expand Down Expand Up @@ -129,7 +129,7 @@ void validate(std::vector<TestNackGeneratorInput>& inputs)
{
listener.Reset(input);

TestPayloadDescriptorHandler* tpdh = new TestPayloadDescriptorHandler(input.isKeyFrame);
auto* tpdh = new TestPayloadDescriptorHandler(input.isKeyFrame);

packet->SetPayloadDescriptorHandler(tpdh);
packet->SetSequenceNumber(input.seq);
Expand Down
5 changes: 2 additions & 3 deletions worker/test/src/RTC/TestRateCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ struct data

void validate(RateCalculator& rate, uint64_t timeBase, std::vector<data>& input)
{
for (auto it = input.begin(); it != input.end(); ++it)
for (auto& item : input)
{
auto& item = *it;

rate.Update(item.size, timeBase + item.offset);

REQUIRE(rate.GetRate(timeBase + item.offset) == item.rate);
}
}
Expand Down
16 changes: 8 additions & 8 deletions worker/test/src/RTC/TestRtpStreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);

// Receive all the packets (some of them not in order and/or duplicated).
SendRtpPacket({ { stream, params.ssrc } }, packet1);
Expand Down Expand Up @@ -164,7 +164,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);

// Receive all the packets (some of them not in order and/or duplicated).
SendRtpPacket({ { stream, params.ssrc } }, packet1);
Expand Down Expand Up @@ -217,7 +217,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params.mimeType.type = RTC::RtpCodecMimeType::Type::AUDIO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);

// Receive all the packets (some of them not in order and/or duplicated).
SendRtpPacket({ { stream, params.ssrc } }, packet1);
Expand Down Expand Up @@ -265,7 +265,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream1 = new RtpStreamSend(&testRtpStreamListener1, params1, mid);
auto* stream1 = new RtpStreamSend(&testRtpStreamListener1, params1, mid);

RtpStream::Params params2;

Expand All @@ -274,7 +274,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params2.useNack = true;
params2.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

RtpStreamSend* stream2 = new RtpStreamSend(&testRtpStreamListener2, params2, mid);
auto* stream2 = new RtpStreamSend(&testRtpStreamListener2, params2, mid);

// Receive all the packets in both streams.
SendRtpPacket({ { stream1, params1.ssrc }, { stream2, params2.ssrc } }, packet1);
Expand Down Expand Up @@ -340,7 +340,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener1, params1, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener1, params1, mid);

// Receive all the packets.
SendRtpPacket({ { stream, params1.ssrc } }, packet1);
Expand Down Expand Up @@ -392,7 +392,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener1, params1, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener1, params1, mid);

// Receive all the packets.
SendRtpPacket({ { stream, params1.ssrc } }, packet1);
Expand Down Expand Up @@ -435,7 +435,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]")
params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO;

std::string mid;
RtpStreamSend* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);
auto* stream = new RtpStreamSend(&testRtpStreamListener, params, mid);

size_t iterations = 10000000;

Expand Down

0 comments on commit f4b3558

Please sign in to comment.