Commit 5a592e6d by ziyue

优化循环池性能

parent e2636c51
ZLToolKit @ 769f0191
Subproject commit d04e9f8a111378ea5935cd9226b23ef9915e1941 Subproject commit 769f01914970bd9021d59f3eba08233886abecb7
...@@ -185,7 +185,7 @@ public: ...@@ -185,7 +185,7 @@ public:
static onceToken token([]() { static onceToken token([]() {
packet_pool.setSize(1024); packet_pool.setSize(1024);
}); });
auto ret = packet_pool.obtain(); auto ret = packet_pool.obtain2();
ret->_buffer.clear(); ret->_buffer.clear();
ret->_prefix_size = 0; ret->_prefix_size = 0;
ret->_dts = 0; ret->_dts = 0;
......
...@@ -129,7 +129,7 @@ Buffer::Ptr HttpFileBody::readData(size_t size) { ...@@ -129,7 +129,7 @@ Buffer::Ptr HttpFileBody::readData(size_t size) {
if(!_map_addr){ if(!_map_addr){
//fread模式 //fread模式
ssize_t iRead; ssize_t iRead;
auto ret = _pool.obtain(); auto ret = _pool.obtain2();
ret->setCapacity(size + 1); ret->setCapacity(size + 1);
do{ do{
iRead = fread(ret->data(), 1, size, _fp.get()); iRead = fread(ret->data(), 1, size, _fp.get());
......
...@@ -180,7 +180,7 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) { ...@@ -180,7 +180,7 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) {
ctx->flags = flags; ctx->flags = flags;
ctx->track_id = track_id; ctx->track_id = track_id;
ctx->buffer = ctx->thiz->_buffer_pool.obtain(); ctx->buffer = ctx->thiz->_buffer_pool.obtain2();
ctx->buffer->setCapacity(bytes + DATA_OFFSET + 1); ctx->buffer->setCapacity(bytes + DATA_OFFSET + 1);
ctx->buffer->setSize(bytes + DATA_OFFSET); ctx->buffer->setSize(bytes + DATA_OFFSET);
return ctx->buffer->data() + DATA_OFFSET; return ctx->buffer->data() + DATA_OFFSET;
......
...@@ -99,7 +99,7 @@ void MpegMuxer::createContext() { ...@@ -99,7 +99,7 @@ void MpegMuxer::createContext() {
/*alloc*/ /*alloc*/
[](void *param, size_t bytes) { [](void *param, size_t bytes) {
MpegMuxer *thiz = (MpegMuxer *) param; MpegMuxer *thiz = (MpegMuxer *) param;
thiz->_current_buffer = thiz->_buffer_pool.obtain();; thiz->_current_buffer = thiz->_buffer_pool.obtain2();
thiz->_current_buffer->setCapacity(bytes + 1); thiz->_current_buffer->setCapacity(bytes + 1);
return (void *) thiz->_current_buffer->data(); return (void *) thiz->_current_buffer->data();
}, },
......
...@@ -72,7 +72,7 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr ...@@ -72,7 +72,7 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr
} }
BufferRaw::Ptr FlvMuxer::obtainBuffer() { BufferRaw::Ptr FlvMuxer::obtainBuffer() {
return _packet_pool.obtain(); return _packet_pool.obtain2();
} }
BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) { BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) {
......
...@@ -138,7 +138,7 @@ RtmpPacket::Ptr RtmpPacket::create(){ ...@@ -138,7 +138,7 @@ RtmpPacket::Ptr RtmpPacket::create(){
static onceToken token([]() { static onceToken token([]() {
packet_pool.setSize(1024); packet_pool.setSize(1024);
}); });
auto ret = packet_pool.obtain(); auto ret = packet_pool.obtain2();
ret->clear(); ret->clear();
return ret; return ret;
#else #else
......
...@@ -799,11 +799,11 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) { ...@@ -799,11 +799,11 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) {
} }
BufferRaw::Ptr RtmpProtocol::obtainBuffer(const void *data, size_t len) { BufferRaw::Ptr RtmpProtocol::obtainBuffer(const void *data, size_t len) {
auto buffer = _packet_pool.obtain(); auto buffer = _packet_pool.obtain2();
if (data && len) { if (data && len) {
buffer->assign((const char *) data, len); buffer->assign((const char *) data, len);
} }
return std::move(buffer); return buffer;
} }
} /* namespace mediakit */ } /* namespace mediakit */
...@@ -555,7 +555,7 @@ RtpPacket::Ptr RtpPacket::create() { ...@@ -555,7 +555,7 @@ RtpPacket::Ptr RtpPacket::create() {
static onceToken token([]() { static onceToken token([]() {
packet_pool.setSize(1024); packet_pool.setSize(1024);
}); });
auto ret = packet_pool.obtain(); auto ret = packet_pool.obtain2();
ret->setSize(0); ret->setSize(0);
return ret; return ret;
#else #else
......
...@@ -136,7 +136,7 @@ void WebRtcTransport::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTran ...@@ -136,7 +136,7 @@ void WebRtcTransport::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTran
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WebRtcTransport::sendSockData(const char *buf, size_t len, RTC::TransportTuple *tuple){ void WebRtcTransport::sendSockData(const char *buf, size_t len, RTC::TransportTuple *tuple){
auto pkt = _packet_pool.obtain(); auto pkt = _packet_pool.obtain2();
pkt->assign(buf, len); pkt->assign(buf, len);
onSendSockData(std::move(pkt), true, tuple ? tuple : _ice_server->GetSelectedTuple()); onSendSockData(std::move(pkt), true, tuple ? tuple : _ice_server->GetSelectedTuple());
} }
...@@ -269,7 +269,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup ...@@ -269,7 +269,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup
void WebRtcTransport::sendRtpPacket(const char *buf, int len, bool flush, void *ctx) { void WebRtcTransport::sendRtpPacket(const char *buf, int len, bool flush, void *ctx) {
if (_srtp_session_send) { if (_srtp_session_send) {
auto pkt = _packet_pool.obtain(); auto pkt = _packet_pool.obtain2();
//预留rtx加入的两个字节 //预留rtx加入的两个字节
pkt->setCapacity((size_t) len + SRTP_MAX_TRAILER_LEN + 2); pkt->setCapacity((size_t) len + SRTP_MAX_TRAILER_LEN + 2);
pkt->assign(buf, len); pkt->assign(buf, len);
...@@ -283,7 +283,7 @@ void WebRtcTransport::sendRtpPacket(const char *buf, int len, bool flush, void * ...@@ -283,7 +283,7 @@ void WebRtcTransport::sendRtpPacket(const char *buf, int len, bool flush, void *
void WebRtcTransport::sendRtcpPacket(const char *buf, int len, bool flush, void *ctx) { void WebRtcTransport::sendRtcpPacket(const char *buf, int len, bool flush, void *ctx) {
if (_srtp_session_send) { if (_srtp_session_send) {
auto pkt = _packet_pool.obtain(); auto pkt = _packet_pool.obtain2();
//预留rtx加入的两个字节 //预留rtx加入的两个字节
pkt->setCapacity((size_t) len + SRTP_MAX_TRAILER_LEN + 2); pkt->setCapacity((size_t) len + SRTP_MAX_TRAILER_LEN + 2);
pkt->assign(buf, len); pkt->assign(buf, len);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论