Commit c5cfbce2 by xia-chu

优化rtp性能

parent b0e1d5d6
......@@ -34,7 +34,7 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
return handleOneRtp(0, TrackVideo, 90000, (unsigned char *) data, data_len);
}
void GB28181Process::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp, int) {
auto pt = rtp->getHeader()->pt;
if (!_rtp_decoder) {
switch (pt) {
......
......@@ -36,7 +36,7 @@ public:
bool inputRtp(bool, const char *data, size_t data_len) override;
protected:
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ;
void onRtpSorted(RtpPacket::Ptr rtp, int track_index) override ;
const char *onSearchPacketTail(const char *data,size_t len) override;
ssize_t onRecvHeader(const char *data,size_t len) override { return 0; };
......
......@@ -14,7 +14,7 @@ namespace mediakit{
RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, size_t len, bool mark, uint32_t stamp) {
uint16_t payload_len = (uint16_t) (len + RtpPacket::kRtpHeaderSize);
auto rtp = ResourcePoolHelper<RtpPacket>::obtainObj();
auto rtp = RtpPacket::create();
rtp->setCapacity(payload_len + RtpPacket::kRtpTcpHeaderSize);
rtp->setSize(payload_len + RtpPacket::kRtpTcpHeaderSize);
rtp->sample_rate = _sample_rate;
......
......@@ -58,9 +58,9 @@ protected:
RingType::Ptr _rtpRing;
};
class RtpInfo : public ResourcePoolHelper<RtpPacket>{
class RtpInfo{
public:
typedef std::shared_ptr<RtpInfo> Ptr;
using Ptr = std::shared_ptr<RtpInfo>;
RtpInfo(uint32_t ssrc, size_t mtu_size, uint32_t sample_rate, uint8_t pt, uint8_t interleaved) {
if (ssrc == 0) {
......@@ -73,7 +73,7 @@ public:
_interleaved = interleaved;
}
~RtpInfo() override {}
virtual ~RtpInfo() {}
//返回rtp负载最大长度
size_t getMaxSize() const {
......
......@@ -19,7 +19,7 @@ RtpReceiver::RtpReceiver() {
int index = 0;
for (auto &sortor : _rtp_sortor) {
sortor.setOnSort([this, index](uint16_t seq, RtpPacket::Ptr &packet) {
onRtpSorted(packet, index);
onRtpSorted(std::move(packet), index);
});
++index;
}
......@@ -61,7 +61,7 @@ bool RtpReceiver::handleOneRtp(int index, TrackType type, int sample_rate, uint8
return false;
}
auto rtp = _rtp_pool.obtain();
auto rtp = RtpPacket::create();
//需要添加4个字节的rtp over tcp头
rtp->setCapacity(RtpPacket::kRtpTcpHeaderSize + len);
rtp->setSize(RtpPacket::kRtpTcpHeaderSize + len);
......@@ -90,10 +90,6 @@ void RtpReceiver::clear() {
}
}
void RtpReceiver::setPoolSize(size_t size) {
_rtp_pool.setSize(size);
}
size_t RtpReceiver::getJitterSize(int index) const{
return _rtp_sortor[index].getJitterSize();
}
......
......@@ -182,7 +182,7 @@ protected:
* @param rtp rtp数据包
* @param track_index track索引
*/
virtual void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) {}
virtual void onRtpSorted(RtpPacket::Ptr rtp, int track_index) {}
/**
* 解析出rtp但还未排序
......@@ -192,7 +192,6 @@ protected:
virtual void onBeforeRtpSorted(const RtpPacket::Ptr &rtp, int track_index) {}
void clear();
void setPoolSize(size_t size);
size_t getJitterSize(int track_index) const;
size_t getCycleCount(int track_index) const;
uint32_t getSSRC(int track_index) const;
......@@ -201,8 +200,6 @@ private:
uint32_t _ssrc[2] = {0, 0};
//rtp排序缓存,根据seq排序
PacketSortor<RtpPacket::Ptr> _rtp_sortor[2];
//rtp循环池
RtspMediaSource::PoolType _rtp_pool;
};
}//namespace mediakit
......
......@@ -531,4 +531,18 @@ size_t RtpPacket::getPayloadSize(){
return getHeader()->getPayloadSize(size() - kRtpTcpHeaderSize);
}
RtpPacket::Ptr RtpPacket::create(){
#if 0
static ResourcePool<RtpPacket> packet_pool;
static onceToken token([]() {
packet_pool.setSize(1024);
});
auto ret = packet_pool.obtain();
ret->setSize(0);
return ret;
#else
return Ptr(new RtpPacket);
#endif
}
}//namespace mediakit
\ No newline at end of file
......@@ -166,6 +166,12 @@ public:
TrackType type;
//音频为采样率,视频一般为90000
uint32_t sample_rate;
static Ptr create();
private:
friend class ResourcePool_l<RtpPacket>;
RtpPacket() = default;
};
class RtpPayload {
......
......@@ -494,10 +494,10 @@ void RtspPlayer::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, uint8_t *data
}
}
void RtspPlayer::onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx){
void RtspPlayer::onRtpSorted(RtpPacket::Ptr rtppt, int trackidx){
_stamp[trackidx] = rtppt->getStampMS();
_rtp_recv_ticker.resetTime();
onRecvRTP(rtppt, _sdp_track[trackidx]);
onRecvRTP(std::move(rtppt), _sdp_track[trackidx]);
}
float RtspPlayer::getPacketLossRate(TrackType type) const{
......
......@@ -33,7 +33,7 @@ using namespace toolkit;
namespace mediakit {
//实现了rtsp播放器协议部分的功能,及数据接收功能
class RtspPlayer: public PlayerBase,public TcpClient, public RtspSplitter, public RtpReceiver {
class RtspPlayer: public PlayerBase, public TcpClient, public RtspSplitter, public RtpReceiver {
public:
typedef std::shared_ptr<RtspPlayer> Ptr;
......@@ -48,7 +48,7 @@ public:
protected:
//派生类回调函数
virtual bool onCheckSDP(const string &sdp) = 0;
virtual void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) = 0;
virtual void onRecvRTP(RtpPacket::Ptr rtp, const SdpTrack::Ptr &track) = 0;
uint32_t getProgressMilliSecond() const;
void seekToMilliSecond(uint32_t ms);
......@@ -70,7 +70,7 @@ protected:
* @param rtp rtp数据包
* @param track_idx track索引
*/
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) override;
void onRtpSorted(RtpPacket::Ptr rtp, int track_idx) override;
/**
* 解析出rtp但还未排序
......
......@@ -59,18 +59,18 @@ private:
return true;
}
void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override {
if (_rtsp_media_src) {
// rtsp直接代理是无法判断该rtp是否是I帧,所以GOP缓存基本是无效的
// 为了减少内存使用,那么我们设置为一直关键帧以便清空GOP缓存
_rtsp_media_src->onWrite(rtp, true);
}
void onRecvRTP(RtpPacket::Ptr rtp, const SdpTrack::Ptr &track) override {
_delegate->inputRtp(rtp);
if (_max_analysis_ms && _delegate->isInited(_max_analysis_ms)) {
PlayerImp<RtspPlayer, RtspDemuxer>::onPlayResult(SockException(Err_success, "play rtsp success"));
_max_analysis_ms = 0;
}
if (_rtsp_media_src) {
// rtsp直接代理是无法判断该rtp是否是I帧,所以GOP缓存基本是无效的
// 为了减少内存使用,那么我们设置为一直关键帧以便清空GOP缓存
_rtsp_media_src->onWrite(std::move(rtp), true);
}
}
//在RtspPlayer中触发onPlayResult事件只是代表收到play回复了,
......
......@@ -913,8 +913,8 @@ void RtspSession::send_NotAcceptable() {
sendRtspResponse("406 Not Acceptable",{"Connection","Close"});
}
void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) {
_push_src->onWrite(rtp, false);
void RtspSession::onRtpSorted(RtpPacket::Ptr rtp, int track_idx) {
_push_src->onWrite(std::move(rtp), false);
}
void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, const struct sockaddr &addr) {
......
......@@ -79,7 +79,7 @@ protected:
ssize_t getContentLength(Parser &parser) override;
////RtpReceiver override////
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) override;
void onRtpSorted(RtpPacket::Ptr rtp, int track_idx) override;
void onBeforeRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override;
///////MediaSourceEvent override///////
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论