From e322db0a044fec82c66cc4e0b0daaa5e3b75b079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E8=A1=B2=E4=B8=8D=E5=87=BA=E5=AE=B6?= Date: Thu, 5 Sep 2024 15:29:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9seq=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E5=99=A8=E9=87=8D=E7=BD=AE=E4=B8=8D=E8=A7=84=E8=8C=83=E7=9A=84?= =?UTF-8?q?rtp=E6=B5=81=20(#3860)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rtp seq在重置回退时,之前的逻辑会一直丢数据,修改后将兼容这种不规范的rtp流。 --- src/Rtsp/RtpReceiver.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Rtsp/RtpReceiver.h b/src/Rtsp/RtpReceiver.h index c2049855..933a14c0 100644 --- a/src/Rtsp/RtpReceiver.h +++ b/src/Rtsp/RtpReceiver.h @@ -68,7 +68,15 @@ public: } if (seq < next_seq && !mayLooped(next_seq, seq)) { - // 无回环风险, 过滤seq回退包 + // 无回环风险, 缓存seq回退包 + _pkt_drop_cache_map.emplace(seq, std::move(packet)); + if (_pkt_drop_cache_map.size() > _max_distance || _ticker.elapsedTime() > _max_buffer_ms) { + // seq回退包太多,可能源端重置seq计数器,这部分数据需要输出 + forceFlush(next_seq); + // 旧的seq计数器的数据清空后把新seq计数器的数据赋值给排序列队 + _pkt_sort_cache_map = std::move(_pkt_drop_cache_map); + popIterator(_pkt_sort_cache_map.begin()); + } return; } _pkt_sort_cache_map.emplace(seq, std::move(packet)); @@ -107,12 +115,13 @@ private: } bool needForceFlush(SEQ seq) { - return !_pkt_sort_cache_map.empty() && (_pkt_sort_cache_map.size() > _max_buffer_size || - distance(seq) > _max_distance || _ticker.elapsedTime() > _max_buffer_ms); + return _pkt_sort_cache_map.size() > _max_buffer_size || distance(seq) > _max_distance || _ticker.elapsedTime() > _max_buffer_ms; } - //外部调用代码确保_pkt_sort_cache_map不为空 void forceFlush(SEQ next_seq) { + if (_pkt_sort_cache_map.empty()) { + return; + } // 寻找距离比next_seq大的最近的seq auto it = _pkt_sort_cache_map.lower_bound(next_seq); if (it == _pkt_sort_cache_map.end()) { @@ -154,6 +163,9 @@ private: } break; } + if (!_pkt_drop_cache_map.empty()) { + _pkt_drop_cache_map.clear(); + } } iterator popIterator(iterator it) { @@ -190,6 +202,8 @@ private: SEQ _last_seq_out = 0; // pkt排序缓存,根据seq排序 std::map _pkt_sort_cache_map; + // 预丢弃包列表 + std::map _pkt_drop_cache_map; // 回调 std::function _cb; };