Limit buffer queue before Bind. (#3634)

* Limit buffer queue before Bind.

* more generic
This commit is contained in:
Raja Subramanian
2025-05-01 13:49:06 +05:30
committed by GitHub
parent 9f5bc9b9b5
commit 086704128c
+8 -1
View File
@@ -393,10 +393,17 @@ func (b *Buffer) Write(pkt []byte) (n int, err error) {
if !b.bound {
packet := make([]byte, len(pkt))
copy(packet, pkt)
b.pPackets = append(b.pPackets, pendingPacket{
startIdx := 0
overflow := len(b.pPackets) - max(b.maxVideoPkts, b.maxAudioPkts)
if overflow > 0 {
startIdx = overflow
}
b.pPackets = append(b.pPackets[startIdx:], pendingPacket{
packet: packet,
arrivalTime: now,
})
b.readCond.Broadcast()
b.Unlock()
return