Commit b4a3b608 by xiongziliang

修复rtmp增长时间戳相关bug

parent fdbed9e8
/* /*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
* *
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
...@@ -130,8 +130,6 @@ public: ...@@ -130,8 +130,6 @@ public:
uint8_t typeId; uint8_t typeId;
uint32_t bodySize = 0; uint32_t bodySize = 0;
uint32_t timeStamp = 0; uint32_t timeStamp = 0;
bool hasAbsStamp = false;
bool hasExtStamp = false;
uint32_t deltaStamp = 0; uint32_t deltaStamp = 0;
uint32_t streamId; uint32_t streamId;
uint32_t chunkId; uint32_t chunkId;
...@@ -153,8 +151,6 @@ public: ...@@ -153,8 +151,6 @@ public:
typeId = that.typeId; typeId = that.typeId;
bodySize = that.bodySize; bodySize = that.bodySize;
timeStamp = that.timeStamp; timeStamp = that.timeStamp;
hasAbsStamp = that.hasAbsStamp;
hasExtStamp = that.hasExtStamp;
deltaStamp = that.deltaStamp; deltaStamp = that.deltaStamp;
streamId = that.streamId; streamId = that.streamId;
chunkId = that.chunkId; chunkId = that.chunkId;
......
...@@ -514,7 +514,7 @@ void RtmpProtocol::handle_rtmp() { ...@@ -514,7 +514,7 @@ void RtmpProtocol::handle_rtmp() {
while (!_strRcvBuf.empty()) { while (!_strRcvBuf.empty()) {
uint8_t flags = _strRcvBuf[0]; uint8_t flags = _strRcvBuf[0];
int iOffset = 0; int iOffset = 0;
static const size_t HEADER_LENGTH[] = { 12, 8, 4, 1 }; static const size_t HEADER_LENGTH[] = {12, 8, 4, 1};
size_t iHeaderLen = HEADER_LENGTH[flags >> 6]; size_t iHeaderLen = HEADER_LENGTH[flags >> 6];
_iNowChunkID = flags & 0x3f; _iNowChunkID = flags & 0x3f;
switch (_iNowChunkID) { switch (_iNowChunkID) {
...@@ -554,17 +554,15 @@ void RtmpProtocol::handle_rtmp() { ...@@ -554,17 +554,15 @@ 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.deltaStamp = load_be24(header.timeStamp);
chunkData.hasExtStamp = chunkData.deltaStamp == 0xFFFFFF;
} }
if (chunkData.hasExtStamp) { if (chunkData.deltaStamp == 0xFFFFFF) {
if (_strRcvBuf.size() < iHeaderLen + iOffset + 4) { if (_strRcvBuf.size() < iHeaderLen + iOffset + 4) {
//need more data //need more data
return; return;
...@@ -583,21 +581,23 @@ void RtmpProtocol::handle_rtmp() { ...@@ -583,21 +581,23 @@ void RtmpProtocol::handle_rtmp() {
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;
chunkData.timeStamp = chunkData.deltaStamp + (chunkData.hasAbsStamp ? 0 : chunkData.timeStamp); if (chunkData.bodySize) {
if(chunkData.bodySize){
handle_rtmpChunk(chunkData); handle_rtmpChunk(chunkData);
} }
chunkData.strBuf.clear(); chunkData.strBuf.clear();
chunkData.hasAbsStamp = false;
chunkData.hasExtStamp = false;
chunkData.deltaStamp = 0;
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论