From 3d83a236b63ab17ce733a062379c8f8e1730e158 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 25 Oct 2018 16:55:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Device/Device.cpp | 4 ++-- src/Rtmp/RtmpMediaSource.h | 8 +++----- src/Rtmp/RtmpPlayerImp.h | 2 +- src/Rtmp/RtmpSession.cpp | 2 +- src/Rtmp/RtmpToRtspMediaSource.cpp | 4 ++-- src/Rtmp/RtmpToRtspMediaSource.h | 4 ++-- src/Rtsp/RtspMediaSource.h | 8 ++------ src/Rtsp/RtspPlayerImp.h | 2 +- src/Rtsp/RtspToRtmpMediaSource.cpp | 8 ++++---- src/Rtsp/RtspToRtmpMediaSource.h | 4 ++-- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index 863a5acd..9346bea7 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -104,7 +104,7 @@ void DevChannel::inputH264(const char* pcData, int iDataLen, uint32_t uiStamp) { uint32_t ui32Ssrc; memcpy(&ui32Ssrc, makeRandStr(4, false).data(), 4); auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) { - onGetRTP(pkt,bKeyPos); + onWrite(pkt,bKeyPos); }; GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Rtp::kVideoMtuSize); _pRtpMaker_h264.reset(new RtpMaker_H264(lam, ui32Ssrc,videoMtu)); @@ -136,7 +136,7 @@ void DevChannel::inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t u uint32_t ssrc; memcpy(&ssrc, makeRandStr(8, false).data() + 4, 4); auto lam = [this](const RtpPacket::Ptr &pkt, bool keyPos) { - onGetRTP(pkt,keyPos); + onWrite(pkt,keyPos); }; GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Rtp::kAudioMtuSize); _pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc, audioMtu,_audio->iSampleRate)); diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index 0db2e733..784bf9ce 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -76,6 +76,7 @@ public: } } + virtual void onGetMetaData(const AMFValue &metadata) { lock_guard lock(_mtxMap); _metadata = metadata; @@ -88,7 +89,8 @@ public: _bAsyncRegist = true; } } - virtual void onGetMedia(const RtmpPacket::Ptr &pkt) { + + void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override { lock_guard lock(_mtxMap); if (pkt->isCfgFrame()) { _mapCfgFrame.emplace(pkt->typeId, pkt); @@ -107,10 +109,6 @@ private: lock_guard lock(_mtxMap); return _iCfgFrameSize != -1 && _iCfgFrameSize == _mapCfgFrame.size(); } - - void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override { - onGetMedia(pkt); - } protected: AMFValue _metadata; unordered_map _mapCfgFrame; diff --git a/src/Rtmp/RtmpPlayerImp.h b/src/Rtmp/RtmpPlayerImp.h index fa093e01..688b9515 100644 --- a/src/Rtmp/RtmpPlayerImp.h +++ b/src/Rtmp/RtmpPlayerImp.h @@ -80,7 +80,7 @@ private: _parser->inputRtmp(chunkData); } if(_pRtmpMediaSrc){ - _pRtmpMediaSrc->onGetMedia(chunkData); + _pRtmpMediaSrc->onWrite(chunkData); } } diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 559aa706..6f901e99 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -509,7 +509,7 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) { if(rtmp_modify_stamp){ chunkData.timeStamp = _stampTicker[chunkData.typeId % 2].elapsedTime(); } - _pPublisherSrc->onGetMedia(std::make_shared(chunkData)); + _pPublisherSrc->onWrite(std::make_shared(chunkData)); } break; default: diff --git a/src/Rtmp/RtmpToRtspMediaSource.cpp b/src/Rtmp/RtmpToRtspMediaSource.cpp index 4d03eaea..71261ca9 100644 --- a/src/Rtmp/RtmpToRtspMediaSource.cpp +++ b/src/Rtmp/RtmpToRtspMediaSource.cpp @@ -83,7 +83,7 @@ void RtmpToRtspMediaSource::makeSDP() { // uint32_t ssrc0; // memcpy(&ssrc0, makeRandStr(4, false).data(), 4); // auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) { -// _pRtspSrc->onGetRTP(pkt,bKeyPos); +// _pRtspSrc->onWrite(pkt,bKeyPos); // }; // // GET_CONFIG_AND_REGISTER(uint32_t,videoMtu,Rtp::kVideoMtuSize); @@ -126,7 +126,7 @@ void RtmpToRtspMediaSource::makeSDP() { // uint32_t ssrc1; // memcpy(&ssrc1, makeRandStr(8, false).data() + 4, 4); // auto lam = [this](const RtpPacket::Ptr &pkt, bool bKeyPos) { -// _pRtspSrc->onGetRTP(pkt,bKeyPos); +// _pRtspSrc->onWrite(pkt,bKeyPos); // }; // GET_CONFIG_AND_REGISTER(uint32_t,audioMtu,Rtp::kAudioMtuSize); // _pRtpMaker_aac.reset(new RtpMaker_AAC(lam, ssrc1, audioMtu,_pParser->getAudioSampleRate())); diff --git a/src/Rtmp/RtmpToRtspMediaSource.h b/src/Rtmp/RtmpToRtspMediaSource.h index 63aca468..41a8dc6f 100644 --- a/src/Rtmp/RtmpToRtspMediaSource.h +++ b/src/Rtmp/RtmpToRtspMediaSource.h @@ -72,14 +72,14 @@ public: RtmpMediaSource::onGetMetaData(_metadata); } - void onGetMedia(const RtmpPacket::Ptr &pkt) override { + void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos) override { if (_pParser) { if (!_pRtspSrc && _pParser->isInited()) { makeSDP(); } _pParser->inputRtmp(pkt); } - RtmpMediaSource::onGetMedia(pkt); + RtmpMediaSource::onWrite(pkt,key_pos); } private: diff --git a/src/Rtsp/RtspMediaSource.h b/src/Rtsp/RtspMediaSource.h index db5ee444..b4c37e40 100644 --- a/src/Rtsp/RtspMediaSource.h +++ b/src/Rtsp/RtspMediaSource.h @@ -85,7 +85,8 @@ public: _strSdp = sdp; regist(); } - virtual void onGetRTP(const RtpPacket::Ptr &rtppt, bool keyPos) { + + void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override { auto &trackRef = _mapTracks[rtppt->type]; trackRef.seq = rtppt->sequence; trackRef.timeStamp = rtppt->timeStamp; @@ -93,11 +94,6 @@ public: trackRef.type = rtppt->type; _pRing->write(rtppt,keyPos); } - -private: - void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override { - onGetRTP(rtppt,keyPos); - } protected: unordered_map _mapTracks; string _strSdp; //媒体描述信息 diff --git a/src/Rtsp/RtspPlayerImp.h b/src/Rtsp/RtspPlayerImp.h index dcf2c154..8a95ef37 100644 --- a/src/Rtsp/RtspPlayerImp.h +++ b/src/Rtsp/RtspPlayerImp.h @@ -84,7 +84,7 @@ private: } if(_pRtspMediaSrc){ - _pRtspMediaSrc->onGetRTP(rtppt,true); + _pRtspMediaSrc->onWrite(rtppt,true); } } diff --git a/src/Rtsp/RtspToRtmpMediaSource.cpp b/src/Rtsp/RtspToRtmpMediaSource.cpp index 15546189..7e97eff4 100644 --- a/src/Rtsp/RtspToRtmpMediaSource.cpp +++ b/src/Rtsp/RtspToRtmpMediaSource.cpp @@ -86,7 +86,7 @@ void RtspToRtmpMediaSource::makeVideoConfigPkt() { rtmpPkt->streamId = STREAM_MEDIA; rtmpPkt->timeStamp = 0; rtmpPkt->typeId = MSG_VIDEO; - _pRtmpSrc->onGetMedia(rtmpPkt); + _pRtmpSrc->onWrite(rtmpPkt); } void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) { if(_pRecorder){ @@ -120,7 +120,7 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) { rtmpPkt->streamId = STREAM_MEDIA; rtmpPkt->timeStamp = frame.timeStamp; rtmpPkt->typeId = MSG_VIDEO; - _pRtmpSrc->onGetMedia(rtmpPkt); + _pRtmpSrc->onWrite(rtmpPkt); } void RtspToRtmpMediaSource::onGetAAC(const AACFrame& frame) { if(_pRecorder){ @@ -139,7 +139,7 @@ void RtspToRtmpMediaSource::onGetAAC(const AACFrame& frame) { rtmpPkt->streamId = STREAM_MEDIA; rtmpPkt->timeStamp = frame.timeStamp; rtmpPkt->typeId = MSG_AUDIO; - _pRtmpSrc->onGetMedia(rtmpPkt); + _pRtmpSrc->onWrite(rtmpPkt); } void RtspToRtmpMediaSource::makeAudioConfigPkt() { @@ -181,7 +181,7 @@ void RtspToRtmpMediaSource::makeAudioConfigPkt() { rtmpPkt->streamId = STREAM_MEDIA; rtmpPkt->timeStamp = 0; rtmpPkt->typeId = MSG_AUDIO; - _pRtmpSrc->onGetMedia(rtmpPkt); + _pRtmpSrc->onWrite(rtmpPkt); #endif } diff --git a/src/Rtsp/RtspToRtmpMediaSource.h b/src/Rtsp/RtspToRtmpMediaSource.h index 8bfc2943..fac15a87 100644 --- a/src/Rtsp/RtspToRtmpMediaSource.h +++ b/src/Rtsp/RtspToRtmpMediaSource.h @@ -61,11 +61,11 @@ public: } RtspMediaSource::onGetSDP(strSdp); } - virtual void onGetRTP(const RtpPacket::Ptr &pRtppkt, bool bKeyPos) override{ + virtual void onWrite(const RtpPacket::Ptr &pRtppkt, bool bKeyPos) override{ if (_pParser) { bKeyPos = _pParser->inputRtp(pRtppkt); } - RtspMediaSource::onGetRTP(pRtppkt, bKeyPos); + RtspMediaSource::onWrite(pRtppkt, bKeyPos); } int readerCount(){