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

This commit is contained in:
xiongziliang 2020-08-04 11:10:40 +08:00
parent 40e68fa0f5
commit 47cc97f696
2 changed files with 12 additions and 15 deletions

View File

@ -132,7 +132,8 @@ public:
uint8_t typeId;
uint32_t bodySize = 0;
uint32_t timeStamp = 0;
uint32_t deltaStamp = 0;
bool hasAbsStamp = false;
uint32_t tsField = 0;
uint32_t streamId;
uint32_t chunkId;
std::string strBuf;
@ -153,7 +154,8 @@ public:
typeId = that.typeId;
bodySize = that.bodySize;
timeStamp = that.timeStamp;
deltaStamp = that.deltaStamp;
hasAbsStamp = that.hasAbsStamp;
tsField = that.tsField;
streamId = that.streamId;
chunkId = that.chunkId;
strBuf = std::move(that.strBuf);

View File

@ -554,20 +554,22 @@ void RtmpProtocol::handle_rtmp() {
chunkData.chunkId = _iNowChunkID;
switch (iHeaderLen) {
case 12:
chunkData.hasAbsStamp = true;
chunkData.streamId = load_le32(header.streamId);
case 8:
chunkData.bodySize = load_be24(header.bodySize);
chunkData.typeId = header.typeId;
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) {
//need more data
return;
}
chunkData.deltaStamp = load_be32(_strRcvBuf.data() + iOffset + iHeaderLen);
timeStamp = load_be32(_strRcvBuf.data() + iOffset + iHeaderLen);
iOffset += 4;
}
@ -580,24 +582,17 @@ void RtmpProtocol::handle_rtmp() {
//need more data
return;
}
if (iHeaderLen == 12) {
//绝对时间戳
chunkData.timeStamp = chunkData.deltaStamp;
} else {
//时间戳增量
chunkData.timeStamp += chunkData.deltaStamp;
}
chunkData.strBuf.append(_strRcvBuf, iHeaderLen + iOffset, iMore);
_strRcvBuf.erase(0, iHeaderLen + iOffset + iMore);
if (chunkData.strBuf.size() == chunkData.bodySize) {
//frame is ready
_iNowStreamID = chunkData.streamId;
if (chunkData.bodySize) {
chunkData.timeStamp = timeStamp + (chunkData.hasAbsStamp ? 0 : chunkData.timeStamp);
if(chunkData.bodySize){
handle_rtmpChunk(chunkData);
}
chunkData.strBuf.clear();
chunkData.hasAbsStamp = false;
}
}
}