适配ZLToolKit最新代码(优化发送性能)

This commit is contained in:
xiongziliang 2019-03-18 18:44:16 +08:00
parent 748adadd6a
commit 082efb126b
7 changed files with 10 additions and 20 deletions

@ -1 +1 @@
Subproject commit 034f0c2911239395030188c40e5b518f7b697b8d
Subproject commit 5d0db2bcd026d6c00423b63d5ad45ef33e717f34

View File

@ -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);

View File

@ -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);
}

View File

@ -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<void * , onDetach > _mapDetach_copy;

View File

@ -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);
}
}

View File

@ -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));
_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++) {

View File

@ -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<struct sockaddr> _apPeerRtpPortAddr[2]; //播放器接收RTP的地址,trackid idx 为数组下标
//RTP over udp_multicast
RtpBroadCaster::Ptr _pBrdcaster;