优化rtp排序逻辑,处理seq回环的情况

This commit is contained in:
xiongziliang 2019-04-11 18:26:40 +08:00
parent dee4f0317a
commit 9fc534d815
3 changed files with 17 additions and 11 deletions

@ -1 +1 @@
Subproject commit c713905a73ba1a86e9978a43e29a3e3d5e6bf77e Subproject commit 942e9bb1eb38285c78fcfef9d7468f249b4d36e4

View File

@ -81,7 +81,7 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
rtppt.payload[0] = '$'; rtppt.payload[0] = '$';
rtppt.payload[1] = rtppt.interleaved; rtppt.payload[1] = rtppt.interleaved;
rtppt.payload[2] = (uiLen & 0xFF00) >> 8; rtppt.payload[2] = uiLen >> 8;
rtppt.payload[3] = (uiLen & 0x00FF); rtppt.payload[3] = (uiLen & 0x00FF);
rtppt.offset = 16; rtppt.offset = 16;
@ -100,14 +100,20 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
memcpy(rtppt.payload + 4, pucData, uiLen); memcpy(rtppt.payload + 4, pucData, uiLen);
/////////////////////////////////RTP排序逻辑/////////////////////////////////// /////////////////////////////////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; _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{ }else{
//正确序列的包 //正确序列的包
_aui64SeqOkCnt[iTrackidx]++; _aui32SeqOkCnt[iTrackidx]++;
} }
_aui16LastSeq[iTrackidx] = rtppt.sequence; _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); _amapRtpSort[iTrackidx].emplace(rtppt.sequence, pt_ptr);
GET_CONFIG_AND_REGISTER(uint32_t,clearCount,Rtp::kClearCount); GET_CONFIG_AND_REGISTER(uint32_t,clearCount,Rtp::kClearCount);
GET_CONFIG_AND_REGISTER(uint32_t,maxRtpCount,Rtp::kMaxRtpCount); 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; _abSortStarted[iTrackidx] = false;
while (_amapRtpSort[iTrackidx].size()) { while (_amapRtpSort[iTrackidx].size()) {
POP_HEAD(iTrackidx) POP_HEAD(iTrackidx)
@ -138,7 +144,7 @@ bool RtpReceiver::handleOneRtp(int iTrackidx,SdpTrack::Ptr &track, unsigned char
void RtpReceiver::clear() { void RtpReceiver::clear() {
CLEAR_ARR(_aui16LastSeq) CLEAR_ARR(_aui16LastSeq)
CLEAR_ARR(_aui32SsrcErrorCnt) CLEAR_ARR(_aui32SsrcErrorCnt)
CLEAR_ARR(_aui64SeqOkCnt) CLEAR_ARR(_aui32SeqOkCnt)
CLEAR_ARR(_abSortStarted) CLEAR_ARR(_abSortStarted)
_amapRtpSort[0].clear(); _amapRtpSort[0].clear();

View File

@ -68,9 +68,9 @@ private:
uint32_t _aui32SsrcErrorCnt[2] = { 0, 0 }; uint32_t _aui32SsrcErrorCnt[2] = { 0, 0 };
/* RTP包排序所用参数 */ /* RTP包排序所用参数 */
uint16_t _aui16LastSeq[2] = { 0 , 0 }; uint16_t _aui16LastSeq[2] = { 0 , 0 };
uint64_t _aui64SeqOkCnt[2] = { 0 , 0}; uint32_t _aui32SeqOkCnt[2] = { 0 , 0};
bool _abSortStarted[2] = { 0 , 0}; bool _abSortStarted[2] = { 0 , 0};
map<uint32_t , RtpPacket::Ptr> _amapRtpSort[2]; map<uint16_t , RtpPacket::Ptr> _amapRtpSort[2];
RtspMediaSource::PoolType _pktPool; RtspMediaSource::PoolType _pktPool;
}; };