From cfbefa0b9e9469fd8586882ec9f8c2c09c5cc61b Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Mon, 29 Jun 2026 11:05:33 +0800 Subject: [PATCH] based on sequence number to indicates IsKeyFrame. --- pkg/sfu/buffer/buffer_base.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/sfu/buffer/buffer_base.go b/pkg/sfu/buffer/buffer_base.go index b0baa6fc1..8855dab4a 100644 --- a/pkg/sfu/buffer/buffer_base.go +++ b/pkg/sfu/buffer/buffer_base.go @@ -790,8 +790,8 @@ func (b *BufferBase) GetPacketsAfter(afterESN uint64) ([]*ExtPacket, bool) { // reconstructPacketsLocked builds self-contained ExtPackets for the sequence-number range // [fromSN, headESN] from the retransmit bucket. Lost packets are skipped. ExtTimestamp is // reconstructed relative to the marked key frame (a video frame cache group spans well under one 32-bit timestamp wrap) -// and IsKeyFrame flags packets at the key-frame timestamp. The dependency descriptor is not -// reconstructed. Caller holds the lock. +// and IsKeyFrame flags only the packet that starts the key frame (the marked sequence number). The +// dependency descriptor is not reconstructed. Caller holds the lock. func (b *BufferBase) reconstructPacketsLocked(fromSN, headESN uint64) []*ExtPacket { keyFrameRTPTS := uint32(b.videoFrameCacheKeyFrameETS) var pkts []*ExtPacket @@ -816,8 +816,10 @@ func (b *BufferBase) reconstructPacketsLocked(fromSN, headESN uint64) []*ExtPack ExtSequenceNumber: sn, ExtTimestamp: extTS, Packet: p, - IsKeyFrame: extTS == b.videoFrameCacheKeyFrameETS, - RawPacket: raw, + // match the normal flow: only the packet that starts the key frame carries IsKeyFrame, + // not every packet sharing the key frame's timestamp + IsKeyFrame: sn == b.videoFrameCacheKeyFrameESN, + RawPacket: raw, }) } return pkts