From ec01f94b173a50a1f8ae1a07c76fd9d7179ffa36 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 3 Feb 2021 19:08:33 +0800 Subject: [PATCH] RTC: Fix NACK remove loop bug --- trunk/src/app/srs_app_rtc_queue.cpp | 28 ++++++++++++++++++++++++---- trunk/src/app/srs_app_rtc_queue.hpp | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/trunk/src/app/srs_app_rtc_queue.cpp b/trunk/src/app/srs_app_rtc_queue.cpp index efa3a6b75..1e9998964 100644 --- a/trunk/src/app/srs_app_rtc_queue.cpp +++ b/trunk/src/app/srs_app_rtc_queue.cpp @@ -146,10 +146,7 @@ SrsRtpPacket2* SrsRtpRingBuffer::at(uint16_t seq) { void SrsRtpRingBuffer::notify_nack_list_full() { - while(begin <= end) { - remove(begin); - ++begin; - } + clear_all_histroy(); begin = end = 0; initialized_ = false; @@ -161,6 +158,29 @@ void SrsRtpRingBuffer::notify_drop_seq(uint16_t seq) advance_to(seq+1); } +void SrsRtpRingBuffer::clear_histroy(uint16_t seq) +{ + // TODO FIXME Did not consider loopback + for (uint16_t i = 0; i < capacity_; i++) { + SrsRtpPacket2* p = queue_[i]; + if (p && p->header.get_sequence() < seq) { + srs_freep(p); + queue_[i] = NULL; + } + } +} + +void SrsRtpRingBuffer::clear_all_histroy() +{ + for (uint16_t i = 0; i < capacity_; i++) { + SrsRtpPacket2* p = queue_[i]; + if (p) { + srs_freep(p); + queue_[i] = NULL; + } + } +} + SrsNackOption::SrsNackOption() { max_count = 15; diff --git a/trunk/src/app/srs_app_rtc_queue.hpp b/trunk/src/app/srs_app_rtc_queue.hpp index 630f4c654..b1d2b2cac 100644 --- a/trunk/src/app/srs_app_rtc_queue.hpp +++ b/trunk/src/app/srs_app_rtc_queue.hpp @@ -87,6 +87,9 @@ public: // TODO: FIXME: Refine it? void notify_nack_list_full(); void notify_drop_seq(uint16_t seq); +public: + void clear_histroy(uint16_t seq); + void clear_all_histroy(); }; struct SrsNackOption