diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index c713905a..942e9bb1 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit c713905a73ba1a86e9978a43e29a3e3d5e6bf77e +Subproject commit 942e9bb1eb38285c78fcfef9d7468f249b4d36e4 diff --git a/src/Rtsp/RtpReceiver.cpp b/src/Rtsp/RtpReceiver.cpp index f14ef433..febc28f4 100644 --- a/src/Rtsp/RtpReceiver.cpp +++ b/src/Rtsp/RtpReceiver.cpp @@ -81,7 +81,7 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char rtppt.payload[0] = '$'; rtppt.payload[1] = rtppt.interleaved; - rtppt.payload[2] = (uiLen & 0xFF00) >> 8; + rtppt.payload[2] = uiLen >> 8; rtppt.payload[3] = (uiLen & 0x00FF); rtppt.offset = 16; @@ -100,14 +100,20 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char memcpy(rtppt.payload + 4, pucData, uiLen); /////////////////////////////////RTP排序逻辑/////////////////////////////////// - if(rtppt.sequence != (uint16_t)(_aui16LastSeq[iTrackidx] + 1) && _aui16LastSeq[iTrackidx] != 0){ + if(rtppt.sequence != _aui16LastSeq[iTrackidx] + 1 && _aui16LastSeq[iTrackidx] != 0){ //包乱序或丢包 - _aui64SeqOkCnt[iTrackidx] = 0; + _aui32SeqOkCnt[iTrackidx] = 0; _abSortStarted[iTrackidx] = true; - //WarnL << "包乱序或丢包:" << trackidx <<" " << rtppt.sequence << " " << _aui16LastSeq[trackidx]; + + if(_aui16LastSeq[iTrackidx] > rtppt.sequence && _aui16LastSeq[iTrackidx] - rtppt.sequence > 0x7FFF){ + //sequence回环,清空所有排序缓存 + while (_amapRtpSort[iTrackidx].size()) { + POP_HEAD(iTrackidx) + } + } }else{ //正确序列的包 - _aui64SeqOkCnt[iTrackidx]++; + _aui32SeqOkCnt[iTrackidx]++; } _aui16LastSeq[iTrackidx] = rtppt.sequence; @@ -116,9 +122,9 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char _amapRtpSort[iTrackidx].emplace(rtppt.sequence, pt_ptr); GET_CONFIG_AND_REGISTER(uint32_t,clearCount,Rtp::kClearCount); GET_CONFIG_AND_REGISTER(uint32_t,maxRtpCount,Rtp::kMaxRtpCount); - if (_aui64SeqOkCnt[iTrackidx] >= clearCount) { + if (_aui32SeqOkCnt[iTrackidx] >= clearCount) { //网络环境改善,需要清空排序缓存 - _aui64SeqOkCnt[iTrackidx] = 0; + _aui32SeqOkCnt[iTrackidx] = 0; _abSortStarted[iTrackidx] = false; while (_amapRtpSort[iTrackidx].size()) { POP_HEAD(iTrackidx) @@ -138,7 +144,7 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char void RtpReceiver::clear() { CLEAR_ARR(_aui16LastSeq) CLEAR_ARR(_aui32SsrcErrorCnt) - CLEAR_ARR(_aui64SeqOkCnt) + CLEAR_ARR(_aui32SeqOkCnt) CLEAR_ARR(_abSortStarted) _amapRtpSort[0].clear(); diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index eb9a7673..fc52f9d8 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -68,9 +68,9 @@ private: uint32_t _aui32SsrcErrorCnt[2] = { 0, 0 }; /* RTP包排序所用参数 */ uint16_t _aui16LastSeq[2] = { 0 , 0 }; - uint64_t _aui64SeqOkCnt[2] = { 0 , 0}; + uint32_t _aui32SeqOkCnt[2] = { 0 , 0}; bool _abSortStarted[2] = { 0 , 0}; - map _amapRtpSort[2]; + map _amapRtpSort[2]; RtspMediaSource::PoolType _pktPool; };