Commit 9fc534d8 by xiongziliang

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

parent dee4f031
Subproject commit c713905a73ba1a86e9978a43e29a3e3d5e6bf77e
Subproject commit 942e9bb1eb38285c78fcfef9d7468f249b4d36e4
......@@ -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();
......
......@@ -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<uint32_t , RtpPacket::Ptr> _amapRtpSort[2];
map<uint16_t , RtpPacket::Ptr> _amapRtpSort[2];
RtspMediaSource::PoolType _pktPool;
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论