From a3e628449e6424836f02e0b6aee181a7b7ef4455 Mon Sep 17 00:00:00 2001 From: JayChen0519 <97513129+JayChen0519@users.noreply.github.com> Date: Fri, 14 Jan 2022 13:14:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3rtsp=E4=BB=A5MULTICAST?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=8B=89=E6=B5=81=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=A5=94=E6=BA=83=E9=97=AE=E9=A2=98=20(#1368)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspPlayer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 8e584de6..a358ad28 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -300,6 +300,20 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) { if (-1 == SockUtil::joinMultiAddrFilter(fd, multiAddr.data(), get_peer_ip().data(),get_local_ip().data())) { SockUtil::joinMultiAddr(fd, multiAddr.data(),get_local_ip().data()); } + + //设置rtcp发送端口 + pRtcpSockRef = createSocket(); + if (!pRtcpSockRef->bindUdpSock(0, "0.0.0.0")) { + //分配端口失败 + throw runtime_error("open udp socket failed"); + } + + //设置发送地址和发送端口 + struct sockaddr_in rtpto; + rtpto.sin_port = ntohs(rtcp_port); + rtpto.sin_family = AF_INET; + rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data()); + pRtcpSockRef->bindPeerAddr((struct sockaddr *)&(rtpto)); } else { createUdpSockIfNecessary(track_idx); //udp单播 From e8b0993493983e830136e2e1311f0e45b08190e3 Mon Sep 17 00:00:00 2001 From: wangcker Date: Fri, 14 Jan 2022 21:53:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=BB=99openrtpserver=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0enable=5Freuse=E5=8F=82=E6=95=B0=20(#1372)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改rtpopen逻辑 * 给openrtpserver接口添加enable_reuse端口 --- server/WebApi.cpp | 11 +++++++++-- src/Rtp/RtpServer.cpp | 6 +++--- src/Rtp/RtpServer.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index e9fce6f9..c1dfec29 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1025,7 +1025,10 @@ void installWebApi() { api_regist("/index/api/openRtpServer",[](API_ARGS_MAP){ CHECK_SECRET(); CHECK_ARGS("port", "enable_tcp", "stream_id"); - + bool enable_reuse=true; + if(!allArgs["enable_reuse"].empty()){ + enable_reuse = allArgs["enable_reuse"].as(); + } auto stream_id = allArgs["stream_id"]; lock_guard lck(s_rtpServerMapMtx); @@ -1034,8 +1037,12 @@ void installWebApi() { throw InvalidArgsException("该stream_id已存在"); } + + + + RtpServer::Ptr server = std::make_shared(); - server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as()); + server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as(),"0.0.0.0",enable_reuse); server->setOnDetach([stream_id]() { //设置rtp超时移除事件 lock_guard lck(s_rtpServerMapMtx); diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index 53dd5b30..29e2341d 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -84,7 +84,7 @@ private: std::shared_ptr _rtcp_addr; }; -void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip) { +void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip,bool enable_reuse) { //创建udp服务器 Socket::Ptr rtp_socket = Socket::createSocket(nullptr, true); Socket::Ptr rtcp_socket = Socket::createSocket(nullptr, true); @@ -95,10 +95,10 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable //取偶数端口 rtp_socket = pair.first; rtcp_socket = pair.second; - } else if (!rtp_socket->bindUdpSock(local_port, local_ip)) { + } else if (!rtp_socket->bindUdpSock(local_port, local_ip,enable_reuse)) { //用户指定端口 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)) { + } else if(!rtcp_socket->bindUdpSock(rtp_socket->get_local_port() + 1, local_ip,enable_reuse)) { // rtcp端口 throw std::runtime_error(StrPrinter << "创建rtcp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true)); } diff --git a/src/Rtp/RtpServer.h b/src/Rtp/RtpServer.h index 14b04b7d..61dfb825 100644 --- a/src/Rtp/RtpServer.h +++ b/src/Rtp/RtpServer.h @@ -41,7 +41,7 @@ public: * @param enable_tcp 是否启用tcp服务器 * @param local_ip 绑定的本地网卡ip */ - void start(uint16_t local_port, const string &stream_id = "", bool enable_tcp = true, const char *local_ip = "0.0.0.0"); + void start(uint16_t local_port, const string &stream_id = "", bool enable_tcp = true, const char *local_ip = "0.0.0.0",bool enable_reuse = true); /** * 获取绑定的本地端口 From c9d755f4e88f83b77c43d00f857f0916ed75d087 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 14 Jan 2022 22:04:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- server/WebApi.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index dd101bcc..a71747c7 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit dd101bcc31290e3d1ec1ae939d937f2712719a0d +Subproject commit a71747c7d0811263b12ef9112ec13fdffe2ab171 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index c1dfec29..5db5bae8 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1025,24 +1025,20 @@ void installWebApi() { api_regist("/index/api/openRtpServer",[](API_ARGS_MAP){ CHECK_SECRET(); CHECK_ARGS("port", "enable_tcp", "stream_id"); - bool enable_reuse=true; - if(!allArgs["enable_reuse"].empty()){ + bool enable_reuse = true; + if (!allArgs["enable_reuse"].empty()) { enable_reuse = allArgs["enable_reuse"].as(); } auto stream_id = allArgs["stream_id"]; lock_guard lck(s_rtpServerMapMtx); - if(s_rtpServerMap.find(stream_id) != s_rtpServerMap.end()) { + if (s_rtpServerMap.find(stream_id) != s_rtpServerMap.end()) { //为了防止RtpProcess所有权限混乱的问题,不允许重复添加相同的stream_id throw InvalidArgsException("该stream_id已存在"); } - - - - RtpServer::Ptr server = std::make_shared(); - server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as(),"0.0.0.0",enable_reuse); + server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as(), "0.0.0.0", enable_reuse); server->setOnDetach([stream_id]() { //设置rtp超时移除事件 lock_guard lck(s_rtpServerMapMtx);