diff --git a/daemon/codec.c b/daemon/codec.c index 68fd50e71..cfa1431fa 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -2422,7 +2422,10 @@ static int __handler_func_sequencer(struct media_packet *mp, struct transcode_pa } ssrc_in->packets_lost = seq->lost_count; - atomic_set_na(&ssrc_in->stats->ext_seq, seq->ext_seq); + // stats->ext_seq is the SRTP receive index (packet_index() in rtp.c and the + // kernel module) and is already updated for every received packet. The + // sequencer's position is an emission position that can legitimately move + // backwards, so it must not be written into the receive index. ilogs(transcoding, LOG_DEBUG, "Processing RTP packet: seq %u, TS %lu", packet->p.seq, packet->ts); diff --git a/lib/codeclib.c b/lib/codeclib.c index 8353b8535..231b2382b 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -590,7 +590,9 @@ out:; ps->a_nxt = -1u; unsigned int ext_seq = ps->roc << 16 | packet->seq; - while (ext_seq < ps->ext_seq) { + // a lower seq is a rollover only if it is far behind (forward wrap-around), + // not when a late or replayed packet is emitted + while (ext_seq < ps->ext_seq && ps->ext_seq - ext_seq >= 0x8000) { ps->roc++; ext_seq += 0x10000; }