通过减少线程切换提高服务器性能

This commit is contained in:
xiongziliang
2019-03-21 22:28:12 +08:00
parent 6238f5aa58
commit b78c14a2a3
9 changed files with 33 additions and 65 deletions

View File

@@ -203,7 +203,7 @@ inline void RtmpPusher::send_metaData(){
sendRtmp(pkt->typeId, _ui32StreamId, pkt->strBuf, pkt->timeStamp, pkt->chunkId );
});
_pRtmpReader = src->getRing()->attach();
_pRtmpReader = src->getRing()->attach(getPoller());
weak_ptr<RtmpPusher> weakSelf = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
_pRtmpReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt){
auto strongSelf = weakSelf.lock();

View File

@@ -336,7 +336,7 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr
onSendMedia(pkt);
});
_pRingReader = src->getRing()->attach();
_pRingReader = src->getRing()->attach(getPoller());
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
SockUtil::setNoDelay(_sock->rawFD(), false);
_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt) {
@@ -344,20 +344,14 @@ void RtmpSession::sendPlayResponse(const string &err,const RtmpMediaSource::Ptr
if (!strongSelf) {
return;
}
strongSelf->async([weakSelf, pkt]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
strongSelf->onSendMedia(pkt);
});
strongSelf->onSendMedia(pkt);
});
_pRingReader->setDetachCB([weakSelf]() {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {
return;
}
strongSelf->safeShutdown();
strongSelf->shutdown();
});
_pPlayerSrc = src;
if (src->getRing()->readerCount() == 1) {
@@ -446,13 +440,7 @@ void RtmpSession::onCmd_pause(AMFDecoder &dec) {
if(!strongSelf) {
return;
}
strongSelf->async([weakSelf,pkt]() {
auto strongSelf = weakSelf.lock();
if(!strongSelf) {
return;
}
strongSelf->onSendMedia(pkt);
});
strongSelf->onSendMedia(pkt);
});
}
}