From ebd2ed2d971243e1b64048dca28139962ea70b8a Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 23 Apr 2019 11:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96rtsp/http/rtmp=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpSession.cpp | 5 +++++ src/Rtmp/RtmpSession.cpp | 4 ++++ src/Rtsp/RtspSession.cpp | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 071f4e5f..7200fce7 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -103,6 +103,8 @@ get_mime_type(const char* name) { HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) { //设置15秒发送超时时间 pSock->setSendTimeOutSecond(15); + //起始接收buffer缓存设置为4K,节省内存 + pSock->setReadBuffer(std::make_shared(4 * 1024)); GET_CONFIG_AND_REGISTER(string,rootPath,Http::kRootPath); _strPath = rootPath; @@ -650,6 +652,9 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) { return false; }; }else{ + //如果是post请求 并且totalContentLen数据超过maxReqSize,那么我们加大接收缓存提升性能 + _sock->setReadBuffer(std::make_shared(256 * 1024)); + //返回不固定长度的content content_len = -1; auto parserCopy = _parser; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index b2a2c87d..fed023f4 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -37,6 +37,8 @@ RtmpSession::RtmpSession(const Socket::Ptr &pSock) : TcpSession(pSock) { DebugL << get_peer_ip(); //设置15秒发送超时时间 pSock->setSendTimeOutSecond(15); + //起始接收buffer缓存设置为4K,节省内存 + pSock->setReadBuffer(std::make_shared(4 * 1024)); } RtmpSession::~RtmpSession() { @@ -171,6 +173,8 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { } _pPublisherSrc.reset(new RtmpToRtspMediaSource(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid)); _pPublisherSrc->setListener(dynamic_pointer_cast(shared_from_this())); + //如果是rtmp推流客户端,那么加大TCP接收缓存,这样能提升接收性能 + _sock->setReadBuffer(std::make_shared(256 * 1024)); }; weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 3bdd4459..2fe7fa0c 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -271,7 +271,7 @@ bool RtspSession::handleReq_RECORD(const Parser &parser){ SockUtil::setNoDelay(_sock->rawFD(),false); if(_rtpType == Rtsp::RTP_TCP){ //如果是rtsp推流服务器,并且是TCP推流,那么加大TCP接收缓存,这样能提升接收性能 - _sock->setReadBuffer(std::make_shared(128 * 1024)); + _sock->setReadBuffer(std::make_shared(256 * 1024)); } (*this) << SocketFlags(kSockFlags); };