From 9a2d54ce9a0822e2a98d10d9a9fb4b83a68b6680 Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Sat, 27 May 2017 09:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3rtmp=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/Rtmp.h | 2 +- src/Rtmp/RtmpProtocol.cpp | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Rtmp/Rtmp.h b/src/Rtmp/Rtmp.h index 2a7819fa..b9e5db74 100644 --- a/src/Rtmp/Rtmp.h +++ b/src/Rtmp/Rtmp.h @@ -93,7 +93,7 @@ public: uint8_t typeId; uint32_t bodySize = 0; uint32_t timeStamp = 0; - bool extStamp = false; + uint32_t deltaStamp = 0; uint32_t streamId; uint32_t chunkId; std::string strBuf; diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index 9cd247b9..245b3918 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -492,35 +492,34 @@ void RtmpProtocol::handle_rtmp() { chunkData.bodySize = load_be24(header.bodySize); chunkData.typeId = header.typeId; case 4: - uint32_t ts = load_be24(header.timeStamp); - if (ts == 0xFFFFFF) { - chunkData.extStamp = true; - }else{ - chunkData.extStamp = false; - chunkData.timeStamp = ts + ((iHeaderLen == 12) ? 0 : chunkData.timeStamp); - } + chunkData.deltaStamp = load_be24(header.timeStamp); } - if (chunkData.extStamp) { + + if (chunkData.deltaStamp == 0xFFFFFF) { if (m_strRcvBuf.size() < iHeaderLen + iOffset + 4) { //need more data return; } - chunkData.timeStamp = load_be32( m_strRcvBuf.data() + iOffset + iHeaderLen); + chunkData.deltaStamp = load_be32( m_strRcvBuf.data() + iOffset + iHeaderLen); iOffset += 4; } - - if (chunkData.bodySize < chunkData.strBuf.size()) { + + if (chunkData.bodySize < chunkData.strBuf.size()) { throw std::runtime_error("非法的bodySize"); } - + auto iMore = min(m_iChunkLenIn, chunkData.bodySize - chunkData.strBuf.size()); if (m_strRcvBuf.size() < iHeaderLen + iOffset + iMore) { //need more data return; } - chunkData.strBuf.append(m_strRcvBuf, iHeaderLen + iOffset, iMore); + + chunkData.strBuf.append(m_strRcvBuf, iHeaderLen + iOffset, iMore); m_strRcvBuf.erase(0, iHeaderLen + iOffset + iMore); + if (chunkData.strBuf.size() == chunkData.bodySize) { + //frame is ready + chunkData.timeStamp = chunkData.deltaStamp + (iHeaderLen == 12 ? 0 : chunkData.timeStamp); m_iNowStreamID = chunkData.streamId; if(chunkData.bodySize){ handle_rtmpChunk(chunkData);