From 2bf16e63e1e01014bf922faed1b4246828ddb734 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 21 Jun 2024 21:04:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E8=AF=81rtp=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8tcp=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- src/Rtp/RtpServer.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 5144e2aa..79c10fe4 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 5144e2aa521df6d473308bfb31172054772a634f +Subproject commit 79c10fe4773819d99efe905bb2fecf3446f3b36c diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index e8c944b0..bcf1675d 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -124,8 +124,9 @@ private: void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_mode, const char *local_ip, bool re_use_port, uint32_t ssrc, int only_track, bool multiplex) { //创建udp服务器 - Socket::Ptr rtp_socket = Socket::createSocket(nullptr, true); - Socket::Ptr rtcp_socket = Socket::createSocket(nullptr, true); + auto poller = EventPollerPool::Instance().getPoller(); + Socket::Ptr rtp_socket = Socket::createSocket(poller, true); + Socket::Ptr rtcp_socket = Socket::createSocket(poller, true); if (local_port == 0) { //随机端口,rtp端口采用偶数 auto pair = std::make_pair(rtp_socket, rtcp_socket); @@ -181,14 +182,14 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ TcpServer::Ptr tcp_server; if (tcp_mode == PASSIVE || tcp_mode == ACTIVE) { - //创建tcp服务器 - tcp_server = std::make_shared(); + auto processor = helper ? helper->getProcess() : nullptr; + // 如果共享同一个processor对象,那么tcp server深圳为单线程模式确保线程安全 + tcp_server = std::make_shared(processor ? poller : nullptr); (*tcp_server)[RtpSession::kStreamID] = stream_id; (*tcp_server)[RtpSession::kSSRC] = ssrc; (*tcp_server)[RtpSession::kOnlyTrack] = only_track; if (tcp_mode == PASSIVE) { weak_ptr weak_self = shared_from_this(); - auto processor = helper ? helper->getProcess() : nullptr; tcp_server->start(local_port, local_ip, 1024, [weak_self, processor](std::shared_ptr &session) { session->setRtpProcess(processor); });