Performance: 使用循环池优化webrtc分发性能

This commit is contained in:
xiongziliang 2021-11-21 11:36:07 +08:00
parent 97f7255f0a
commit dd30ab22cf
2 changed files with 4 additions and 3 deletions

View File

@ -313,6 +313,7 @@ void WebRtcTransportImp::onCreate(){
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) { WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) {
InfoL << getIdentifier(); InfoL << getIdentifier();
_packet_pool.setSize(64);
} }
WebRtcTransportImp::~WebRtcTransportImp() { WebRtcTransportImp::~WebRtcTransportImp() {
@ -329,7 +330,7 @@ void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sock
WarnL << "send data failed:" << len; WarnL << "send data failed:" << len;
return; return;
} }
auto ptr = BufferRaw::create(); auto ptr = _packet_pool.obtain();
ptr->assign(buf, len); ptr->assign(buf, len);
//一次性发送一帧的rtp数据提高网络io性能 //一次性发送一帧的rtp数据提高网络io性能
_session->setSendFlushFlag(flush); _session->setSendFlushFlag(flush);

View File

@ -214,8 +214,6 @@ struct WrappedRtpTrack : public WrappedMediaTrack {
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) override; void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) override;
}; };
class WebRtcTransportImp : public WebRtcTransport { class WebRtcTransportImp : public WebRtcTransport {
public: public:
using Ptr = std::shared_ptr<WebRtcTransportImp>; using Ptr = std::shared_ptr<WebRtcTransportImp>;
@ -281,6 +279,8 @@ private:
unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track; unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track;
//根据接收rtp的pt获取相关信息 //根据接收rtp的pt获取相关信息
unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track; unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
//循环池
ResourcePool<BufferRaw> _packet_pool;
}; };
class WebRtcTransportManager { class WebRtcTransportManager {