From 5404a5266a12db070d2801d63eed10bc06d715f1 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 21 Nov 2021 11:28:14 +0800 Subject: [PATCH] =?UTF-8?q?Performance:=20=E4=BD=BF=E7=94=A8=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E6=B1=A0=E4=BC=98=E5=8C=96http-flv=E5=88=86=E5=8F=91?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/FlvMuxer.cpp | 12 ++++++++++-- src/Rtmp/FlvMuxer.h | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Rtmp/FlvMuxer.cpp b/src/Rtmp/FlvMuxer.cpp index 84f0eb1a..5728d30f 100644 --- a/src/Rtmp/FlvMuxer.cpp +++ b/src/Rtmp/FlvMuxer.cpp @@ -16,6 +16,10 @@ namespace mediakit { +FlvMuxer::FlvMuxer(){ + _packet_pool.setSize(64); +} + void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media) { if (!media) { throw std::runtime_error("RtmpMediaSource 无效"); @@ -62,15 +66,19 @@ void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr }); } +BufferRaw::Ptr FlvMuxer::obtainBuffer() { + return _packet_pool.obtain(); +} + BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) { - auto buffer = BufferRaw::create(); + auto buffer = obtainBuffer(); buffer->assign((const char *) data, len); return buffer; } void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &src) { //发送flv文件头 - auto buffer = BufferRaw::create(); + auto buffer = obtainBuffer(); buffer->setCapacity(sizeof(FLVHeader)); buffer->setSize(sizeof(FLVHeader)); diff --git a/src/Rtmp/FlvMuxer.h b/src/Rtmp/FlvMuxer.h index 2f4a389c..caf1903c 100644 --- a/src/Rtmp/FlvMuxer.h +++ b/src/Rtmp/FlvMuxer.h @@ -22,7 +22,7 @@ namespace mediakit { class FlvMuxer { public: using Ptr = std::shared_ptr; - FlvMuxer() = default; + FlvMuxer(); virtual ~FlvMuxer() = default; void stop(); @@ -39,8 +39,10 @@ private: void onWriteFlvTag(const RtmpPacket::Ptr &pkt, uint32_t time_stamp, bool flush); void onWriteFlvTag(uint8_t type, const Buffer::Ptr &buffer, uint32_t time_stamp, bool flush); BufferRaw::Ptr obtainBuffer(const void *data, size_t len); + BufferRaw::Ptr obtainBuffer(); private: + ResourcePool _packet_pool; //时间戳修整器 Stamp _stamp[2]; RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;