Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Apr 26, 2024
1 parent 3eddec2 commit fa538f7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 62 deletions.
19 changes: 0 additions & 19 deletions include/rtc/rtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,25 +354,6 @@ struct RTC_CPP_EXPORT RtpRtx {
size_t copyTo(RtpHeader *dest, size_t totalSize, uint8_t originalPayloadType);
};

// For backward compatibility, do not use
using RTP_ExtensionHeader [[deprecated]] = RtpExtensionHeader;
using RTP [[deprecated]] = RtpHeader;
using RTCP_ReportBlock [[deprecated]] = RtcpReportBlock;
using RTCP_HEADER [[deprecated]] = RtcpHeader;
using RTCP_FB_HEADER [[deprecated]] = RtcpFbHeader;
using RTCP_SR [[deprecated]] = RtcpSr;
using RTCP_SDES_ITEM [[deprecated]] = RtcpSdesItem;
using RTCP_SDES_CHUNK [[deprecated]] = RtcpSdesChunk;
using RTCP_SDES [[deprecated]] = RtcpSdes;
using RTCP_RR [[deprecated]] = RtcpRr;
using RTCP_REMB [[deprecated]] = RtcpRemb;
using RTCP_PLI [[deprecated]] = RtcpPli;
using RTCP_FIR_PART [[deprecated]] = RtcpFirPart;
using RTCP_FIR [[deprecated]] = RtcpFir;
using RTCP_NACK_PART [[deprecated]] = RtcpNackPart;
using RTCP_NACK [[deprecated]] = RtcpNack;
using RTP_RTX [[deprecated]] = RtpRtx;

#pragma pack(pop)

} // namespace rtc
Expand Down
4 changes: 2 additions & 2 deletions src/h264rtpdepacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ message_vector H264RtpDepacketizer::buildFrames(message_vector::iterator begin,
}

if (!accessUnit.empty()) {
out.emplace_back(make_message(accessUnit.begin(), accessUnit.end(), Message::Binary, 0,
nullptr, frameInfo));
out.emplace_back(
make_message(std::move(accessUnit), Message::Binary, 0, nullptr, frameInfo));
}

return out;
Expand Down
64 changes: 24 additions & 40 deletions src/impl/icetransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,24 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
if (!mAgent)
throw std::runtime_error("Failed to create the ICE agent");

// Filter STUN servers
servers.erase(std::remove_if(servers.begin(), servers.end(),
[](const IceServer &server) {
return server.hostname.empty() ||
server.type != IceServer::Type::Turn;
}),
servers.end());

// Add TURN servers
for (auto &server : servers) {
if (mTURNServersAdded++ >= MAX_TURN_SERVERS_COUNT) {
break;
}

addIceServer(server);
}
for (const auto &server : servers)
if (!server.hostname.empty() && server.type != IceServer::Type::Stun)
addIceServer(server);
}

void IceTransport::addIceServer(IceServer server) {
if (server.hostname.empty() || server.type != IceServer::Type::Turn) {
if (server.hostname.empty())
return;

if (server.type != IceServer::Type::Turn) {
PLOG_WARNING << "Only TURN servers are supported as additional ICE servers";
return;
}

if (mTurnServersAdded >= MAX_TURN_SERVERS_COUNT)
return;

if (server.port == 0)
server.port = 3478; // TURN UDP port

Expand All @@ -168,9 +162,10 @@ void IceTransport::addIceServer(IceServer server) {
turn_server.password = server.password.c_str();
turn_server.port = server.port;

if (juice_add_turn_server(mAgent.get(), &turn_server) != 0) {
if (juice_add_turn_server(mAgent.get(), &turn_server) != 0)
throw std::runtime_error("Failed to add TURN server");
}

++mTurnServersAdded;
}

IceTransport::~IceTransport() {
Expand Down Expand Up @@ -229,15 +224,10 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) {

void IceTransport::gatherLocalCandidates(string mid, std::vector<IceServer> additionalIceServers) {
mMid = std::move(mid);
std::shuffle(additionalIceServers.begin(), additionalIceServers.end(), utils::random_engine());

for (auto &server : additionalIceServers) {
if (mTURNServersAdded++ >= MAX_TURN_SERVERS_COUNT) {
break;
}

std::shuffle(additionalIceServers.begin(), additionalIceServers.end(), utils::random_engine());
for (const auto &server : additionalIceServers)
addIceServer(server);
}

// Change state now as candidates calls can be synchronous
changeGatheringState(GatheringState::InProgress);
Expand Down Expand Up @@ -559,18 +549,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
break;
}

// Filter STUN servers
servers.erase(std::remove_if(servers.begin(), servers.end(),
[](const IceServer &server) {
return server.hostname.empty() ||
server.type != IceServer::Type::Turn;
}),
servers.end());

// Add TURN servers
for (auto &server : servers) {
addIceServer(server);
}
for (const auto &server : servers)
if (!server.hostname.empty() && server.type != IceServer::Type::Stun)
addIceServer(server);

g_signal_connect(G_OBJECT(mNiceAgent.get()), "component-state-changed",
G_CALLBACK(StateChangeCallback), this);
Expand All @@ -588,7 +570,10 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
}

void IceTransport::addIceServer(IceServer server) {
if (server.hostname.empty() || server.type != IceServer::Type::Turn) {
if (server.hostname.empty())
return;

if (server.type != IceServer::Type::Turn) {
PLOG_WARNING << "Only TURN servers are supported as additional ICE servers";
return;
}
Expand Down Expand Up @@ -724,11 +709,10 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) {

void IceTransport::gatherLocalCandidates(string mid, std::vector<IceServer> additionalIceServers) {
mMid = std::move(mid);
std::shuffle(additionalIceServers.begin(), additionalIceServers.end(), utils::random_engine());

for (auto &server : additionalIceServers) {
std::shuffle(additionalIceServers.begin(), additionalIceServers.end(), utils::random_engine());
for (const auto &server : additionalIceServers)
addIceServer(server);
}

// Change state now as candidates calls can be synchronous
changeGatheringState(GatheringState::InProgress);
Expand Down
2 changes: 1 addition & 1 deletion src/impl/icetransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class IceTransport : public Transport {

#if !USE_NICE
unique_ptr<juice_agent_t, void (*)(juice_agent_t *)> mAgent;
int mTURNServersAdded = 0;
int mTurnServersAdded = 0;

static void StateChangeCallback(juice_agent_t *agent, juice_state_t state, void *user_ptr);
static void CandidateCallback(juice_agent_t *agent, const char *sdp, void *user_ptr);
Expand Down

0 comments on commit fa538f7

Please sign in to comment.