From 80bcf53ccf4645b3c3b905ff4ab9d906c4fa9b94 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sun, 7 Feb 2021 14:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0ZLToolKit=E5=B9=B6=E9=80=82?= =?UTF-8?q?=E9=85=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- api/source/mk_tcp.cpp | 3 ++- src/Rtmp/FlvMuxer.cpp | 14 ++++++++++---- src/Rtmp/FlvMuxer.h | 1 + src/Rtmp/RtmpProtocol.cpp | 13 ++++--------- src/Rtmp/RtmpProtocol.h | 4 +--- src/Rtp/PSEncoder.cpp | 2 +- src/Rtsp/Rtsp.cpp | 3 ++- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 147332ed..7138d326 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 147332ed51c8da49764e6d227034340d86cf7800 +Subproject commit 7138d3263d4c409fae0f2ae3164612c2e5ea92a0 diff --git a/api/source/mk_tcp.cpp b/api/source/mk_tcp.cpp index b4d45148..b0e6d626 100644 --- a/api/source/mk_tcp.cpp +++ b/api/source/mk_tcp.cpp @@ -254,7 +254,8 @@ API_EXPORT void API_CALL mk_tcp_client_send_safe(mk_tcp_client ctx, const char * assert(ctx && data); TcpClientForC::Ptr *client = (TcpClientForC::Ptr *)ctx; weak_ptr weakClient = *client; - Buffer::Ptr buf = (*client)->obtainBuffer(data,len); + auto buf = BufferRaw::create(); + buf->assign(data,len); (*client)->async([weakClient,buf](){ auto strongClient = weakClient.lock(); if(strongClient){ diff --git a/src/Rtmp/FlvMuxer.cpp b/src/Rtmp/FlvMuxer.cpp index 5ff3cdb3..7f09d963 100644 --- a/src/Rtmp/FlvMuxer.cpp +++ b/src/Rtmp/FlvMuxer.cpp @@ -67,6 +67,12 @@ void FlvMuxer::start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr & }); } +BufferRaw::Ptr FlvMuxer::obtainBuffer(const void *data, size_t len) { + auto buffer = BufferRaw::create(); + buffer->assign((const char *) data, len); + return buffer; +} + void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) { //发送flv文件头 char flv_file_header[] = "FLV\x1\x5\x0\x0\x0\x9"; // have audio and have video @@ -92,11 +98,11 @@ void FlvMuxer::onWriteFlvHeader(const RtmpMediaSource::Ptr &mediaSrc) { } //flv header - onWrite(std::make_shared(flv_file_header, sizeof(flv_file_header) - 1), false); + onWrite(obtainBuffer(flv_file_header, sizeof(flv_file_header) - 1), false); auto size = htonl(0); //PreviousTagSize0 Always 0 - onWrite(std::make_shared((char *)&size,4), false); + onWrite(obtainBuffer((char *)&size,4), false); auto &metadata = mediaSrc->getMetaData(); @@ -144,12 +150,12 @@ void FlvMuxer::onWriteFlvTag(uint8_t type, const Buffer::Ptr &buffer, uint32_t t header.timestamp_ex = (uint8_t) ((time_stamp >> 24) & 0xff); set_be24(header.timestamp, time_stamp & 0xFFFFFF); //tag header - onWrite(std::make_shared((char *)&header, sizeof(header)), false); + onWrite(obtainBuffer((char *)&header, sizeof(header)), false); //tag data onWrite(buffer, false); uint32_t size = htonl((uint32_t)(buffer->size() + sizeof(header))); //PreviousTagSize - onWrite(std::make_shared((char *)&size,4), flush); + onWrite(obtainBuffer((char *)&size,4), flush); } void FlvMuxer::onWriteRtmp(const RtmpPacket::Ptr &pkt,bool flush) { diff --git a/src/Rtmp/FlvMuxer.h b/src/Rtmp/FlvMuxer.h index fd2995a2..b046de84 100644 --- a/src/Rtmp/FlvMuxer.h +++ b/src/Rtmp/FlvMuxer.h @@ -37,6 +37,7 @@ private: void onWriteRtmp(const RtmpPacket::Ptr &pkt, 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); + BufferRaw::Ptr obtainBuffer(const void *data, size_t len); private: //时间戳修整器 diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index ef66d7d2..9a05d15b 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -10,9 +10,6 @@ #include "RtmpProtocol.h" #include "Rtmp/utils.h" -#include "Util/util.h" -#include "Util/onceToken.h" -#include "Thread/ThreadPool.h" #include "RtmpMediaSource.h" using namespace toolkit; @@ -760,13 +757,11 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) { } } -BufferRaw::Ptr RtmpProtocol::obtainBuffer() { - return std::make_shared() ;//_bufferPool.obtain(); -} - BufferRaw::Ptr RtmpProtocol::obtainBuffer(const void *data, size_t len) { - auto buffer = obtainBuffer(); - buffer->assign((const char *) data, len); + auto buffer = BufferRaw::create(); + if (data && len) { + buffer->assign((const char *) data, len); + } return buffer; } diff --git a/src/Rtmp/RtmpProtocol.h b/src/Rtmp/RtmpProtocol.h index f6beff7d..794c379f 100644 --- a/src/Rtmp/RtmpProtocol.h +++ b/src/Rtmp/RtmpProtocol.h @@ -53,9 +53,6 @@ protected: protected: void reset(); - BufferRaw::Ptr obtainBuffer(); - BufferRaw::Ptr obtainBuffer(const void *data, size_t len); - void sendAcknowledgement(uint32_t size); void sendAcknowledgementSize(uint32_t size); void sendPeerBandwidth(uint32_t size); @@ -70,6 +67,7 @@ protected: void sendResponse(int type, const string &str); void sendRtmp(uint8_t type, uint32_t stream_index, const std::string &buffer, uint32_t stamp, int chunk_id); void sendRtmp(uint8_t type, uint32_t stream_index, const Buffer::Ptr &buffer, uint32_t stamp, int chunk_id); + BufferRaw::Ptr obtainBuffer(const void *data = nullptr, size_t len = 0); private: void handle_C1_simple(const char *data); diff --git a/src/Rtp/PSEncoder.cpp b/src/Rtp/PSEncoder.cpp index 4b7cf80e..a2951a74 100644 --- a/src/Rtp/PSEncoder.cpp +++ b/src/Rtp/PSEncoder.cpp @@ -14,7 +14,7 @@ namespace mediakit{ PSEncoder::PSEncoder() { - _buffer = std::make_shared(); + _buffer = BufferRaw::create(); init(); } diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 2d2c6d13..08466cc5 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -415,7 +415,8 @@ string printSSRC(uint32_t ui32Ssrc) { } Buffer::Ptr makeRtpOverTcpPrefix(uint16_t size, uint8_t interleaved){ - auto rtp_tcp = std::make_shared(RtpPacket::kRtpTcpHeaderSize); + auto rtp_tcp = BufferRaw::create(); + rtp_tcp->setCapacity(RtpPacket::kRtpTcpHeaderSize); rtp_tcp->setSize(RtpPacket::kRtpTcpHeaderSize); auto ptr = rtp_tcp->data(); ptr[0] = '$';