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);