From 44bb1ba5ef72b3a9b73b93d04d6fe7c47c54727a Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 20 Oct 2020 10:38:31 +0800 Subject: [PATCH] =?UTF-8?q?rtp=E7=AB=AF=E5=8F=A3=E5=8F=96=E5=81=B6?= =?UTF-8?q?=E6=95=B0:#526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpServer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index 5b92226b..d417e148 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -25,7 +25,15 @@ RtpServer::~RtpServer() { void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip) { //创建udp服务器 Socket::Ptr udp_server = Socket::createSocket(nullptr, false); - if (!udp_server->bindUdpSock(local_port, local_ip)) { + if (local_port == 0) { + //随机端口,rtp端口采用偶数 + Socket::Ptr rtcp_server = Socket::createSocket(nullptr, false); + auto pair = std::make_pair(udp_server, rtcp_server); + makeSockPair(pair, local_ip); + //取偶数端口 + udp_server = pair.first; + } else if (!udp_server->bindUdpSock(local_port, local_ip)) { + //用户指定端口 throw std::runtime_error(StrPrinter << "bindUdpSock on " << local_ip << ":" << local_port << " failed:" << get_uv_errmsg(true)); } //设置udp socket读缓存