mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
Merge branch 'master' of github.com:ZLMediaKit/ZLMediaKit
This commit is contained in:
commit
9f06dc3aab
@ -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));
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace mediakit {
|
||||
class FlvMuxer {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<FlvMuxer>;
|
||||
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<BufferRaw> _packet_pool;
|
||||
//时间戳修整器
|
||||
Stamp _stamp[2];
|
||||
RtmpMediaSource::RingType::RingReader::Ptr _ring_reader;
|
||||
|
@ -55,6 +55,7 @@ static string openssl_HMACsha256(const void *key, size_t key_len, const void *da
|
||||
namespace mediakit {
|
||||
|
||||
RtmpProtocol::RtmpProtocol() {
|
||||
_packet_pool.setSize(64);
|
||||
_next_step_func = [this](const char *data, size_t len) {
|
||||
return handle_C0C1(data, len);
|
||||
};
|
||||
@ -776,7 +777,7 @@ void RtmpProtocol::handle_chunk(RtmpPacket::Ptr packet) {
|
||||
}
|
||||
|
||||
BufferRaw::Ptr RtmpProtocol::obtainBuffer(const void *data, size_t len) {
|
||||
auto buffer = BufferRaw::create();
|
||||
auto buffer = _packet_pool.obtain();
|
||||
if (data && len) {
|
||||
buffer->assign((const char *) data, len);
|
||||
}
|
||||
|
@ -107,6 +107,8 @@ private:
|
||||
function<const char * (const char *data, size_t len)> _next_step_func;
|
||||
////////////Chunk////////////
|
||||
unordered_map<int, std::pair<RtmpPacket::Ptr/*now*/, RtmpPacket::Ptr/*last*/> > _map_chunk_data;
|
||||
//循环池
|
||||
ResourcePool<BufferRaw> _packet_pool;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
@ -313,6 +313,7 @@ void WebRtcTransportImp::onCreate(){
|
||||
|
||||
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) {
|
||||
InfoL << getIdentifier();
|
||||
_packet_pool.setSize(64);
|
||||
}
|
||||
|
||||
WebRtcTransportImp::~WebRtcTransportImp() {
|
||||
@ -329,7 +330,7 @@ void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sock
|
||||
WarnL << "send data failed:" << len;
|
||||
return;
|
||||
}
|
||||
auto ptr = BufferRaw::create();
|
||||
auto ptr = _packet_pool.obtain();
|
||||
ptr->assign(buf, len);
|
||||
//一次性发送一帧的rtp数据,提高网络io性能
|
||||
_session->setSendFlushFlag(flush);
|
||||
@ -385,10 +386,10 @@ void WebRtcTransportImp::onStartWebRTC() {
|
||||
_ssrc_to_track[track->offer_ssrc_rtx] = track;
|
||||
|
||||
//rtp pt --> MediaTrack
|
||||
_pt_to_track.emplace(track->plan_rtp->pt, new WrappedRtpTrack(track, _twcc_ctx, *this));
|
||||
_pt_to_track.emplace(track->plan_rtp->pt, std::unique_ptr<WrappedMediaTrack>(new WrappedRtpTrack(track, _twcc_ctx, *this)));
|
||||
if (track->plan_rtx) {
|
||||
//rtx pt --> MediaTrack
|
||||
_pt_to_track.emplace(track->plan_rtx->pt, new WrappedRtxTrack(track));
|
||||
_pt_to_track.emplace(track->plan_rtx->pt, std::unique_ptr<WrappedMediaTrack>(new WrappedRtxTrack(track)));
|
||||
}
|
||||
if (m_offer->type != TrackApplication) {
|
||||
//记录rtp ext类型与id的关系,方便接收或发送rtp时修改rtp ext id
|
||||
|
@ -214,8 +214,6 @@ struct WrappedRtpTrack : public WrappedMediaTrack {
|
||||
void inputRtp(const char *buf, size_t len, uint64_t stamp_ms, RtpHeader *rtp) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class WebRtcTransportImp : public WebRtcTransport {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcTransportImp>;
|
||||
@ -281,6 +279,8 @@ private:
|
||||
unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track;
|
||||
//根据接收rtp的pt获取相关信息
|
||||
unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||
//循环池
|
||||
ResourcePool<BufferRaw> _packet_pool;
|
||||
};
|
||||
|
||||
class WebRtcTransportManager {
|
||||
|
Loading…
Reference in New Issue
Block a user