From 3917b6451cdffd1e95a1b4c93092dd596c7236ea Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 27 May 2019 16:09:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=8E=B7=E5=8F=96=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E8=AF=BB=E5=8F=96=E5=99=A8=E4=B8=AA=E6=95=B0=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- src/Common/MediaSource.h | 4 ++++ src/Rtmp/RtmpMediaSource.h | 6 +++++- src/Rtmp/RtmpToRtspMediaSource.h | 4 ++++ src/Rtsp/RtspMediaSource.h | 7 ++++++- src/Rtsp/RtspSession.cpp | 2 +- src/Rtsp/RtspToRtmpMediaSource.h | 3 +++ 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 8f656dfd..079fae27 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 8f656dfdff2d7c83583a609212716ae8db921fbf +Subproject commit 079fae2798687300ff55cfd53b6f80010abe6b81 diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index cf709e45..3c6a0e38 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -54,10 +54,13 @@ public: //拖动进度条 return false; } + virtual bool close() { //通知其停止推流 return false; } + + virtual void onReaderChanged(const EventPoller::Ptr &poller,int size,bool add_flag){} }; class MediaInfo { @@ -166,6 +169,7 @@ public: } } + virtual int readerCount() = 0; protected: void regist() ; bool unregist() ; diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index b4534484..b5818791 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -64,6 +64,10 @@ public: return _pRing; } + int readerCount() override { + return _pRing->readerCount(); + } + const AMFValue &getMetaData() const { lock_guard lock(_mtxMap); return _metadata; @@ -87,7 +91,7 @@ public: _mapCfgFrame[pkt->typeId] = pkt; } else{ if(!_bRegisted){ - MediaSource::regist(); + regist(); _bRegisted = true; } _mapStamp[pkt->typeId] = pkt->timeStamp; diff --git a/src/Rtmp/RtmpToRtspMediaSource.h b/src/Rtmp/RtmpToRtspMediaSource.h index 1613b270..c4eff001 100644 --- a/src/Rtmp/RtmpToRtspMediaSource.h +++ b/src/Rtmp/RtmpToRtspMediaSource.h @@ -89,6 +89,10 @@ public: _rtspMuxer->setListener(listener); } } + + int readerCount() override { + return RtmpMediaSource::readerCount() + _rtspMuxer->readerCount(); + } private: RtmpDemuxer::Ptr _rtmpDemuxer; RtspMediaSourceMuxer::Ptr _rtspMuxer; diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index 91139070..aef2e6b6 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -65,7 +65,12 @@ public: //获取媒体源的rtp环形缓冲 return _pRing; } - const string& getSdp() const { + + int readerCount() override { + return _pRing->readerCount(); + } + + const string& getSdp() const { //获取该源的媒体描述信息 return _strSdp; } diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 2ec4179c..c0672114 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -716,7 +716,7 @@ bool RtspSession::handleReq_Play(const Parser &parser) { auto iStartTime = 1000 * atof(strStart.data()); InfoL << "rtsp seekTo(ms):" << iStartTime; useBuf = !pMediaSrc->seekTo(iStartTime); - }else if(pMediaSrc->getRing()->readerCount() == 0){ + }else if(pMediaSrc->readerCount() == 0){ //第一个消费者 pMediaSrc->seekTo(0); } diff --git a/src/Rtsp/RtspToRtmpMediaSource.h b/src/Rtsp/RtspToRtmpMediaSource.h index 7be5d00c..f5d28770 100644 --- a/src/Rtsp/RtspToRtmpMediaSource.h +++ b/src/Rtsp/RtspToRtmpMediaSource.h @@ -85,6 +85,9 @@ public: _rtmpMuxer->setListener(listener); } } + int readerCount() override { + return RtspMediaSource::readerCount() + _rtmpMuxer->readerCount(); + } private: RtspDemuxer::Ptr _rtspDemuxer; RtmpMediaSourceMuxer::Ptr _rtmpMuxer;