mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
Performance: 使用循环池优化http-flv分发性能
This commit is contained in:
parent
1cba3f4d58
commit
5404a5266a
@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
|
FlvMuxer::FlvMuxer(){
|
||||||
|
_packet_pool.setSize(64);
|
||||||
|
}
|
||||||
|
|
||||||
void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media) {
|
void FlvMuxer::start(const EventPoller::Ptr &poller, const RtmpMediaSource::Ptr &media) {
|
||||||
if (!media) {
|
if (!media) {
|
||||||
throw std::runtime_error("RtmpMediaSource 无效");
|
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) {
|
BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) {
|
||||||
auto buffer = BufferRaw::create();
|
auto buffer = obtainBuffer();
|
||||||
buffer->assign((const char *) data, len);
|
buffer->assign((const char *) data, len);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &src) {
|
void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &src) {
|
||||||
//发送flv文件头
|
//发送flv文件头
|
||||||
auto buffer = BufferRaw::create();
|
auto buffer = obtainBuffer();
|
||||||
buffer->setCapacity(sizeof(FLVHeader));
|
buffer->setCapacity(sizeof(FLVHeader));
|
||||||
buffer->setSize(sizeof(FLVHeader));
|
buffer->setSize(sizeof(FLVHeader));
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace mediakit {
|
|||||||
class FlvMuxer {
|
class FlvMuxer {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<FlvMuxer>;
|
using Ptr = std::shared_ptr<FlvMuxer>;
|
||||||
FlvMuxer() = default;
|
FlvMuxer();
|
||||||
virtual ~FlvMuxer() = default;
|
virtual ~FlvMuxer() = default;
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
@ -39,8 +39,10 @@ private:
|
|||||||
void onWriteFlvTag(const RtmpPacket::Ptr &pkt, uint32_t time_stamp, bool flush);
|
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);
|
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(const void *data, size_t len);
|
||||||
|
BufferRaw::Ptr obtainBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ResourcePool<BufferRaw> _packet_pool;
|
||||||
//时间戳修整器
|
//时间戳修整器
|
||||||
Stamp _stamp[2];
|
Stamp _stamp[2];
|
||||||
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
||||||
|
Loading…
Reference in New Issue
Block a user