From a32c97f8b5b2e4b274dfad70a596a7ac918657e5 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 4 Dec 2017 23:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZLToolKit | 1 - build_for_ios.sh | 9 +-- src/Rtmp/RtmpMediaSource.h | 17 +++-- src/Rtmp/RtmpParser.cpp | 32 ++++----- src/Rtmp/RtmpParser.h | 6 +- src/Rtmp/RtmpPlayer.cpp | 2 +- src/Rtmp/RtmpPlayer.h | 8 ++- src/Rtmp/RtmpPlayerImp.h | 2 +- src/Rtmp/RtmpProtocol.cpp | 2 +- src/Rtmp/RtmpProtocol.h | 4 ++ src/Rtmp/RtmpPusher.cpp | 8 +-- src/Rtmp/RtmpPusher.h | 3 + src/Rtmp/RtmpSession.cpp | 16 ++--- src/Rtmp/RtmpSession.h | 7 +- src/Rtmp/RtmpToRtspMediaSource.h | 2 +- src/Rtsp/RtspSession.h | 3 + src/Rtsp/RtspToRtmpMediaSource.cpp | 106 ++++++++++++++--------------- src/Rtsp/RtspToRtmpMediaSource.h | 1 - 18 files changed, 118 insertions(+), 111 deletions(-) delete mode 160000 ZLToolKit diff --git a/ZLToolKit b/ZLToolKit deleted file mode 160000 index dd0bc0b2..00000000 --- a/ZLToolKit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dd0bc0b226bdf2997e3c8bcb53be4705839256c9 diff --git a/build_for_ios.sh b/build_for_ios.sh index e34145ca..7105bff5 100755 --- a/build_for_ios.sh +++ b/build_for_ios.sh @@ -1,12 +1,5 @@ #!/bin/bash -path=`pwd` -wget https://raw.githubusercontent.com/xiongziliang/ZLToolKit/master/build_for_ios.sh -O toolkit_build.sh -sudo chmod +x ./toolkit_build.sh -./toolkit_build.sh -cd $path -cd .. -git clone --depth=50 https://github.com/xiongziliang/ZLMediaKit.git -cd ZLMediaKit + mkdir -p ios_build rm -rf ./build ln -s ./ios_build build diff --git a/src/Rtmp/RtmpMediaSource.h b/src/Rtmp/RtmpMediaSource.h index 7b2e0b78..6a9d4c21 100644 --- a/src/Rtmp/RtmpMediaSource.h +++ b/src/Rtmp/RtmpMediaSource.h @@ -55,11 +55,11 @@ namespace Rtmp { class RtmpMediaSource: public enable_shared_from_this { public: typedef std::shared_ptr Ptr; - typedef RingBuffer RingType; + typedef RingBuffer RingType; RtmpMediaSource(const string &strApp, const string &strId) : m_strApp(strApp), m_strId(strId), - m_pRing(new RingBuffer()), + m_pRing(new RingBuffer()), m_thPool( MediaSender::sendThread()) { } virtual ~RtmpMediaSource() { @@ -130,15 +130,14 @@ public: virtual void onGetMetaData(const AMFValue &_metadata) { m_metadata = _metadata; } - virtual void onGetMedia(const RtmpPacket &_pkt) { - RtmpPacket & pkt = const_cast(_pkt); - if (pkt.isCfgFrame()) { + virtual void onGetMedia(const RtmpPacket::Ptr &pkt) { + if (pkt->isCfgFrame()) { lock_guard lock(m_mtxMap); - m_mapCfgFrame.emplace(pkt.typeId, pkt); + m_mapCfgFrame.emplace(pkt->typeId, pkt); } auto _ring = m_pRing; m_thPool.async([_ring,pkt]() { - _ring->write(pkt,pkt.isVideoKeyFrame()); + _ring->write(pkt,pkt->isVideoKeyFrame()); }); } bool seekTo(uint32_t ui32Stamp) { @@ -164,11 +163,11 @@ protected: function m_onStamp; private: AMFValue m_metadata; - unordered_map m_mapCfgFrame; + unordered_map m_mapCfgFrame; mutable recursive_mutex m_mtxMap; string m_strApp; //媒体app string m_strId; //媒体id - RingBuffer::Ptr m_pRing; //rtp环形缓冲 + RingBuffer::Ptr m_pRing; //rtp环形缓冲 ThreadPool &m_thPool; static unordered_map > > g_mapMediaSrc; //静态的媒体源表 static recursive_mutex g_mtxMediaSrc; ///访问静态的媒体源表的互斥锁 diff --git a/src/Rtmp/RtmpParser.cpp b/src/Rtmp/RtmpParser.cpp index af57e3e6..2a7e9113 100644 --- a/src/Rtmp/RtmpParser.cpp +++ b/src/Rtmp/RtmpParser.cpp @@ -78,8 +78,8 @@ RtmpParser::~RtmpParser() { // TODO Auto-generated destructor stub } -bool RtmpParser::inputRtmp(const RtmpPacket &pkt) { - switch (pkt.typeId) { +bool RtmpParser::inputRtmp(const RtmpPacket::Ptr &pkt) { + switch (pkt->typeId) { case MSG_VIDEO: if (m_bHaveVideo) { return inputVideo(pkt); @@ -95,38 +95,38 @@ bool RtmpParser::inputRtmp(const RtmpPacket &pkt) { } } -inline bool RtmpParser::inputVideo(const RtmpPacket& pkt) { - if (pkt.isCfgFrame()) { +inline bool RtmpParser::inputVideo(const RtmpPacket::Ptr &pkt) { + if (pkt->isCfgFrame()) { //WarnL << " got h264 cfg"; if (m_strSPS.size()) { return false; } m_strSPS.assign("\x00\x00\x00\x01", 4); - m_strSPS.append(pkt.getH264SPS()); + m_strSPS.append(pkt->getH264SPS()); m_strPPS.assign("\x00\x00\x00\x01", 4); - m_strPPS.append(pkt.getH264PPS()); + m_strPPS.append(pkt->getH264PPS()); - getAVCInfo(pkt.getH264SPS(), m_iVideoWidth, m_iVideoHeight, m_fVideoFps); + getAVCInfo(pkt->getH264SPS(), m_iVideoWidth, m_iVideoHeight, m_fVideoFps); return false; } if (m_strSPS.size()) { - uint32_t iTotalLen = pkt.strBuf.size(); + uint32_t iTotalLen = pkt->strBuf.size(); uint32_t iOffset = 5; while(iOffset + 4 < iTotalLen){ uint32_t iFrameLen; - memcpy(&iFrameLen, pkt.strBuf.data() + iOffset, 4); + memcpy(&iFrameLen, pkt->strBuf.data() + iOffset, 4); iFrameLen = ntohl(iFrameLen); iOffset += 4; if(iFrameLen + iOffset > iTotalLen){ break; } - _onGetH264(pkt.strBuf.data() + iOffset, iFrameLen, pkt.timeStamp); + _onGetH264(pkt->strBuf.data() + iOffset, iFrameLen, pkt->timeStamp); iOffset += iFrameLen; } } - return pkt.isVideoKeyFrame(); + return pkt->isVideoKeyFrame(); } inline void RtmpParser::_onGetH264(const char* pcData, int iLen, uint32_t ui32TimeStamp) { switch (pcData[0] & 0x1F) { @@ -157,19 +157,19 @@ inline void RtmpParser::onGetH264(const char* pcData, int iLen, uint32_t ui32Tim m_h264frame.data.clear(); } -inline bool RtmpParser::inputAudio(const RtmpPacket& pkt) { - if (pkt.isCfgFrame()) { +inline bool RtmpParser::inputAudio(const RtmpPacket::Ptr &pkt) { + if (pkt->isCfgFrame()) { if (m_strAudioCfg.size()) { return false; } - m_strAudioCfg = pkt.getAacCfg(); - m_iSampleBit = pkt.getAudioSampleBit(); + m_strAudioCfg = pkt->getAacCfg(); + m_iSampleBit = pkt->getAudioSampleBit(); makeAdtsHeader(m_strAudioCfg,m_adts); getAACInfo(m_adts, m_iSampleRate, m_iChannel); return false; } if (m_strAudioCfg.size()) { - onGetAAC(pkt.strBuf.data() + 2, pkt.strBuf.size() - 2, pkt.timeStamp); + onGetAAC(pkt->strBuf.data() + 2, pkt->strBuf.size() - 2, pkt->timeStamp); } return false; } diff --git a/src/Rtmp/RtmpParser.h b/src/Rtmp/RtmpParser.h index 73ef1c63..c189f99d 100644 --- a/src/Rtmp/RtmpParser.h +++ b/src/Rtmp/RtmpParser.h @@ -48,7 +48,7 @@ public: RtmpParser(const AMFValue &val); virtual ~RtmpParser(); - bool inputRtmp(const RtmpPacket &pkt); + bool inputRtmp(const RtmpPacket::Ptr &pkt); void setOnVideoCB(const function &cb) override{ lock_guard lck(m_mtxCB); @@ -116,8 +116,8 @@ private: inline void onCheckMedia(const AMFValue &obj); //返回值:true 代表是i帧第一个rtp包 - inline bool inputVideo(const RtmpPacket &pkt); - inline bool inputAudio(const RtmpPacket &pkt); + inline bool inputVideo(const RtmpPacket::Ptr &pkt); + inline bool inputAudio(const RtmpPacket::Ptr &pkt); inline void _onGetH264(const char *pcData, int iLen, uint32_t ui32TimeStamp); inline void onGetH264(const char *pcData, int iLen, uint32_t ui32TimeStamp); inline void onGetAAC(const char *pcData, int iLen, uint32_t ui32TimeStamp); diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 6004f6d1..9cb0ba0d 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -312,7 +312,7 @@ void RtmpPlayer::onRtmpChunk(RtmpPacket &chunkData) { if (m_aNowStampTicker[idx].elapsedTime() > 500) { m_adNowStamp[idx] = chunkData.timeStamp; } - _onMediaData(chunkData); + _onMediaData(std::make_shared(chunkData)); } break; default: diff --git a/src/Rtmp/RtmpPlayer.h b/src/Rtmp/RtmpPlayer.h index 037d6316..8a84223c 100644 --- a/src/Rtmp/RtmpPlayer.h +++ b/src/Rtmp/RtmpPlayer.h @@ -59,7 +59,7 @@ public: void teardown() override; protected: virtual bool onCheckMeta(AMFValue &val) =0; - virtual void onMediaData(RtmpPacket &chunkData) =0; + virtual void onMediaData(const RtmpPacket::Ptr &chunkData) =0; float getProgressTime() const; void seekToTime(float fTime); private: @@ -70,7 +70,7 @@ private: m_pBeatTimer.reset(); onShutdown(ex); } - void _onMediaData(RtmpPacket &chunkData) { + void _onMediaData(const RtmpPacket::Ptr &chunkData) { m_mediaTicker.resetTime(); onMediaData(chunkData); } @@ -108,6 +108,10 @@ private: void onSendRawData(const char *pcRawData, int iSize) override { send(pcRawData, iSize); } + void onSendRawData(string &&strData) override { + send(std::move(strData)); + } + template inline void addOnResultCB(const FUN &fun) { diff --git a/src/Rtmp/RtmpPlayerImp.h b/src/Rtmp/RtmpPlayerImp.h index 277da067..45be0f7b 100644 --- a/src/Rtmp/RtmpPlayerImp.h +++ b/src/Rtmp/RtmpPlayerImp.h @@ -69,7 +69,7 @@ private: return false; } } - void onMediaData(RtmpPacket &chunkData) override { + void onMediaData(const RtmpPacket::Ptr &chunkData) override { if(m_parser){ m_parser->inputRtmp(chunkData); } diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index 70516819..1c0a65ab 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -221,7 +221,7 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId, strSend.append(strBuf, pos, chunk); pos += chunk; } - onSendRawData(strSend.data(),strSend.size()); + onSendRawData(std::move(strSend)); m_ui32ByteSent += strSend.size(); if (m_ui32WinSize > 0 && m_ui32ByteSent - m_ui32LastSent >= m_ui32WinSize) { m_ui32LastSent = m_ui32ByteSent; diff --git a/src/Rtmp/RtmpProtocol.h b/src/Rtmp/RtmpProtocol.h index ecaa0dbc..678bc45c 100644 --- a/src/Rtmp/RtmpProtocol.h +++ b/src/Rtmp/RtmpProtocol.h @@ -54,6 +54,10 @@ public: void reset(); protected: virtual void onSendRawData(const char *pcRawData,int iSize) = 0; + virtual void onSendRawData(string &&strData) { + onSendRawData(strData.data(),strData.size()); + }; + virtual void onRtmpChunk(RtmpPacket &chunkData) = 0; virtual void onStreamBegin(uint32_t ui32StreamId){ diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index 6c3e8da3..eef7dcca 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -202,18 +202,18 @@ inline void RtmpPusher::send_metaData(){ enc << "@setDataFrame" << "onMetaData" << src->getMetaData(); sendRequest(MSG_DATA, enc.data()); - src->getConfigFrame([&](const RtmpPacket &pkt){ - sendRtmp(pkt.typeId, m_ui32StreamId, pkt.strBuf, pkt.timeStamp, pkt.chunkId); + src->getConfigFrame([&](const RtmpPacket::Ptr &pkt){ + sendRtmp(pkt->typeId, m_ui32StreamId, pkt->strBuf, pkt->timeStamp, pkt->chunkId); }); m_pRtmpReader = src->getRing()->attach(); weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); - m_pRtmpReader->setReadCB([weakSelf](const RtmpPacket &pkt){ + m_pRtmpReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt){ auto strongSelf = weakSelf.lock(); if(!strongSelf) { return; } - strongSelf->sendRtmp(pkt.typeId, strongSelf->m_ui32StreamId, pkt.strBuf, pkt.timeStamp, pkt.chunkId); + strongSelf->sendRtmp(pkt->typeId, strongSelf->m_ui32StreamId, pkt->strBuf, pkt->timeStamp, pkt->chunkId); }); m_pRtmpReader->setDetachCB([weakSelf](){ auto strongSelf = weakSelf.lock(); diff --git a/src/Rtmp/RtmpPusher.h b/src/Rtmp/RtmpPusher.h index 1c27a2ff..4793d2a2 100644 --- a/src/Rtmp/RtmpPusher.h +++ b/src/Rtmp/RtmpPusher.h @@ -65,6 +65,9 @@ protected: void onSendRawData(const char *pcRawData, int iSize) override { send(pcRawData, iSize); } + void onSendRawData(string &&strData) override { + send(std::move(strData)); + } private: void init(const RtmpMediaSource::Ptr &src); void onShutdown(const SockException &ex) { diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 3b5117e2..d62cb32e 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -207,14 +207,14 @@ void RtmpSession::doPlay(){ invoke << "onMetaData" << src->getMetaData(); sendResponse(MSG_DATA, invoke.data()); - src->getConfigFrame([&](const RtmpPacket &pkt) { + src->getConfigFrame([&](const RtmpPacket::Ptr &pkt) { //DebugL<<"send initial frame"; onSendMedia(pkt); }); m_pRingReader = src->getRing()->attach(); weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); - m_pRingReader->setReadCB([weakSelf](const RtmpPacket& pkt){ + m_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt){ auto strongSelf = weakSelf.lock(); if(!strongSelf) { return; @@ -271,7 +271,7 @@ void RtmpSession::onCmd_pause(AMFDecoder &dec) { m_pRingReader->setReadCB(nullptr); } else { weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); - m_pRingReader->setReadCB([weakSelf](const RtmpPacket& pkt) { + m_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt) { auto strongSelf = weakSelf.lock(); if(!strongSelf) { return; @@ -334,7 +334,7 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) { if (!m_pPublisherSrc) { throw std::runtime_error("Not a rtmp publisher!"); } - m_pPublisherSrc->onGetMedia(chunkData); + m_pPublisherSrc->onGetMedia(std::make_shared(chunkData)); if(!m_bPublisherSrcRegisted && m_pPublisherSrc->ready()){ m_bPublisherSrcRegisted = true; m_pPublisherSrc->regist(); @@ -363,9 +363,9 @@ void RtmpSession::onCmd_seek(AMFDecoder &dec) { sendReply("onStatus", nullptr, status); } -void RtmpSession::onSendMedia(const RtmpPacket& pkt) { - auto modifiedStamp = pkt.timeStamp; - auto &firstStamp = m_aui32FirstStamp[pkt.typeId % 2]; +void RtmpSession::onSendMedia(const RtmpPacket::Ptr &pkt) { + auto modifiedStamp = pkt->timeStamp; + auto &firstStamp = m_aui32FirstStamp[pkt->typeId % 2]; if(!firstStamp){ firstStamp = modifiedStamp; } @@ -377,7 +377,7 @@ void RtmpSession::onSendMedia(const RtmpPacket& pkt) { CLEAR_ARR(m_aui32FirstStamp); modifiedStamp = 0; } - sendRtmp(pkt.typeId, pkt.streamId, pkt.strBuf, modifiedStamp, pkt.chunkId); + sendRtmp(pkt->typeId, pkt->streamId, pkt->strBuf, modifiedStamp, pkt->chunkId); } } /* namespace Rtmp */ diff --git a/src/Rtmp/RtmpSession.h b/src/Rtmp/RtmpSession.h index ff92a9ac..3b679d4e 100644 --- a/src/Rtmp/RtmpSession.h +++ b/src/Rtmp/RtmpSession.h @@ -60,7 +60,7 @@ private: typedef void (RtmpSession::*rtmpCMDHandle)(AMFDecoder &dec); static unordered_map g_mapCmd; - RingBuffer::RingReader::Ptr m_pRingReader; + RingBuffer::RingReader::Ptr m_pRingReader; std::shared_ptr m_pPublisherSrc; bool m_bPublisherSrcRegisted = false; std::weak_ptr m_pPlayerSrc; @@ -80,10 +80,13 @@ private: void onCmd_pause(AMFDecoder &dec); void setMetaData(AMFDecoder &dec); - void onSendMedia(const RtmpPacket &pkt); + void onSendMedia(const RtmpPacket::Ptr &pkt); void onSendRawData(const char *pcRawData,int iSize) override{ send(pcRawData, iSize); } + void onSendRawData(string &&strData) override{ + send(std::move(strData)); + } void onRtmpChunk(RtmpPacket &chunkData) override; template diff --git a/src/Rtmp/RtmpToRtspMediaSource.h b/src/Rtmp/RtmpToRtspMediaSource.h index 645b04fe..1b24d23f 100644 --- a/src/Rtmp/RtmpToRtspMediaSource.h +++ b/src/Rtmp/RtmpToRtspMediaSource.h @@ -73,7 +73,7 @@ public: RtmpMediaSource::onGetMetaData(_metadata); } - virtual void onGetMedia(const RtmpPacket &pkt) override { + virtual void onGetMedia(const RtmpPacket::Ptr &pkt) override { if (m_pParser) { if (!m_pRtspSrc && m_pParser->isInited()) { makeSDP(); diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index 7008f439..c1b85031 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -62,6 +62,9 @@ private: int send(const string &strBuf) override { return m_pSender->send(strBuf); } + int send(string &&strBuf) override { + return m_pSender->send(std::move(strBuf)); + } int send(const char *pcBuf, int iSize) override { return m_pSender->send(pcBuf, iSize); } diff --git a/src/Rtsp/RtspToRtmpMediaSource.cpp b/src/Rtsp/RtspToRtmpMediaSource.cpp index 7686969d..c3e9e6f3 100644 --- a/src/Rtsp/RtspToRtmpMediaSource.cpp +++ b/src/Rtsp/RtspToRtmpMediaSource.cpp @@ -66,40 +66,40 @@ void RtspToRtmpMediaSource::makeVideoConfigPkt() { flags |= (FLV_KEY_FRAME << 4); bool is_config = true; - m_rtmpPkt.strBuf.clear(); + RtmpPacket::Ptr rtmpPkt(new RtmpPacket); //////////header - m_rtmpPkt.strBuf.push_back(flags); - m_rtmpPkt.strBuf.push_back(!is_config); - m_rtmpPkt.strBuf.append("\x0\x0\x0", 3); + rtmpPkt->strBuf.push_back(flags); + rtmpPkt->strBuf.push_back(!is_config); + rtmpPkt->strBuf.append("\x0\x0\x0", 3); ////////////sps - m_rtmpPkt.strBuf.push_back(1); // version + rtmpPkt->strBuf.push_back(1); // version string m_sps = m_pParser->getSps().substr(4); string m_pps = m_pParser->getPps().substr(4); //DebugL<strBuf.push_back(m_sps[1]); // profile + rtmpPkt->strBuf.push_back(m_sps[2]); // compat + rtmpPkt->strBuf.push_back(m_sps[3]); // level + rtmpPkt->strBuf.push_back(0xff); // 6 bits reserved + 2 bits nal size length - 1 (11) + rtmpPkt->strBuf.push_back(0xe1); // 3 bits reserved + 5 bits number of sps (00001) uint16_t size = m_sps.size(); size = htons(size); - m_rtmpPkt.strBuf.append((char *) &size, 2); - m_rtmpPkt.strBuf.append(m_sps); + rtmpPkt->strBuf.append((char *) &size, 2); + rtmpPkt->strBuf.append(m_sps); /////////////pps - m_rtmpPkt.strBuf.push_back(1); // version + rtmpPkt->strBuf.push_back(1); // version size = m_pps.size(); size = htons(size); - m_rtmpPkt.strBuf.append((char *) &size, 2); - m_rtmpPkt.strBuf.append(m_pps); + rtmpPkt->strBuf.append((char *) &size, 2); + rtmpPkt->strBuf.append(m_pps); - m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size(); - m_rtmpPkt.chunkId = CHUNK_VIDEO; - m_rtmpPkt.streamId = STREAM_MEDIA; - m_rtmpPkt.timeStamp = 0; - m_rtmpPkt.typeId = MSG_VIDEO; - m_pRtmpSrc->onGetMedia(m_rtmpPkt); + rtmpPkt->bodySize = rtmpPkt->strBuf.size(); + rtmpPkt->chunkId = CHUNK_VIDEO; + rtmpPkt->streamId = STREAM_MEDIA; + rtmpPkt->timeStamp = 0; + rtmpPkt->typeId = MSG_VIDEO; + m_pRtmpSrc->onGetMedia(rtmpPkt); } void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) { if(m_pRecorder){ @@ -119,40 +119,40 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) { flags |= (FLV_INTER_FRAME << 4); break; } - m_rtmpPkt.strBuf.clear(); - m_rtmpPkt.strBuf.push_back(flags); - m_rtmpPkt.strBuf.push_back(!is_config); - m_rtmpPkt.strBuf.append("\x0\x0\x0", 3); + RtmpPacket::Ptr rtmpPkt(new RtmpPacket); + rtmpPkt->strBuf.push_back(flags); + rtmpPkt->strBuf.push_back(!is_config); + rtmpPkt->strBuf.append("\x0\x0\x0", 3); uint32_t size = frame.data.size() - 4; size = htonl(size); - m_rtmpPkt.strBuf.append((char *) &size, 4); - m_rtmpPkt.strBuf.append(&frame.data[4], frame.data.size() - 4); + rtmpPkt->strBuf.append((char *) &size, 4); + rtmpPkt->strBuf.append(&frame.data[4], frame.data.size() - 4); - m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size(); - m_rtmpPkt.chunkId = CHUNK_VIDEO; - m_rtmpPkt.streamId = STREAM_MEDIA; - m_rtmpPkt.timeStamp = frame.timeStamp; - m_rtmpPkt.typeId = MSG_VIDEO; - m_pRtmpSrc->onGetMedia(m_rtmpPkt); + rtmpPkt->bodySize = rtmpPkt->strBuf.size(); + rtmpPkt->chunkId = CHUNK_VIDEO; + rtmpPkt->streamId = STREAM_MEDIA; + rtmpPkt->timeStamp = frame.timeStamp; + rtmpPkt->typeId = MSG_VIDEO; + m_pRtmpSrc->onGetMedia(rtmpPkt); } void RtspToRtmpMediaSource::onGetAdts(const AdtsFrame& frame) { if(m_pRecorder){ m_pRecorder->inputAAC((char *) frame.data, frame.aac_frame_length, frame.timeStamp); } - m_rtmpPkt.strBuf.clear(); + RtmpPacket::Ptr rtmpPkt(new RtmpPacket); //////////header uint8_t is_config = false; - m_rtmpPkt.strBuf.push_back(m_ui8AudioFlags); - m_rtmpPkt.strBuf.push_back(!is_config); - m_rtmpPkt.strBuf.append((char *) frame.data + 7, frame.aac_frame_length - 7); + rtmpPkt->strBuf.push_back(m_ui8AudioFlags); + rtmpPkt->strBuf.push_back(!is_config); + rtmpPkt->strBuf.append((char *) frame.data + 7, frame.aac_frame_length - 7); - m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size(); - m_rtmpPkt.chunkId = CHUNK_AUDIO; - m_rtmpPkt.streamId = STREAM_MEDIA; - m_rtmpPkt.timeStamp = frame.timeStamp; - m_rtmpPkt.typeId = MSG_AUDIO; - m_pRtmpSrc->onGetMedia(m_rtmpPkt); + rtmpPkt->bodySize = rtmpPkt->strBuf.size(); + rtmpPkt->chunkId = CHUNK_AUDIO; + rtmpPkt->streamId = STREAM_MEDIA; + rtmpPkt->timeStamp = frame.timeStamp; + rtmpPkt->typeId = MSG_AUDIO; + m_pRtmpSrc->onGetMedia(rtmpPkt); } void RtspToRtmpMediaSource::makeAudioConfigPkt() { @@ -180,19 +180,19 @@ void RtspToRtmpMediaSource::makeAudioConfigPkt() { m_ui8AudioFlags = (flvAudioType << 4) | (flvSampleRate << 2) | (flvSampleBit << 1) | flvStereoOrMono; - m_rtmpPkt.strBuf.clear(); + RtmpPacket::Ptr rtmpPkt(new RtmpPacket); //////////header uint8_t is_config = true; - m_rtmpPkt.strBuf.push_back(m_ui8AudioFlags); - m_rtmpPkt.strBuf.push_back(!is_config); - m_rtmpPkt.strBuf.append(m_pParser->getAudioCfg()); + rtmpPkt->strBuf.push_back(m_ui8AudioFlags); + rtmpPkt->strBuf.push_back(!is_config); + rtmpPkt->strBuf.append(m_pParser->getAudioCfg()); - m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size(); - m_rtmpPkt.chunkId = CHUNK_AUDIO; - m_rtmpPkt.streamId = STREAM_MEDIA; - m_rtmpPkt.timeStamp = 0; - m_rtmpPkt.typeId = MSG_AUDIO; - m_pRtmpSrc->onGetMedia(m_rtmpPkt); + rtmpPkt->bodySize = rtmpPkt->strBuf.size(); + rtmpPkt->chunkId = CHUNK_AUDIO; + rtmpPkt->streamId = STREAM_MEDIA; + rtmpPkt->timeStamp = 0; + rtmpPkt->typeId = MSG_AUDIO; + m_pRtmpSrc->onGetMedia(rtmpPkt); } void RtspToRtmpMediaSource::makeMetaData() { diff --git a/src/Rtsp/RtspToRtmpMediaSource.h b/src/Rtsp/RtspToRtmpMediaSource.h index b38f6c54..fe74cea5 100644 --- a/src/Rtsp/RtspToRtmpMediaSource.h +++ b/src/Rtsp/RtspToRtmpMediaSource.h @@ -101,7 +101,6 @@ public: private: RtpParser::Ptr m_pParser; RtmpMediaSource::Ptr m_pRtmpSrc; - RtmpPacket m_rtmpPkt; uint8_t m_ui8AudioFlags = 0; MediaRecorder::Ptr m_pRecorder; bool m_bEnableFile = true;