Commit 74621618 by xiongziliang

优化http/rtsp推流器/rtmp推流器内存占用

parent ebd2ed2d
......@@ -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();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论