From 305f27234426463ea1d83cb96bbe90bd98d85a3a Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Sat, 27 May 2017 14:37:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3rtmp=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/Rtmp.h | 1 + src/Rtmp/RtmpProtocol.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Rtmp/Rtmp.h b/src/Rtmp/Rtmp.h index 0a233f71..9c274cdf 100644 --- a/src/Rtmp/Rtmp.h +++ b/src/Rtmp/Rtmp.h @@ -95,6 +95,7 @@ public: uint32_t bodySize = 0; uint32_t timeStamp = 0; bool hasAbsStamp = false; + bool hasExtStamp = false; uint32_t deltaStamp = 0; uint32_t streamId; uint32_t chunkId; diff --git a/src/Rtmp/RtmpProtocol.cpp b/src/Rtmp/RtmpProtocol.cpp index fb497e87..2defe6d3 100644 --- a/src/Rtmp/RtmpProtocol.cpp +++ b/src/Rtmp/RtmpProtocol.cpp @@ -450,6 +450,10 @@ void RtmpProtocol::handle_rtmp() { static const size_t HEADER_LENGTH[] = { 12, 8, 4, 1 }; size_t iHeaderLen = HEADER_LENGTH[flags >> 6]; m_iNowChunkID = flags & 0x3f; + if(m_iNowChunkID >10){ + int i=0; + i++; + } switch (m_iNowChunkID) { case 0: { //0 值表示二字节形式,并且 ID 范围 64 - 319 @@ -494,14 +498,15 @@ void RtmpProtocol::handle_rtmp() { chunkData.typeId = header.typeId; case 4: chunkData.deltaStamp = load_be24(header.timeStamp); + chunkData.hasExtStamp = chunkData.deltaStamp == 0xFFFFFF; } - if (chunkData.deltaStamp == 0xFFFFFF) { + if (chunkData.hasExtStamp) { if (m_strRcvBuf.size() < iHeaderLen + iOffset + 4) { //need more data return; } - chunkData.deltaStamp = load_be32( m_strRcvBuf.data() + iOffset + iHeaderLen); + chunkData.deltaStamp = load_be32(m_strRcvBuf.data() + iOffset + iHeaderLen); iOffset += 4; } @@ -520,13 +525,16 @@ void RtmpProtocol::handle_rtmp() { if (chunkData.strBuf.size() == chunkData.bodySize) { //frame is ready + m_iNowStreamID = chunkData.streamId; chunkData.timeStamp = chunkData.deltaStamp + (chunkData.hasAbsStamp ? 0 : chunkData.timeStamp); - chunkData.hasAbsStamp = false; - m_iNowStreamID = chunkData.streamId; + if(chunkData.bodySize){ handle_rtmpChunk(chunkData); } chunkData.strBuf.clear(); + chunkData.hasAbsStamp = false; + chunkData.hasExtStamp = false; + chunkData.deltaStamp = 0; } } }