Commit 47cc97f6 by xiongziliang

修复rtmp增长时间戳相关问题

parent 40e68fa0
...@@ -132,7 +132,8 @@ public: ...@@ -132,7 +132,8 @@ public:
uint8_t typeId; uint8_t typeId;
uint32_t bodySize = 0; uint32_t bodySize = 0;
uint32_t timeStamp = 0; uint32_t timeStamp = 0;
uint32_t deltaStamp = 0; bool hasAbsStamp = false;
uint32_t tsField = 0;
uint32_t streamId; uint32_t streamId;
uint32_t chunkId; uint32_t chunkId;
std::string strBuf; std::string strBuf;
...@@ -153,7 +154,8 @@ public: ...@@ -153,7 +154,8 @@ public:
typeId = that.typeId; typeId = that.typeId;
bodySize = that.bodySize; bodySize = that.bodySize;
timeStamp = that.timeStamp; timeStamp = that.timeStamp;
deltaStamp = that.deltaStamp; hasAbsStamp = that.hasAbsStamp;
tsField = that.tsField;
streamId = that.streamId; streamId = that.streamId;
chunkId = that.chunkId; chunkId = that.chunkId;
strBuf = std::move(that.strBuf); strBuf = std::move(that.strBuf);
......
...@@ -554,20 +554,22 @@ void RtmpProtocol::handle_rtmp() { ...@@ -554,20 +554,22 @@ void RtmpProtocol::handle_rtmp() {
chunkData.chunkId = _iNowChunkID; chunkData.chunkId = _iNowChunkID;
switch (iHeaderLen) { switch (iHeaderLen) {
case 12: case 12:
chunkData.hasAbsStamp = true;
chunkData.streamId = load_le32(header.streamId); chunkData.streamId = load_le32(header.streamId);
case 8: case 8:
chunkData.bodySize = load_be24(header.bodySize); chunkData.bodySize = load_be24(header.bodySize);
chunkData.typeId = header.typeId; chunkData.typeId = header.typeId;
case 4: case 4:
chunkData.deltaStamp = load_be24(header.timeStamp); chunkData.tsField = load_be24(header.timeStamp);
} }
if (chunkData.deltaStamp == 0xFFFFFF) { auto timeStamp = chunkData.tsField;
if (chunkData.tsField == 0xFFFFFF) {
if (_strRcvBuf.size() < iHeaderLen + iOffset + 4) { if (_strRcvBuf.size() < iHeaderLen + iOffset + 4) {
//need more data //need more data
return; return;
} }
chunkData.deltaStamp = load_be32(_strRcvBuf.data() + iOffset + iHeaderLen); timeStamp = load_be32(_strRcvBuf.data() + iOffset + iHeaderLen);
iOffset += 4; iOffset += 4;
} }
...@@ -580,24 +582,17 @@ void RtmpProtocol::handle_rtmp() { ...@@ -580,24 +582,17 @@ void RtmpProtocol::handle_rtmp() {
//need more data //need more data
return; return;
} }
if (iHeaderLen == 12) {
//绝对时间戳
chunkData.timeStamp = chunkData.deltaStamp;
} else {
//时间戳增量
chunkData.timeStamp += chunkData.deltaStamp;
}
chunkData.strBuf.append(_strRcvBuf, iHeaderLen + iOffset, iMore); chunkData.strBuf.append(_strRcvBuf, iHeaderLen + iOffset, iMore);
_strRcvBuf.erase(0, iHeaderLen + iOffset + iMore); _strRcvBuf.erase(0, iHeaderLen + iOffset + iMore);
if (chunkData.strBuf.size() == chunkData.bodySize) { if (chunkData.strBuf.size() == chunkData.bodySize) {
//frame is ready //frame is ready
_iNowStreamID = chunkData.streamId; _iNowStreamID = chunkData.streamId;
if (chunkData.bodySize) { chunkData.timeStamp = timeStamp + (chunkData.hasAbsStamp ? 0 : chunkData.timeStamp);
if(chunkData.bodySize){
handle_rtmpChunk(chunkData); handle_rtmpChunk(chunkData);
} }
chunkData.strBuf.clear(); chunkData.strBuf.clear();
chunkData.hasAbsStamp = false;
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论