mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
优化http/rtsp推流器/rtmp推流器内存占用
This commit is contained in:
parent
ebd2ed2d97
commit
74621618ff
@ -115,6 +115,9 @@ void HttpClient::onConnect(const SockException &ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
//先假设http客户端只会接收一点点数据(只接受http头,节省内存)
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(1 * 1024));
|
||||
|
||||
_totalBodySize = 0;
|
||||
_recvedBodySize = 0;
|
||||
HttpRequestSplitter::reset();
|
||||
@ -155,6 +158,9 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
}
|
||||
|
||||
if(_parser["Transfer-Encoding"] == "chunked"){
|
||||
//我们认为这种情况下后面应该有大量的数据过来,加大接收缓存提高性能
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(256 * 1024));
|
||||
|
||||
//如果Transfer-Encoding字段等于chunked,则认为后续的content是不限制长度的
|
||||
_totalBodySize = -1;
|
||||
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data,uint64_t len){
|
||||
@ -179,6 +185,8 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) {
|
||||
//但是由于我们没必要等content接收完毕才回调onRecvContent(因为这样浪费内存并且要多次拷贝数据)
|
||||
//所以返回-1代表我们接下来分段接收content
|
||||
_recvedBodySize = 0;
|
||||
//根据_totalBodySize设置接收缓存大小
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(MAX(_totalBodySize + 1,256 * 1024)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -130,6 +130,9 @@ void RtmpPusher::onConnect(const SockException &err){
|
||||
onPublishResult(err);
|
||||
return;
|
||||
}
|
||||
//推流器不需要多大的接收缓存,节省内存占用
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(1 * 1024));
|
||||
|
||||
weak_ptr<RtmpPusher> weakSelf = dynamic_pointer_cast<RtmpPusher>(shared_from_this());
|
||||
startClientSession([weakSelf](){
|
||||
auto strongSelf=weakSelf.lock();
|
||||
|
@ -139,6 +139,8 @@ void RtspPusher::onConnect(const SockException &err) {
|
||||
onPublishResult(err);
|
||||
return;
|
||||
}
|
||||
//推流器不需要多大的接收缓存,节省内存占用
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(1 * 1024));
|
||||
sendAnnounce();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user