mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-05 10:58:11 +08:00
通过减少线程切换提高服务器性能
This commit is contained in:
@@ -124,7 +124,7 @@ RtpBroadCaster::RtpBroadCaster(const string &strLocalIp,const string &strVhost,c
|
||||
bzero(&(peerAddr.sin_zero), sizeof peerAddr.sin_zero);
|
||||
_apUdpSock[i]->setSendPeerAddr((struct sockaddr *)&peerAddr);
|
||||
}
|
||||
_pReader = src->getRing()->attach();
|
||||
_pReader = src->getRing()->attach(nullptr);
|
||||
_pReader->setReadCB([this](const RtpPacket::Ptr &pkt){
|
||||
int i = (int)(pkt->type);
|
||||
auto &pSock = _apUdpSock[i];
|
||||
|
||||
@@ -74,7 +74,7 @@ static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE;
|
||||
|
||||
RtspSession::RtspSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
//设置15秒发送超时时间
|
||||
pSock->setSendTimeOutSecond(15);
|
||||
pSock->setSendTimeOutSecond(45);
|
||||
|
||||
DebugL << get_peer_ip();
|
||||
}
|
||||
@@ -628,7 +628,7 @@ bool RtspSession::handleReq_Setup(const Parser &parser) {
|
||||
if(!strongSelf) {
|
||||
return;
|
||||
}
|
||||
strongSelf->safeShutdown();
|
||||
strongSelf->shutdown();
|
||||
});
|
||||
}
|
||||
int iSrvPort = _pBrdcaster->getPort(trackRef->_type);
|
||||
@@ -731,28 +731,22 @@ bool RtspSession::handleReq_Play(const Parser &parser) {
|
||||
|
||||
if (!_pRtpReader && _rtpType != PlayerBase::RTP_MULTICAST) {
|
||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||
_pRtpReader = pMediaSrc->getRing()->attach(useBuf);
|
||||
_pRtpReader = pMediaSrc->getRing()->attach(getPoller(),useBuf);
|
||||
_pRtpReader->setDetachCB([weakSelf]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return;
|
||||
}
|
||||
strongSelf->safeShutdown();
|
||||
strongSelf->shutdown();
|
||||
});
|
||||
_pRtpReader->setReadCB([weakSelf](const RtpPacket::Ptr &pack) {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return;
|
||||
}
|
||||
strongSelf->async([weakSelf,pack](){
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return;
|
||||
}
|
||||
if(strongSelf->_enableSendRtp) {
|
||||
strongSelf->sendRtpPacket(pack);
|
||||
}
|
||||
});
|
||||
if(strongSelf->_enableSendRtp) {
|
||||
strongSelf->sendRtpPacket(pack);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user