From fa538f76849c3ef3803972f676ea56d8f394877e Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Fri, 26 Apr 2024 23:53:24 +0200 Subject: [PATCH] Cleanup --- include/rtc/rtp.hpp | 19 ----------- src/h264rtpdepacketizer.cpp | 4 +-- src/impl/icetransport.cpp | 64 ++++++++++++++----------------------- src/impl/icetransport.hpp | 2 +- 4 files changed, 27 insertions(+), 62 deletions(-) diff --git a/include/rtc/rtp.hpp b/include/rtc/rtp.hpp index 503a61ff5..7eb89e516 100644 --- a/include/rtc/rtp.hpp +++ b/include/rtc/rtp.hpp @@ -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 diff --git a/src/h264rtpdepacketizer.cpp b/src/h264rtpdepacketizer.cpp index 2a03c95bd..f2ddabb4c 100644 --- a/src/h264rtpdepacketizer.cpp +++ b/src/h264rtpdepacketizer.cpp @@ -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; diff --git a/src/impl/icetransport.cpp b/src/impl/icetransport.cpp index a2c56b0aa..a27a2ed32 100644 --- a/src/impl/icetransport.cpp +++ b/src/impl/icetransport.cpp @@ -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 @@ -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() { @@ -229,15 +224,10 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) { void IceTransport::gatherLocalCandidates(string mid, std::vector 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); @@ -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); @@ -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; } @@ -724,11 +709,10 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) { void IceTransport::gatherLocalCandidates(string mid, std::vector 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); diff --git a/src/impl/icetransport.hpp b/src/impl/icetransport.hpp index 0dc3c2608..4133bcc2f 100644 --- a/src/impl/icetransport.hpp +++ b/src/impl/icetransport.hpp @@ -81,7 +81,7 @@ class IceTransport : public Transport { #if !USE_NICE unique_ptr 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);