From 1dec350dcd65673e581ff7cdd9eee60e6d4e02f2 Mon Sep 17 00:00:00 2001 From: ljx0305 Date: Wed, 15 Mar 2023 14:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3on=5Frtp=5Fserver=5Ftimeout?= =?UTF-8?q?=20hook=E6=97=B6=E8=8E=B7=E5=8F=96=E7=9A=84=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E9=9D=9E=E7=9C=9F=E5=AE=9E=E7=AB=AF=E5=8F=A3=20(#2297)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在调用openRtpServer接口时,如果传入的端口为0(随机端口), 那么在触发on_rtp_server_timeout hook时的端口为0 --- src/Rtp/RtpServer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index 9d276c77..741200ba 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -161,12 +161,13 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ //随机端口,rtp端口采用偶数 auto pair = std::make_pair(rtp_socket, rtcp_socket); makeSockPair(pair, local_ip, re_use_port); + local_port = rtp_socket->get_local_port(); } else if (!rtp_socket->bindUdpSock(local_port, local_ip, re_use_port)) { //用户指定端口 throw std::runtime_error(StrPrinter << "创建rtp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true)); - } else if (!rtcp_socket->bindUdpSock(rtp_socket->get_local_port() + 1, local_ip, re_use_port)) { + } else if (!rtcp_socket->bindUdpSock(local_port + 1, local_ip, re_use_port)) { // rtcp端口 - throw std::runtime_error(StrPrinter << "创建rtcp端口 " << local_ip << ":" << rtp_socket->get_local_port() + 1 << " 失败:" << get_uv_errmsg(true)); + throw std::runtime_error(StrPrinter << "创建rtcp端口 " << local_ip << ":" << local_port + 1 << " 失败:" << get_uv_errmsg(true)); } //设置udp socket读缓存 @@ -181,7 +182,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ (*tcp_server)[RtpSession::kSSRC] = ssrc; (*tcp_server)[RtpSession::kOnlyAudio] = only_audio; if (tcp_mode == PASSIVE) { - tcp_server->start(rtp_socket->get_local_port(), local_ip); + tcp_server->start(local_port, local_ip); } else if (stream_id.empty()) { // tcp主动模式时只能一个端口一个流,必须指定流id; 创建TcpServer对象也仅用于传参 throw std::runtime_error(StrPrinter << "tcp主动模式时必需指定流id"); @@ -216,7 +217,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ //单端口多线程接收多个流,根据ssrc区分流 udp_server = std::make_shared(rtp_socket->getPoller()); (*udp_server)[RtpSession::kOnlyAudio] = only_audio; - udp_server->start(rtp_socket->get_local_port(), local_ip); + udp_server->start(local_port, local_ip); rtp_socket = nullptr; #else //单端口单线程接收多个流