@@ -81,13 +81,13 @@ bool AdaptiveJitterBuffer::processFrame(uint16_t seq, const uint8_t* data, uint3
8181 // create frame and add to ready list
8282 BufferedFrame* frame = new BufferedFrame (seq, data, length);
8383 readyFrames.push_back (frame);
84-
84+
8585 // advance expected sequence
8686 m_nextExpectedSeq = (m_nextExpectedSeq + 1 ) & 0xFFFF ;
87-
87+
8888 // flush any subsequent sequential frames from buffer
8989 flushSequentialFrames (readyFrames);
90-
90+
9191 return true ;
9292 }
9393
@@ -97,10 +97,17 @@ bool AdaptiveJitterBuffer::processFrame(uint16_t seq, const uint8_t* data, uint3
9797 if (diff < 0 ) {
9898 // check if it's severely out of order (> 1000 packets behind)
9999 if (diff < -1000 ) {
100- // ;ikely a sequence wraparound with new stream - reset
100+ // likely a sequence wraparound with new stream - reset
101101 m_nextExpectedSeq = seq;
102+
103+ // cleanup any buffered frames, delete and clear list
104+ for (auto & pair : m_buffer) {
105+ if (pair.second != nullptr ) {
106+ delete pair.second ;
107+ }
108+ }
102109 m_buffer.clear ();
103-
110+
104111 BufferedFrame* frame = new BufferedFrame (seq, data, length);
105112 readyFrames.push_back (frame);
106113 m_nextExpectedSeq = (m_nextExpectedSeq + 1 ) & 0xFFFF ;
@@ -157,7 +164,7 @@ void AdaptiveJitterBuffer::checkTimeouts(std::vector<BufferedFrame*>& timedOutFr
157164 BufferedFrame* frame = pair.second ;
158165 if (frame != nullptr ) {
159166 uint64_t age = currentTime - frame->timestamp ;
160-
167+
161168 if (age >= m_maxWaitTime) {
162169 toRemove.push_back (pair.first );
163170 }
@@ -177,7 +184,7 @@ void AdaptiveJitterBuffer::checkTimeouts(std::vector<BufferedFrame*>& timedOutFr
177184 timedOutFrames.push_back (it->second );
178185 m_buffer.erase (it);
179186 m_timedOutFrames++;
180-
187+
181188 // update next expected sequence to skip the gap
182189 int32_t diff = seqDiff (seq, m_nextExpectedSeq);
183190 if (diff >= 0 ) {
0 commit comments