From f5187e8b0d2e2c5e29d24c02e45044b07fbc8a7a Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 20 Jan 2020 16:22:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96GOP=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- src/Rtmp/RtmpMediaSource.h | 5 +++-- src/Rtmp/RtmpMediaSourceImp.h | 2 +- src/Rtsp/RtspMediaSource.h | 8 ++++---- src/Rtsp/RtspMediaSourceImp.h | 2 +- src/Rtsp/RtspPlayerImp.h | 2 ++ 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 3850c1ad..8eaecbd6 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 3850c1adcc5d184c6da0dd263ac011388bb2ffee +Subproject commit 8eaecbd6dd8bed0bee6a61168255653127a20a43 diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index e6f9178f..b09bbf53 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -46,6 +46,7 @@ #include "Thread/ThreadPool.h" using namespace toolkit; +#define RTMP_GOP_SIZE 512 namespace mediakit { /** @@ -70,7 +71,7 @@ public: RtmpMediaSource(const string &vhost, const string &app, const string &stream_id, - int ring_size = 0) : + int ring_size = RTMP_GOP_SIZE) : MediaSource(RTMP_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) { } @@ -146,7 +147,7 @@ public: //rtmp包缓存最大允许512个,如果是纯视频(25fps)大概为20秒数据 //但是这个是GOP缓存的上限值,真实的GOP缓存大小等于两个I帧之间的包数的两倍 //而且每次遇到I帧,则会清空GOP缓存,所以真实的GOP缓存远小于此值 - _ring = std::make_shared(_ring_size,512,std::move(lam)); + _ring = std::make_shared(_ring_size,std::move(lam)); onReaderChanged(0); if(_metadata){ diff --git a/src/Rtmp/RtmpMediaSourceImp.h b/src/Rtmp/RtmpMediaSourceImp.h index 482ad5aa..fca06936 100644 --- a/src/Rtmp/RtmpMediaSourceImp.h +++ b/src/Rtmp/RtmpMediaSourceImp.h @@ -54,7 +54,7 @@ public: * @param id 流id * @param ringSize 环形缓存大小 */ - RtmpMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = 0) : RtmpMediaSource(vhost, app, id, ringSize) { + RtmpMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = RTMP_GOP_SIZE) : RtmpMediaSource(vhost, app, id, ringSize) { _demuxer = std::make_shared(); _demuxer->setTrackListener(this); } diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index 21263b9d..a99ee60d 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -35,17 +35,17 @@ #include "Common/config.h" #include "Common/MediaSource.h" #include "RtpCodec.h" - #include "Util/logger.h" #include "Util/RingBuffer.h" #include "Util/TimeTicker.h" #include "Util/ResourcePool.h" #include "Util/NoticeCenter.h" #include "Thread/ThreadPool.h" - using namespace std; using namespace toolkit; +#define RTP_GOP_SIZE 2048 + namespace mediakit { /** @@ -70,7 +70,7 @@ public: RtspMediaSource(const string &vhost, const string &app, const string &stream_id, - int ring_size = 0) : + int ring_size = RTP_GOP_SIZE) : MediaSource(RTSP_SCHEMA, vhost, app, stream_id), _ring_size(ring_size) {} virtual ~RtspMediaSource() {} @@ -182,7 +182,7 @@ public: //rtp包缓存最大允许2048个,大概最多3MB数据 //但是这个是GOP缓存的上限值,真实的GOP缓存大小等于两个I帧之间的包数的两倍 //而且每次遇到I帧,则会清空GOP缓存,所以真实的GOP缓存远小于此值 - _ring = std::make_shared(_ring_size,2048, std::move(lam)); + _ring = std::make_shared(_ring_size, std::move(lam)); onReaderChanged(0); if (!_sdp.empty()) { regist(); diff --git a/src/Rtsp/RtspMediaSourceImp.h b/src/Rtsp/RtspMediaSourceImp.h index e5f78121..4586df2b 100644 --- a/src/Rtsp/RtspMediaSourceImp.h +++ b/src/Rtsp/RtspMediaSourceImp.h @@ -45,7 +45,7 @@ public: * @param id 流id * @param ringSize 环形缓存大小 */ - RtspMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = 0) : RtspMediaSource(vhost, app, id,ringSize) { + RtspMediaSourceImp(const string &vhost, const string &app, const string &id, int ringSize = RTP_GOP_SIZE) : RtspMediaSource(vhost, app, id,ringSize) { _demuxer = std::make_shared(); _demuxer->setTrackListener(this); } diff --git a/src/Rtsp/RtspPlayerImp.h b/src/Rtsp/RtspPlayerImp.h index 99b008ed..f61ac7c6 100644 --- a/src/Rtsp/RtspPlayerImp.h +++ b/src/Rtsp/RtspPlayerImp.h @@ -72,6 +72,8 @@ private: } void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override { if(_pRtspMediaSrc){ + // rtsp直接代理是无法判断该rtp是否是I帧,所以GOP缓存基本是无效的 + // 为了减少内存使用,那么我们设置为一直关键帧以便清空GOP缓存 _pRtspMediaSrc->onWrite(rtp,true); } _delegate->inputRtp(rtp);