From 082efb126bafee087e39203aa0e5b2cccdfe9d55 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 18 Mar 2019 18:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DZLToolKit=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81(=E4=BC=98=E5=8C=96=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=80=A7=E8=83=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZLToolKit | 2 +- src/Http/HttpSession.cpp | 3 --- src/Rtmp/RtmpSession.cpp | 2 -- src/Rtsp/RtpBroadCaster.cpp | 3 ++- src/Rtsp/RtspPlayer.cpp | 3 ++- src/Rtsp/RtspSession.cpp | 16 +++++----------- src/Rtsp/RtspSession.h | 1 - 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/ZLToolKit b/ZLToolKit index 034f0c29..5d0db2bc 160000 --- a/ZLToolKit +++ b/ZLToolKit @@ -1 +1 @@ -Subproject commit 034f0c2911239395030188c40e5b518f7b697b8d +Subproject commit 5d0db2bcd026d6c00423b63d5ad45ef33e717f34 diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 91d94bf7..f06dfd93 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -100,9 +100,6 @@ get_mime_type(const char* name) { HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) { - - //设置10秒发送缓存 - pSock->setSendBufSecond(10); //设置15秒发送超时时间 pSock->setSendTimeOutSecond(15); diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 5274b947..84db6650 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -35,8 +35,6 @@ static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE; RtmpSession::RtmpSession(const Socket::Ptr &pSock) : TcpSession(pSock) { DebugL << get_peer_ip(); - //设置10秒发送缓存 - pSock->setSendBufSecond(10); //设置15秒发送超时时间 pSock->setSendTimeOutSecond(15); } diff --git a/src/Rtsp/RtpBroadCaster.cpp b/src/Rtsp/RtpBroadCaster.cpp index 79815143..ec6077c9 100644 --- a/src/Rtsp/RtpBroadCaster.cpp +++ b/src/Rtsp/RtpBroadCaster.cpp @@ -122,6 +122,7 @@ RtpBroadCaster::RtpBroadCaster(const string &strLocalIp,const string &strVhost,c peerAddr.sin_port = htons(_apUdpSock[i]->get_local_port()); peerAddr.sin_addr.s_addr = htonl(*_multiAddr); bzero(&(peerAddr.sin_zero), sizeof peerAddr.sin_zero); + _apUdpSock[i]->setSendPeerAddr((struct sockaddr *)&peerAddr); } _pReader = src->getRing()->attach(); _pReader->setReadCB([this](const RtpPacket::Ptr &pkt){ @@ -129,7 +130,7 @@ RtpBroadCaster::RtpBroadCaster(const string &strLocalIp,const string &strVhost,c auto &pSock = _apUdpSock[i]; auto &peerAddr = _aPeerUdpAddr[i]; BufferRtp::Ptr buffer(new BufferRtp(pkt,4)); - pSock->send(buffer,SOCKET_DEFAULE_FLAGS,(struct sockaddr *)(&peerAddr)); + pSock->send(buffer); }); _pReader->setDetachCB([this](){ unordered_map _mapDetach_copy; diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 984fefe0..18f3935e 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -317,7 +317,8 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int uiTrackIndex) rtpto.sin_port = ntohs(port); rtpto.sin_family = AF_INET; rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().c_str()); - pUdpSockRef->send("\xce\xfa\xed\xfe", 4,SOCKET_DEFAULE_FLAGS, (struct sockaddr *) &rtpto); + pUdpSockRef->setSendPeerAddr((struct sockaddr *)&(rtpto)); + pUdpSockRef->send("\xce\xfa\xed\xfe", 4); } } diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index deb590c3..0dcec6cc 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2016 xiongziliang <771730766@qq.com> @@ -73,8 +73,6 @@ static recursive_mutex g_mtxGetter; static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE; RtspSession::RtspSession(const Socket::Ptr &pSock) : TcpSession(pSock) { - //设置10秒发送缓存 - pSock->setSendBufSecond(10); //设置15秒发送超时时间 pSock->setSendTimeOutSecond(15); @@ -604,7 +602,7 @@ bool RtspSession::handleReq_Setup(const Parser &parser) { peerAddr.sin_port = htons(ui16PeerPort); peerAddr.sin_addr.s_addr = inet_addr(get_peer_ip().data()); bzero(&(peerAddr.sin_zero), sizeof peerAddr.sin_zero); - _apPeerRtpPortAddr[trackIdx].reset((struct sockaddr *) (new struct sockaddr_in(peerAddr))); + pSockRtp->setSendPeerAddr((struct sockaddr *)(&peerAddr)); //尝试获取客户端nat映射地址 startListenPeerUdpData(trackIdx); //InfoL << "分配端口:" << srv_port; @@ -992,13 +990,9 @@ inline void RtspSession::sendRtpPacket(const RtpPacket::Ptr & pkt) { shutdown(); return; } - auto &peerAddr = _apPeerRtpPortAddr[iTrackIndex]; - if (!peerAddr) { - return; - } - BufferRtp::Ptr buffer(new BufferRtp(pkt,4)); + BufferRtp::Ptr buffer(new BufferRtp(pkt,4)); _ui64TotalBytes += buffer->size(); - pSock->send(buffer,SOCKET_DEFAULE_FLAGS, peerAddr.get()); + pSock->send(buffer); } break; default: @@ -1028,7 +1022,7 @@ inline void RtspSession::onRcvPeerUdpData(int iTrackIdx, const Buffer::Ptr &pBuf return; } //设置真实的客户端nat映射端口号 - _apPeerRtpPortAddr[iTrackIdx / 2].reset(new struct sockaddr(addr)); + _apRtpSock[iTrackIdx / 2]->setSendPeerAddr(&addr); _abGotPeerUdp[iTrackIdx / 2] = true; _bGotAllPeerUdp = true;//先假设获取到完整的rtp探测包 for (unsigned int i = 0; i < _aTrackInfo.size(); i++) { diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index 3c7a1c8e..3aa2009f 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -167,7 +167,6 @@ private: bool _abGotPeerUdp[2] = { false, false }; //获取客户端udp端口计数 Socket::Ptr _apRtpSock[2]; //RTP端口,trackid idx 为数组下标 Socket::Ptr _apRtcpSock[2];//RTCP端口,trackid idx 为数组下标 - std::shared_ptr _apPeerRtpPortAddr[2]; //播放器接收RTP的地址,trackid idx 为数组下标 //RTP over udp_multicast RtpBroadCaster::Ptr _pBrdcaster;